|
@@ -8,16 +8,23 @@
|
|
|
* @version
|
|
|
*/
|
|
|
|
|
|
+const isPre = function (data) {
|
|
|
+ return data.sid !== stageId;
|
|
|
+};
|
|
|
const spreadSetting = {
|
|
|
cols: [
|
|
|
- {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 185, formatter: '@'},
|
|
|
- {title: '金额', colSpan: '1', rowSpan: '1', field: 'e_type', hAlign: 1, width: 80, formatter: '@'},
|
|
|
- {title: '本期金额', colSpan: '1', rowSpan: '1', field: 'quantity', hAlign: 2, width: 100, type: 'Number'},
|
|
|
- {title: '截止本期金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 100, type: 'Number', readOnly: true},
|
|
|
- {title: '时间', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 100, type: 'Number'},
|
|
|
- {title: '编号', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 100, type: 'Number'},
|
|
|
- {title: '依据材料证明', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 100, type: 'Number'},
|
|
|
- {title: '备注', colSpan: '1', rowSpan: '1', field: 'memo', hAlign: 0, width: 150, formatter: '@', cellType: 'ellipsisAutoTip'}
|
|
|
+ {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 235, formatter: '@', readOnly: isPre, },
|
|
|
+ {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 100, type: 'Number', readOnly: isPre, },
|
|
|
+ {title: '时间', colSpan: '1', rowSpan: '1', field: 'real_time', hAlign: 1, width: 150, formatter: '@', readOnly: isPre, },
|
|
|
+ {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: isPre, },
|
|
|
+ {title: '依据材料证明', colSpan: '1', rowSpan: '1', field: 'proof', hAlign: 0, width: 180, formatter: '@', readOnly: isPre, },
|
|
|
+ {
|
|
|
+ title: '计量期', colSpan: '1', rowSpan: '1', field: 'sorder', hAlign: 1, width: 100, formatter: '@',
|
|
|
+ getValue: function (data) {
|
|
|
+ return '第' + data.sorder + '期';
|
|
|
+ }, readOnly: true,
|
|
|
+ },
|
|
|
+ {title: '备注', colSpan: '1', rowSpan: '1', field: 'memo', hAlign: 0, width: 180, formatter: '@', cellType: 'ellipsisAutoTip', readOnly: isPre, }
|
|
|
],
|
|
|
emptyRows: 3,
|
|
|
headRows: 1,
|
|
@@ -30,6 +37,7 @@ $(document).ready(() => {
|
|
|
autoFlashHeight();
|
|
|
const bonusSpread = SpreadJsObj.createNewSpread($('#bonus-spread')[0]);
|
|
|
const bonusSheet = bonusSpread.getActiveSheet();
|
|
|
+ spreadSetting.readOnly = readOnly;
|
|
|
SpreadJsObj.initSheet(bonusSheet, spreadSetting);
|
|
|
|
|
|
$.subMenu({
|
|
@@ -48,5 +56,353 @@ $(document).ready(() => {
|
|
|
autoFlashHeight();
|
|
|
bonusSpread.refresh();
|
|
|
}
|
|
|
- });
|
|
|
+ });
|
|
|
+
|
|
|
+ class Bonus {
|
|
|
+ constructor () {
|
|
|
+ this.data = [];
|
|
|
+ }
|
|
|
+ resortData() {
|
|
|
+ this.data.sort(function (a, b) {
|
|
|
+ return a.sorder !== b.sorder ? a.sorder - b.sorder : a.order - b.order;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ loadDatas(datas) {
|
|
|
+ this.data = datas;
|
|
|
+ this.resortData();
|
|
|
+ }
|
|
|
+ loadUpdateData(updateData) {
|
|
|
+ if (updateData.add) {
|
|
|
+ for (const a of updateData.add) {
|
|
|
+ this.data.push(a);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (updateData.update) {
|
|
|
+ for (const u of updateData.update) {
|
|
|
+ const d = this.data.find(function (x) {
|
|
|
+ return u.id === x.id;
|
|
|
+ });
|
|
|
+ if (d) {
|
|
|
+ _.assign(d, u);
|
|
|
+ } else {
|
|
|
+ this.data.push(d);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (updateData.del) {
|
|
|
+ _.remove(this.data, function (d) {
|
|
|
+ return updateData.del.indexOf(d.id) >= 0;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ this.resortData();
|
|
|
+ }
|
|
|
+ getCurStageNewOrder() {
|
|
|
+ const cur = this.data.filter(function (x) {
|
|
|
+ return x.sid === stageId;
|
|
|
+ });
|
|
|
+ return cur && cur.length > 0 ? cur.length + 1 : 1;
|
|
|
+ }
|
|
|
+ checkCurFirst(bonusData) {
|
|
|
+ const cur = this.data.filter(function (x) {
|
|
|
+ return x.sid === stageId;
|
|
|
+ });
|
|
|
+ return cur.indexOf(bonusData) === 0;
|
|
|
+ }
|
|
|
+ checkCurLast(bonusData) {
|
|
|
+ const cur = this.data.filter(function (x) {
|
|
|
+ return x.sid === stageId;
|
|
|
+ });
|
|
|
+ return cur.indexOf(bonusData) === cur.length - 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const bonusObj = new Bonus();
|
|
|
+
|
|
|
+ postData(window.location.pathname + '/load', null, function (result) {
|
|
|
+ bonusObj.loadDatas(result);
|
|
|
+ SpreadJsObj.loadSheetData(bonusSheet, SpreadJsObj.DataType.Data, bonusObj.data);
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!readOnly) {
|
|
|
+ const bonusOprObj = {
|
|
|
+ /**
|
|
|
+ * 删除按钮响应事件
|
|
|
+ * @param sheet
|
|
|
+ */
|
|
|
+ deletePress: function (sheet) {
|
|
|
+ if (!sheet.zh_setting || readOnly) return;
|
|
|
+
|
|
|
+ const sortData = sheet.zh_data;
|
|
|
+ const datas = [];
|
|
|
+ const sels = sheet.getSelections();
|
|
|
+ if (!sels || !sels[0]) return;
|
|
|
+ const hint = {
|
|
|
+ name: {type: 'warning', msg: '名称不能为空,如需删除甲供材料请使用右键删除'},
|
|
|
+ };
|
|
|
+
|
|
|
+ for (let iRow = sels[0].row; iRow < sels[0].row + sels[0].rowCount; iRow++) {
|
|
|
+ let bDel = false;
|
|
|
+ const node = sortData[iRow];
|
|
|
+ if (node) {
|
|
|
+ const data = {id: node.id};
|
|
|
+ for (let iCol = sels[0].col; iCol < sels[0].col + sels[0].colCount; iCol++) {
|
|
|
+ const colSetting = sheet.zh_setting.cols[iCol];
|
|
|
+ if (colSetting.field === 'name') {
|
|
|
+ toastMessageUniq(hint.name);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const style = sheet.getStyle(iRow, iCol);
|
|
|
+ if (!style.locked) {
|
|
|
+ const colSetting = sheet.zh_setting.cols[iCol];
|
|
|
+ data[colSetting.field] = null;
|
|
|
+ bDel = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (bDel) {
|
|
|
+ datas.push(data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (datas.length > 0) {
|
|
|
+ postData(window.location.pathname + '/update', {updateType: 'update', updateData: datas}, function (result) {
|
|
|
+ bonusObj.loadUpdateData(result);
|
|
|
+ SpreadJsObj.reLoadSheetData(bonusSheet);
|
|
|
+ }, function () {
|
|
|
+ SpreadJsObj.reLoadSheetData(bonusSheet);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ delete: function () {
|
|
|
+ const sheet = bonusSheet;
|
|
|
+ if (!sheet.zh_setting || readOnly) return;
|
|
|
+
|
|
|
+ const sortData = sheet.zh_data;
|
|
|
+ const datas = [];
|
|
|
+ const sels = sheet.getSelections();
|
|
|
+ if (!sels || !sels[0]) return;
|
|
|
+ const hint = {
|
|
|
+ isOld: {type: 'warning', msg: '本项为往期数据,不可删除'},
|
|
|
+ invalidDel: {type: 'warning', msg: '本项不是您新增的,只有原报和新增人可删除'},
|
|
|
+ };
|
|
|
+
|
|
|
+ for (let iRow = sels[0].row, iLen = sels[0].row + sels[0].rowCount; iRow < iLen; iRow++) {
|
|
|
+ const node = sortData[iRow];
|
|
|
+ if (node.sid !== stageID) {
|
|
|
+ toastMessageUniq(hint.isOld);
|
|
|
+ continue;
|
|
|
+ } else {
|
|
|
+ if (node.uid !== userID || stageUserId !== userID) {
|
|
|
+ toastMessageUniq(hint.invalidDel);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ datas.push(node.id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (datas.length > 0) {
|
|
|
+ postData(window.location.pathname + '/update', {del: datas}, function (result) {
|
|
|
+ bonusObj.loadUpdateData(result);
|
|
|
+ SpreadJsObj.reLoadSheetData(sheet);
|
|
|
+ }, function () {
|
|
|
+ SpreadJsObj.reLoadSheetData(sheet);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ editEnded: function (e, info) {
|
|
|
+ if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
|
|
|
+
|
|
|
+ const node = info.sheet.zh_data[info.row];
|
|
|
+ const col = info.sheet.zh_setting.cols[info.col];
|
|
|
+ const data = {};
|
|
|
+
|
|
|
+ if (node) {
|
|
|
+ data.update = {};
|
|
|
+ data.update.id = node.id;
|
|
|
+
|
|
|
+ const oldValue = node ? node[col.field] : null;
|
|
|
+ const newValue = trimInvalidChar(info.editingText);
|
|
|
+ if (oldValue == info.editingText || ((!oldValue || oldValue === '') && (newValue === ''))) {
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ data.update[col.field] = newValue;
|
|
|
+ } else {
|
|
|
+ if (col.field !== 'name') {
|
|
|
+ toastr.warning('新增奖罚金,请先输入名称');
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ data.add = {};
|
|
|
+ data.add.order = bonusObj.getCurStageNewOrder();
|
|
|
+ data.add.name = trimInvalidChar(info.editingText);
|
|
|
+ }
|
|
|
+
|
|
|
+ postData(window.location.pathname + '/update', data, function (result) {
|
|
|
+ bonusObj.loadUpdateData(result);
|
|
|
+ SpreadJsObj.reLoadSheetData(info.sheet);
|
|
|
+ }, function () {
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ clipboardPasting(e, info) {
|
|
|
+ const setting = info.sheet.zh_setting, sortData = info.sheet.zh_data;
|
|
|
+ info.cancel = true;
|
|
|
+
|
|
|
+ if (!setting || !sortData) return;
|
|
|
+ const pasteData = info.pasteData.html
|
|
|
+ ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
|
|
|
+ : (info.pasteData.text === ''
|
|
|
+ ? SpreadJsObj.Clipboard.getAnalysisPasteText()
|
|
|
+ : SpreadJsObj.analysisPasteText(info.pasteData.text));
|
|
|
+ const hint = {
|
|
|
+ name: {type: 'warning', msg: '奖罚金名称不可为空,已过滤'},
|
|
|
+ tp: {type: 'warning', msg: '输入的 金额 非法,已过滤'},
|
|
|
+ };
|
|
|
+
|
|
|
+ const uDatas = [], iDatas = [], maxOrder = bonusObj.getCurStageNewOrder();
|
|
|
+ for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
|
|
|
+ const curRow = info.cellRange.row + iRow;
|
|
|
+ const node = sortData[curRow];
|
|
|
+
|
|
|
+ let bPaste = false;
|
|
|
+ const data = {};
|
|
|
+ for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
|
|
|
+ const curCol = info.cellRange.col + iCol;
|
|
|
+ const colSetting = setting.cols[curCol];
|
|
|
+ const value = trimInvalidChar(pasteData[iRow][iCol]);
|
|
|
+
|
|
|
+ if (colSetting.field === 'name' && (!value || value === '')) {
|
|
|
+ toastMessageUniq(hint.name);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (colSetting.type === 'Number') {
|
|
|
+ const num = _.toNumber(value);
|
|
|
+ if (num) {
|
|
|
+ data[colSetting.field] = num;
|
|
|
+ bPaste = true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ data[colSetting.field] = value;
|
|
|
+ bPaste = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (bPaste) {
|
|
|
+ if (node) {
|
|
|
+ data.id = node.id;
|
|
|
+ uDatas.push(data);
|
|
|
+ } else {
|
|
|
+ data.order = maxOrder + iRow;
|
|
|
+ iDatas.push(data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const updateData = {};
|
|
|
+ if (uDatas.length > 0) updateData.update = uDatas;
|
|
|
+ if (iDatas.length > 0) updateData.add = iDatas;
|
|
|
+ if (uDatas.length > 0 || iDatas.length > 0) {
|
|
|
+ postData(window.location.pathname + '/update', updateData, function (result) {
|
|
|
+ bonusObj.loadUpdateData(result);
|
|
|
+ SpreadJsObj.reLoadSheetData(info.sheet);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ SpreadJsObj.reLoadSheetData(info.sheet);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ upMove: function () {
|
|
|
+ const sheet = bonusSheet;
|
|
|
+ const sels = sheet.getSelections(), sortData = sheet.zh_data;
|
|
|
+ const node = sortData[sels[0].row];
|
|
|
+ const preNode = sortData[sels[0].row - 1];
|
|
|
+ const data = [
|
|
|
+ {id: node.id, order: preNode.order},
|
|
|
+ {id: preNode.id, order: node.order}
|
|
|
+ ];
|
|
|
+ postData(window.location.pathname + '/update', {update: data}, function (result) {
|
|
|
+ bonusObj.loadUpdateData(result);
|
|
|
+ SpreadJsObj.reLoadRowsData(sheet, [sels[0].row, sels[0].row - 1]);
|
|
|
+ sheet.setSelection(sels[0].row - 1, sels[0].col, sels[0].rowCount, sels[0].colCount);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ downMove: function () {
|
|
|
+ const sheet = bonusSheet;
|
|
|
+ const sels = sheet.getSelections(), sortData = sheet.zh_data;
|
|
|
+ const node = sortData[sels[0].row];
|
|
|
+ const nextNode = sortData[sels[0].row + 1];
|
|
|
+ const data = [
|
|
|
+ {id: node.id, order: nextNode.order},
|
|
|
+ {id: nextNode.id, order: node.order}
|
|
|
+ ];
|
|
|
+ postData(window.location.pathname + '/update', {update: data}, function (result) {
|
|
|
+ bonusObj.loadUpdateData(result);
|
|
|
+ SpreadJsObj.reLoadRowsData(sheet, [sels[0].row, sels[0].row + 1]);
|
|
|
+ sheet.setSelection(sels[0].row + 1, sels[0].col, sels[0].rowCount, sels[0].colCount);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ bonusSheet.bind(spreadNS.Events.EditEnded, bonusOprObj.editEnded);
|
|
|
+ bonusSheet.bind(spreadNS.Events.ClipboardPasting, bonusOprObj.clipboardPasting);
|
|
|
+ SpreadJsObj.addDeleteBind(bonusSpread, bonusOprObj.deletePress);
|
|
|
+ $.contextMenu({
|
|
|
+ selector: '#bonus-spread',
|
|
|
+ build: function ($trigger, e) {
|
|
|
+ const target = SpreadJsObj.safeRightClickSelection($trigger, e, bonusSpread);
|
|
|
+ return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
|
|
|
+ },
|
|
|
+ items: {
|
|
|
+ del: {
|
|
|
+ name: '删除',
|
|
|
+ icon: 'fa-remove',
|
|
|
+ callback: function (key, opt) {
|
|
|
+ bonusOprObj.delete();
|
|
|
+ },
|
|
|
+ disabled: function (key, opt) {
|
|
|
+ const sels = bonusSheet.getSelections();
|
|
|
+ if (!sels || !sels[0]) return true;
|
|
|
+
|
|
|
+ const row = sels[0].row;
|
|
|
+ const node = bonusObj.data[row];
|
|
|
+ return node === undefined || node === null || node.sid !== stageId;
|
|
|
+ },
|
|
|
+ visible: function (key, opt) {
|
|
|
+ return !readOnly;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ sprDel: '------------',
|
|
|
+ upMove: {
|
|
|
+ name: '上移',
|
|
|
+ icon: 'fa-arrow-up',
|
|
|
+ callback: function (key, opt) {
|
|
|
+ bonusOprObj.upMove();
|
|
|
+ },
|
|
|
+ disabled: function (key, opt) {
|
|
|
+ const sels = bonusSheet.getSelections();
|
|
|
+ if (!sels || !sels[0] || sels[0].row === 0) return true;
|
|
|
+
|
|
|
+ const row = sels[0].row;
|
|
|
+ const node = bonusObj.data[row];
|
|
|
+ return node === undefined || node === null || node.sid !== stageId || bonusObj.checkCurFirst(node);
|
|
|
+ },
|
|
|
+ visible: function (key, opt) {
|
|
|
+ return !readOnly;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ downMove: {
|
|
|
+ name: '下移',
|
|
|
+ icon: 'fa-arrow-down',
|
|
|
+ callback: function (key, opt) {
|
|
|
+ bonusOprObj.downMove();
|
|
|
+ },
|
|
|
+ disabled: function (key, opt) {
|
|
|
+ const sels = bonusSheet.getSelections();
|
|
|
+ if (!sels || !sels[0] || sels[0].row >= bonusObj.data.length - 1) return true;
|
|
|
+
|
|
|
+ const row = sels[0].row;
|
|
|
+ const node = bonusObj.data[row];
|
|
|
+ return node === undefined || node === null || node.sid !== stageId || bonusObj.checkCurLast(node);
|
|
|
+ },
|
|
|
+ visible: function (key, opt) {
|
|
|
+ return !readOnly;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|