创建版本
This commit is contained in:
@@ -0,0 +1,565 @@
|
||||
function getPanelHeight(v) {
|
||||
var list = $('.list-jqgrid').position();
|
||||
var position = list.top + v +'px';
|
||||
return 'calc(100vh - ' + position + ')';
|
||||
}
|
||||
|
||||
(function (window, $) {
|
||||
|
||||
const localeText = {
|
||||
page: "页",
|
||||
more: "更多",
|
||||
to: "到",
|
||||
of: "至",
|
||||
next: "下一页",
|
||||
last: "上一页",
|
||||
first: "首页",
|
||||
previous: "上一页",
|
||||
loadingOoo: "加载中...",
|
||||
selectAll: "查询全部",
|
||||
searchOoo: "查询...",
|
||||
blanks: "空白",
|
||||
filterOoo: "过滤...",
|
||||
applyFilter: "daApplyFilter...",
|
||||
equals: "相等",
|
||||
notEqual: "不相等",
|
||||
lessThan: "小于",
|
||||
greaterThan: "大于",
|
||||
lessThanOrEqual: "小于等于",
|
||||
greaterThanOrEqual: "大于等于",
|
||||
inRange: "范围",
|
||||
contains: "包含",
|
||||
notContains: "不包含",
|
||||
startsWith: "开始于",
|
||||
endsWith: "结束于",
|
||||
group: "组",
|
||||
columns: "列",
|
||||
filters: "筛选",
|
||||
rowGroupColumns: "laPivot Cols",
|
||||
rowGroupColumnsEmptyMessage: "la drag cols to group",
|
||||
valueColumns: "laValue Cols",
|
||||
pivotMode: "laPivot-Mode",
|
||||
groups: "laGroups",
|
||||
values: "值",
|
||||
pivots: "laPivots",
|
||||
valueColumnsEmptyMessage: "la drag cols to aggregate",
|
||||
pivotColumnsEmptyMessage: "la drag here to pivot",
|
||||
toolPanelButton: "la tool panel",
|
||||
noRowsToShow: "数据为空",
|
||||
pinColumn: "laPin Column",
|
||||
//valueAggregation: "laValue Agg",
|
||||
//autosizeThiscolumn: "laAutosize Diz",
|
||||
//autosizeAllColumns: "laAutsoie em All",
|
||||
groupBy: "排序",
|
||||
ungroupBy: "不排序",
|
||||
resetColumns: "重置列",
|
||||
expandAll: "展开全部",
|
||||
collapseAll: "关闭",
|
||||
toolPanel: "工具面板",
|
||||
export: "导出",
|
||||
csvExport: "导出为CSV格式文件",
|
||||
excelExport: "导出到Excel",
|
||||
//pinLeft: "laPin <<",
|
||||
//pinRight: "laPin >>",
|
||||
//noPin: "laDontPin <>",
|
||||
sum: "总数",
|
||||
min: "最小值",
|
||||
max: "最大值",
|
||||
none: "无",
|
||||
count: "总",
|
||||
average: "平均值",
|
||||
copy: "复制",
|
||||
copyWithHeaders: "携带表头复制",
|
||||
ctrlC: "ctrl + C",
|
||||
paste: "粘贴",
|
||||
ctrlV: "ctrl + V"
|
||||
};
|
||||
|
||||
function OptionCellRenderer() {}
|
||||
OptionCellRenderer.prototype.init = function (params) {
|
||||
if (params.node.rowPinned) {
|
||||
return;
|
||||
}
|
||||
this.eGui = document.createElement('div');
|
||||
this.eGui.className = 'options';
|
||||
this.eGui.innerHTML = '<a data-toggle="event" data-action="option" data-type="add" data-index="'+ params.rowIndex +'" data-id="'+ params.data.id +'" class="fa fa-plus" title="新增行"></a> <a data-toggle="event" data-action="option" data-type="delete" data-id="'+ params.data.id +'" data-index="'+ params.rowIndex +'" class="fa fa-times" title="删除行"></a></div>';
|
||||
};
|
||||
OptionCellRenderer.prototype.getGui = function () {
|
||||
return this.eGui;
|
||||
};
|
||||
|
||||
function HtmlCellRenderer() {}
|
||||
HtmlCellRenderer.prototype.init = function (params) {
|
||||
this.eGui = document.createElement('span');
|
||||
this.eGui.innerHTML = (params.value || '');
|
||||
};
|
||||
HtmlCellRenderer.prototype.getGui = function () {
|
||||
return this.eGui;
|
||||
};
|
||||
|
||||
function ActionCellRenderer() {}
|
||||
ActionCellRenderer.prototype.init = function (params) {
|
||||
var gridOptions = params.api.gridCore.gridOptions;
|
||||
if (params.node.rowPinned) {
|
||||
return;
|
||||
}
|
||||
if (params.data == undefined) {
|
||||
return;
|
||||
}
|
||||
var data = params.data;
|
||||
|
||||
var links = '';
|
||||
if (data.master_id > 0) {
|
||||
params.colDef.options.forEach(function (action) {
|
||||
if (action.display) {
|
||||
var html = '<a data-toggle="event" class="option" data-action="' + action.action + '" data-master_name="' + data.name + '" data-master_id="' + data.master_id + '" href="javascript:;">' + action.name + '</a>';
|
||||
links += gridOptions.actionCellBeforeRender(html, action, data) || '';
|
||||
}
|
||||
});
|
||||
}
|
||||
this.eGui = document.createElement('span');
|
||||
this.eGui.innerHTML = links;
|
||||
};
|
||||
ActionCellRenderer.prototype.getGui = function () {
|
||||
return this.eGui;
|
||||
};
|
||||
|
||||
function SelectCellEditor() {}
|
||||
SelectCellEditor.prototype.init = function(params) {
|
||||
this.grid = params;
|
||||
this.selectedKey = null;
|
||||
this.items = params.colDef.cellEditorParams.values;
|
||||
this.eInput = document.createElement('input');
|
||||
this.eInput.value = params.value || '';
|
||||
this.eInput.className = 'ag-cell-edit-input form-control';
|
||||
};
|
||||
SelectCellEditor.prototype.getGui = function(params) {
|
||||
return this.eInput;
|
||||
};
|
||||
|
||||
SelectCellEditor.prototype.afterGuiAttached = function() {
|
||||
var me = this;
|
||||
var grid = me.grid;
|
||||
var oValue = me.eInput.value;
|
||||
// 初始化编辑器
|
||||
$(me.eInput).agDropdownCellEditor({
|
||||
grid: me,
|
||||
arrow: 'fa-caret-down',
|
||||
data: {
|
||||
items: me.items,
|
||||
selected: grid.data[grid.select_key],
|
||||
},
|
||||
select: function(item) {
|
||||
if (item) {
|
||||
grid.data[grid.select_key] = item.id;
|
||||
me.eInput.value = item.name;
|
||||
me.selectedKey = item.id;
|
||||
} else {
|
||||
me.eInput.value = oValue;
|
||||
}
|
||||
grid.stopEditing();
|
||||
}
|
||||
});
|
||||
me.eInput.focus();
|
||||
me.eInput.select();
|
||||
};
|
||||
SelectCellEditor.prototype.getValue = function() {
|
||||
return this.eInput.value;
|
||||
};
|
||||
SelectCellEditor.prototype.destroy = function() {
|
||||
$('body').find('.combo-select').remove();
|
||||
};
|
||||
|
||||
function CheckboxCellRenderer() {}
|
||||
CheckboxCellRenderer.prototype.init = function (params) {
|
||||
var value = params.value;
|
||||
var values = params.colDef.cellEditorParams.values;
|
||||
this.eGui = document.createElement('div');
|
||||
this.eGui.innerHTML = values[value] || values[0];
|
||||
};
|
||||
CheckboxCellRenderer.prototype.getGui = function () {
|
||||
return this.eGui;
|
||||
};
|
||||
function CheckboxCellEditor() {}
|
||||
CheckboxCellEditor.prototype.init = function(params) {
|
||||
var value = params.value;
|
||||
this.eInput = document.createElement('input');
|
||||
this.eInput.type = 'checkbox';
|
||||
this.eInput.checked = value;
|
||||
this.eInput.value = value;
|
||||
};
|
||||
CheckboxCellEditor.prototype.getGui = function(params) {
|
||||
return this.eInput;
|
||||
};
|
||||
|
||||
CheckboxCellEditor.prototype.afterGuiAttached = function() {
|
||||
var me = this;
|
||||
me.eInput.focus();
|
||||
me.eInput.select();
|
||||
};
|
||||
CheckboxCellEditor.prototype.getValue = function() {
|
||||
return this.eInput.checked ? 1 : 0;
|
||||
};
|
||||
CheckboxCellEditor.prototype.destroy = function() {
|
||||
};
|
||||
|
||||
function DialogCellEditor() {}
|
||||
DialogCellEditor.prototype.init = function(params) {
|
||||
this.params = params;
|
||||
this.eInput = document.createElement('div');
|
||||
this.eInput.tabIndex = '-1';
|
||||
var key = params.colDef.field + '_' + params.data.id;
|
||||
var query = params.query;
|
||||
query.multi = 1;
|
||||
query.is_grid = 1;
|
||||
query.url = params.url;
|
||||
query.grid_id = params.data.id;
|
||||
query.title = params.title;
|
||||
var url = '';
|
||||
$.each(query, function(k, v) {
|
||||
url += ' data-' + k + '="' + v + '"';
|
||||
});
|
||||
this.query = query;
|
||||
this.eInput.innerHTML = '<input class="ag-cell-edit-input" value="' + (params.value || '') + '" id="' + key + '"><a class="combo-arrow" data-toggle="dialog-view" '+ url +'><i class="fa fa-search"></i></a>';
|
||||
this.eInput.className = 'ag-input-wrapper ag-input-dialog-wrapper';
|
||||
};
|
||||
DialogCellEditor.prototype.getGui = function(params) {
|
||||
return this.eInput;
|
||||
};
|
||||
|
||||
DialogCellEditor.prototype.afterGuiAttached = function() {
|
||||
var me = this;
|
||||
$(me.eInput).find('input').gdooSuggest({item:me.params.data, query:me.query})
|
||||
.on('onSelect', function(e, item) {
|
||||
me.params.data[me.query.name] = item[me.query.name];
|
||||
me.eInput.querySelector('input').value = item[me.query.name];
|
||||
});
|
||||
me.eInput.querySelector('input').select();
|
||||
};
|
||||
DialogCellEditor.prototype.getValue = function() {
|
||||
return this.params.data[this.params.query.name];
|
||||
};
|
||||
DialogCellEditor.prototype.destroy = function() {
|
||||
var me = this;
|
||||
$(me.eInput).find('input').off();
|
||||
};
|
||||
|
||||
DialogCellEditor.prototype.isPopup = function () {
|
||||
return false;
|
||||
};
|
||||
|
||||
function DateCellEditor() {}
|
||||
DateCellEditor.prototype.init = function(params) {
|
||||
this.params = params.colDef.cellEditorParams;
|
||||
this.eInput = document.createElement('div');
|
||||
this.eInput.innerHTML = '<input type="text" class="ag-cell-edit-input" data-toggle="date" value="' + (params.value || '') + '">';
|
||||
this.eInput.className = 'ag-input-wrapper ag-input-date-wrapper';
|
||||
};
|
||||
DateCellEditor.prototype.getGui = function(params) {
|
||||
return this.eInput;
|
||||
};
|
||||
DateCellEditor.prototype.afterGuiAttached = function() {
|
||||
this.eInput.querySelector('input').click();
|
||||
};
|
||||
DateCellEditor.prototype.getValue = function() {
|
||||
return this.eInput.querySelector('input').value;
|
||||
};
|
||||
DateCellEditor.prototype.destroy = function() {
|
||||
};
|
||||
|
||||
function agGridOptions() {
|
||||
|
||||
// 定义ag-grid默认参数
|
||||
var gridOptions = {
|
||||
defaultColDef: {
|
||||
minWidth: 100,
|
||||
enableRowGroup: true,
|
||||
enablePivot: true,
|
||||
enableValue: true,
|
||||
sortable: true,
|
||||
resizable: true,
|
||||
filter: true,
|
||||
comparator: function(a, b) {
|
||||
if (this.cellRenderer == 'htmlCellRenderer') {
|
||||
a = delHtmlTag(a);
|
||||
b = delHtmlTag(b);
|
||||
return a.localeCompare(b);
|
||||
}
|
||||
return typeof a === 'string' ? a.localeCompare(b) : (a > b ? 1 : (a < b ? -1 : 0));
|
||||
}
|
||||
},
|
||||
pinnedBottomRowData: [],
|
||||
rowDragManaged: true,
|
||||
suppressRowClickSelection: true,
|
||||
rowMultiSelectWithClick: false,
|
||||
rowSelection: 'multiple',
|
||||
localeText: localeText,
|
||||
suppressAnimationFrame: true,
|
||||
// suppressAutoSize: true,
|
||||
suppressContextMenu: true,
|
||||
// 关闭参数检查
|
||||
suppressPropertyNamesCheck: true,
|
||||
// pagination: true,
|
||||
// rowModelType: 'infinite',
|
||||
// paginationPageSize: 25,
|
||||
// cacheBlockSize: 25,
|
||||
// suppressPaginationPanel: true,
|
||||
suppressCellSelection: true,
|
||||
enableCellTextSelection: true,
|
||||
// 自定义后端数据地址
|
||||
remoteDataUrl: '',
|
||||
remoteParams: {},
|
||||
dialogList: {},
|
||||
editableList: {},
|
||||
autoColumnsToFit: true,
|
||||
lastEditCell: {},
|
||||
selectedRows: [],
|
||||
pager: false,
|
||||
pagerDom: null,
|
||||
pagePer: 50,
|
||||
// 格式化数字时候默认值是否强行为空
|
||||
numberEmptyDefaultValue: false,
|
||||
pageList: [50, 100, 500, 1000, 2000, 5000, 10000, 20000, 50000],
|
||||
|
||||
onCellEditingStarted(params) {
|
||||
this.lastEditCell = params;
|
||||
},
|
||||
remoteSuccessed() {},
|
||||
onGridSizeChanged(params) {
|
||||
},
|
||||
onGridReady(params) {
|
||||
},
|
||||
onFirstDataRendered(params) {
|
||||
var me = this;
|
||||
var api = me.api;
|
||||
if (me.autoColumnsToFit) {
|
||||
api.sizeColumnsToFit();
|
||||
}
|
||||
|
||||
if (typeof me.onCustomFirstDataRendered == "function") {
|
||||
me.onCustomFirstDataRendered.call(me, params);
|
||||
}
|
||||
|
||||
// 计算合计行
|
||||
me.generatePinnedBottomData();
|
||||
},
|
||||
onCellValueChanged(params) {
|
||||
this.generatePinnedBottomData();
|
||||
},
|
||||
getRowStyle(params) {
|
||||
},
|
||||
onRowClicked(params) {
|
||||
var selected = params.node.isSelected();
|
||||
if (selected === false) {
|
||||
params.node.setSelected(true, true);
|
||||
}
|
||||
},
|
||||
getSelectedRows() {
|
||||
return this.selectedRows;
|
||||
},
|
||||
onRowSelected(params) {
|
||||
var me = this;
|
||||
var node = params.node;
|
||||
if (node.selected) {
|
||||
me.selectedRows.push(node.data);
|
||||
} else {
|
||||
for (let i = 0; i < me.selectedRows.length; i++) {
|
||||
var select = me.selectedRows[i];
|
||||
if (node.data.id == select.id) {
|
||||
me.selectedRows.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeof me.onCustomRowSelected == "function") {
|
||||
me.onCustomRowSelected.call(me, params);
|
||||
}
|
||||
},
|
||||
onRowDoubleClicked(params) {
|
||||
console.log('onRowDoubleClicked');
|
||||
},
|
||||
/*
|
||||
getRowNodeId_bak(data) {
|
||||
if (data.id) {
|
||||
return data.id;
|
||||
}
|
||||
},
|
||||
*/
|
||||
columnTypes: {
|
||||
number: {
|
||||
cellClass: 'ag-cell-number',
|
||||
valueFormatter: function (params) {
|
||||
var me = this;
|
||||
if (params.node.rowPinned) {
|
||||
if(params.colDef.calcFooter) {
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
var options = params.colDef.numberOptions || {};
|
||||
var places = options.places == undefined ? 2 : options.places;
|
||||
var separator = options.separator == undefined ? '.' : options.separator;
|
||||
var thousands = options.thousands == undefined ? ',' : options.thousands;
|
||||
var defaultValue = options.default == undefined ? 0 : options.default;
|
||||
var value = parseFloat(params.value);
|
||||
|
||||
if (isNaN(value) || value == 0) {
|
||||
return gridOptions.numberEmptyDefaultValue == false ? defaultValue : '';
|
||||
}
|
||||
value = number_format(value, places, separator, thousands);
|
||||
return value;
|
||||
},
|
||||
valueParser: function (params) {
|
||||
var value = parseFloat(params.newValue);
|
||||
if (isNaN(value)) {
|
||||
return 0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
},
|
||||
sn: {
|
||||
cellClass: 'ag-cell-sn',
|
||||
valueFormatter: function (params) {
|
||||
if (params.node.rowPinned) {
|
||||
return '';
|
||||
}
|
||||
return parseInt(params.node.childIndex) + 1
|
||||
},
|
||||
valueParser: function (params) {
|
||||
return parseFloat(params.newValue);
|
||||
}
|
||||
},
|
||||
datetime: {
|
||||
cellClass: 'ag-cell-datetime',
|
||||
valueFormatter: function (params) {
|
||||
if (params.node.rowPinned) {
|
||||
return '';
|
||||
}
|
||||
return format_datetime(params.value);
|
||||
},
|
||||
valueParser: function (params) {
|
||||
return parseFloat(params.newValue);
|
||||
}
|
||||
},
|
||||
date: {
|
||||
cellClass: 'ag-cell-date',
|
||||
valueFormatter: function (params) {
|
||||
if (params.node.rowPinned) {
|
||||
return '';
|
||||
}
|
||||
return format_date(params.value);
|
||||
},
|
||||
valueParser: function (params) {
|
||||
return parseFloat(params.newValue);
|
||||
}
|
||||
}
|
||||
},
|
||||
components: {
|
||||
'optionCellRenderer': OptionCellRenderer,
|
||||
'actionCellRenderer': ActionCellRenderer,
|
||||
'htmlCellRenderer': HtmlCellRenderer,
|
||||
'selectCellEditor': SelectCellEditor,
|
||||
'dialogCellEditor': DialogCellEditor,
|
||||
'dateCellEditor': DateCellEditor,
|
||||
'checkboxCellEditor': CheckboxCellEditor,
|
||||
'checkboxCellRenderer': CheckboxCellRenderer,
|
||||
},
|
||||
overlayLoadingTemplate: '<span class="ag-overlay-loading-center">数据加载中...</span>',
|
||||
overlayNoRowsTemplate: '<div style="padding-top:20px;"><img alt="暂无数据" src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjQiIGhlaWdodD0iNDEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgPGcgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMCAxKSIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIj4KICAgIDxlbGxpcHNlIGZpbGw9IiNGNUY1RjUiIGN4PSIzMiIgY3k9IjMzIiByeD0iMzIiIHJ5PSI3Ii8+CiAgICA8ZyBmaWxsLXJ1bGU9Im5vbnplcm8iIHN0cm9rZT0iI0Q5RDlEOSI+CiAgICAgIDxwYXRoIGQ9Ik01NSAxMi43Nkw0NC44NTQgMS4yNThDNDQuMzY3LjQ3NCA0My42NTYgMCA0Mi45MDcgMEgyMS4wOTNjLS43NDkgMC0xLjQ2LjQ3NC0xLjk0NyAxLjI1N0w5IDEyLjc2MVYyMmg0NnYtOS4yNHoiLz4KICAgICAgPHBhdGggZD0iTTQxLjYxMyAxNS45MzFjMC0xLjYwNS45OTQtMi45MyAyLjIyNy0yLjkzMUg1NXYxOC4xMzdDNTUgMzMuMjYgNTMuNjggMzUgNTIuMDUgMzVoLTQwLjFDMTAuMzIgMzUgOSAzMy4yNTkgOSAzMS4xMzdWMTNoMTEuMTZjMS4yMzMgMCAyLjIyNyAxLjMyMyAyLjIyNyAyLjkyOHYuMDIyYzAgMS42MDUgMS4wMDUgMi45MDEgMi4yMzcgMi45MDFoMTQuNzUyYzEuMjMyIDAgMi4yMzctMS4zMDggMi4yMzctMi45MTN2LS4wMDd6IiBmaWxsPSIjRkFGQUZBIi8+CiAgICA8L2c+CiAgPC9nPgo8L3N2Zz4K"><div style="padding-top:5px;color:#999;">暂无数据</div></div>',
|
||||
};
|
||||
|
||||
gridOptions.generatePinnedBottomData = function() {
|
||||
var me = this;
|
||||
var result = {};
|
||||
var renderer = false;
|
||||
var columns = gridOptions.columnApi.getAllGridColumns();
|
||||
columns.forEach(function (item) {
|
||||
if (item.colDef.calcFooter) {
|
||||
renderer = true;
|
||||
result[item.colId] = me.calculatePinnedBottomData(item);
|
||||
}
|
||||
});
|
||||
if (renderer) {
|
||||
me.api.setPinnedBottomRowData([result]);
|
||||
}
|
||||
}
|
||||
gridOptions.calculatePinnedBottomData = function(item) {
|
||||
var value = 0;
|
||||
gridOptions.api.forEachNode(function (row) {
|
||||
value += toNumber(row.data[item.colId]);
|
||||
});
|
||||
return value == 0 ? '' : value;
|
||||
}
|
||||
|
||||
// 格式化行按钮
|
||||
gridOptions.actionCellBeforeRender = function(html, action, data) {
|
||||
return html;
|
||||
}
|
||||
|
||||
gridOptions.remoteData = function (params, success) {
|
||||
var me = this;
|
||||
let remoteParams = gridOptions.remoteParams;
|
||||
for (let key in params) {
|
||||
remoteParams[key] = params[key];
|
||||
}
|
||||
gridOptions.api.showLoadingOverlay();
|
||||
$.post(gridOptions.remoteDataUrl, remoteParams, function (res) {
|
||||
|
||||
if (res.per_page) {
|
||||
if (me.pagerDom === null) {
|
||||
var div = me.api.gridCore.eGridDiv;
|
||||
var pageId = div.id + '-pager';
|
||||
$(div).after('<div id="' + pageId + '" class="ag-pager"></div>');
|
||||
me.pagerDom = $('#' + pageId).Paging({
|
||||
pagesize: res.per_page,
|
||||
count: res.total,
|
||||
current: res.current_page,
|
||||
pageSizeList: [50, 100, 500, 1000, 2000, 5000, 10000, 20000, 50000],
|
||||
callback: function(page, size, count) {
|
||||
me.remoteData2({page: page, limit: size});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
me.pagerDom[0].render({
|
||||
pagesize: res.per_page,
|
||||
count: res.total,
|
||||
current: res.current_page
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
gridOptions.api.hideOverlay();
|
||||
gridOptions.api.setRowData(res.data);
|
||||
gridOptions.generatePinnedBottomData();
|
||||
|
||||
if (typeof success === 'function') {
|
||||
success(res);
|
||||
}
|
||||
gridOptions.remoteSuccessed.call(gridOptions, res.data);
|
||||
|
||||
}, 'json');
|
||||
}
|
||||
|
||||
gridOptions.remoteData2 = function (params, success) {
|
||||
var me = this;
|
||||
let remoteParams = gridOptions.remoteParams;
|
||||
for (let key in params) {
|
||||
remoteParams[key] = params[key];
|
||||
}
|
||||
gridOptions.api.showLoadingOverlay();
|
||||
$.post(gridOptions.remoteDataUrl, remoteParams, function (res) {
|
||||
|
||||
gridOptions.api.hideOverlay();
|
||||
gridOptions.api.setRowData(res.data);
|
||||
gridOptions.generatePinnedBottomData();
|
||||
if (typeof success === 'function') {
|
||||
success(res);
|
||||
}
|
||||
gridOptions.remoteSuccessed.call(gridOptions, res.data);
|
||||
|
||||
}, 'json');
|
||||
}
|
||||
|
||||
return gridOptions;
|
||||
}
|
||||
window.agGridOptions = agGridOptions;
|
||||
})(window, jQuery);
|
||||
@@ -0,0 +1,454 @@
|
||||
(function ($, undefined) {
|
||||
|
||||
var pluginName = 'agDropdownCellEditor',
|
||||
dataKey = 'ag.dropdown.celleditor';
|
||||
|
||||
var defaults = {
|
||||
maxHeight: 200
|
||||
};
|
||||
|
||||
// Utility functions
|
||||
var keys = {
|
||||
ESC: 27,
|
||||
TAB: 9,
|
||||
RETURN: 13,
|
||||
LEFT: 37,
|
||||
UP: 38,
|
||||
RIGHT: 39,
|
||||
DOWN: 40,
|
||||
ENTER: 13,
|
||||
SHIFT: 16
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param {[Node]} element [Select element]
|
||||
* @param {[Object]} options [Option object]
|
||||
*/
|
||||
var Plugin = function (input, options) {
|
||||
this.grid = options.grid;
|
||||
this.config = options.config;
|
||||
this.items = options.data.items;
|
||||
this.selected = options.data.selected;
|
||||
this.hook = options.hook;
|
||||
|
||||
this.arrow = options.arrow || 'icon-search';
|
||||
|
||||
this.name = options.name;
|
||||
|
||||
this.onSelect = options.select || function() {};
|
||||
|
||||
this.$input = $(input);
|
||||
|
||||
// Settings
|
||||
this.settings = $.extend({}, defaults, options);
|
||||
|
||||
// Initialize
|
||||
this.init();
|
||||
|
||||
$.fn[pluginName].instances.push(this);
|
||||
|
||||
};
|
||||
|
||||
$.extend(Plugin.prototype, {
|
||||
init: function () {
|
||||
// Construct the comboselect
|
||||
this._construct();
|
||||
|
||||
// Add event bindings
|
||||
this._events();
|
||||
},
|
||||
_construct: function () {
|
||||
|
||||
var me = this;
|
||||
|
||||
// Wrap the Select
|
||||
this.$container = $('<div class="combo-select combo-open combo-'+ me.name +'" />');
|
||||
|
||||
// Append dropdown arrow
|
||||
this.$arrow = $('<div class="combo-arrow"><i class="fa '+ this.arrow + '"></i></div>');
|
||||
|
||||
// Append dropdown
|
||||
this.$dropdown = $('<ul class="combo-dropdown" />').appendTo(this.$container);
|
||||
|
||||
// Create dropdown options
|
||||
this._build();
|
||||
|
||||
this.$input.after(this.$arrow);
|
||||
|
||||
$('body').append(this.$container);
|
||||
|
||||
var height = this.$input.outerHeight();
|
||||
var width = this.$input.outerWidth();
|
||||
var offset = this.$input.offset();
|
||||
this.$container.css({width: width + 2, left: offset.left - 1, top: offset.top + height + 1});
|
||||
},
|
||||
_build: function () {
|
||||
|
||||
var me = this;
|
||||
|
||||
var o = '', k = 0;
|
||||
|
||||
o += '<li class="option-item-empty">无匹配选项</li>';
|
||||
|
||||
$.each(this.items, function (i, e) {
|
||||
|
||||
if (e == 'optgroup') {
|
||||
return o += '<li class="option-group">' + this.label + '</li>';
|
||||
}
|
||||
o += '<li class="' + (this.disabled ? 'option-disabled' : "option-item") + ' ' + (this.id == me.selected ? 'option-selected' : '') + '" data-index="' + (k) + '" data-value="' + this.id + '">' + (this.name) + '<i>' + this.code + '</i></li>';
|
||||
k++;
|
||||
})
|
||||
|
||||
this.$dropdown.html(o)
|
||||
// Items
|
||||
this.$items = this.$dropdown.children();
|
||||
},
|
||||
|
||||
_events: function () {
|
||||
var me = this;
|
||||
|
||||
this.$arrow.off();
|
||||
this.$container.off();
|
||||
this.$input.off();
|
||||
|
||||
// Dropdown Arrow: click
|
||||
this.$arrow.on('click.arrow', $.proxy(this._toggle, this));
|
||||
|
||||
// Dropdown: close
|
||||
this.$container.on('dropdown:close', $.proxy(this._close, this));
|
||||
|
||||
// Dropdown: open
|
||||
this.$container.on('dropdown:open', $.proxy(this._open, this));
|
||||
|
||||
// Dropdown: update
|
||||
this.$container.on('dropdown:update', $.proxy(this._update, this));
|
||||
|
||||
// Input: keydown
|
||||
this.$input.on('keydown', $.proxy(this._keydown, this));
|
||||
|
||||
// Input: keyup
|
||||
this.$input.on('keyup', $.proxy(this._keyup, this));
|
||||
|
||||
// Dropdown item: click
|
||||
this.$container.on('click.item', '.option-item', $.proxy(this._select, this));
|
||||
},
|
||||
_keydown: function (event) {
|
||||
|
||||
switch (event.which) {
|
||||
case keys.ESC:
|
||||
this.$container.trigger('dropdown:close');
|
||||
break;
|
||||
|
||||
case keys.UP:
|
||||
this._move('up', event);
|
||||
event.stopPropagation();
|
||||
break;
|
||||
|
||||
case keys.DOWN:
|
||||
this._move('down', event);
|
||||
event.stopPropagation();
|
||||
break;
|
||||
|
||||
case keys.TAB:
|
||||
this._enter(event);
|
||||
break;
|
||||
|
||||
case keys.RIGHT:
|
||||
//this._autofill(event);
|
||||
break;
|
||||
|
||||
case keys.ENTER:
|
||||
this._enter(event);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
_keyup: function (event) {
|
||||
|
||||
switch (event.which) {
|
||||
|
||||
case keys.ESC:
|
||||
case keys.ENTER:
|
||||
case keys.UP:
|
||||
case keys.DOWN:
|
||||
case keys.LEFT:
|
||||
case keys.RIGHT:
|
||||
case keys.TAB:
|
||||
case keys.SHIFT:
|
||||
break;
|
||||
|
||||
default:
|
||||
this._filter(event.target.value);
|
||||
break;
|
||||
}
|
||||
},
|
||||
_enter: function (event) {
|
||||
var item = this._getHovered();
|
||||
this._select(item);
|
||||
},
|
||||
_move: function (dir, event) {
|
||||
var items = this._getVisible(),
|
||||
current = this._getHovered(),
|
||||
index = current.prevAll('.option-item').filter(':visible').length,
|
||||
total = items.length;
|
||||
|
||||
switch (dir) {
|
||||
case 'up':
|
||||
index--;
|
||||
(index < 0) && (index = (total - 1));
|
||||
break;
|
||||
|
||||
case 'down':
|
||||
index++;
|
||||
(index >= total) && (index = 0);
|
||||
break;
|
||||
}
|
||||
|
||||
items.removeClass('option-hover')
|
||||
.eq(index)
|
||||
.addClass('option-hover');
|
||||
|
||||
if (!this.opened) this.$container.trigger('dropdown:open');
|
||||
|
||||
this._fixScroll();
|
||||
},
|
||||
|
||||
_select: function (event) {
|
||||
|
||||
var item = event.currentTarget ? $(event.currentTarget) : $(event);
|
||||
|
||||
//if (!item.length) return;
|
||||
|
||||
var index = item.data('index');
|
||||
this._selectByIndex(index);
|
||||
this.$container.trigger('dropdown:close');
|
||||
},
|
||||
|
||||
/**
|
||||
* Set selected index and trigger change
|
||||
* @type {[type]}
|
||||
*/
|
||||
_selectByIndex: function (index) {
|
||||
|
||||
if (typeof index == 'undefined') {
|
||||
// 为空设置不选中
|
||||
index = -1;
|
||||
}
|
||||
|
||||
this._getAll()
|
||||
.removeClass('option-selected')
|
||||
.filter(function() {
|
||||
return $(this).data('index') == index
|
||||
}).addClass('option-selected')
|
||||
|
||||
this._change();
|
||||
},
|
||||
|
||||
_autofill: function () {
|
||||
var item = this._getHovered();
|
||||
if (item.length) {
|
||||
var index = item.data('index');
|
||||
this._selectByIndex(index);
|
||||
}
|
||||
},
|
||||
_filter: function (search) {
|
||||
|
||||
var self = this,
|
||||
items = this._getAll(),
|
||||
needle = $.trim(search).toLowerCase(),
|
||||
reEscape = new RegExp('(\\' + ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\'].join('|\\') + ')', 'g'),
|
||||
pattern = '(' + search.replace(reEscape, '\\$1') + ')';
|
||||
|
||||
// Unwrap all markers
|
||||
$('.combo-marker', items).contents().unwrap();
|
||||
// Search
|
||||
if (needle) {
|
||||
// Hide Disabled and optgroups
|
||||
this.$items.filter('.option-group, .option-disabled').hide();
|
||||
items
|
||||
.hide()
|
||||
.filter(function () {
|
||||
|
||||
var $this = $(this),
|
||||
text = $.trim($this.text()).toLowerCase();
|
||||
|
||||
// Found
|
||||
if (text.toString().indexOf(needle) != -1) {
|
||||
|
||||
// Wrap the selection
|
||||
$this
|
||||
.html(function (index, oldhtml) {
|
||||
return oldhtml.replace(new RegExp(pattern, 'gi'), '<span class="combo-marker">$1</span>');
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
})
|
||||
.show();
|
||||
} else {
|
||||
items.show();
|
||||
}
|
||||
|
||||
// Open the dropdown
|
||||
this.$container.trigger('dropdown:open');
|
||||
|
||||
// 搜索结果为不存在时候显示
|
||||
if(this._getVisible().length == 0) {
|
||||
this.$items.filter('.option-item-empty').show();
|
||||
} else {
|
||||
this.$items.filter('.option-item-empty').hide();
|
||||
}
|
||||
},
|
||||
|
||||
_highlight: function() {
|
||||
/*
|
||||
1. Check if there is a selected item
|
||||
2. Add hover class to it
|
||||
3. If not add hover class to first item
|
||||
*/
|
||||
var visible = this._getVisible().removeClass('option-hover'),
|
||||
$selected = visible.filter('.option-selected');
|
||||
|
||||
if ($selected.length) {
|
||||
$selected.addClass('option-hover');
|
||||
} else {
|
||||
visible.removeClass('option-hover')
|
||||
.first()
|
||||
.addClass('option-hover');
|
||||
}
|
||||
},
|
||||
|
||||
_updateInput: function() {
|
||||
var item = this._getAll().filter('.option-selected');
|
||||
var index = item.data('index');
|
||||
|
||||
this.onSelect.call(this, this.items[index]);
|
||||
/*
|
||||
if (index) {
|
||||
this.onSelect.call(this, this.items[index]);
|
||||
} else {
|
||||
this.onSelect.call(this, this.items[index]);
|
||||
}*/
|
||||
},
|
||||
_focus: function (event) {
|
||||
// Toggle focus class
|
||||
this.$container.toggleClass('combo-focus', !this.opened);
|
||||
// Open combo
|
||||
if (!this.opened) this.$container.trigger('dropdown:open');
|
||||
},
|
||||
_change: function () {
|
||||
this._updateInput();
|
||||
},
|
||||
_getAll: function () {
|
||||
return this.$items.filter('.option-item');
|
||||
},
|
||||
_getVisible: function () {
|
||||
return this.$items.filter('.option-item').filter(':visible')
|
||||
},
|
||||
_getHovered: function () {
|
||||
return this._getVisible().filter('.option-hover');
|
||||
},
|
||||
_open: function () {
|
||||
var self = this
|
||||
this.$container.addClass('combo-open');
|
||||
this.$arrow.addClass('combo-arrow-open');
|
||||
this.opened = true;
|
||||
|
||||
// Highligh the items
|
||||
this._highlight();
|
||||
|
||||
// Fix scroll
|
||||
this._fixScroll();
|
||||
|
||||
// Close all others
|
||||
$.each($.fn[pluginName].instances, function(i, plugin) {
|
||||
if (plugin != self && plugin.opened) plugin.$container.trigger('dropdown:close');
|
||||
})
|
||||
},
|
||||
|
||||
_toggle: function(e) {
|
||||
this.opened ? this._close.call(this) : this._open.call(this);
|
||||
this.$input.focus();
|
||||
e.stopPropagation();
|
||||
},
|
||||
_close: function() {
|
||||
this.$container.removeClass('combo-open combo-focus');
|
||||
this.$arrow.removeClass('combo-arrow-open');
|
||||
this.$container.trigger('dropdown:closed');
|
||||
this.opened = false;
|
||||
// Show all items
|
||||
this.$items.filter('.option-item').show();
|
||||
},
|
||||
_fixScroll: function() {
|
||||
|
||||
// If dropdown is hidden
|
||||
if (this.$dropdown.is(':hidden')) return;
|
||||
|
||||
// Else
|
||||
var item = this._getHovered();
|
||||
|
||||
if (!item.length) return;
|
||||
|
||||
// Scroll
|
||||
var offsetTop,
|
||||
upperBound,
|
||||
lowerBound,
|
||||
heightDelta = item.outerHeight();
|
||||
|
||||
offsetTop = item[0].offsetTop;
|
||||
upperBound = this.$dropdown.scrollTop();
|
||||
lowerBound = upperBound + this.settings.maxHeight - heightDelta;
|
||||
|
||||
if (offsetTop < upperBound) {
|
||||
this.$dropdown.scrollTop(offsetTop);
|
||||
} else if (offsetTop > lowerBound) {
|
||||
this.$dropdown.scrollTop(offsetTop - this.settings.maxHeight + heightDelta);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*/
|
||||
_update: function() {
|
||||
this.$dropdown.empty();
|
||||
this._build();
|
||||
},
|
||||
|
||||
/**
|
||||
* 销毁
|
||||
*/
|
||||
dispose: function() {
|
||||
// 删除dom
|
||||
this.$arrow.remove();
|
||||
this.$input.remove();
|
||||
this.$dropdown.remove();
|
||||
}
|
||||
});
|
||||
|
||||
$.fn[pluginName] = function(options, args) {
|
||||
|
||||
this.each(function() {
|
||||
|
||||
var $e = $(this),
|
||||
instance = $e.data('plugin_' + dataKey);
|
||||
|
||||
if (typeof options === 'string') {
|
||||
if (instance && typeof instance[options] === 'function') {
|
||||
instance[options](args);
|
||||
}
|
||||
} else {
|
||||
if (instance && instance.dispose) {
|
||||
instance.dispose();
|
||||
}
|
||||
$.data(this, "plugin_" + dataKey, new Plugin(this, options));
|
||||
}
|
||||
});
|
||||
return this;
|
||||
};
|
||||
$.fn[pluginName].instances = [];
|
||||
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,451 @@
|
||||
;(function($) {
|
||||
|
||||
var inputLock; // 用于中文输入法输入时锁定搜索
|
||||
var grid = null;
|
||||
|
||||
/**
|
||||
* 设置或获取输入框的 alt 值
|
||||
*/
|
||||
function setOrGetAlt($input, val) {
|
||||
return val !== undefined ? $input.attr('alt', val) : $input.attr('alt');
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字段名是否在 options.effectiveFields 配置项中
|
||||
* @param {String} field 要判断的字段名
|
||||
* @param {Object} options
|
||||
* @return {Boolean} effectiveFields 为空时始终返回 true
|
||||
*/
|
||||
function inEffectiveFields(field, options) {
|
||||
var effectiveFields = options.effectiveFields;
|
||||
|
||||
return !(field === '__index' || effectiveFields.length && !~$.inArray(field, effectiveFields));
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字段名是否在 options.searchFields 搜索字段配置中
|
||||
*/
|
||||
function inSearchFields(field, options) {
|
||||
return ~$.inArray(field, options.searchFields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示下拉列表
|
||||
*/
|
||||
function showDropMenu($input, options) {
|
||||
var $dropdownMenu = $('#gdoo-gird-suggest');
|
||||
if (!$dropdownMenu.is(':visible')) {
|
||||
$dropdownMenu.show();
|
||||
$input.trigger('onShowDropdown', [options ? options.data : []]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏下拉列表
|
||||
*/
|
||||
function hideDropMenu($input, options) {
|
||||
var $dropdownMenu = $('#gdoo-gird-suggest');
|
||||
if ($dropdownMenu.is(':visible')) {
|
||||
$dropdownMenu.hide();
|
||||
$input.trigger('onHideDropdown', [options ? options.data : []]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下拉列表刷新
|
||||
* 作为 fnGetData 的 callback 函数调用
|
||||
*/
|
||||
function refreshDropMenu($input, data, options) {
|
||||
showDropMenu($input, options);
|
||||
grid.remoteParams.q = $input.val();
|
||||
// 读取数据
|
||||
grid.remoteData();
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下拉列表刷新
|
||||
* 作为 fnGetData 的 callback 函数调用
|
||||
*/
|
||||
function refreshDropMenu2($input, options) {
|
||||
|
||||
var params = options.query;
|
||||
params.suggest = true;
|
||||
|
||||
var $dropdownMenu = $('#gdoo-gird-suggest');
|
||||
$dropdownMenu.html('<div style="height:180px;overflow:auto;width:auto;"><div id="suggest-'+ params.id +'" class="ag-theme-balham" style="width:100%;height:180px;border-left:1px solid #BDC3C7;border-right:1px solid #BDC3C7;"></div></div>');
|
||||
|
||||
var option = gdoo.formKey(params);
|
||||
var event = gdoo.event.get(option.key);
|
||||
event.trigger('query', params);
|
||||
event.trigger('open', params);
|
||||
|
||||
var sid = params.prefix == 1 ? 'sid' : 'id';
|
||||
var gridDiv = document.querySelector("#suggest-" + params.id);
|
||||
grid = new agGridOptions();
|
||||
var multiple = params.multi == 0 ? false : true;
|
||||
grid.remoteDataUrl = app.url(params.url);
|
||||
grid.remoteParams = params;
|
||||
grid.rowSelection = multiple ? 'multiple' : 'single';
|
||||
|
||||
grid.suppressRowClickSelection = true;
|
||||
grid.columnDefs = [
|
||||
//{suppressMenu: true, cellClass:'text-center', checkboxSelection: true, headerCheckboxSelection: multiple, suppressSizeToFit: true, sortable: false, width: 40},
|
||||
//{suppressMenu: true, cellClass:'text-center', sortable: false, suppressSizeToFit: true, cellRenderer: 'htmlCellRenderer', field: 'images', headerName: '图片', width: 40},
|
||||
{suppressMenu: true, cellClass:'text-center', sortable: true, field: 'code', headerName: '存货编码', width: 100},
|
||||
{suppressMenu: true, cellClass:'text-left', sortable: true, field: 'name', headerName: '产品名称', minWidth: 140},
|
||||
{suppressMenu: true, cellClass:'text-center', sortable: true, field: 'spec', headerName: '规格型号', width: 100},
|
||||
{suppressMenu: true, cellClass:'text-center', sortable: true, field: 'barcode', headerName: '产品条码', width: 120},
|
||||
{suppressMenu: true, cellClass:'text-center', sortable: true, field: 'unit_id_name', headerName: '计量单位', width: 80},
|
||||
{suppressMenu: true, cellClass:'text-right', field: 'price', headerName: '价格', width: 80}
|
||||
];
|
||||
|
||||
grid.onRowClicked = function (row) {
|
||||
var ret = grid.writeSelected(row.data);
|
||||
if (ret) {
|
||||
hideDropMenu($input, options);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 写入选中
|
||||
*/
|
||||
grid.writeSelected = function(selectedRow) {
|
||||
var ret = true;
|
||||
var list = gdoo.forms[params.form_id];
|
||||
var links = list.links[params.id];
|
||||
var item = options.item;
|
||||
// 如果传入的行id为0
|
||||
if (query.grid_id == 0) {
|
||||
query.grid_id = list.lastEditCell.data.id;
|
||||
}
|
||||
for (key in links) {
|
||||
item[key] = selectedRow[links[key]];
|
||||
}
|
||||
|
||||
if (event.exist('onSelect')) {
|
||||
ret = event.trigger('onSelect', item, selectedRow);
|
||||
}
|
||||
|
||||
list.lastEditCell.data = item;
|
||||
list.api.memoryStore.update(item);
|
||||
$input.trigger('onSelect', [item]);
|
||||
list.generatePinnedBottomData();
|
||||
return ret;
|
||||
}
|
||||
|
||||
new agGrid.Grid(gridDiv, grid);
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测 keyword 与 value 是否存在互相包含
|
||||
* @param {String} keyword 用户输入的关键字
|
||||
* @param {String} key 匹配字段的 key
|
||||
* @param {String} value key 字段对应的值
|
||||
* @param {Object} options
|
||||
* @return {Boolean} 包含/不包含
|
||||
*/
|
||||
function isInWord(keyword, key, value, options) {
|
||||
value = $.trim(value);
|
||||
|
||||
if (options.ignorecase) {
|
||||
keyword = keyword.toLocaleLowerCase();
|
||||
value = value.toLocaleLowerCase();
|
||||
}
|
||||
|
||||
return value &&
|
||||
(inEffectiveFields(key, options) || inSearchFields(key, options)) && // 必须在有效的搜索字段中
|
||||
(
|
||||
~value.indexOf(keyword) || // 匹配值包含关键字
|
||||
options.twoWayMatch && ~keyword.indexOf(value) // 关键字包含匹配值
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 ajax 或 json 参数获取数据
|
||||
*/
|
||||
function getData(keyword, $input, callback, options) {
|
||||
var data, validData, filterData = [], i, key, len;
|
||||
|
||||
keyword = keyword || '';
|
||||
|
||||
// 给了url参数,则从服务器 ajax 请求
|
||||
if (options.url) {
|
||||
callback($input, options.data, options);
|
||||
} else {
|
||||
data = options.data;
|
||||
validData = data;
|
||||
// 本地的 data 数据,则在本地过滤
|
||||
if (validData) {
|
||||
if (keyword) {
|
||||
// 输入不为空时则进行匹配
|
||||
len = data.length;
|
||||
for (i = 0; i < len; i++) {
|
||||
for (key in data[i]) {
|
||||
if (data[i][key] && isInWord(keyword, key, data[i][key] + '', options)) {
|
||||
filterData.push(data[i]);
|
||||
filterData[filterData.length - 1].__index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
filterData = data;
|
||||
}
|
||||
}
|
||||
callback($input, filterData, options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得 clearable 清除按钮
|
||||
*/
|
||||
function getIClear($input, options) {
|
||||
var $iClear = $input.prev('i.clearable');
|
||||
|
||||
// 是否可清除已输入的内容(添加清除按钮)
|
||||
if (options.clearable && !$iClear.length) {
|
||||
$iClear = $('<i class="clearable glyphicon glyphicon-remove"></i>')
|
||||
.prependTo($input.parent());
|
||||
}
|
||||
|
||||
return $iClear.css({
|
||||
position: 'absolute',
|
||||
top: 12,
|
||||
// right: options.showBtn ? Math.max($input.next('.input-group-btn').width(), 33) + 2 : 12,
|
||||
zIndex: 4,
|
||||
cursor: 'pointer',
|
||||
fontSize: 12
|
||||
}).hide();
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认的配置选项
|
||||
* @type {Object}
|
||||
*/
|
||||
var defaultOptions = {
|
||||
query: {},
|
||||
item: {},
|
||||
data: [],
|
||||
allowNoKeyword: true,
|
||||
ignorecase: false,
|
||||
searchFields: [],
|
||||
twoWayMatch: true,
|
||||
delay: 300,
|
||||
showBtn: true,
|
||||
clearable: false,
|
||||
/* key */
|
||||
keyLeft: 37,
|
||||
keyUp: 38,
|
||||
keyRight: 39,
|
||||
keyDown: 40,
|
||||
keyEnter: 13,
|
||||
fnGetData: getData
|
||||
};
|
||||
|
||||
var methods = {
|
||||
init: function(options) {
|
||||
// 参数设置
|
||||
var self = this;
|
||||
options = options || {};
|
||||
|
||||
options = $.extend(true, {}, defaultOptions, options);
|
||||
|
||||
return self.each(function() {
|
||||
var $input = $(this),
|
||||
$parent = $input.parent(),
|
||||
$iClear = getIClear($input, options),
|
||||
isMouseenterMenu,
|
||||
keyupTimer; // keyup 与 input 事件延时定时器
|
||||
|
||||
var $dropdownMenu = $('#gdoo-gird-suggest');
|
||||
if ($dropdownMenu.length === 0) {
|
||||
$dropdownMenu = $('<div class="gdoo-gird-suggest" id="gdoo-gird-suggest" style="position:absolute;display:none;box-shadow:0 2px 5px 0 rgb(0 0 0 / 26%);"></div>');
|
||||
$('body').append($dropdownMenu);
|
||||
}
|
||||
refreshDropMenu2($input, options);
|
||||
|
||||
/*
|
||||
var offset = $input.offset();
|
||||
var height = $input.outerHeight();
|
||||
$dropdownMenu.css({left: offset.left - 1, top: offset.top + height - 1});
|
||||
*/
|
||||
|
||||
$input.off();
|
||||
|
||||
// 是否显示 button 按钮
|
||||
if (!options.showBtn) {
|
||||
$input.css('borderRadius', 4);
|
||||
$parent.css('width', '100%').find('.btn:eq(0)').hide();
|
||||
}
|
||||
|
||||
// 移除 disabled 类,并禁用自动完成
|
||||
$input.removeClass('disabled').prop('disabled', false).attr('autocomplete', 'off');
|
||||
|
||||
// 开始事件处理
|
||||
$input.on('keydown', function(event) {
|
||||
// 当提示层显示时才对键盘事件处理
|
||||
if (!$dropdownMenu.is(':visible')) {
|
||||
return;
|
||||
}
|
||||
if (event.keyCode === options.keyEnter) {
|
||||
hideDropMenu($input, options);
|
||||
}
|
||||
|
||||
}).on('compositionstart', function(event) {
|
||||
// 中文输入开始,锁定
|
||||
inputLock = true;
|
||||
}).on('compositionend', function(event) {
|
||||
// 中文输入结束,解除锁定
|
||||
inputLock = false;
|
||||
}).on('keyup input paste', function(event) {
|
||||
var word;
|
||||
|
||||
// 如果弹起的键是回车、向上或向下方向键则返回
|
||||
if (~$.inArray(event.keyCode, [options.keyDown, options.keyUp, options.keyEnter])) {
|
||||
$input.val($input.val()); // 让鼠标输入跳到最后
|
||||
return;
|
||||
}
|
||||
|
||||
clearTimeout(keyupTimer);
|
||||
keyupTimer = setTimeout(function() {
|
||||
// 锁定状态,返回
|
||||
if (inputLock) {
|
||||
return;
|
||||
}
|
||||
|
||||
word = $input.val();
|
||||
|
||||
// 若输入框值没有改变则返回
|
||||
if ($.trim(word) && word === setOrGetAlt($input)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 是否允许空数据查询
|
||||
if (!word.length && !options.allowNoKeyword) {
|
||||
return;
|
||||
}
|
||||
|
||||
options.fnGetData($.trim(word), $input, refreshDropMenu, options);
|
||||
}, options.delay || 300);
|
||||
|
||||
}).on('blur', function() {
|
||||
// 不是进入下拉列表状态,则隐藏列表
|
||||
if (!isMouseenterMenu) {
|
||||
hideDropMenu($input, options);
|
||||
}
|
||||
}).on('focus', function() {
|
||||
|
||||
$dropdownMenu.off();
|
||||
|
||||
var w = $(window).width();
|
||||
var h = $(window).height();
|
||||
|
||||
var width = $input.outerWidth();
|
||||
var height = $input.outerHeight();
|
||||
var offset = $input.offset();
|
||||
|
||||
var dw = $dropdownMenu.outerWidth();
|
||||
var dh = $dropdownMenu.outerHeight();
|
||||
|
||||
var css = {top: offset.top + height};
|
||||
// 判断是否小于768
|
||||
if (w < 768) {
|
||||
css.minWidth = 360;
|
||||
css.left = 14;
|
||||
css.right = 14;
|
||||
} else {
|
||||
css.left = offset.left - 1;
|
||||
// 右边超出
|
||||
if (w < offset.left + dw + 10) {
|
||||
css.left = offset.left - dw + width + 1;
|
||||
}
|
||||
// 下边超出
|
||||
if (h < offset.top + dh + 10) {
|
||||
css.top = offset.top - dh;
|
||||
}
|
||||
}
|
||||
$dropdownMenu.css(css);
|
||||
|
||||
// 列表中滑动时,输入框失去焦点
|
||||
$dropdownMenu.on('mouseenter', function() {
|
||||
isMouseenterMenu = 1;
|
||||
$input.blur();
|
||||
}).on('mouseleave', function() {
|
||||
isMouseenterMenu = 0;
|
||||
$input.focus();
|
||||
}).on('click', function() {
|
||||
// 阻止冒泡
|
||||
return false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// 存在清空按钮
|
||||
if ($iClear.length) {
|
||||
$iClear.click(function () {
|
||||
});
|
||||
|
||||
$parent.mouseenter(function() {
|
||||
if (!$input.prop('disabled')) {
|
||||
$iClear.css('right', options.showBtn ? Math.max($input.next('.input-group-btn').width(), 33) + 2 : 12).show();
|
||||
}
|
||||
}).mouseleave(function() {
|
||||
$iClear.hide();
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
show: function() {
|
||||
return this.each(function() {
|
||||
$(this).click();
|
||||
});
|
||||
},
|
||||
hide: function() {
|
||||
return this.each(function() {
|
||||
hideDropMenu($(this));
|
||||
});
|
||||
},
|
||||
disable: function() {
|
||||
return this.each(function() {
|
||||
$(this).attr('disabled', true).parent().find('.btn:eq(0)').prop('disabled', true);
|
||||
});
|
||||
},
|
||||
enable: function() {
|
||||
return this.each(function() {
|
||||
$(this).attr('disabled', false).parent().find('.btn:eq(0)').prop('disabled', false);
|
||||
});
|
||||
},
|
||||
destroy: function() {
|
||||
return this.each(function() {
|
||||
$(this).off().removeData('gdooSuggest').removeAttr('style')
|
||||
.parent().find('.btn:eq(0)').off().show().attr('data-toggle', 'dropdown').prop('disabled', false) // .addClass(disabled);
|
||||
.next().css('display', '').off();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$.fn['gdooSuggest'] = function(options) {
|
||||
// 方法判断
|
||||
if (typeof options === 'string' && methods[options]) {
|
||||
var inited = true;
|
||||
this.each(function() {
|
||||
if (!$(this).data('gdooSuggest')) {
|
||||
return inited = false;
|
||||
}
|
||||
});
|
||||
// 只要有一个未初始化,则全部都不执行方法,除非是 init 或 version
|
||||
if (!inited && 'init' !== options && 'version' !== options) {
|
||||
return this;
|
||||
}
|
||||
|
||||
// 如果是方法,则参数第一个为函数名,从第二个开始为函数参数
|
||||
return methods[options].apply(this, [].slice.call(arguments, 1));
|
||||
} else {
|
||||
// 调用初始化方法
|
||||
return methods.init.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,307 @@
|
||||
var formGridList = {};
|
||||
|
||||
function gridForms(master, table, options) {
|
||||
options.master = master;
|
||||
var grid = gridForm(table, options);
|
||||
formGridList[master].push(grid);
|
||||
return grid;
|
||||
}
|
||||
|
||||
function gridForm(table, options) {
|
||||
|
||||
var defaults = {
|
||||
heightTop: 70,
|
||||
data: [],
|
||||
dataType: 'local',
|
||||
};
|
||||
options = $.extend(defaults, options);
|
||||
|
||||
var grid = new agGridOptions();
|
||||
grid.suppressLoadingOverlay = true;
|
||||
grid.suppressNoRowsOverlay = true;
|
||||
grid.rowMultiSelectWithClick = false;
|
||||
grid.singleClickEdit = true;
|
||||
grid.rowSelection = 'single';
|
||||
grid.suppressCellSelection = false;
|
||||
grid.suppressRowClickSelection = false;
|
||||
grid.columnDefs = options.columns;
|
||||
grid.links = options.links;
|
||||
|
||||
grid.tableTitle = options.title;
|
||||
grid.tableKey = options.table;
|
||||
|
||||
grid.defaultColDef.sortable = false;
|
||||
grid.defaultColDef.filter = false;
|
||||
grid.defaultColDef.suppressMenu = true;
|
||||
grid.defaultColDef.suppressNavigable = true;
|
||||
grid.isEditing = false;
|
||||
grid.isEditingDialog = false;
|
||||
|
||||
var event = gdoo.event.get('grid.' + table);
|
||||
|
||||
var editable = event.editable || {};
|
||||
grid.defaultColDef.editable = function(params) {
|
||||
if (params.node.rowPinned) {
|
||||
return false;
|
||||
}
|
||||
var col = params.colDef;
|
||||
var fun = editable[col.field];
|
||||
if (typeof fun == 'function') {
|
||||
return fun.call(grid, params);
|
||||
} else {
|
||||
if (params.colDef._editable) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
grid.getRowNodeId = function(data) {
|
||||
if (data.id) {
|
||||
return data.id;
|
||||
}
|
||||
}
|
||||
|
||||
grid.onRowClicked = function(row) {
|
||||
};
|
||||
|
||||
grid.stopEditingWhenGridLosesFocus = false;
|
||||
|
||||
grid.onRowDoubleClicked = function (row) {
|
||||
};
|
||||
|
||||
grid.onCellEditingStarted = function(params) {
|
||||
grid.lastEditCell = params;
|
||||
grid.isEditingDialog = params.colDef.cellEditor == 'dialogCellEditor';
|
||||
grid.isEditing = true;
|
||||
}
|
||||
grid.onCellEditingStopped = function() {
|
||||
grid.isEditing = false;
|
||||
if (grid.isEditingDialog) {
|
||||
$('#gdoo-gird-suggest').hide();
|
||||
}
|
||||
}
|
||||
|
||||
var autoHeight = false;
|
||||
var gridDiv = document.querySelector('#grid_' + table);
|
||||
if (gridDiv.style.height == '') {
|
||||
autoHeight = true;
|
||||
gridDiv.style.height = getTabContentHeight() + 'px';
|
||||
}
|
||||
|
||||
event.trigger('init', grid);
|
||||
|
||||
new agGrid.Grid(gridDiv, grid);
|
||||
|
||||
grid.api.dialogSelected = function(query) {
|
||||
|
||||
var dialogEvent = gdoo.event.get(query.form_id + '.' + query.id);
|
||||
var links = options.links[query.id];
|
||||
|
||||
var dialog = gdoo.dialogs[query.form_id + '_' + query.id];
|
||||
|
||||
var selectedRows = dialog.getSelectedRows();
|
||||
var store = grid.api.memoryStore;
|
||||
var rows = [];
|
||||
grid.api.forEachNode(function(rowNode, index) {
|
||||
if (rowNode.data[query.id] == undefined) {
|
||||
rows.push(rowNode.data);
|
||||
}
|
||||
});
|
||||
|
||||
// 如果传入的行id为0
|
||||
if (query.grid_id == 0) {
|
||||
query.grid_id = grid.lastEditCell.data.id;
|
||||
}
|
||||
|
||||
for (let i = 0; i < selectedRows.length; i++) {
|
||||
var row = rows[i];
|
||||
var update = true;
|
||||
if (row == undefined) {
|
||||
row = {};
|
||||
update = false;
|
||||
}
|
||||
if (selectedRows.length == 1) {
|
||||
var res = grid.api.getSelectedRows();
|
||||
if (res.length == 0) {
|
||||
row = {};
|
||||
if (query.grid_id) {
|
||||
var node = grid.api.getRowNode(query.grid_id);
|
||||
row = node.data;
|
||||
update = true;
|
||||
}
|
||||
} else {
|
||||
if (query.grid_id) {
|
||||
row = res[0];
|
||||
update = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var selectedRow = selectedRows[i];
|
||||
for (key in links) {
|
||||
row[key] = selectedRow[links[key]];
|
||||
}
|
||||
|
||||
dialogEvent.trigger('onSelect', row, selectedRow);
|
||||
|
||||
if (update) {
|
||||
store.update(row);
|
||||
} else {
|
||||
store.create(row);
|
||||
}
|
||||
|
||||
// 数据设置
|
||||
if (selectedRows.length == 1) {
|
||||
if (query.grid_id) {
|
||||
$('#' + query.name + '_' + query.grid_id).val(row[query.name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
grid.generatePinnedBottomData();
|
||||
}
|
||||
|
||||
grid.api.memoryStore = {
|
||||
lastIndex: 1,
|
||||
created: [],
|
||||
updated: [],
|
||||
deleted: [],
|
||||
create(row, index) {
|
||||
this.lastIndex++;
|
||||
row['id'] = 'draft_' + this.lastIndex;
|
||||
row = grid.calcRow(row);
|
||||
this.created.push(row);
|
||||
grid.api.updateRowData({add:[row], addIndex: index});
|
||||
|
||||
},
|
||||
update(row) {
|
||||
row = grid.calcRow(row);
|
||||
this.updated.push(row);
|
||||
grid.api.updateRowData({update:[row]});
|
||||
},
|
||||
delete(row, draft) {
|
||||
if (draft == false) {
|
||||
this.deleted.push(row);
|
||||
}
|
||||
// 删除创建里的草稿数据
|
||||
this.created = this.created.filter(function(item) {
|
||||
return (item.id == row.id) ? false : true;
|
||||
});
|
||||
|
||||
// 删除更新后的数据
|
||||
this.updated = this.updated.filter(function(item) {
|
||||
return (item.id == row.id) ? false : true;
|
||||
});
|
||||
var res = grid.api.updateRowData({remove: [row]});
|
||||
grid.generatePinnedBottomData();
|
||||
}
|
||||
};
|
||||
|
||||
grid.onFirstDataRendered = function(params) {
|
||||
var api = this.api;
|
||||
// 计算合计行
|
||||
this.generatePinnedBottomData();
|
||||
};
|
||||
|
||||
grid.calcRow = function(row, col) {
|
||||
for(var i = 0; i < options.columns.length; i++) {
|
||||
var column = options.columns[i];
|
||||
if (column.calcRow) {
|
||||
var fun = new Function('data', 'column', column.calcRow);
|
||||
var value = parseFloat(fun(row, col || {}));
|
||||
if (isNaN(value) || value === 0) {
|
||||
value = '';
|
||||
}
|
||||
row[column.field] = value;
|
||||
}
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
grid.onCellValueChanged = function(params) {
|
||||
var me = this;
|
||||
if (params.oldValue == params.newValue) {
|
||||
return;
|
||||
}
|
||||
var data = params.data;
|
||||
data = me.calcRow(data, params.column);
|
||||
me.api.updateRowData({update:[data]});
|
||||
me.generatePinnedBottomData();
|
||||
};
|
||||
|
||||
// 本地数据类型,初始化一条数据
|
||||
if (options.dataType == 'local') {
|
||||
if (options.data.length > 0) {
|
||||
if (typeof event.dataLoaded == 'function') {
|
||||
event.dataLoaded.call(grid, options.data);
|
||||
}
|
||||
grid.api.updateRowData({add:options.data});
|
||||
} else {
|
||||
grid.api.memoryStore.create({});
|
||||
}
|
||||
}
|
||||
|
||||
// 删除方法
|
||||
grid.api.deleteRow = function(data) {
|
||||
var rowNode = grid.api.getRowNode(data.id);
|
||||
var row = rowNode.data;
|
||||
// 检查删除的是否是草稿
|
||||
var id = '' + row.id;
|
||||
var draft = id.indexOf('draft_');
|
||||
if (draft === 0) {
|
||||
grid.api.memoryStore.delete(row, true);
|
||||
} else {
|
||||
grid.api.memoryStore.delete(row, false);
|
||||
}
|
||||
}
|
||||
|
||||
// 绑定自定义事件
|
||||
var $gridDiv = $(gridDiv);
|
||||
$gridDiv.off();
|
||||
|
||||
$gridDiv.on('click', '[data-toggle="event"]', function () {
|
||||
var data = $(this).data();
|
||||
if (data.action == 'option') {
|
||||
if (data.type == 'add') {
|
||||
grid.api.memoryStore.create({});
|
||||
} else {
|
||||
// 最后一行不能删除
|
||||
var count = grid.api.getDisplayedRowCount();
|
||||
if (count > 1) {
|
||||
grid.api.deleteRow(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 编辑器失去焦点关闭
|
||||
$gridDiv.on('blur', '.ag-input-wrapper', function() {
|
||||
if (grid.isEditingDialog) {
|
||||
return;
|
||||
}
|
||||
if (grid.isEditing) {
|
||||
grid.api.stopEditing();
|
||||
}
|
||||
});
|
||||
|
||||
function getTabContentHeight() {
|
||||
var list = $('#tab-content-' + options.master).position();
|
||||
var height = $(window).height() - list.top - options.heightTop;
|
||||
return height > 320 ? height : 320;
|
||||
}
|
||||
|
||||
grid.onGridReady = function (params) {
|
||||
|
||||
event.trigger('ready', grid);
|
||||
|
||||
if (autoHeight) {
|
||||
window.addEventListener('resize', function() {
|
||||
setTimeout(function() {
|
||||
gridDiv.style.height = getTabContentHeight() + 'px';
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
gdoo.forms[table] = grid;
|
||||
return grid;
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
(function($) {
|
||||
|
||||
var COUNT = 0
|
||||
|
||||
$.fn.dialog = function(options) {
|
||||
|
||||
var self = this,
|
||||
$this = $(self),
|
||||
$body = $(document.body),
|
||||
$element = $this.closest('.dialog');
|
||||
this.options = options;
|
||||
|
||||
var create = function() {
|
||||
|
||||
// fade
|
||||
var element = '<div class="dialog modal"><div class="modal-dialog"><div class="modal-content">';
|
||||
|
||||
if (options.title) {
|
||||
element += '<div class="modal-header"><button type="button" data-dismiss="dialog" class="close">×</button><h4 class="modal-title"></h4></div>';
|
||||
}
|
||||
|
||||
element += '<div class="modal-body"></div>';
|
||||
|
||||
if (options.buttons.length > 0) {
|
||||
element += '<div class="modal-footer"></div>';
|
||||
}
|
||||
|
||||
element += '</div></div></div>';
|
||||
|
||||
// 窗口创建一个以上遮罩只显示一层
|
||||
// options.backdrop = COUNT > 0 ? '' : options.backdrop;
|
||||
|
||||
$element = $(element);
|
||||
$body.append($element);
|
||||
$element.find(".modal-body").append($this);
|
||||
$element.modal({backdrop:options.backdrop});
|
||||
|
||||
//if(options.draggable === true) {
|
||||
$('.modal-dialog').draggable({
|
||||
handle: ".modal-header",
|
||||
iframeFix: true,
|
||||
});
|
||||
//}
|
||||
}
|
||||
|
||||
var createButton = function(_options) {
|
||||
|
||||
var buttons = (_options || options || {}).buttons || {},
|
||||
$btnrow = $element.find(".modal-footer");
|
||||
|
||||
// clear old buttons
|
||||
$btnrow.html('');
|
||||
|
||||
for (var button in buttons) {
|
||||
|
||||
var btn = buttons[button],
|
||||
id = '',
|
||||
text = '',
|
||||
classed = 'btn-default',
|
||||
click = '';
|
||||
|
||||
classed = btn['class'] || btn.classed || classed;
|
||||
|
||||
$button = $('<button type="button" class="btn btn-sm '+ classed +'">'+ btn.text +'</button>');
|
||||
$button.data('click', btn.click);
|
||||
|
||||
if (btn.id) {
|
||||
$button.attr("id", btn.id);
|
||||
}
|
||||
|
||||
$btnrow.append($button);
|
||||
}
|
||||
|
||||
$btnrow.on('click', function(e) {
|
||||
var click = $(e.target).data('click');
|
||||
if (typeof click === 'function') {
|
||||
click.call(self, e);
|
||||
}
|
||||
});
|
||||
$btnrow.data('buttons', buttons);
|
||||
}
|
||||
|
||||
var show = function() {
|
||||
$element.modal('show');
|
||||
var showHandler = options.onShow || function() {};
|
||||
showHandler.call(self);
|
||||
}
|
||||
|
||||
var close = function() {
|
||||
$element.modal('hide');
|
||||
}
|
||||
|
||||
var destroy = function() {
|
||||
$element.remove();
|
||||
}
|
||||
|
||||
if (options.constructor == Object) {
|
||||
|
||||
var defaults = {
|
||||
show: true,
|
||||
backdrop: true,
|
||||
destroy: false
|
||||
}
|
||||
|
||||
options = $.extend(defaults, options);
|
||||
|
||||
if ($element.size() == 0) {
|
||||
create();
|
||||
createButton();
|
||||
|
||||
$element.find('.modal-title').html(options['title']);
|
||||
|
||||
if (options['dialogClass']) {
|
||||
$element.find('.modal-dialog').addClass(options['dialogClass']);
|
||||
}
|
||||
|
||||
$element.on('click',"[data-dismiss='dialog']", function() {
|
||||
var closeHandler = options.onClose || close;
|
||||
closeHandler.call(self);
|
||||
});
|
||||
|
||||
$element.one('show.bs.modal', function() {
|
||||
COUNT++;
|
||||
})
|
||||
|
||||
$element.one('hidden.bs.modal', function() {
|
||||
|
||||
COUNT--
|
||||
|
||||
if (COUNT > 0) {
|
||||
$element.modal('checkScrollbar')
|
||||
$body.addClass('modal-open')
|
||||
$element.modal('setScrollbar')
|
||||
}
|
||||
|
||||
// 取消绑定的事件
|
||||
// $element.off('click',"[data-dismiss='dialog']");
|
||||
|
||||
// 删除 $element
|
||||
if (options.destroy == true) {
|
||||
destroy();
|
||||
}
|
||||
});
|
||||
|
||||
if (options.modalClass) {
|
||||
$element.addClass(options.modalClass);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.show) {
|
||||
show();
|
||||
}
|
||||
}
|
||||
|
||||
if (options == "destroy") {
|
||||
options.destroy = true
|
||||
close();
|
||||
}
|
||||
|
||||
if (options == "close") {
|
||||
close();
|
||||
}
|
||||
|
||||
if (options == "show") {
|
||||
show();
|
||||
}
|
||||
return self;
|
||||
}
|
||||
})(jQuery);
|
||||
|
||||
(function($) {
|
||||
|
||||
var modal = {
|
||||
ok: {text: "确定", classed: 'btn-info'},
|
||||
cancel: {text: "取消", classed: 'btn-default'}
|
||||
};
|
||||
|
||||
$.messager = {};
|
||||
$.messager.alert = function(title, message, callback) {
|
||||
|
||||
if (arguments.length < 2) {
|
||||
message = title || "";
|
||||
title = " "
|
||||
}
|
||||
|
||||
$("<div>" + message + "</div>").dialog({
|
||||
title: title,
|
||||
destroy: true,
|
||||
dialogClass:'modal-sm',
|
||||
buttons: [{
|
||||
text: modal.ok.text,
|
||||
classed: modal.ok.classed || "btn-success",
|
||||
click: function() {
|
||||
|
||||
if(typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
$(this).dialog("destroy");
|
||||
}
|
||||
}]
|
||||
});
|
||||
};
|
||||
|
||||
$.messager.confirm = function(title, message, callback) {
|
||||
$("<div>" + message + "</div>").dialog({
|
||||
title: title,
|
||||
destroy : true,
|
||||
backdrop: 'static',
|
||||
dialogClass:'modal-sm modal-confirm',
|
||||
buttons: [{
|
||||
text: modal.cancel.text,
|
||||
classed : modal.cancel.classed || "btn-danger",
|
||||
click: function() {
|
||||
$(this).dialog("destroy");
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callback(false);
|
||||
}
|
||||
}
|
||||
},{
|
||||
text: modal.ok.text,
|
||||
classed: modal.ok.classed || "btn-success",
|
||||
click: function() {
|
||||
|
||||
$(this).dialog("destroy");
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callback(true);
|
||||
}
|
||||
}
|
||||
}]
|
||||
});
|
||||
};
|
||||
})(jQuery);
|
||||
|
||||
(function($) {
|
||||
var dialogIndex = 0;
|
||||
$.dialog = function(options) {
|
||||
var oldIndex = dialogIndex;
|
||||
var defaultOptions = {
|
||||
title:'Dialog',
|
||||
modalClass:'no-padder',
|
||||
dialogClass:'modal-md',
|
||||
destroy: true,
|
||||
index: dialogIndex,
|
||||
onShow: function() {
|
||||
var me = this;
|
||||
var url = options['url'];
|
||||
if (url) {
|
||||
var url = url + (url.indexOf('?') < 0 ? '?' : '&') + 'dialog_index=' + oldIndex;
|
||||
$.get(url, function(data) {
|
||||
me.html(data);
|
||||
});
|
||||
}
|
||||
if (options['html']) {
|
||||
this.html(options['html']);
|
||||
}
|
||||
},
|
||||
buttons:[{
|
||||
text: "取消",
|
||||
click: function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
},{
|
||||
text: "确定",
|
||||
'class': "btn-primary",
|
||||
click: function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}]
|
||||
};
|
||||
options = $.extend(defaultOptions, options);
|
||||
var id = 'gdoo-dialog-' + dialogIndex;
|
||||
var $target = $('#' + id);
|
||||
if ($target.length == 0) {
|
||||
$target = $('<div/>', {id: id});
|
||||
dialogIndex++;
|
||||
}
|
||||
$target.dialog(options);
|
||||
return oldIndex;
|
||||
}
|
||||
|
||||
})(jQuery);
|
||||
|
||||
(function($) {
|
||||
|
||||
$.toastr = function(type, title, content) {
|
||||
toastr.options = {
|
||||
"closeButton": true,
|
||||
"debug": false,
|
||||
"progressBar": false,
|
||||
"positionClass": "toast-top-right",
|
||||
//"positionClass": "toast-top-center",
|
||||
"onclick": null,
|
||||
"showDuration": "300",
|
||||
"hideDuration": "1000",
|
||||
"timeOut": "5000",
|
||||
"extendedTimeOut": "1000",
|
||||
"showEasing": "swing",
|
||||
"hideEasing": "linear",
|
||||
"showMethod": "fadeIn",
|
||||
"hideMethod": "fadeOut"
|
||||
}
|
||||
toastr[type](title, content)
|
||||
}
|
||||
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,223 @@
|
||||
(function($) {
|
||||
|
||||
'use strict';
|
||||
|
||||
var grid = null;
|
||||
|
||||
/**
|
||||
* 默认的配置选项
|
||||
* @type {Object}
|
||||
*/
|
||||
var defaultOptions = {
|
||||
query: {},
|
||||
item: {},
|
||||
data: [],
|
||||
delay: 300,
|
||||
showBtn: true,
|
||||
clearable: false,
|
||||
keyLeft: 37,
|
||||
keyUp: 38,
|
||||
keyRight: 39,
|
||||
keyDown: 40,
|
||||
keyEnter: 13
|
||||
};
|
||||
|
||||
/**
|
||||
* 显示下拉列表
|
||||
*/
|
||||
function showSuggest($input, options) {
|
||||
var $dropdownMenu = $('#gdoo-suggest');
|
||||
if (!$dropdownMenu.is(':visible')) {
|
||||
$dropdownMenu.show();
|
||||
$input.trigger('onShowSuggest', [options ? options.data : []]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏下拉列表
|
||||
*/
|
||||
function hideSuggest($input, options) {
|
||||
var $dropdownMenu = $('#gdoo-suggest');
|
||||
if ($dropdownMenu.is(':visible')) {
|
||||
$dropdownMenu.hide();
|
||||
$input.trigger('onHideSuggest', [options ? options.data : []]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新数据
|
||||
* ajax请求携带q参数
|
||||
*/
|
||||
function refreshData($input, options, params) {
|
||||
showSuggest($input, options);
|
||||
|
||||
var event = gdoo.event.get(params.form_id + '.' + params.id);
|
||||
event.trigger('open', params);
|
||||
event.trigger('query', params);
|
||||
|
||||
params.suggest = true;
|
||||
params.q = $input.val();
|
||||
|
||||
grid.rowSelection = params.multi == 1 ? 'multiple' : 'single';
|
||||
grid.remoteDataUrl = app.url(params.url);
|
||||
grid.remoteParams = params;
|
||||
|
||||
// 读取数据
|
||||
grid.remoteData();
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建 Suggest的agGrid
|
||||
* 作为 fnGetData 的 callback 函数调用
|
||||
*/
|
||||
function buildSuggest($input, options, params) {
|
||||
|
||||
var $dropdownMenu = $('#gdoo-suggest');
|
||||
$dropdownMenu.html('<div style="height:180px;overflow:auto;width:auto;"><div id="suggest-aggrid" class="ag-theme-balham" style="width:100%;height:180px;border-left:1px solid #BDC3C7;border-right:1px solid #BDC3C7;"></div></div>');
|
||||
|
||||
var gridDiv = document.querySelector("#suggest-aggrid");
|
||||
grid = new agGridOptions();
|
||||
|
||||
grid.suppressRowClickSelection = true;
|
||||
grid.columnDefs = [
|
||||
//{suppressMenu: true, cellClass:'text-center', checkboxSelection: true, headerCheckboxSelection: multiple, suppressSizeToFit: true, sortable: false, width: 40},
|
||||
//{suppressMenu: true, cellClass:'text-center', sortable: false, suppressSizeToFit: true, cellRenderer: 'htmlCellRenderer', field: 'images', headerName: '图片', width: 40},
|
||||
{suppressMenu: true, cellClass:'text-center', sortable: true, field: 'code', headerName: '存货编码', width: 100},
|
||||
{suppressMenu: true, cellClass:'text-left', sortable: true, field: 'name', headerName: '产品名称', minWidth: 140},
|
||||
{suppressMenu: true, cellClass:'text-center', sortable: true, field: 'spec', headerName: '规格型号', width: 100},
|
||||
{suppressMenu: true, cellClass:'text-center', sortable: true, field: 'barcode', headerName: '产品条码', width: 120},
|
||||
{suppressMenu: true, cellClass:'text-center', sortable: true, field: 'unit_id_name', headerName: '计量单位', width: 80},
|
||||
{suppressMenu: true, cellClass:'text-right', field: 'price', headerName: '价格', width: 80}
|
||||
];
|
||||
|
||||
grid.onRowClicked = function (row) {
|
||||
var ret = grid.writeSelected([row.data]);
|
||||
if (ret) {
|
||||
hideSuggest($input, options);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 写入选中
|
||||
*/
|
||||
grid.writeSelected = function(rows) {
|
||||
var params = grid.remoteParams;
|
||||
var sid = params.prefix == 1 ? 'sid' : 'id';
|
||||
var id = [];
|
||||
var text = [];
|
||||
$.each(rows, function(index, row) {
|
||||
id.push(row[sid]);
|
||||
text.push(row.name);
|
||||
});
|
||||
|
||||
var input_id = params.form_id + '_' + params.id;
|
||||
$('#'+input_id).val(id.join(','));
|
||||
$('#'+input_id+'_text').val(text.join(','));
|
||||
|
||||
var event = gdoo.event.get(params.form_id + '.' + params.id);
|
||||
if (event.exist('onSelect')) {
|
||||
return event.trigger('onSelect', grid.rowSelection == 'multiple' ? rows : rows[0]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
new agGrid.Grid(gridDiv, grid);
|
||||
return $input;
|
||||
}
|
||||
|
||||
$.fn.gdooDialogInput = function(options) {
|
||||
var self = this;
|
||||
options = options || {};
|
||||
options = $.extend(true, {}, defaultOptions, options);
|
||||
|
||||
$('body').append('<div class="gdoo-gird-suggest" id="gdoo-suggest" style="position:absolute;display:none;box-shadow:0 2px 5px 0 rgb(0 0 0 / 26%);"></div>');
|
||||
|
||||
return self.each(function() {
|
||||
var $input = $(this);
|
||||
var params = $input.data();
|
||||
var keyupTimer = null;
|
||||
var isMouseenter = 0;
|
||||
|
||||
var $dropdownMenu = $('#gdoo-suggest');
|
||||
buildSuggest($input, options, params);
|
||||
|
||||
$input.off();
|
||||
|
||||
// 开始事件处理
|
||||
$input.on('keydown', function(event) {
|
||||
// 当提示层显示时才对键盘事件处理
|
||||
if (!$dropdownMenu.is(':visible')) {
|
||||
return;
|
||||
}
|
||||
if (event.keyCode === options.keyEnter) {
|
||||
hideSuggest($input, options);
|
||||
}
|
||||
}).on('keyup input paste', function(event) {
|
||||
// 如果弹起的键是回车、向上或向下方向键则返回
|
||||
if (~ $.inArray(event.keyCode, [options.keyDown, options.keyUp, options.keyEnter])) {
|
||||
$input.val($input.val()); // 让鼠标输入跳到最后
|
||||
return;
|
||||
}
|
||||
|
||||
clearTimeout(keyupTimer);
|
||||
keyupTimer = setTimeout(function() {
|
||||
refreshData($input, options, params);
|
||||
}, options.delay);
|
||||
|
||||
}).on('focus', function() {
|
||||
|
||||
$dropdownMenu.off();
|
||||
|
||||
var w = $(window).width();
|
||||
var h = $(window).height();
|
||||
|
||||
var width = $input.outerWidth();
|
||||
var height = $input.outerHeight();
|
||||
var offset = $input.offset();
|
||||
|
||||
var dw = $dropdownMenu.outerWidth();
|
||||
var dh = $dropdownMenu.outerHeight();
|
||||
|
||||
var css = {top: offset.top + height - 1};
|
||||
// 判断是否小于768
|
||||
if (w < 768) {
|
||||
css.minWidth = 360;
|
||||
css.left = 14;
|
||||
css.right = 14;
|
||||
} else {
|
||||
css.left = offset.left;
|
||||
// 右边超出
|
||||
if (w < offset.left + dw + 10) {
|
||||
css.left = offset.left - dw + width;
|
||||
}
|
||||
// 下边超出
|
||||
if (h < offset.top + dh + 10) {
|
||||
css.top = offset.top - dh + 1;
|
||||
}
|
||||
}
|
||||
$dropdownMenu.css(css);
|
||||
|
||||
// 列表中滑动时,输入框失去焦点
|
||||
$dropdownMenu.on('mouseenter', function() {
|
||||
isMouseenter = 1;
|
||||
$input.blur();
|
||||
}).on('mouseleave', function() {
|
||||
isMouseenter = 0;
|
||||
$input.focus();
|
||||
}).on('click', function() {
|
||||
// 阻止冒泡
|
||||
return false;
|
||||
});
|
||||
|
||||
}).on('blur', function() {
|
||||
// 隐藏对话框
|
||||
if (!isMouseenter) {
|
||||
hideSuggest($input, options);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,50 @@
|
||||
(function($) {
|
||||
var GdooEvent = function(args) {
|
||||
var me = this;
|
||||
me.args = args;
|
||||
me.trigger = function(fun) {
|
||||
if (typeof me.args[fun] == 'function') {
|
||||
var args = [];
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
return me.args[fun].apply(me, args);
|
||||
}
|
||||
}
|
||||
me.exist = function(fun) {
|
||||
if (typeof me.args[fun] == 'function') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
var gdoo = {
|
||||
formKey(params) {
|
||||
if (params.form_id) {
|
||||
var key = params.form_id + '.' + params.id;
|
||||
var id = params.form_id + '_' + params.id;
|
||||
var name = params.form_id + '_' + params.name;
|
||||
} else {
|
||||
var key = params.id;
|
||||
var id = params.id;
|
||||
var name = params.name;
|
||||
}
|
||||
return {id: id, key: key, name: name};
|
||||
},
|
||||
widgets: {},
|
||||
forms: {},
|
||||
dialogs: {},
|
||||
grids: {},
|
||||
event: {
|
||||
events: {},
|
||||
set: function(tag, fun) {
|
||||
this.events[tag] = new GdooEvent(fun);
|
||||
},
|
||||
get: function(tag) {
|
||||
return this.events[tag] || new GdooEvent({});
|
||||
}
|
||||
}
|
||||
};
|
||||
window.gdoo = gdoo;
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
* `GdooWebSocket` constructor.
|
||||
*
|
||||
* @param {Object} opts
|
||||
* {
|
||||
* url websocket链接地址
|
||||
* pingTimeout 未收到消息多少秒之后发送ping请求,默认15000毫秒
|
||||
pongTimeout 发送ping之后,未收到消息超时时间,默认10000毫秒
|
||||
reconnectTimeout 尝试重连的间隔时间,默认2000毫秒
|
||||
pingMsg ping 消息值,默认ping
|
||||
repeatLimit 重连尝试次数。默认不限制
|
||||
* }
|
||||
* @api public
|
||||
*/
|
||||
|
||||
var GdooWebSocket = function({
|
||||
url,
|
||||
pingTimeout = 15000,
|
||||
pongTimeout = 10000,
|
||||
reconnectTimeout = 2000,
|
||||
pingMsg = 'ping',
|
||||
repeatLimit = null
|
||||
}){
|
||||
this.opts = {
|
||||
url: url,
|
||||
pingTimeout: pingTimeout,
|
||||
pongTimeout: pongTimeout,
|
||||
reconnectTimeout: reconnectTimeout,
|
||||
pingMsg: pingMsg,
|
||||
repeatLimit: repeatLimit
|
||||
};
|
||||
|
||||
this.ws = null; //websocket实例
|
||||
this.repeat = 0;
|
||||
|
||||
// override hook function
|
||||
this.onclose = () => {};
|
||||
this.onerror = () => {};
|
||||
this.onopen = () => {};
|
||||
this.onmessage = () => {};
|
||||
this.onreconnect = () => {};
|
||||
this.onsend = () => {};
|
||||
this.onreconnectCountDown = () => {};
|
||||
|
||||
this.createWebSocket();
|
||||
}
|
||||
|
||||
GdooWebSocket.prototype.createWebSocket = function() {
|
||||
try {
|
||||
this.ws = new WebSocket(this.opts.url);
|
||||
this.initEventHandle();
|
||||
} catch (e) {
|
||||
this.reconnect();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
GdooWebSocket.prototype.initEventHandle = function() {
|
||||
this.ws.onclose = (e) => {
|
||||
this.onclose(e);
|
||||
this.reconnect();
|
||||
};
|
||||
this.ws.onerror = (e) => {
|
||||
this.onerror(e);
|
||||
this.reconnect();
|
||||
};
|
||||
this.ws.onopen = () => {
|
||||
this.repeat = 0;
|
||||
this.onopen();
|
||||
//心跳检测重置
|
||||
this.heartCheck();
|
||||
};
|
||||
this.ws.onmessage = (event) => {
|
||||
this.onmessage(event);
|
||||
//如果获取到消息,心跳检测重置
|
||||
//拿到任何消息都说明当前连接是正常的
|
||||
this.heartCheck();
|
||||
};
|
||||
};
|
||||
|
||||
GdooWebSocket.prototype.reconnect = function() {
|
||||
if (this.opts.repeatLimit > 0 && this.opts.repeatLimit <= this.repeat) return; //limit repeat the number
|
||||
if (this.lockReconnect || this.forbidReconnect) return;
|
||||
this.lockReconnect = true;
|
||||
this.repeat++; //必须在lockReconnect之后,避免进行无效计数
|
||||
|
||||
this.onreconnect();
|
||||
|
||||
// 倒计时重连
|
||||
this.countDown = options.reconnectTimeout / 1000;
|
||||
this.reconnectCountDown();
|
||||
|
||||
// 没连接上会一直重连,设置延迟避免请求过多
|
||||
setTimeout(() => {
|
||||
this.createWebSocket();
|
||||
this.lockReconnect = false;
|
||||
}, this.opts.reconnectTimeout);
|
||||
};
|
||||
|
||||
GdooWebSocket.prototype.send = function(msg) {
|
||||
this.ws.send(msg);
|
||||
this.onsend(msg);
|
||||
};
|
||||
|
||||
//心跳检测
|
||||
GdooWebSocket.prototype.heartCheck = function() {
|
||||
this.heartReset();
|
||||
this.heartStart();
|
||||
};
|
||||
|
||||
GdooWebSocket.prototype.heartStart = function() {
|
||||
// 不再重连就不再执行心跳
|
||||
if (this.forbidReconnect) return;
|
||||
|
||||
this.pingTimeoutId = setTimeout(() => {
|
||||
// 这里发送一个心跳,后端收到后,返回一个心跳消息,
|
||||
// onmessage拿到返回的心跳就说明连接正常
|
||||
this.ws.send(this.opts.pingMsg);
|
||||
this.onsend(this.opts.pingMsg);
|
||||
|
||||
// 如果超过一定时间还没重置,说明后端主动断开了
|
||||
this.pongTimeoutId = setTimeout(() => {
|
||||
// 如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
|
||||
this.ws.close();
|
||||
}, this.opts.pongTimeout);
|
||||
|
||||
}, this.opts.pingTimeout);
|
||||
};
|
||||
|
||||
GdooWebSocket.prototype.reconnectCountDown = function() {
|
||||
this.onreconnectCountDown(this.countDown);
|
||||
if (this.countDown > 0) {
|
||||
this.countDownTimeoutId = setTimeout(() => {
|
||||
this.reconnectCountDown();
|
||||
}, 1000);
|
||||
}
|
||||
this.countDown--;
|
||||
}
|
||||
|
||||
GdooWebSocket.prototype.heartReset = function() {
|
||||
clearTimeout(this.pingTimeoutId);
|
||||
clearTimeout(this.pongTimeoutId);
|
||||
clearTimeout(this.countDownTimeoutId);
|
||||
};
|
||||
|
||||
GdooWebSocket.prototype.close = function() {
|
||||
// 如果手动关闭连接,不再重连
|
||||
this.forbidReconnect = true;
|
||||
this.heartReset();
|
||||
this.ws.close();
|
||||
};
|
||||
@@ -0,0 +1,521 @@
|
||||
(function(window) {
|
||||
|
||||
var calc = {
|
||||
/**
|
||||
* 人民币计算大写
|
||||
* @param {type} currencyDigits
|
||||
* @returns {String}
|
||||
*/
|
||||
'rmb': function(currencyDigits) {
|
||||
// Constants:
|
||||
var MAXIMUM_NUMBER = 99999999999.99;
|
||||
// Predefine the radix characters and currency symbols for output:
|
||||
var YUANCAPITAL = {
|
||||
ZERO: "零",
|
||||
ONE: "壹",
|
||||
TWO: "贰",
|
||||
THREE: "叁",
|
||||
FOUR: "肆",
|
||||
FIVE: "伍",
|
||||
SIX: "陆",
|
||||
SEVEN: "柒",
|
||||
EIGHT: "捌",
|
||||
NINE: "玖",
|
||||
TEN: "拾",
|
||||
HUNDRED: "佰",
|
||||
THOUSAND: "仟",
|
||||
TEN_THOUSAND: "万",
|
||||
HUNDRED_MILLION: "亿",
|
||||
DOLLAR: "元",
|
||||
TEN_CENT: "角",
|
||||
CENT: "分",
|
||||
INTEGER: "整"
|
||||
};
|
||||
|
||||
var CN_ZERO = YUANCAPITAL.ZERO;
|
||||
var CN_ONE = YUANCAPITAL.ONE;
|
||||
var CN_TWO = YUANCAPITAL.TWO;
|
||||
var CN_THREE = YUANCAPITAL.THREE;
|
||||
var CN_FOUR = YUANCAPITAL.FOUR;
|
||||
var CN_FIVE = YUANCAPITAL.FIVE;
|
||||
var CN_SIX = YUANCAPITAL.SIX;
|
||||
var CN_SEVEN = YUANCAPITAL.SEVEN;
|
||||
var CN_EIGHT = YUANCAPITAL.EIGHT;
|
||||
var CN_NINE = YUANCAPITAL.NINE;
|
||||
var CN_TEN = YUANCAPITAL.TEN;
|
||||
var CN_HUNDRED = YUANCAPITAL.HUNDRED;
|
||||
var CN_THOUSAND = YUANCAPITAL.THOUSAND;
|
||||
var CN_TEN_THOUSAND = YUANCAPITAL.TEN_THOUSAND;
|
||||
var CN_HUNDRED_MILLION = YUANCAPITAL.HUNDRED_MILLION;
|
||||
var CN_DOLLAR = YUANCAPITAL.DOLLAR;
|
||||
var CN_TEN_CENT = YUANCAPITAL.TEN_CENT;
|
||||
var CN_CENT = YUANCAPITAL.CENT;
|
||||
var CN_INTEGER = YUANCAPITAL.INTEGER;
|
||||
// Variables:
|
||||
var integral; // Represent integral part of digit number.
|
||||
var decimal; // Represent decimal part of digit number.
|
||||
var outputCharacters; // The output result.
|
||||
var parts;
|
||||
var digits, radices, bigRadices, decimals;
|
||||
var zeroCount;
|
||||
var i, p, d;
|
||||
var quotient, modulus;
|
||||
// Validate input string:
|
||||
currencyDigits = currencyDigits.toString();
|
||||
if (currencyDigits == "") {
|
||||
return "";
|
||||
}
|
||||
if (currencyDigits.match(/[^,.\d]/) != null) {
|
||||
return "";
|
||||
}
|
||||
if ((currencyDigits).match(/^((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/) == null) {
|
||||
return "";
|
||||
}
|
||||
// Normalize the format of input digits:
|
||||
currencyDigits = currencyDigits.replace(/,/g, ""); // Remove comma delimiters.
|
||||
currencyDigits = currencyDigits.replace(/^0+/, ""); // Trim zeros at the beginning.
|
||||
// Assert the number is not greater than the maximum number.
|
||||
if (Number(currencyDigits) > MAXIMUM_NUMBER) {
|
||||
return "";
|
||||
}
|
||||
// Process the coversion from currency digits to characters:
|
||||
// Separate integral and decimal parts before processing coversion:
|
||||
parts = currencyDigits.split(".");
|
||||
if (parts.length > 1) {
|
||||
integral = parts[0];
|
||||
decimal = parts[1];
|
||||
// Cut down redundant decimal digits that are after the second.
|
||||
decimal = decimal.substr(0, 2);
|
||||
}
|
||||
else {
|
||||
integral = parts[0];
|
||||
decimal = "";
|
||||
}
|
||||
// Prepare the characters corresponding to the digits:
|
||||
digits = new Array(CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT, CN_NINE);
|
||||
radices = new Array("", CN_TEN, CN_HUNDRED, CN_THOUSAND);
|
||||
bigRadices = new Array("", CN_TEN_THOUSAND, CN_HUNDRED_MILLION);
|
||||
decimals = new Array(CN_TEN_CENT, CN_CENT);
|
||||
// Start processing:
|
||||
outputCharacters = "";
|
||||
// Process integral part if it is larger than 0:
|
||||
if (Number(integral) > 0) {
|
||||
zeroCount = 0;
|
||||
for (i = 0; i < integral.length; i++) {
|
||||
p = integral.length - i - 1;
|
||||
d = integral.substr(i, 1);
|
||||
quotient = p / 4;
|
||||
modulus = p % 4;
|
||||
if (d == "0") {
|
||||
zeroCount++;
|
||||
}
|
||||
else {
|
||||
if (zeroCount > 0) {
|
||||
outputCharacters += digits[0];
|
||||
}
|
||||
zeroCount = 0;
|
||||
outputCharacters += digits[Number(d)] + radices[modulus];
|
||||
}
|
||||
if (modulus == 0 && zeroCount < 4) {
|
||||
outputCharacters += bigRadices[quotient];
|
||||
}
|
||||
}
|
||||
outputCharacters += CN_DOLLAR;
|
||||
}
|
||||
// Process decimal part if there is:
|
||||
if (decimal != "") {
|
||||
for (i = 0; i < decimal.length; i++) {
|
||||
d = decimal.substr(i, 1);
|
||||
if (d != "0") {
|
||||
outputCharacters += digits[Number(d)] + decimals[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
// Confirm and return the final output string:
|
||||
if (outputCharacters == "") {
|
||||
outputCharacters = CN_ZERO + CN_DOLLAR;
|
||||
}
|
||||
if (decimal == "") {
|
||||
outputCharacters += CN_INTEGER;
|
||||
}
|
||||
//outputCharacters = CN_SYMBOL + outputCharacters;
|
||||
return outputCharacters;
|
||||
},
|
||||
/**
|
||||
* 最大值
|
||||
* @returns {unresolved}
|
||||
*/
|
||||
'max': function() {
|
||||
if (arguments.length == 0) {
|
||||
return;
|
||||
}
|
||||
var maxNum = arguments[0];
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
maxNum = Math.max(maxNum, arguments[i]);
|
||||
}
|
||||
return parseFloat(maxNum);
|
||||
},
|
||||
/**
|
||||
* 最小值
|
||||
* @returns {unresolved}
|
||||
*/
|
||||
'min': function() {
|
||||
if (arguments.length == 0) {
|
||||
return;
|
||||
}
|
||||
var minNum = arguments[0];
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
minNum = Math.min(minNum, arguments[i]);
|
||||
}
|
||||
return parseFloat(minNum);
|
||||
},
|
||||
/**
|
||||
* 平均值
|
||||
* @returns {unresolved}
|
||||
*/
|
||||
'avg': function() {
|
||||
var args = arguments,
|
||||
len = args.length,
|
||||
i = 0,
|
||||
sum = 0;
|
||||
|
||||
for(; i < len && (sum += parseFloat(args[i])); i++ ){
|
||||
}
|
||||
return sum / len;
|
||||
},
|
||||
/**
|
||||
* 取模运算
|
||||
* @returns {String}
|
||||
*/
|
||||
'mod': function() {
|
||||
if (arguments.length == 0) {
|
||||
return;
|
||||
}
|
||||
var firstNum = arguments[0];
|
||||
var secondNum = arguments[1];
|
||||
var result = firstNum % secondNum;
|
||||
result = isNaN(result) ? "" : parseFloat(result);
|
||||
return result;
|
||||
},
|
||||
/**
|
||||
* 绝对值
|
||||
* @param {type} val
|
||||
* @returns {@exp;Math@call;abs}
|
||||
*/
|
||||
'abs': function(val) {
|
||||
return Math.abs(parseFloat(val));
|
||||
},
|
||||
/**
|
||||
* 获取值
|
||||
* @param {type} val
|
||||
* @returns {@exp;Math@call;floor|Number}
|
||||
*/
|
||||
'val': function(val, prec) {
|
||||
return (isNaN(val) || val === Infinity) ? 0 : val.toFixed(prec);
|
||||
},
|
||||
/**
|
||||
* 天数计算
|
||||
* @param {type} val
|
||||
* @returns {Number|@exp;Math@call;floor}
|
||||
*/
|
||||
'day': function(val) {
|
||||
return val == 0 ? 0 : Math.floor(val / 86400);
|
||||
},
|
||||
/**
|
||||
* 小时
|
||||
* @param {type} val
|
||||
* @returns {@exp;Math@call;floor|Number}
|
||||
*/
|
||||
'hour': function(val) {
|
||||
return val == 0 ? 0 : Math.floor(val / 3600);
|
||||
},
|
||||
/**
|
||||
* 日期计算
|
||||
* @param {type} val
|
||||
* @returns {String}
|
||||
*/
|
||||
'date': function(val) {
|
||||
var TIME = {
|
||||
YEAR: "年",
|
||||
HALFYEAR: "半年",
|
||||
QUARTER: "季",
|
||||
MONTH: "月",
|
||||
WEEK: "周",
|
||||
DAY: "天",
|
||||
HOUR: "小时",
|
||||
MIN: "分",
|
||||
MINS: "分钟",
|
||||
SEC: "秒",
|
||||
SECS: "秒钟",
|
||||
INVALID_DATE: "日期格式无效",
|
||||
WEEKS: "星期",
|
||||
WEEKDAYS: "日一二三四五六"
|
||||
};
|
||||
return (val >= 0) ? Math.floor(val / 86400) + TIME.DAY + Math.floor((val % 86400) / 3600) + TIME.HOUR + Math.floor((val % 3600) / 60) + TIME.MIN + Math.floor(val % 60) + TIME.SEC : TIME.INVALID_DATE; //'日期格式无效'
|
||||
},
|
||||
/**
|
||||
* 列表控件计算
|
||||
* @param {type} olist
|
||||
* @param {type} col
|
||||
* @returns {Number}
|
||||
*/
|
||||
'list': function(table_id, col) {
|
||||
|
||||
var output = 0;
|
||||
var tbody = document.getElementById('body_' + table_id);
|
||||
|
||||
for (var i = 0; i < tbody.rows.length; i++) {
|
||||
|
||||
for (var j = 0; j < tbody.rows[i].cells.length; j++) {
|
||||
|
||||
if (j == col) {
|
||||
|
||||
var child = tbody.rows[i].cells[j].firstChild;
|
||||
|
||||
if (child && child.tagName) {
|
||||
|
||||
var val = child.value || child.innerText;
|
||||
|
||||
val = (val == "" || val.replace(/\s/g, '') == "") ? 0 : val;
|
||||
val = (isNaN(val)) ? NaN : val;
|
||||
output += parseFloat(val);
|
||||
} else {
|
||||
output += parseFloat(child.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return parseFloat(output);
|
||||
},
|
||||
/**
|
||||
* 计算控件获取item的值
|
||||
* @param {type} $item
|
||||
* @returns {@exp;d@call;getTime|Number|@exp;document@call;getElementById}
|
||||
*/
|
||||
'getVal': function(id, type) {
|
||||
var $item = $('#' + id);
|
||||
if ($item.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
// $item.data('flag')
|
||||
if (type == 'listview') {
|
||||
return document.getElementById('lv_' + id);
|
||||
} else if (type == 'date') {
|
||||
var val = $('#' + id).val();
|
||||
//var val = $item.parent().data("datetimepicker").getDate();
|
||||
var d = new Date(val);
|
||||
return d.getTime() / 1000;
|
||||
} else {
|
||||
var val = $item.val();
|
||||
if (val == "") {
|
||||
val = 0;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
},
|
||||
/**
|
||||
数字合计
|
||||
*/
|
||||
sum: function() {
|
||||
var args = [].slice.call(arguments, 0),
|
||||
len, item, sum = 0;
|
||||
|
||||
for (len = args.length; len--;) {
|
||||
item = parseFloat(args[len]);
|
||||
// if item=>NaN
|
||||
sum += (item === item ? item : 0);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
|
||||
var listView = {
|
||||
calc: calc,
|
||||
field: {},
|
||||
data: {},
|
||||
total: {},
|
||||
editor: function(key, i, j) {
|
||||
var field = listView.field[key];
|
||||
var type = field.type[j];
|
||||
var size = field.size[j];
|
||||
|
||||
var css = field.checks[j] == 'SYS_NOT_NULL' ? 'input-required' : 'input-text';
|
||||
var readonly = field.writes[j] == true ? false : true;
|
||||
|
||||
var value = '';
|
||||
if(listView.data[key][i])
|
||||
{
|
||||
value = listView.data[key][i][j] == undefined ? '' : listView.data[key][i][j];
|
||||
}
|
||||
|
||||
var name = key+'['+i+']['+j+']';
|
||||
var id = key+'_'+i+'_'+j;
|
||||
switch(type)
|
||||
{
|
||||
case "empty":
|
||||
var out = '<span tyle="width:'+size+'px;" id="'+id+'"></span>';
|
||||
break;
|
||||
case "text":
|
||||
var out = readonly == 0 ? '<input autocomplete="off" type="text" style="width:'+size+'px;" class="'+css+'" name="'+name+'" id="'+id+'" value="'+value+'">' : '<span id="'+id+'">'+value+'</span>';
|
||||
break;
|
||||
case "textarea":
|
||||
var out = readonly == 0 ? '<textarea style="width:'+size+'px;" class="'+css+'" name="'+name+'" id="'+id+'">'+value+'</textarea>' : '<span id="'+id+'">'+value+'</span>';
|
||||
break;
|
||||
case "calc":
|
||||
var out = readonly == 0 ? '<input type="text" style="width:'+size+'px;" class="readonly" name="'+name+'" id="'+id+'" value="'+value+'" readonly>' : '<span id="'+id+'">'+value+'</span>';
|
||||
break;
|
||||
|
||||
case "select":
|
||||
var option = field.value[j].split(',');
|
||||
var r = [];
|
||||
r.push('<select style=width:'+size+'px;" name="'+name+'" id="'+id+'">');
|
||||
for (var i = 0; i < option.length; i++)
|
||||
{
|
||||
var selected = value == option[i] ? ' selected' : '';
|
||||
r.push('<option value="'+option[i]+'"'+selected+'>'+option[i]+'</option>');
|
||||
}
|
||||
r.push('</select>');
|
||||
out = readonly == 0 ? r.join("\n") : '<span id="'+id+'">'+value+'</span>';
|
||||
break;
|
||||
|
||||
case "radio":
|
||||
var option = field.value[j].split(',');
|
||||
var r = [];
|
||||
for (var i = 0; i < option.length; i++)
|
||||
{
|
||||
var checked = value == option[i] ? ' checked' : '';
|
||||
r.push('<label class="checkbox"><input type="radio" name="'+name+'" id="'+id+'"'+checked+'>'+option[i]+'</label>');
|
||||
}
|
||||
out = readonly == 0 ? r.join("\n") : '<span id="'+id+'">'+value+'</span>';
|
||||
break;
|
||||
|
||||
case "checkbox":
|
||||
var option = field.value[j].split(',');
|
||||
var r = [];
|
||||
for (var i = 0; i < option.length; i++)
|
||||
{
|
||||
var checked = value == option[i] ? ' checked' : '';
|
||||
r.push('<label class="checkbox"><input type="checkbox" name="'+name+'" id="'+id+'"'+checked+'>'+option[i]+'</label>');
|
||||
}
|
||||
out = readonly == 0 ? r.join("\n") : '<span id="'+id+'">'+value+'</span>';
|
||||
break;
|
||||
|
||||
case "datetime":
|
||||
out = readonly == 0 ? '<input autocomplete="off" type="text" style=width:'+size+'px;" onfocus="datePicker({dateFmt:\'yyyy-MM-dd\'});" class="'+css+' popDate" value="'+value+'" name="'+name+'" id="'+id+'">' : '<span id="'+id+'">'+value+'</span>';
|
||||
break;
|
||||
}
|
||||
return out;
|
||||
},
|
||||
rowUpdate: function(obj)
|
||||
{
|
||||
var e = obj.target.id.split('_');
|
||||
if (e.length == 4)
|
||||
{
|
||||
var key = e[0]+'_'+e[1];
|
||||
listView.rowSum(key, e[2]);
|
||||
listView.footerSum(key);
|
||||
};
|
||||
},
|
||||
footerSum: function(key)
|
||||
{
|
||||
var body = document.getElementById('body_' + key);
|
||||
var field = listView.field[key];
|
||||
var sum = field.sum;
|
||||
|
||||
var readonly = field.readonly;
|
||||
for (var i = 0; i < sum.length; i++)
|
||||
{
|
||||
if(sum[i] == true)
|
||||
{
|
||||
var row = 0;
|
||||
for (var j = 0; j < body.rows.length; j++)
|
||||
{
|
||||
var td = body.rows[j].cells[i+1];
|
||||
var value = field.readonly == 0 ? $(td).find('input,select').val() : $(td).find('span').text();
|
||||
value = parseFloat(value);
|
||||
row += isNaN(value) ? 0 : Math.round(parseFloat(value)*10000)/10000;
|
||||
}
|
||||
row = row.toFixed(2);
|
||||
$('#total_'+key+'_'+i).html(row);
|
||||
}
|
||||
}
|
||||
},
|
||||
rowSum: function(key, j) {
|
||||
|
||||
var field = listView.field[key];
|
||||
var type = field.type;
|
||||
var value = field.value;
|
||||
var readonly = field.readonly;
|
||||
var calc = [];
|
||||
|
||||
for (var i = 0; i < type.length; i++) {
|
||||
|
||||
if(type[i] == 'calc') {
|
||||
|
||||
calc[i] = value[i];
|
||||
|
||||
for (var k = 0; k < type.length; k++) {
|
||||
var n = k+1;
|
||||
var td = $('#'+key+'_'+j+'_'+k);
|
||||
var td_value = readonly== 0 ? td.val() : td.text();
|
||||
calc[i] = calc[i].replace('['+n+']', parseFloat(td_value));
|
||||
|
||||
}
|
||||
row = isNaN(eval(calc[i])) ? 0 : Math.round(parseFloat(eval(calc[i]))*10000)/10000;
|
||||
row = row.toFixed(2);
|
||||
var obj = $('#'+key+'_'+j+'_'+i);
|
||||
readonly== 0 ? obj.val(row) : obj.text(row);
|
||||
}
|
||||
}
|
||||
},
|
||||
rowAdd: function(key)
|
||||
{
|
||||
i = listView.total[key];
|
||||
var tr = [];
|
||||
tr.push('<tr><td align="center">'+(i+1)+'</td>');
|
||||
for (var j = 0; j < listView.field[key].type.length; j++)
|
||||
{
|
||||
tr.push('<td>'+listView.editor(key,i,j)+'</td>');
|
||||
}
|
||||
|
||||
// 检查字段是否为只读
|
||||
if (listView.field[key].readonly == 0) {
|
||||
var option = i > 0 ? '<a class="option" href="javascript:;" onclick="listView.deleteRow(\''+key+'\',this);">删除</a>' : '<a class="option" onclick="listView.rowAdd(\''+key+'\');" href="javascript:;">添加</a>';
|
||||
tr.push('<td align="center" style="white-space:nowrap;">'+option+'</td></tr>');
|
||||
}
|
||||
|
||||
$('#body_'+key).append(tr.join("\n"));
|
||||
// 累加行
|
||||
listView.total[key]++;
|
||||
},
|
||||
deleteRow:function(key, obj) {
|
||||
var tr = obj.parentNode.parentNode;
|
||||
tr.parentNode.removeChild(tr);
|
||||
// 总计列总数
|
||||
listView.footerSum(key);
|
||||
},
|
||||
init:function(key) {
|
||||
// 初始化列表视图
|
||||
listView.total[key] = 0;
|
||||
|
||||
// 新建的时候默认显示一行
|
||||
var length = listView.data[key].length > 0 ? listView.data[key].length : 1;
|
||||
|
||||
for (var i = 0; i < length; i++)
|
||||
{
|
||||
// 添加一行
|
||||
listView.rowAdd(key);
|
||||
|
||||
// 计算小计行
|
||||
listView.rowSum(key, i);
|
||||
|
||||
};
|
||||
|
||||
// 总计列总数
|
||||
listView.footerSum(key);
|
||||
}
|
||||
}
|
||||
|
||||
window.listView = listView;
|
||||
|
||||
})(window);
|
||||
@@ -0,0 +1,138 @@
|
||||
|
||||
function checkMQ() {
|
||||
// 检查移动或桌面设备
|
||||
return window.getComputedStyle(document.querySelector('.main-content'), '::before').getPropertyValue('content').replace(/'/g, "").replace(/"/g, "");
|
||||
}
|
||||
|
||||
function addTab(url, id, name) {
|
||||
|
||||
var size = $('#tabs-list').find('#tab_tab_' + id).length;
|
||||
if (size > 0) {
|
||||
$.addtabs.add({
|
||||
id: id,
|
||||
iframeId: id,
|
||||
target: "#tabs-list",
|
||||
url: app.url(url),
|
||||
title: name,
|
||||
loadbar: true,
|
||||
refresh: true
|
||||
});
|
||||
} else {
|
||||
$.addtabs.add({
|
||||
id: id,
|
||||
target: "#tabs-list",
|
||||
url: app.url(url),
|
||||
loadbar: true,
|
||||
title: name
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
// 不刷新页面改变地址
|
||||
if(history.replaceState) {
|
||||
var i = url.replace(settings.public_url + '/', '');
|
||||
history.replaceState(null, '', settings.public_url + '?i=' + i);
|
||||
}
|
||||
*/
|
||||
|
||||
if ($('.side-nav').hasClass('nav-is-visible')) {
|
||||
var sidebar = $('.side-nav'),
|
||||
scroll = $('.nav-scroll'),
|
||||
sidebarTrigger = $('.nav-trigger');
|
||||
$([sidebar, sidebarTrigger, scroll]).toggleClass('nav-is-visible');
|
||||
}
|
||||
|
||||
// 删除hover样式
|
||||
$('.side-nav').find('.hover').removeClass('hover');
|
||||
$('.side-nav').find('.selected').removeClass('selected');
|
||||
}
|
||||
|
||||
$(function() {
|
||||
|
||||
var $body = $('body');
|
||||
|
||||
$('[data-toggle="addtab"]').on('click', function(event) {
|
||||
event.preventDefault();
|
||||
// 无ID不触发事件
|
||||
var data = $(this).data();
|
||||
if(data.id == undefined) {
|
||||
return;
|
||||
}
|
||||
addTab(data.url, data.id, data.name);
|
||||
});
|
||||
|
||||
// 缓存dom元素
|
||||
var mainContent = $('.main-content'),
|
||||
header = $('.main-header'),
|
||||
sidebar = $('.side-nav'),
|
||||
scroll = $('.nav-scroll'),
|
||||
sidebarTrigger = $('.nav-trigger');
|
||||
|
||||
// 仅移动 - 当用户单击菜单时打开侧边栏
|
||||
sidebarTrigger.on('click', function(event) {
|
||||
event.preventDefault();
|
||||
$([sidebar, sidebarTrigger, scroll]).toggleClass('nav-is-visible');
|
||||
});
|
||||
|
||||
// 初始化折叠菜单
|
||||
var folded = localStorage.getItem("side-folded");
|
||||
if (folded === 'on') {
|
||||
$body.addClass('side-folded');
|
||||
$('.folded').addClass('active');
|
||||
}
|
||||
|
||||
// 折叠左边菜单
|
||||
$(document).on('click', "[data-toggle=side-folded]", function(event) {
|
||||
event.preventDefault();
|
||||
$(this).toggleClass('active');
|
||||
$body.toggleClass('side-folded');
|
||||
// 保存折叠菜单到本地
|
||||
localStorage.setItem("side-folded", $body.hasClass('side-folded') === true ? 'on' : 'off');
|
||||
});
|
||||
|
||||
// 单击项并显示子菜单
|
||||
$('.has-children > a').on('click', function(event) {
|
||||
|
||||
var mq = checkMQ(),
|
||||
selectedItem = $(this);
|
||||
|
||||
if( mq == 'mobile' || mq == 'tablet' ) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
if (selectedItem.parent('li').hasClass('selected')) {
|
||||
selectedItem.parent('li').removeClass('selected');
|
||||
} else {
|
||||
selectedItem.parent().parent().find('>.has-children.selected').removeClass('selected');
|
||||
selectedItem.parent('li').addClass('selected');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('.has-children').on('mouseover mouseout', function(event) {
|
||||
|
||||
var mq = checkMQ();
|
||||
|
||||
if (mq == 'desktop') {
|
||||
// 鼠标悬浮
|
||||
if (event.type == 'mouseover') {
|
||||
var wh = $(window).height();
|
||||
$(this).addClass('hover');
|
||||
var list = $(this).find('ul:visible').not('.fix');
|
||||
list.each(function(i) {
|
||||
var uh = $(this).height();
|
||||
var p = $(this).offset();
|
||||
var c = wh - p.top - uh - 25;
|
||||
/* 二级菜单和三级菜单高出window */
|
||||
if (c < 0) {
|
||||
$(this).css({top:c});
|
||||
$(this).addClass('fix');
|
||||
}
|
||||
});
|
||||
// 鼠标离开
|
||||
} else if(event.type == 'mouseout') {
|
||||
$(this).removeClass('hover');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,790 @@
|
||||
(function (window) {
|
||||
|
||||
// 循环子表
|
||||
function gridListData(table) {
|
||||
var gets = {};
|
||||
var tables = formGridList[table] || [];
|
||||
if (tables.length) {
|
||||
for (var i = 0; i < tables.length; i++) {
|
||||
var t = tables[i];
|
||||
var store = t.api.memoryStore;
|
||||
var rows = [];
|
||||
|
||||
t.api.stopEditing();
|
||||
t.api.forEachNode(function(rowNode) {
|
||||
var data = rowNode.data;
|
||||
if (isNotEmpty(data[t.dataKey])) {
|
||||
var id = '' + data.id;
|
||||
var draft = id.indexOf('draft_');
|
||||
if (draft === 0) {
|
||||
data.id = 0;
|
||||
}
|
||||
rows.push(data);
|
||||
}
|
||||
});
|
||||
|
||||
var event = gdoo.event.get('grid.' + t.tableKey);
|
||||
|
||||
if (event.exist('onSaveBefore')) {
|
||||
var ret = event.trigger('onSaveBefore', rows);
|
||||
if (ret === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (rows.length == 0) {
|
||||
toastrError(t.tableTitle + '不能为空。');
|
||||
return false;
|
||||
} else {
|
||||
gets[t.tableKey] = {rows: rows, deleteds: store.deleted};
|
||||
}
|
||||
}
|
||||
}
|
||||
return gets;
|
||||
}
|
||||
|
||||
// 刷新所有相关grid
|
||||
function reloadGrid(table) {
|
||||
var iframes = top.document.getElementsByTagName("iframe");
|
||||
for (var i=0; i < iframes.length; i++) {
|
||||
var iframe = iframes[i];
|
||||
var igdoo = iframe.contentWindow.gdoo;
|
||||
if (iframe.id == 'tab_iframe_dashboard') {
|
||||
// 刷新首页全部部件
|
||||
var widgets = Object.values(igdoo.widgets);
|
||||
widgets.forEach(function(grid) {
|
||||
grid.remoteData();
|
||||
});
|
||||
} else {
|
||||
// 刷新全部页面的相关grid
|
||||
if (igdoo && igdoo.grids) {
|
||||
var grids = igdoo.grids;
|
||||
if (grids[table]) {
|
||||
grids[table].grid.remoteData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.gridListData = gridListData;
|
||||
|
||||
var model = {
|
||||
bill_url: '',
|
||||
audit: function (table) {
|
||||
var form = $('#' + table);
|
||||
var key = form.find('#master_key').val();
|
||||
var run_id = form.find('#master_run_id').val();
|
||||
var step_id = form.find('#master_step_id').val();
|
||||
var run_log_id = form.find('#master_run_log_id').val();
|
||||
var uri = $('#' + table).find('#master_uri').val();
|
||||
var url = app.url(uri + '/flowAudit', {key:key, run_id:run_id, step_id:step_id, run_log_id:run_log_id});
|
||||
$.dialog({
|
||||
title: '单据审批',
|
||||
url: url,
|
||||
buttons: [{
|
||||
text: '取消',
|
||||
'class': 'btn-default',
|
||||
click: function () {
|
||||
$(this).dialog('close');
|
||||
}
|
||||
},{
|
||||
text: '提交',
|
||||
'class': 'btn-info',
|
||||
click: function () {
|
||||
var query = $('#myturn,#' + table).serialize();
|
||||
// 循环子表
|
||||
var gets = gridListData(table);
|
||||
if(gets === false) {
|
||||
return;
|
||||
}
|
||||
var loading = layer.msg('数据提交中...', {
|
||||
icon: 16, shade: 0.1, time: 1000 * 120
|
||||
});
|
||||
$.post(app.url(uri + '/flowAudit'), query + '&' + $.param(gets), function (res) {
|
||||
if (res.status) {
|
||||
reloadGrid(table);
|
||||
toastrSuccess(res.data);
|
||||
if (res.url) {
|
||||
location.href = res.url;
|
||||
}
|
||||
} else {
|
||||
toastrError(res.data);
|
||||
}
|
||||
}, 'json').complete(function() {
|
||||
layer.close(loading);
|
||||
});
|
||||
}
|
||||
}]
|
||||
});
|
||||
}, draft: function (table) {
|
||||
var uri = $('#' + table).find('#master_uri').val();
|
||||
var query = $('#myturn,#' + table).serialize();
|
||||
// 循环子表
|
||||
var gets = gridListData(table);
|
||||
if(gets === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
var loading = layer.msg('数据提交中...', {
|
||||
icon: 16, shade: 0.1, time: 1000 * 120
|
||||
});
|
||||
|
||||
var event = gdoo.event.get('grid.' + table);
|
||||
|
||||
$.post(app.url(uri + '/flowDraft'), query + '&' + $.param(gets), function (res) {
|
||||
|
||||
if (event.exist('onSaveAfter')) {
|
||||
res = event.trigger('onSaveAfter', res);
|
||||
}
|
||||
|
||||
if (res.status) {
|
||||
reloadGrid(table);
|
||||
toastrSuccess(res.data);
|
||||
if (res.url) {
|
||||
location.href = res.url;
|
||||
}
|
||||
} else {
|
||||
toastrError(res.data);
|
||||
}
|
||||
}, 'json').complete(function() {
|
||||
layer.close(loading);
|
||||
});
|
||||
|
||||
}, remove: function (url) {
|
||||
$.messager.confirm('操作警告', '确定要删除吗?', function (btn) {
|
||||
if (btn == true) {
|
||||
$.post(url, function (res) {
|
||||
if (res.status) {
|
||||
toastrSuccess(res.data);
|
||||
location.reload();
|
||||
} else {
|
||||
toastrError(res.data);
|
||||
}
|
||||
}, 'json');
|
||||
}
|
||||
});
|
||||
}, store: function (table) {
|
||||
var uri = $('#' + table).find('#master_uri').val();
|
||||
var query = $('#' + table).serialize();
|
||||
// 循环子表
|
||||
var gets = gridListData(table);
|
||||
if(gets === false) {
|
||||
return;
|
||||
}
|
||||
var loading = layer.msg('数据提交中...', {
|
||||
icon: 16, shade: 0.1, time: 1000 * 120
|
||||
});
|
||||
$.post(app.url(uri + '/store'), query + '&' + $.param(gets), function (res) {
|
||||
if (res.status) {
|
||||
reloadGrid(table);
|
||||
toastrSuccess(res.data);
|
||||
if (res.url) {
|
||||
location.href = res.url;
|
||||
}
|
||||
} else {
|
||||
toastrError(res.data);
|
||||
}
|
||||
}, 'json').complete(function() {
|
||||
layer.close(loading);
|
||||
});
|
||||
|
||||
}, read: function (table) {
|
||||
var uri = $('#' + table).find('#master_uri').val();
|
||||
var query = $('#' + table).serialize();
|
||||
var loading = layer.msg('数据提交中...', {
|
||||
icon: 16, shade: 0.1
|
||||
});
|
||||
$.post(app.url(uri + '/flowRead'), query, function (res) {
|
||||
if (res.status) {
|
||||
reloadGrid(table);
|
||||
toastrSuccess(res.data);
|
||||
location.reload();
|
||||
} else {
|
||||
toastrError(res.data);
|
||||
}
|
||||
}, 'json').complete(function() {
|
||||
layer.close(loading);
|
||||
});
|
||||
},
|
||||
reset: function (table) {
|
||||
$.messager.confirm('操作警告', '确定要重置流程吗', function(btn) {
|
||||
if (btn == true) {
|
||||
var uri = $('#' + table).find('#master_uri').val();
|
||||
var query = $('#' + table).serialize();
|
||||
var loading = layer.msg('数据提交中...', {
|
||||
icon: 16, shade: 0.1
|
||||
});
|
||||
$.post(app.url(uri + '/flowReset'), query, function (res) {
|
||||
if (res.status) {
|
||||
location.reload();
|
||||
} else {
|
||||
toastrError(res.data);
|
||||
}
|
||||
}, 'json').complete(function() {
|
||||
layer.close(loading);
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
auditLog: function (key) {
|
||||
var url = app.url('index/workflow/flowLog', {key: key});
|
||||
$.dialog({
|
||||
title: '审批记录',
|
||||
dialogClass: 'modal-lg',
|
||||
url: url,
|
||||
buttons: [{
|
||||
text: '取消',
|
||||
'class': 'btn-default',
|
||||
click: function () {
|
||||
$(this).dialog('close');
|
||||
}
|
||||
}]
|
||||
});
|
||||
},
|
||||
revise: function (key) {
|
||||
var url = app.url('index/workflow/flowRevise', {key: key});
|
||||
formDialog({
|
||||
title: '流程修正',
|
||||
url: url,
|
||||
dialogClass: 'modal-md',
|
||||
id: 'revise-form',
|
||||
success: function(res) {
|
||||
toastrSuccess(res.data);
|
||||
location.reload();
|
||||
$(this).dialog("close");
|
||||
},
|
||||
error: function(res) {
|
||||
toastrError(res.data);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 流程撤回
|
||||
model.recall = function (table) {
|
||||
var key = $('#' + table).find('#master_key').val();
|
||||
var uri = $('#' + table).find('#master_uri').val();
|
||||
var log_id = $('#' + table).find('#master_recall_log_id').val();
|
||||
var url = app.url(uri + '/recall', {key: key, log_id: log_id});
|
||||
$.dialog({
|
||||
title: '撤回单据',
|
||||
url: url,
|
||||
buttons: [{
|
||||
text: "取消",
|
||||
'class': "btn-default",
|
||||
click: function () {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
},{
|
||||
text: "提交",
|
||||
'class': "btn-info",
|
||||
click: function () {
|
||||
var me = this;
|
||||
var query = $('#myrecall').serialize();
|
||||
var loading = layer.msg('数据提交中...', {
|
||||
icon: 16, shade: 0.1, time: 1000 * 120
|
||||
});
|
||||
$.post(app.url(uri + '/recall'), query, function (res) {
|
||||
if (res.status) {
|
||||
reloadGrid(table);
|
||||
toastrSuccess(res.data);
|
||||
location.reload();
|
||||
} else {
|
||||
toastrError(res.data);
|
||||
}
|
||||
}, 'json').complete(function() {
|
||||
layer.close(loading);
|
||||
});
|
||||
}
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
// 弃审单据
|
||||
model.abort = function (table) {
|
||||
var key = $('#' + table).find('#master_key').val();
|
||||
var uri = $('#' + table).find('#master_uri').val();
|
||||
var url = app.url(uri + '/abort', {key: key});
|
||||
$.dialog({
|
||||
title: '弃审单据',
|
||||
url: url,
|
||||
buttons: [{
|
||||
text: "取消",
|
||||
'class': "btn-default",
|
||||
click: function () {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
},{
|
||||
text: "提交",
|
||||
'class': "btn-info",
|
||||
click: function () {
|
||||
var me = this;
|
||||
var query = $('#myabort').serialize();
|
||||
var loading = layer.msg('数据提交中...', {
|
||||
icon: 16, shade: 0.1, time: 1000 * 120
|
||||
});
|
||||
$.post(app.url(uri + '/abort'), query, function (res) {
|
||||
if (res.status) {
|
||||
reloadGrid(table);
|
||||
toastrSuccess(res.data);
|
||||
location.reload();
|
||||
} else {
|
||||
toastrError(res.data);
|
||||
}
|
||||
}, 'json').complete(function() {
|
||||
layer.close(loading);
|
||||
});
|
||||
}
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
// 普通审核弃审
|
||||
model.audit2 = function (table) {
|
||||
var key = $('#' + table).find('#master_key').val();
|
||||
var uri = $('#' + table).find('#master_uri').val();
|
||||
$.messager.confirm('操作警告', '确定要审核单据吗', function(btn) {
|
||||
if (btn == true) {
|
||||
var loading = layer.msg('数据提交中...', {
|
||||
icon: 16, shade: 0.1
|
||||
});
|
||||
$.post(app.url(uri + '/audit'), {key: key}, function (res) {
|
||||
if (res.status) {
|
||||
reloadGrid(table);
|
||||
toastrSuccess(res.data);
|
||||
location.reload();
|
||||
} else {
|
||||
toastrError(res.data);
|
||||
}
|
||||
}, 'json').complete(function() {
|
||||
layer.close(loading);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 普通审核弃审
|
||||
model.abort2 = function (table) {
|
||||
var key = $('#' + table).find('#master_key').val();
|
||||
var uri = $('#' + table).find('#master_uri').val();
|
||||
$.messager.confirm('操作警告', '确定要弃审单据吗', function(btn) {
|
||||
if (btn == true) {
|
||||
var loading = layer.msg('数据提交中...', {
|
||||
icon: 16, shade: 0.1, time: 1000 * 30
|
||||
});
|
||||
$.post(app.url(uri + '/abort'), {key: key}, function (res) {
|
||||
if (res.status) {
|
||||
reloadGrid(table);
|
||||
top.$.toastr('success', res.data);
|
||||
location.reload();
|
||||
} else {
|
||||
top.$.toastr('error', res.data);
|
||||
}
|
||||
}, 'json').complete(function() {
|
||||
layer.close(loading);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 子表新增
|
||||
model.createRow = function (table) {
|
||||
var grid = gdoo.forms[table];
|
||||
var onCreateRow = window[table + '.onCreateRow'];
|
||||
if (typeof onCreateRow == 'function') {
|
||||
var ret = onCreateRow.call(grid, table);
|
||||
if (ret === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
grid.api.memoryStore.create({});
|
||||
}
|
||||
|
||||
// 子表删除
|
||||
model.deleteRow = function (table) {
|
||||
var grid = gdoo.forms[table];
|
||||
var onDeleteRow = window[table + '.onDeleteRow'];
|
||||
if (typeof onDeleteRow == 'function') {
|
||||
var ret = onDeleteRow.call(grid, table);
|
||||
if (ret === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
let selectedNodes = grid.api.getSelectedNodes();
|
||||
if (selectedNodes && selectedNodes.length === 1) {
|
||||
let selectedNode = selectedNodes[0];
|
||||
grid.api.deleteRow(selectedNode.data);
|
||||
grid.api.forEachNode((node) => {
|
||||
if (node.childIndex === (selectedNode.childIndex)) {
|
||||
node.setSelected(true);
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 快速搜索
|
||||
model.quickFilter = function (table) {
|
||||
var grid = gdoo.forms[table];
|
||||
var $div = $('#' + table + '_quick_filter_text');
|
||||
var $el = $div.dialog({
|
||||
title: '<i class="fa fa-filter"></i> 过滤' + grid.tableTitle,
|
||||
modalClass:'no-padder',
|
||||
dialogClass:'modal-sm',
|
||||
buttons: [
|
||||
{text: "确定", classed: 'btn-info', click: function() {
|
||||
grid.api.setQuickFilter($div.find('input').val());
|
||||
$el.dialog("close");
|
||||
}
|
||||
},{
|
||||
text: "取消", classed: 'btn-default', click: function() {
|
||||
$el.dialog("close");
|
||||
}}
|
||||
]
|
||||
}).on('keydown', function(e) {
|
||||
if (e.keyCode == 13) {
|
||||
grid.api.setQuickFilter($div.find('input').val());
|
||||
$el.dialog("close");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 子表关闭
|
||||
model.closeRow = function (table) {
|
||||
var me = this;
|
||||
var grid = gdoo.forms[table];
|
||||
var rows = grid.api.getSelectedRows();
|
||||
if (rows.length > 0) {
|
||||
var id = rows[0].id;
|
||||
top.$.messager.confirm('操作提醒', '是否要关闭选中的行数据?', function(btn) {
|
||||
if (btn == true) {
|
||||
var loading = layer.msg('数据提交中...', {
|
||||
icon: 16, shade: 0.1, time: 1000 * 120
|
||||
});
|
||||
$.post(app.url(me.bill_url + '/closeRow'), {table: table,id: id}, function(res) {
|
||||
if (res.status) {
|
||||
toastrSuccess(res.data);
|
||||
grid.remoteData();
|
||||
} else {
|
||||
toastrError(res.data);
|
||||
}
|
||||
},'json').complete(function() {
|
||||
layer.close(loading);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
toastrError('最少选择一行记录。');
|
||||
}
|
||||
}
|
||||
|
||||
// 子表关闭所有
|
||||
model.closeAllRow = function (table) {
|
||||
var me = this;
|
||||
var grid = gdoo.forms[table];
|
||||
var ids = [];
|
||||
grid.api.forEachNode(function(node) {
|
||||
ids.push(node.data.id);
|
||||
});
|
||||
if (ids.length > 0) {
|
||||
top.$.messager.confirm('操作提醒', '是否要关闭所有行数据?', function(btn) {
|
||||
if (btn == true) {
|
||||
var loading = layer.msg('数据提交中...', {
|
||||
icon: 16, shade: 0.1, time: 1000 * 120
|
||||
});
|
||||
$.post(app.url(me.bill_url + '/closeAllRow'), {table: table,ids: ids}, function(res) {
|
||||
if (res.status) {
|
||||
toastrSuccess(res.data);
|
||||
grid.remoteData();
|
||||
} else {
|
||||
toastrError(res.data);
|
||||
}
|
||||
},'json').complete(function() {
|
||||
layer.close(loading);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
toastrError('最少选择一行记录。');
|
||||
}
|
||||
}
|
||||
|
||||
window.flow = model;
|
||||
})(window);
|
||||
|
||||
(function($) {
|
||||
function gridAction(table, name) {
|
||||
this.name = name;
|
||||
this.table = table;
|
||||
this.routes = {};
|
||||
this.dialogType = 'dialog';
|
||||
|
||||
this.show = function(data, key, name) {
|
||||
var me = this;
|
||||
|
||||
if (data.flow_form_edit == 1) {
|
||||
me.audit(data);
|
||||
return;
|
||||
}
|
||||
|
||||
var url = app.url(me.bill_url + '/show', {id: data.master_id});
|
||||
if (me.dialogType == 'dialog') {
|
||||
viewDialog({
|
||||
title: me.name,
|
||||
dialogClass: 'modal-lg',
|
||||
url: url,
|
||||
close: function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (isEmpty(key)) {
|
||||
key = me.bill_url.replace(/\//g,'_') + '_show';
|
||||
}
|
||||
if (isEmpty(name)) {
|
||||
name = me.name;
|
||||
}
|
||||
top.addTab(me.bill_url + '/show?id=' + data.master_id, key, name);
|
||||
}
|
||||
}
|
||||
|
||||
this.import = function() {
|
||||
var me = this;
|
||||
var grid = gdoo.grids[me.table].grid;
|
||||
formDialog({
|
||||
title: '数据导入',
|
||||
url: app.url(me.bill_url + '/import'),
|
||||
dialogClass: 'modal-md',
|
||||
id: 'import-dialog',
|
||||
onSubmit: function() {
|
||||
var fd = new FormData();
|
||||
fd.append("file", $('#import_file')[0].files[0]);
|
||||
var loading = layer.msg('数据提交中...', {
|
||||
icon: 16, shade: 0.1, time: 1000 * 120
|
||||
});
|
||||
$.ajax({
|
||||
url: app.url(me.bill_url + '/import'),
|
||||
type: "POST",
|
||||
data: fd,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
complete: function() {
|
||||
layer.close(loading);
|
||||
},
|
||||
success: function(res) {
|
||||
if (res.status) {
|
||||
$('#modal-import-dialog').dialog('close');
|
||||
grid.remoteData();
|
||||
toastrSuccess(res.data);
|
||||
} else {
|
||||
toastrError(res.data);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.delete = function() {
|
||||
var me = this;
|
||||
var grid = gdoo.grids[me.table].grid;
|
||||
var rows = grid.api.getSelectedRows();
|
||||
var ids = [];
|
||||
$.each(rows, function(index, row) {
|
||||
ids.push(row.master_id);
|
||||
});
|
||||
|
||||
if (ids.length > 0) {
|
||||
var content = ids.length + '个' + me.name + '将被删除?';
|
||||
top.$.messager.confirm('删除' + me.name, content, function(btn) {
|
||||
if (btn == true) {
|
||||
var loading = layer.msg('数据提交中...', {
|
||||
icon: 16, shade: 0.1, time: 1000 * 120
|
||||
});
|
||||
$.post(app.url(me.bill_url + '/delete'), {id: ids}, function(res) {
|
||||
if (res.status) {
|
||||
toastrSuccess(res.data);
|
||||
grid.remoteData();
|
||||
} else {
|
||||
toastrError(res.data);
|
||||
}
|
||||
},'json').complete(function() {
|
||||
layer.close(loading);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
toastrError('最少选择一行记录。');
|
||||
}
|
||||
}
|
||||
|
||||
this.created_by = function(data) {
|
||||
var me = this;
|
||||
var grid = gdoo.grids[me.table].grid;
|
||||
formDialog({
|
||||
title: '私信',
|
||||
url: app.url('user/message/create', {user_id: data.id}),
|
||||
storeUrl: app.url('model/form/store'),
|
||||
id: 'user_message',
|
||||
dialogClass:'modal-md',
|
||||
success: function(res) {
|
||||
toastrSuccess(res.data);
|
||||
grid.remoteData();
|
||||
$(this).dialog("close");
|
||||
},
|
||||
error: function(res) {
|
||||
toastrError(res.data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.create = function() {
|
||||
var me = this;
|
||||
var grid = gdoo.grids[me.table].grid;
|
||||
if (me.dialogType == 'dialog') {
|
||||
formDialog({
|
||||
title: '新建' + me.name,
|
||||
url: app.url(me.bill_url + '/create'),
|
||||
storeUrl: app.url(me.bill_url + '/store'),
|
||||
id: me.table,
|
||||
table: me.table,
|
||||
dialogClass: 'modal-lg',
|
||||
success: function(res) {
|
||||
toastrSuccess(res.data);
|
||||
grid.remoteData();
|
||||
$(this).dialog("close");
|
||||
},
|
||||
error: function(res) {
|
||||
toastrError(res.data);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var key = me.bill_url.replace(/\//g,'_') + '_show';
|
||||
top.addTab(me.bill_url + '/create', key, me.name);
|
||||
}
|
||||
}
|
||||
|
||||
this.edit = function(data) {
|
||||
var me = this;
|
||||
var grid = gdoo.grids[me.table].grid;
|
||||
if (me.dialogType == 'dialog') {
|
||||
formDialog({
|
||||
title: '编辑' + me.name,
|
||||
url: app.url(me.bill_url + '/edit', {id: data.master_id}),
|
||||
storeUrl: app.url(me.bill_url + '/store'),
|
||||
id: me.table,
|
||||
table: me.table,
|
||||
dialogClass: 'modal-lg',
|
||||
success: function(res) {
|
||||
toastrSuccess(res.data);
|
||||
grid.remoteData();
|
||||
$(this).dialog("close");
|
||||
},
|
||||
error: function(res) {
|
||||
toastrError(res.data);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var key = me.bill_url.replace(/\//g,'_') + '_show';
|
||||
top.addTab(me.bill_url + '/edit?id=' + data.master_id, key, me.name);
|
||||
}
|
||||
}
|
||||
|
||||
this.audit = function(data) {
|
||||
var me = this;
|
||||
var grid = gdoo.grids[me.table].grid;
|
||||
if (me.dialogType == 'dialog') {
|
||||
formDialog({
|
||||
title: '审核' + me.name,
|
||||
url: app.url(me.bill_url + '/audit', {id: data.master_id}),
|
||||
storeUrl: app.url(me.bill_url + '/store'),
|
||||
id: me.table,
|
||||
table: me.table,
|
||||
dialogClass: 'modal-lg',
|
||||
success: function(res) {
|
||||
toastrSuccess(res.data);
|
||||
grid.remoteData();
|
||||
$(this).dialog("close");
|
||||
},
|
||||
error: function(res) {
|
||||
toastrError(res.data);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var key = me.bill_url.replace(/\//g,'_') + '_show';
|
||||
top.addTab(me.bill_url + '/audit?id=' + data.master_id, key, me.name);
|
||||
}
|
||||
}
|
||||
|
||||
this.batchEdit = function() {
|
||||
var me = this;
|
||||
var grid = gdoo.grids[me.table].grid;
|
||||
var rows = grid.api.getSelectedRows();
|
||||
var ids = [];
|
||||
$.each(rows, function(index, row) {
|
||||
ids.push(row.master_id);
|
||||
});
|
||||
if (ids.length > 0) {
|
||||
formDialog({
|
||||
title: '批量编辑',
|
||||
dialogClass: 'modal-sm',
|
||||
id: 'batch-edit-form',
|
||||
url: app.url(me.bill_url + '/batchEdit', {ids: ids.join(',')}),
|
||||
success: function(res) {
|
||||
toastrSuccess(res.data);
|
||||
grid.remoteData();
|
||||
$(this).dialog("close");
|
||||
},
|
||||
close: function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
toastrError('最少选择一行记录。');
|
||||
}
|
||||
}
|
||||
|
||||
// 导出
|
||||
this.export = function() {
|
||||
var me = this;
|
||||
var grid = gdoo.grids[me.table].grid;
|
||||
LocalExport(grid, me.name);
|
||||
}
|
||||
|
||||
this.filter = function() {
|
||||
var me = this;
|
||||
var config = gdoo.grids[me.table];
|
||||
var grid = config.grid;
|
||||
var search = config.search;
|
||||
// 过滤数据
|
||||
$(search.advanced.el).dialog({
|
||||
title: '高级搜索',
|
||||
modalClass: 'no-padder',
|
||||
buttons: [{
|
||||
text: "取消",
|
||||
'class': "btn-default",
|
||||
click: function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
},{
|
||||
text: "确定",
|
||||
'class': "btn-info",
|
||||
click: function() {
|
||||
var query = search.advanced.el.serializeArray();
|
||||
var params = {};
|
||||
search.queryType = 'advanced';
|
||||
$.map(query, function(row) {
|
||||
params[row.name] = row.value;
|
||||
});
|
||||
params['page'] = 1;
|
||||
grid.remoteData(params);
|
||||
$(this).dialog("close");
|
||||
return false;
|
||||
}
|
||||
}]
|
||||
});
|
||||
}
|
||||
}
|
||||
window.gridAction = gridAction;
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,119 @@
|
||||
function createRealtime() {
|
||||
var me = this;
|
||||
var lockReconnect = false;
|
||||
var reconnectTimeout = null;
|
||||
var ws;
|
||||
var handlers = {};
|
||||
handlers.open = function(data) {};
|
||||
handlers.message = function(data) {};
|
||||
handlers.close = function(data) {};
|
||||
handlers.pong = function(data) {};
|
||||
handlers.error = function(data) {};
|
||||
|
||||
var socketUrl = null;
|
||||
this.on = function(name, fun) {
|
||||
handlers[name] = fun;
|
||||
return this;
|
||||
}
|
||||
this.connect = function(url) {
|
||||
socketUrl = url;
|
||||
createWebSocket();
|
||||
}
|
||||
|
||||
/*
|
||||
// 注册频道,暂时没用
|
||||
this.subscribe = function(channel_name) {
|
||||
return new channel(channel_name);
|
||||
}
|
||||
|
||||
var channel = function(channel_name) {
|
||||
var that = this;
|
||||
this.channel_name = channel_name;
|
||||
this.members = {};
|
||||
this.on = function(event_name, callback) {
|
||||
handlers[that.channel_name + '.' + event_name] = callback;
|
||||
return that;
|
||||
}
|
||||
this.emit = function(event_name, data) {
|
||||
return me.emit(that.channel_name, event_name, data);
|
||||
}
|
||||
}
|
||||
|
||||
this.emit = function(channel_name, event_name, data) {
|
||||
return ws.send({channel:channel_name, event:event_name, data:data});
|
||||
};
|
||||
*/
|
||||
|
||||
function createWebSocket() {
|
||||
try {
|
||||
ws = new WebSocket(socketUrl);
|
||||
me.ws = ws;
|
||||
init();
|
||||
} catch(e) {
|
||||
console.debug('WebSocket catch', e);
|
||||
reconnect();
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
ws.onclose = function (event) {
|
||||
handlers.close.call(me, event);
|
||||
reconnect();
|
||||
};
|
||||
ws.onerror = function(event) {
|
||||
handlers.error.call(me, event);
|
||||
reconnect();
|
||||
};
|
||||
ws.onopen = function (event) {
|
||||
handlers.open.call(me, event);
|
||||
heartCheck.reset();
|
||||
};
|
||||
ws.onmessage = function (res) {
|
||||
var packet = JSON.parse(res.data);
|
||||
var event = packet['event'];
|
||||
var data = packet['data'];
|
||||
var handler = handlers[event];
|
||||
if (typeof handler == 'function') {
|
||||
handler.call(me, data, packet);
|
||||
} else {
|
||||
handlers.message.call(me, data, packet);
|
||||
}
|
||||
heartCheck.reset();
|
||||
}
|
||||
}
|
||||
|
||||
function reconnect() {
|
||||
if (lockReconnect) {
|
||||
return;
|
||||
};
|
||||
lockReconnect = true;
|
||||
if (reconnectTimeout) {
|
||||
clearTimeout(reconnectTimeout);
|
||||
}
|
||||
reconnectTimeout = setTimeout(function () {
|
||||
createWebSocket();
|
||||
lockReconnect = false;
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
var heartCheck = {
|
||||
interval: 1000 * 5,
|
||||
timeout: null,
|
||||
serverTimeout: null,
|
||||
reset: function () {
|
||||
clearTimeout(this.timeout);
|
||||
clearTimeout(this.serverTimeout);
|
||||
this.start();
|
||||
},
|
||||
start: function () {
|
||||
heartCheck.timeout = setTimeout(function() {
|
||||
console.debug("ping...");
|
||||
ws.send('{"event":"ping"}');
|
||||
heartCheck.serverTimeout = setTimeout(function() {
|
||||
ws.close();
|
||||
}, heartCheck.interval);
|
||||
}, heartCheck.interval);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -0,0 +1,501 @@
|
||||
(function($) {
|
||||
|
||||
'use strict';
|
||||
|
||||
$.fn.searchForm = function(options) {
|
||||
var self = this;
|
||||
var element = [];
|
||||
var data = options.data;
|
||||
var advanced = options.advanced == 1 ? 1 : (data.advanced == 1 ? 1 : 0);
|
||||
var form_id = self.attr('id');
|
||||
|
||||
var assign = false;
|
||||
var values = {};
|
||||
|
||||
var _field = 'search-field-';
|
||||
var _condition = 'search-condition-';
|
||||
var _value = 'search-value-';
|
||||
|
||||
if (advanced) {
|
||||
_field = 'advanced-' + _field;
|
||||
_condition = 'advanced-' + _condition;
|
||||
_value = 'advanced-' + _value;
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
||||
if(advanced) {
|
||||
$.each(data.field, function(i) {
|
||||
var type = self.find('#' + _field + i).data('type');
|
||||
setValues(type, i, data.option[i]);
|
||||
});
|
||||
|
||||
} else {
|
||||
var e = self.find('#' + _field + '0');
|
||||
e.val(data['field'][0]);
|
||||
var type = e.find('option:selected').data('type');
|
||||
setValues(type, 0, data.option[0]);
|
||||
|
||||
e.on('change', function() {
|
||||
assign = true;
|
||||
var index = this.selectedIndex - 1;
|
||||
var type = $(this).find('option:selected').data('type');
|
||||
element[0].value.empty();
|
||||
setValues(type, 0, data.option[index]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function setValues(type, i, config) {
|
||||
self.find('#' + _value + i)
|
||||
element[i] = {
|
||||
condition: self.find('#' + _condition + i),
|
||||
value: self.find('#' + _value + i)
|
||||
};
|
||||
|
||||
setCondition(i, type, data['condition'][i] || '');
|
||||
handle[type].call(self, i, config);
|
||||
}
|
||||
|
||||
function setCondition(i, type, selected) {
|
||||
|
||||
var e = element[i].condition.empty();
|
||||
var condition = {};
|
||||
|
||||
if(assign == true) {
|
||||
selected = '';
|
||||
}
|
||||
|
||||
condition.number = [
|
||||
{key:"eq",value:'等于'},
|
||||
{key:"neq",value:'不等于'},
|
||||
{key:"gt",value:'大于'},
|
||||
{key:"lt",value:'小于'}
|
||||
];
|
||||
|
||||
condition.date = [
|
||||
{key:"eq",value:'等于'},
|
||||
{key:"neq",value:'不等于'},
|
||||
{key:"gt",value:'大于'},
|
||||
{key:"lt",value:'小于'}
|
||||
];
|
||||
|
||||
condition.second = [
|
||||
{key:"eq",value:'等于'},
|
||||
{key:"neq",value:'不等于'},
|
||||
{key:"gt",value:'大于'},
|
||||
{key:"lt",value:'小于'}
|
||||
];
|
||||
|
||||
condition.text = [
|
||||
{key:"like",value:'包含'},
|
||||
{key:"not_like",value:'不包含'},
|
||||
{key:"eq",value:'等于'},
|
||||
{key:"neq",value:'不等于'},
|
||||
{key:"gt",value:'大于'},
|
||||
{key:"lt",value:'小于'},
|
||||
{key:"empty",value:'为空'},
|
||||
{key:"not_empty",value:'不为空'}
|
||||
];
|
||||
|
||||
if(type == 'second' || type == 'text' || type == 'number' || type == 'date') {
|
||||
|
||||
var value = selected || condition[type][0].key;
|
||||
|
||||
$.map(condition[type], function(row) {
|
||||
e.append('<option value="'+row.key+'">'+row.value+'</option>');
|
||||
});
|
||||
e.parent('div').css("display","inline-block");
|
||||
|
||||
} else if(type == 'birthday') {
|
||||
e.append('<option value="birthday">birthday</option>');
|
||||
e.parent('div').hide();
|
||||
var value = 'birthday';
|
||||
|
||||
} else if(type == 'date2') {
|
||||
e.append('<option value="date2">date2</option>');
|
||||
e.parent('div').hide();
|
||||
var value = 'date2';
|
||||
} else if(type == 'region') {
|
||||
e.append('<option value="region">region</option>');
|
||||
e.parent('div').hide();
|
||||
var value = 'region';
|
||||
} else if(type == 'second2') {
|
||||
e.append('<option value="second2">second2</option>');
|
||||
e.parent('div').hide();
|
||||
var value = 'second2';
|
||||
|
||||
} else if(type == 'dialog') {
|
||||
e.append('<option value="dialog">dialog</option>');
|
||||
e.parent('div').hide();
|
||||
var value = 'dialog';
|
||||
|
||||
} else {
|
||||
e.append('<option value="eq">eq</option>');
|
||||
e.parent('div').hide();
|
||||
var value = 'eq';
|
||||
}
|
||||
e.val(value);
|
||||
|
||||
toggleValue(i, value);
|
||||
e.on('change', function() {
|
||||
toggleValue(i, $(this).val());
|
||||
});
|
||||
}
|
||||
|
||||
function toggleValue(i, value) {
|
||||
var e = element[i].value;
|
||||
|
||||
if(value == 'empty' || value == 'not_empty') {
|
||||
e.hide();
|
||||
} else {
|
||||
e.show();
|
||||
}
|
||||
}
|
||||
|
||||
function attr(i, id) {
|
||||
|
||||
var value = _value;
|
||||
var name = 'search';
|
||||
var res = {};
|
||||
|
||||
var id_0 = '';
|
||||
var id_1 = '';
|
||||
|
||||
if (id != undefined) {
|
||||
id_0 = '-' + id;
|
||||
id_1 = '_' + id;
|
||||
}
|
||||
|
||||
res.id = form_id + '_' + value + i + id_0;
|
||||
res.name = name + '_' + i + id_1;
|
||||
|
||||
if (assign == false) {
|
||||
if(id_0) {
|
||||
var v1 = data['search'][i][id];
|
||||
res.value = v1 == undefined ? '' : v1;
|
||||
} else {
|
||||
var v1 = data['search'][i];
|
||||
res.value = v1 == undefined ? '' : v1;
|
||||
}
|
||||
} else {
|
||||
res.value = '';
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
function _option(rows) {
|
||||
var type = $.type(rows);
|
||||
var option = advanced == true ? '<option value=""> - </option>' : '';
|
||||
if(type == 'array' || type == 'object') {
|
||||
$.map(rows, function(row) {
|
||||
option += '<option value="'+row.id+'">'+row.name+'</option>';
|
||||
});
|
||||
} else {
|
||||
option = option.concat(rows);
|
||||
}
|
||||
return option;
|
||||
}
|
||||
|
||||
self._select = function(config, i, id, space) {
|
||||
var a = attr(i, id);
|
||||
var d = _option(config);
|
||||
var e = $('<select name="'+a.name+'" id="'+a.id+'" class="form-control input-sm">'+d+'</select>');
|
||||
element[i].value.append(e);
|
||||
if (a.value !== '') {
|
||||
e.val(a.value);
|
||||
}
|
||||
}
|
||||
|
||||
self._text = function(i, id, space) {
|
||||
var a = attr(i, id);
|
||||
var e = $('<input name="'+a.name+'" id="'+a.id+'" value="'+a.value+'" type="text" class="form-control input-sm">');
|
||||
element[i].value.append(e);
|
||||
}
|
||||
|
||||
self._year = function(i, id, space) {
|
||||
var a = attr(i, id);
|
||||
var e = $('<input name="'+a.name+'" id="'+a.id+'" value="'+a.value+'" type="text" autocomplete="off" data-toggle="date" data-format="yyyy" class="form-control input-sm">');
|
||||
element[i].value.append(e);
|
||||
}
|
||||
|
||||
self._date = function(i, id, space) {
|
||||
var a = attr(i, id);
|
||||
var e = $('<input name="'+a.name+'" id="'+a.id+'" value="'+a.value+'" type="text" autocomplete="off" data-toggle="date" class="form-control input-sm">');
|
||||
element[i].value.append(e);
|
||||
}
|
||||
|
||||
self._date2 = function(i, id, space) {
|
||||
var a0 = attr(i, 0);
|
||||
var a1 = attr(i, 1);
|
||||
var e = $('<table class="table date-field"><tr><td><input name="'+a0.name+'" id="'+a0.id+'" value="'+a0.value+'" type="text" data-toggle="date" autocomplete="off" class="form-control input-sm"></td><td class="date-apart"> - </td><td><input name="'+a1.name+'" id="'+a1.id+'" value="'+a1.value+'" type="text" autocomplete="off" data-toggle="date" class="form-control input-sm"></td></tr></table>');
|
||||
element[i].value.append(e);
|
||||
}
|
||||
|
||||
self._second2 = function(i, id, space) {
|
||||
var a0 = attr(i, 0);
|
||||
var a1 = attr(i, 1);
|
||||
var e = $('<table class="table date-field"><tr><td><input name="'+a0.name+'" id="'+a0.id+'" value="'+a0.value+'" type="text" autocomplete="off" data-toggle="date" class="form-control input-sm"></td><td class="date-apart"> - </td><td><input name="'+a1.name+'" id="'+a1.id+'" value="'+a1.value+'" type="text" autocomplete="off" data-toggle="date" class="form-control input-sm"></td></tr></table>');
|
||||
element[i].value.append(e);
|
||||
}
|
||||
self._birthday = function(i, id, space) {
|
||||
var a0 = attr(i, 0);
|
||||
var a1 = attr(i, 1);
|
||||
var e = $('<input name="'+a0.name+'" id="'+a0.id+'" value="'+a0.value+'" type="text" data-toggle="date" autocomplete="off" data-format="MM-dd" class="form-control input-sm"> - <input name="'+a1.name+'" id="'+a1.id+'" value="'+a1.value+'" type="text" data-toggle="date" autocomplete="off" data-format="MM-dd" class="form-control input-sm">');
|
||||
element[i].value.append(e);
|
||||
}
|
||||
self._birthday2 = function(i, id, space) {
|
||||
var a0 = attr(i, 0);
|
||||
var a1 = attr(i, 1);
|
||||
var e = $('<input name="'+a0.name+'" id="'+a0.id+'" value="'+a0.value+'" type="text" data-toggle="date" autocomplete="off" data-format="MM-dd" class="form-control input-sm"> - <input name="'+a1.name+'" id="'+a1.id+'" value="'+a1.value+'" type="text" data-toggle="date" autocomplete="off" data-format="MM-dd" class="form-control input-sm">');
|
||||
element[i].value.append(e);
|
||||
}
|
||||
self._dialog = function(config, i, id, space) {
|
||||
var a0 = attr(i, id);
|
||||
var query = [];
|
||||
if (config.query) {
|
||||
config.query['multi'] = config.query['multi'] == 'undefined' ? 1 : config.query['multi'];
|
||||
$.each(config.query, function(k, v) {
|
||||
query.push('data-' + k + '="'+v+'"');
|
||||
});
|
||||
}
|
||||
|
||||
if (advanced) {
|
||||
var field = self.find('#' + _field + i);
|
||||
} else {
|
||||
var field = self.find('#' + _field + '0').find('option:selected');
|
||||
}
|
||||
var options = field.data();
|
||||
var e = '<div class="select-group input-group">';
|
||||
e += '<input class="form-control input-sm" data-toggle="dialog-view" readonly="readonly" data-title="'+ options.title +'" data-url="' + config.url +'" data-id="'+a0.id+'" '+ query.join(' ') +' style="min-width:153px;cursor:pointer;" id="' + a0.id + '_text" />';
|
||||
e += '<input type="hidden" id="' + a0.id + '" name="' + a0.name + '" value="' + a0.value +'">';
|
||||
e += '<div class="input-group-btn">';
|
||||
e += '<a data-toggle="dialog-clear" data-id="' + a0.id + '" class="btn btn-sm btn-default"><i class="fa fa-times"></i></a>';
|
||||
e += '</div>';
|
||||
element[i].value.append($(e));
|
||||
}
|
||||
self._product_category = function(i, query) {
|
||||
|
||||
var category = self.attr(i, 0);
|
||||
var product = self.attr(i, 1);
|
||||
|
||||
var category_id = category.value;
|
||||
var product_id = product.value;
|
||||
|
||||
element[i].value.append('<select name="'+category.name+'" id="'+category.id+'" class="form-control input-sm"></select> <select name="'+product.name+'" id="'+product.id+'" class="form-control input-sm"></select>');
|
||||
|
||||
$.post(app.url('product/category/dialog', query), function(res) {
|
||||
var option = '<option value=""> - </option>';
|
||||
$.map(res.rows, function(row) {
|
||||
option += '<option value="'+row.id+'">' + row.layer_space + row.name + '</option>';
|
||||
});
|
||||
var e = $('#'+category.id).html(option);
|
||||
if(category_id) {
|
||||
e.val(category_id);
|
||||
}
|
||||
_product(i);
|
||||
});
|
||||
|
||||
self.on('change', '#'+category.id, function() {
|
||||
category_id = this.value;
|
||||
product_id = 0;
|
||||
_product(i);
|
||||
});
|
||||
|
||||
function _product(i) {
|
||||
var option = '<option value=""> - </option>';
|
||||
if(category_id) {
|
||||
var q = {
|
||||
field_0: 'product.category_id',
|
||||
condition_0: 'eq',
|
||||
search_0: category_id,
|
||||
limit: 0
|
||||
};
|
||||
$.post(app.url('product/product/dialog', q), function(res) {
|
||||
$.map(res.data, function(row) {
|
||||
option += '<option value="'+row.id+'">'+row.text+'</option>';
|
||||
});
|
||||
var e = $('#'+product.id).html(option);
|
||||
if(product_id) {
|
||||
e.val(product_id);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$('#'+product.id).html(option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var handle = {
|
||||
empty: function(i) {
|
||||
element[i].value.empty();
|
||||
},
|
||||
text: function(i) {
|
||||
self._text(i);
|
||||
},
|
||||
select2: function(i) {
|
||||
self._text(i);
|
||||
},
|
||||
select: function(i, config) {
|
||||
self._select(config, i);
|
||||
},
|
||||
number: function(i) {
|
||||
self._text(i);
|
||||
},
|
||||
year: function(i) {
|
||||
self._year(i);
|
||||
},
|
||||
date: function(i) {
|
||||
self._date(i);
|
||||
},
|
||||
date2: function(i) {
|
||||
self._date2(i);
|
||||
},
|
||||
birthday: function(i) {
|
||||
self._birthday(i);
|
||||
},
|
||||
dialog: function(i, config) {
|
||||
self._dialog(config, i);
|
||||
},
|
||||
second: function(i) {
|
||||
self._date(i);
|
||||
},
|
||||
second2: function(i) {
|
||||
self._second2(i);
|
||||
},
|
||||
option: function(i, config) {
|
||||
self._select(config, i);
|
||||
},
|
||||
address: function(i) {
|
||||
var province = attr(i, 0);
|
||||
var city = attr(i, 1);
|
||||
var e = '<select name="'+province.name+'" id="'+province.id+'" class="form-control input-sm"></select> <select name="'+city.name+'" id="'+city.id+'" class="form-control input-sm"></select>';
|
||||
element[i].value.append(e);
|
||||
new pcas(province.id, city.id, province.value, city.value);
|
||||
},
|
||||
region: function(i) {
|
||||
var province = attr(i, 0);
|
||||
var city = attr(i, 1);
|
||||
var county = attr(i, 2);
|
||||
|
||||
var province_id = province.value;
|
||||
var city_id = city.value;
|
||||
var county_id = county.value;
|
||||
|
||||
element[i].value.append('<select name="'+province.name+'" id="'+province.id+'" class="form-control input-sm"></select> <select name="'+city.name+'" id="'+city.id+'" class="form-control input-sm"></select> <select name="'+county.name+'" id="'+county.id+'" class="form-control input-sm"></select>');
|
||||
$.get(app.url('index/api/region',{layer:1}), function(res) {
|
||||
|
||||
var option = '';
|
||||
$.map(res, function(row) {
|
||||
option += '<option value="'+row.id+'">'+row.name+'</option>';
|
||||
});
|
||||
var e = $('#'+province.id).html(option);
|
||||
if(province_id) {
|
||||
e.val(province_id);
|
||||
}
|
||||
|
||||
_city(i);
|
||||
_county(i);
|
||||
|
||||
self.on('change', '#'+province.id, function() {
|
||||
province_id = this.value;
|
||||
city_id = 0;
|
||||
county_id = 0;
|
||||
_city(i);
|
||||
_county(i);
|
||||
});
|
||||
|
||||
self.on('change', '#'+city.id, function() {
|
||||
city_id = this.value;
|
||||
county_id = 0;
|
||||
_county(i);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
function _city(i, space) {
|
||||
$.get(app.url('index/api/region', {layer:2,parent_id:province_id}), function(res) {
|
||||
var option = '';
|
||||
$.map(res, function(row) {
|
||||
option += '<option value="'+row.id+'">'+row.name+'</option>';
|
||||
});
|
||||
var e = $('#'+city.id).html(option);
|
||||
if(city_id) {
|
||||
e.val(city_id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function _county(i, space) {
|
||||
$.get(app.url('index/api/region', {layer:3,parent_id:city_id}), function(res) {
|
||||
var option = '';
|
||||
$.map(res, function(row) {
|
||||
option += '<option value="'+row.id+'">'+row.name+'</option>';
|
||||
});
|
||||
var e = $('#'+county.id).html(option);
|
||||
if(county_id) {
|
||||
e.val(county_id);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
circle: function(i) {
|
||||
var circle = self.attr(i, 0);
|
||||
var customer = self.attr(i, 1);
|
||||
|
||||
var circle_id = circle.value;
|
||||
var customer_id = customer.value;
|
||||
|
||||
element[i].value.append('<select name="'+circle.name+'" id="'+circle.id+'" class="form-control input-sm"></select> <select name="'+customer.name+'" id="'+customer.id+'" class="form-control input-sm"></select>');
|
||||
|
||||
$.post(app.url('customer/circle/dialog'), function(res) {
|
||||
var option = '<option value=""> - </option>';
|
||||
$.map(res, function(row) {
|
||||
option += '<option value="'+row.id+'">'+row.name+'</option>';
|
||||
});
|
||||
var e = $('#'+circle.id).html(option);
|
||||
if(circle_id) {
|
||||
e.val(circle_id);
|
||||
}
|
||||
_customer(i);
|
||||
});
|
||||
|
||||
self.on('change', '#'+circle.id, function() {
|
||||
circle_id = this.value;
|
||||
customer_id = 0;
|
||||
_customer(i);
|
||||
});
|
||||
|
||||
function _customer(i) {
|
||||
var option = '<option value=""> - </option>';
|
||||
if(circle_id) {
|
||||
$.post(app.url('customer/customer/dialog', {limit: 500, circle_id: circle_id}), function(res) {
|
||||
$.map(res.data, function(row) {
|
||||
option += '<option value="'+row.id+'">'+row.text+'</option>';
|
||||
});
|
||||
var e = $('#'+customer.id).html(option);
|
||||
if(customer_id) {
|
||||
e.val(customer_id);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$('#'+customer.id).html(option);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.attr = attr;
|
||||
self.element = element;
|
||||
self.options = options;
|
||||
|
||||
if(typeof(options.init) == 'function') {
|
||||
options.init.call(this, handle);
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,96 @@
|
||||
var select2List = {};
|
||||
|
||||
(function($) {
|
||||
|
||||
$.fn.select2Field = function(options) {
|
||||
$this = $(this);
|
||||
var key = $this.attr('key');
|
||||
var event = gdoo.event.get(key);
|
||||
|
||||
var defaults = {
|
||||
width: '100%',
|
||||
placeholder:' - ',
|
||||
allowClear: true,
|
||||
minimumInputLength: 0,
|
||||
// 不需要每次都获取数据
|
||||
resultCache: true,
|
||||
ajax: {
|
||||
type: 'POST',
|
||||
url: '',
|
||||
dataType: 'json',
|
||||
delay: 250,
|
||||
cache: false,
|
||||
data: function (params) {
|
||||
var query = options.ajaxParams || {};
|
||||
query.field_0 = options.search_key + '.name';
|
||||
query.condition_0 = 'like';
|
||||
query.search_0 = (params.term || '');
|
||||
query.page = (params.page || 1);
|
||||
query.resultCache = true;
|
||||
event.trigger('query', select2, query);
|
||||
return query;
|
||||
},
|
||||
processResults: function (res, params) {
|
||||
return {
|
||||
results: res.data,
|
||||
pagination: {
|
||||
more: res.current_page < res.last_page
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
escapeMarkup: function(markup) {
|
||||
return markup;
|
||||
},
|
||||
templateResult: function(m) {
|
||||
return m.text;
|
||||
},
|
||||
// 函数用来渲染结果
|
||||
templateSelection: function(m) {
|
||||
return m.text;
|
||||
},
|
||||
createTag: function (params) {
|
||||
var term = $.trim(params.term);
|
||||
if (term === '') {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
id: 'draft_' + term,
|
||||
text: term
|
||||
}
|
||||
},
|
||||
initSelection: function(element, callback) {
|
||||
var data = {id: element.val(), text: element.text()};
|
||||
callback(data);
|
||||
}
|
||||
};
|
||||
|
||||
options = $.extend(true, {}, defaults, options);
|
||||
|
||||
event.trigger('init', options);
|
||||
|
||||
var select2 = $this.select2(options);
|
||||
|
||||
select2.on('select2:select', function(e) {
|
||||
event.trigger('onSelect', e.params.data);
|
||||
});
|
||||
|
||||
select2.on('select2:opening', function() {
|
||||
});
|
||||
|
||||
select2.on('select2:open', function() {
|
||||
//select2.select2();
|
||||
/*
|
||||
var data = $(this).data('select2');
|
||||
$('.select2-link').remove();
|
||||
data.$results.parents('.select2-results')
|
||||
.append('<div class="select2-link"><a> <i class="fa fa-plus-square"></i> 更多</a></div>')
|
||||
.on('click', function () {
|
||||
data.trigger('close');
|
||||
});
|
||||
*/
|
||||
});
|
||||
|
||||
return select2;
|
||||
}
|
||||
})(jQuery);
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user