| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463 | 
							- 'use strict';
 
- /**
 
-  * 期 - 甲供材料
 
-  *
 
-  * @author Mai
 
-  * @date 2020/2/12
 
-  * @version
 
-  */
 
- $(document).ready(() => {
 
-     autoFlashHeight();
 
-     const spreadSetting = {
 
-         cols: [
 
-             {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
 
-             {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', cellType: 'unit'},
 
-             {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
 
-             {title: '本期到场|数量',  colSpan: '2|1', rowSpan: '1|1', field: 'arrive_qty', hAlign: 2, width: 60, type: 'Number'},
 
-             {title: '|金额',  colSpan: '|1', rowSpan: '|1', field: 'arrive_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},
 
-             {title: '截止本期到场|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_arrive_qty', hAlign: 2, width: 60, type: 'Number', readOnly: true},
 
-             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_arrive_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},
 
-             {title: '本期扣回|数量', colSpan: '2|1', rowSpan: '1|1', field: 'deduct_qty', hAlign: 2, width: 60, type: 'Number'},
 
-             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'deduct_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},
 
-             {title: '截止本期扣回|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_deduct_qty', hAlign: 2, width: 60, type: 'Number', readOnly: true},
 
-             {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_deduct_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},
 
-             {title: '材料来源', colSpan: '1', rowSpan: '2', field: 'source', hAlign: 0, width: 80, formatter: '@'},
 
-             {title: '单据号', colSpan: '1', rowSpan: '2', field: 'bills_code', hAlign: 0, width: 80, formatter: '@'},
 
-             {title: '检验单编号', colSpan: '1', rowSpan: '2', field: 'check_code', hAlign: 0, width: 80, formatter: '@'},
 
-             {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'}
 
-         ],
 
-         emptyRows: readOnly ? 0 : 3,
 
-         headRows: 2,
 
-         headRowHeight: [25, 25],
 
-         defaultRowHeight: 21,
 
-         headerFont: '12px 微软雅黑',
 
-         font: '12px 微软雅黑',
 
-         readOnly: readOnly,
 
-         getColor: function (sheet, data, row, col, defaultColor) {
 
-             if (data) {
 
-                 if (data.end_deduct_tp) {
 
-                     return data.end_deduct_qty >= 0
 
-                         ? data.end_deduct_qty > data.end_arrive_qty ? '#f8d7da' : defaultColor
 
-                         : data.end_deduct_qty < data.end_arrive_qty ? '#f8d7da' : defaultColor;
 
-                 } else {
 
-                     return defaultColor;
 
-                 }
 
-             } else {
 
-                 return defaultColor;
 
-             }
 
-         },
 
-     };
 
-     const jgclSpread = SpreadJsObj.createNewSpread($('#jgcl-spread')[0]);
 
-     const jgclSheet = jgclSpread.getActiveSheet();
 
-     SpreadJsObj.initSheet(jgclSheet, spreadSetting);
 
-     $.subMenu({
 
-         menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
 
-         toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
 
-         key: 'menu.1.0.0',
 
-         miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
 
-         callback: function (info) {
 
-             if (info.mini) {
 
-                 $('.panel-title').addClass('fluid');
 
-                 $('#sub-menu').removeClass('panel-sidebar');
 
-             } else {
 
-                 $('.panel-title').removeClass('fluid');
 
-                 $('#sub-menu').addClass('panel-sidebar');
 
-             }
 
-             autoFlashHeight();
 
-             jgclSpread.refresh();
 
-         }
 
-     });
 
-     class Jgcl {
 
-         constructor () {
 
-             this.data = [];
 
-         }
 
-         resortData() {
 
-             this.data.sort(function (a, b) {
 
-                 return a.order - b.order;
 
-             });
 
-         }
 
-         calculateAll() {
 
-             for (const d of this.data) {
 
-                 d.end_arrive_qty = ZhCalc.add(d.pre_arrive_qty, d.arrive_qty);
 
-                 d.end_arrive_tp = ZhCalc.add(d.pre_arrive_tp, d.arrive_tp);
 
-                 d.end_deduct_qty = ZhCalc.add(d.pre_deduct_qty, d.deduct_qty);
 
-                 d.end_deduct_tp = ZhCalc.add(d.pre_deduct_tp, d.deduct_tp);
 
-             }
 
-         }
 
-         loadDatas(datas) {
 
-             this.data = datas;
 
-             this.calculateAll();
 
-             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.calculateAll();
 
-             this.resortData();
 
-         }
 
-         sum () {
 
-             const result = {
 
-                 arrive_tp: 0,
 
-                 end_arrive_tp: 0,
 
-                 deduct_tp: 0,
 
-                 end_deduct_tp: 0,
 
-             };
 
-             for (const d of this.data) {
 
-                 result.arrive_tp = ZhCalc.add(result.arrive_tp, d.arrive_tp);
 
-                 result.end_arrive_tp = ZhCalc.add(result.end_arrive_tp, d.end_arrive_tp);
 
-                 result.deduct_tp = ZhCalc.add(result.deduct_tp, d.deduct_tp);
 
-                 result.end_deduct_tp = ZhCalc.add(result.end_deduct_tp, d.end_deduct_tp);
 
-             }
 
-             return result;
 
-         }
 
-     }
 
-     const jgclObj = new Jgcl();
 
-     const refreshSum = function () {
 
-         const sum = jgclObj.sum();
 
-         const html = [];
 
-         const getTrHtml = function (name, value) {
 
-             return '<tr><td>' + name + '</td><td class="text-right">' + (!checkZero(value) ? value : '') + ' </td></tr>';
 
-         };
 
-         html.push(getTrHtml('本期到场', sum.arrive_tp));
 
-         html.push(getTrHtml('截止本期到场', sum.end_arrive_tp));
 
-         html.push(getTrHtml('本期扣回', sum.deduct_tp));
 
-         html.push(getTrHtml('截止本期扣回', sum.end_deduct_tp));
 
-         /*html.push('本期到场:' + sum.arrive_tp + ';');
 
-         html.push('截止本期到场:' + sum.end_arrive_tp + ';');
 
-         html.push('本期扣回:' + sum.deduct_tp + ';');
 
-         html.push('截止本期扣回:' + sum.end_deduct_tp + ';');*/
 
-         $('#sum').html(html.join(' '));
 
-     };
 
-     postData(window.location.pathname + '/load', null, function (result) {
 
-         jgclObj.loadDatas(result);
 
-         SpreadJsObj.loadSheetData(jgclSheet, SpreadJsObj.DataType.Data, jgclObj.data);
 
-         refreshSum();
 
-     });
 
-     if (!readOnly) {
 
-         const jgclOprObj = {
 
-             /**
 
-              * 删除按钮响应事件
 
-              * @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;
 
-                 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') {
 
-                                 toastr.error('名称不能为空,如需删除甲供材料请使用右键删除');
 
-                                 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', {update: datas}, function (result) {
 
-                         jgclObj.loadUpdateData(result);
 
-                         SpreadJsObj.reLoadSheetData(jgclSheet);
 
-                         refreshSum();
 
-                     }, function () {
 
-                         SpreadJsObj.reLoadSheetData(jgclSheet);
 
-                     });
 
-                 }
 
-             },
 
-             deleteJgcl: 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 = {
 
-                     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.pre_used) {
 
-                         toastMessageUniq(hint.isOld);
 
-                         continue;
 
-                     } else {
 
-                         if (node.add_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) {
 
-                         jgclObj.loadUpdateData(result);
 
-                         SpreadJsObj.reLoadSheetData(jgclSheet);
 
-                         refreshSum();
 
-                     }, function () {
 
-                         SpreadJsObj.reLoadSheetData(jgclSheet);
 
-                     });
 
-                 }
 
-             },
 
-             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 = info.row + 1;
 
-                     data.add.name = trimInvalidChar(info.editingText);
 
-                 }
 
-                 postData(window.location.pathname + '/update', data, function (result) {
 
-                     jgclObj.loadUpdateData(result);
 
-                     SpreadJsObj.reLoadSheetData(info.sheet);
 
-                     refreshSum();
 
-                 }, function () {
 
-                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                 });
 
-             },
 
-             editStarting(e, info) {
 
-                 if (!info.sheet.zh_setting || !info.sheet.zh_data) {
 
-                     info.cancel = true;
 
-                     return;
 
-                 }
 
-                 const col = info.sheet.zh_setting.cols[info.col];
 
-                 const node = info.sheet.zh_data[info.row];
 
-                 if (!node) return;
 
-                 switch (col.field) {
 
-                     case 'name':
 
-                     case 'unit':
 
-                     case 'unit_price':
 
-                         info.cancel = readOnly || node.pre_used;
 
-                         break;
 
-                 }
 
-             },
 
-             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: '甲供材料名称不可为空,已过滤'},
 
-                     unit_price: {type: 'warning', msg: '输入的 单价 非法,已过滤'},
 
-                     arrive_qty: {type: 'warning', msg: '输入的 本期到场-数量 非法,已过滤'},
 
-                     reduce_qty: {type: 'warning', msg: '输入的 本期扣回-数量 非法,已过滤'},
 
-                 };
 
-                 const uDatas = [], iDatas = [];
 
-                 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 = curRow + 1;
 
-                             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) {
 
-                         jgclObj.loadUpdateData(result);
 
-                         SpreadJsObj.reLoadSheetData(info.sheet);
 
-                         refreshSum();
 
-                     });
 
-                 } else {
 
-                     SpreadJsObj.reLoadSheetData(info.sheet);
 
-                 }
 
-             },
 
-             upMove: function () {
 
-                 const sels = jgclSheet.getSelections(), sortData = jgclSheet.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) {
 
-                     jgclObj.loadUpdateData(result);
 
-                     SpreadJsObj.reLoadRowsData(jgclSheet, [sels[0].row, sels[0].row - 1]);
 
-                     jgclSheet.setSelection(sels[0].row - 1, sels[0].col, sels[0].rowCount, sels[0].colCount);
 
-                 });
 
-             },
 
-             downMove: function () {
 
-                 const sels = jgclSheet.getSelections(), sortData = jgclSheet.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) {
 
-                     jgclObj.loadUpdateData(result);
 
-                     SpreadJsObj.reLoadRowsData(jgclSheet, [sels[0].row, sels[0].row + 1]);
 
-                     jgclSheet.setSelection(sels[0].row + 1, sels[0].col, sels[0].rowCount, sels[0].colCount);
 
-                 });
 
-             }
 
-         };
 
-         jgclSheet.bind(spreadNS.Events.EditEnded, jgclOprObj.editEnded);
 
-         jgclSheet.bind(spreadNS.Events.EditStarting, jgclOprObj.editStarting);
 
-         jgclSheet.bind(spreadNS.Events.ClipboardPasting, jgclOprObj.clipboardPasting);
 
-         SpreadJsObj.addDeleteBind(jgclSpread, jgclOprObj.deletePress);
 
-         $.contextMenu({
 
-             selector: '#jgcl-spread',
 
-             build: function ($trigger, e) {
 
-                 const target = SpreadJsObj.safeRightClickSelection($trigger, e, jgclSpread);
 
-                 return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
 
-             },
 
-             items: {
 
-                 del: {
 
-                     name: '删除',
 
-                     icon: 'fa-remove',
 
-                     callback: function (key, opt) {
 
-                         jgclOprObj.deleteJgcl(jgclSheet);
 
-                     },
 
-                     disabled: function (key, opt) {
 
-                         const sels = jgclSheet.getSelections();
 
-                         if (!sels || !sels[0]) return true;
 
-                         const row = sels[0].row;
 
-                         const node = jgclObj.data[row];
 
-                         return node === undefined || node === null;
 
-                     },
 
-                     visible: function (key, opt) {
 
-                         return !readOnly;
 
-                     }
 
-                 },
 
-                 sprDel: '------------',
 
-                 upMove: {
 
-                     name: '上移',
 
-                     icon: 'fa-arrow-up',
 
-                     callback: function (key, opt) {
 
-                         jgclOprObj.upMove();
 
-                     },
 
-                     disabled: function (key, opt) {
 
-                         const sels = jgclSheet.getSelections();
 
-                         if (!sels || !sels[0] || sels[0].row === 0) return true;
 
-                         const row = sels[0].row;
 
-                         const node = jgclObj.data[row];
 
-                         return node === undefined || node === null;
 
-                     },
 
-                     visible: function (key, opt) {
 
-                         return !readOnly;
 
-                     }
 
-                 },
 
-                 downMove: {
 
-                     name: '下移',
 
-                     icon: 'fa-arrow-down',
 
-                     callback: function (key, opt) {
 
-                         jgclOprObj.downMove();
 
-                     },
 
-                     disabled: function (key, opt) {
 
-                         const sels = jgclSheet.getSelections();
 
-                         if (!sels || !sels[0] || sels[0].row >= jgclObj.data.length - 1) return true;
 
-                         const row = sels[0].row;
 
-                         const node = jgclObj.data[row];
 
-                         return node === undefined || node === null;
 
-                     },
 
-                     visible: function (key, opt) {
 
-                         return !readOnly;
 
-                     }
 
-                 }
 
-             },
 
-         })
 
-     }
 
- });
 
 
  |