123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245 |
- 'use strict';
- /**
- * 变更令详细页js
- *
- * @author EllisRan.
- * @date 2018/11/22
- * @version
- */
- // 编号排序,多重判断
- function sortByCode(a, b) {
- let code1 = a.code.split('-');
- let code2 = b.code.split('-');
- let code1length = code1.length;
- let code2length = code2.length;
- for (let i = 0; i < code1length; i ++) {
- if (i+1 <= code2length) {
- if (code1[i] != code2[i]) {
- if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
- return parseInt(code1[i]) - parseInt(code2[i]);
- } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
- return 1;
- } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
- return -1;
- } else {
- const str1length = code1[i].length;
- const str2length = code2[i].length;
- for (let j = 0; j < str1length; j++) {
- if (j+1 <= str2length) {
- if (code1[i].charAt(j) != code2[i].charAt(j)) {
- return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
- } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
- if (str1length == str2length) {
- return 0;
- } else {
- return str1length - str2length;
- }
- }
- } else {
- if (j+1 >= str1length) {
- return 1;
- } else {
- return -1;
- }
- }
- }
- }
- } else if (i+1 == code1length && code1[i] == code2[i]) {
- if (code1length == code2length) {
- return 0;
- } else {
- return code1length - code2length;
- }
- }
- } else {
- if (i+1 >= code1length) {
- return 1;
- } else {
- return -1;
- }
- }
- }
- }
- $.event.special.valuechange = {
- teardown: function (namespaces) {
- $(this).unbind('.valuechange');
- },
- handler: function (e) {
- $.event.special.valuechange.triggerChanged($(this));
- },
- add: function (obj) {
- $(this).on('keyup.valuechange cut.valuechange paste.valuechange input.valuechange', obj.selector, $.event.special.valuechange.handler)
- },
- triggerChanged: function (element) {
- var current = element[0].contentEditable === 'true' ? element.html() : element.val()
- , previous = typeof element.data('previous') === 'undefined' ? element[0].defaultValue : element.data('previous');
- if (current !== previous) {
- element.trigger('valuechange', [element.data('previous')]);
- element.data('previous', current);
- }
- }
- };
- function getPasteHint (str, row = '') {
- let returnObj = str;
- if (row) {
- returnObj.msg = '清单第' + (row+1) + '行' + str.msg;
- }
- return returnObj;
- }
- $(document).ready(() => {
- const changeSpreadSetting = {
- cols: [
- {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit2'},
- {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit2'},
- {title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
- {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: false},
- {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit2', cellType: 'unit', comboItems: changeUnits, comboEdit: true},
- {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit2', getValue: 'getValue.unit_price'},
- {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.oamount'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
- {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: false, getValue: 'getValue.camount'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
- {title: '操作', colSpan: '1', rowSpan: '2', field: 'del_list', hAlign: 1, width: 40, readOnly: true, cellType: 'mouseTouch', getValue: 'getValue.del_list'},
- ],
- emptyRows: 0,
- headRows: 2,
- headRowHeight: [25, 25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: readOnly,
- rowHeader:[
- {
- rowHeaderType: 'circle',
- setting: {
- size: 5,
- indent: 16,
- getColor: function (index, data) {
- if (!data) return;
- if(data.lid != 0) return;
- return '#007bff';
- }
- },
- },
- ],
- localCache: {
- key: 'changes-spread',
- colWidth: true,
- }
- };
- const changeCol = {
- getValue: {
- unit_price: function(data) {
- return ZhCalc.round(data.unit_price, unitPriceUnit);
- },
- oa_tp: function (data) {
- return ZhCalc.round(ZhCalc.mul(data.unit_price, data.oamount), totalPriceUnit);
- },
- ca_tp: function (data) {
- return ZhCalc.round(ZhCalc.mul(data.unit_price, data.camount), totalPriceUnit);
- },
- oamount: function (data) {
- return ZhCalc.round(data.oamount, findDecimal(data.unit));
- },
- camount: function (data) {
- return ZhCalc.round(data.camount, findDecimal(data.unit));
- },
- del_list: function (data) {
- return !_.find(changeUsedData, { id: data.id }) ? '移除' : '';
- }
- },
- readOnly: {
- isEdit: function (data) {
- return !readOnly && data.lid != 0;
- },
- isEdit2: function (data) {
- return !readOnly && (data.lid != 0 || (data.lid == 0 && _.findIndex(changeUsedData, { id: data.id }) !== -1));
- },
- },
- };
- const changeSpreadObj = {
- makeSjsFooter: function () {
- // 增加汇总行并设为锁定禁止编辑状态
- changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
- changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
- changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
- changeSpreadObj.countSum();
- },
- countSum: function() {
- const rowCount = changeSpreadSheet.getRowCount();
- let oSum = 0,
- cSum = 0;
- for(var i = 0; i < rowCount - 1; i++){
- oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 7));
- cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 9));
- }
- changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, oSum !== 0 ? oSum : null);
- changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 9, cSum !== 0 ? cSum : null);
- },
- add: function () {
- postData(window.location.pathname + '/save', {type: 'add'}, function (result) {
- if (result) {
- changeList.push(result);
- changeSpreadSheet.addRows(changeList.length - 1, 1);
- SpreadJsObj.reLoadRowData(changeSpreadSheet, changeList.length - 1);
- changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
- changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
- changeSpreadObj.resetXmjSpread();
- }
- });
- },
- batchAdd: function(num) {
- postData(window.location.pathname + '/save', {type: 'batchadd', num}, function (result) {
- if (result) {
- changeList = _.concat(changeList, result);
- SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
- changeSpreadObj.makeSjsFooter();
- changeSpreadObj.resetXmjSpread();
- }
- });
- },
- del: function () {
- const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
- const index = changeList.indexOf(select);
- if (index > -1 && !_.find(changeUsedData, { id: select.id })) {
- postData(window.location.pathname + '/save', {type: 'del', id: select.id}, function (result) {
- changeList.splice(index, 1);
- changeSpreadSheet.deleteRows(index, 1);
- const sel = changeSpreadSheet.getSelections();
- changeSpreadSheet.setSelection(0, 0, 1, 1);
- changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
- if (select.lid != 0) {
- tableDataRemake(changeListData);
- }
- changeSpreadObj.countSum();
- });
- }
- },
- resetXmjSpread: function(data = null) {
- const xmj = [];
- if (data && data.lid != 0 && data.xmj_code !== '' && data.xmj_code !== null) {
- const newData = JSON.parse(JSON.stringify(data));
- if (newData.bwmx === newData.xmj_jldy) {
- newData.bwmx = '';
- }
- xmj.push(newData);
- }
- SpreadJsObj.loadSheetData(xmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, xmj);
- },
- selectionChanged: function (e, info) {
- const sel = info.sheet.getSelections()[0];
- const col = info.sheet.zh_setting.cols[sel.col];
- const data = SpreadJsObj.getSelectObject(info.sheet);
- if (col && col.field === 'del_list' && !_.find(changeUsedData, { id: data.id })) {
- changeSpreadObj.del();
- }
- changeSpreadObj.resetXmjSpread(data);
- },
- deletePress: function (sheet) {
- return;
- },
- editEnded: function (e, info) {
- if (info.sheet.zh_setting) {
- const select = SpreadJsObj.getSelectObject(info.sheet);
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field === 'del_list') {
- return;
- }
- // 未改变值则不提交
- let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
- const orgValue = select[col.field];
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- // 判断部分值是否输入的是数字判断和数据计算
- if (col.type === 'Number') {
- if (isNaN(validText)) {
- toastr.error('不能输入其它非数字类型字符');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if (col.field === 'unit_price') {
- validText = ZhCalc.round(validText, unitPriceUnit);
- } else {
- validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- }
- }
- if (col.field === 'unit') {
- select.camount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
- select.oamount = ZhCalc.round(select.oamount, findDecimal(validText)) || 0;
- }
- if(col.field === 'camount') {
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { id: select.id });
- if (usedInfo && usedInfo.used_qty >= 0 && validText < usedInfo.used_qty) {
- toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.used_qty);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (usedInfo && usedInfo.used_qty < 0 && validText > usedInfo.used_qty) {
- toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.used_qty);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- }
- select[col.field] = validText;
- console.log(select);
- delete select.waitingLoading;
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
- changeList.splice(info.row, 1, select);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- changeSpreadObj.countSum();
- }, function () {
- select[col.field] = orgValue;
- if(col.field === 'camount') {
- select.spamount = orgValue;
- }
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- }
- },
- clipboardPasted(e, info) {
- const hint = {
- cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
- numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
- };
- const range = info.cellRange;
- const sortData = info.sheet.zh_data || [];
- if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
- toastMessageUniq(hint.cellError);
- // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
- SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
- SpreadJsObj.reLoadSheetData(changeSpreadSheet);
- changeSpreadObj.makeSjsFooter();
- return;
- }
- if (sortData.length > 0 && range.col + range.colCount > 10) {
- toastMessageUniq(hint.cellError);
- SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
- SpreadJsObj.reLoadSheetData(changeSpreadSheet);
- changeSpreadObj.makeSjsFooter();
- return;
- }
- const data = [];
- // const rowData = [];
- for (let iRow = 0; iRow < range.rowCount; iRow++) {
- let bPaste = true;
- const curRow = range.row + iRow;
- // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
- const cLData = { id: sortData[curRow].id };
- const hintRow = range.rowCount > 1 ? curRow : '';
- let sameCol = 0;
- for (let iCol = 0; iCol < range.colCount; iCol++) {
- const curCol = range.col + iCol;
- const colSetting = info.sheet.zh_setting.cols[curCol];
- if (!colSetting) continue;
- let validText = info.sheet.getText(curRow, curCol);
- validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
- const orgValue = sortData[curRow][colSetting.field];
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
- sameCol++;
- if (range.colCount === sameCol) {
- bPaste = false;
- }
- continue;
- }
- if (colSetting.type === 'Number') {
- if (isNaN(validText)) {
- toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
- bPaste = false;
- continue;
- }
- if (colSetting.field === 'unit_price') {
- validText = ZhCalc.round(validText, unitPriceUnit);
- } else {
- validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
- }
- if(colSetting.field === 'camount') {
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { id: sortData[curRow].id });
- if (usedInfo && usedInfo.used_qty >= 0 && validText < usedInfo.used_qty) {
- toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.used_qty);
- bPaste = false;
- continue;
- } else if (usedInfo && usedInfo.used_qty < 0 && validText > usedInfo.used_qty) {
- toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.used_qty);
- bPaste = false;
- continue;
- }
- }
- }
- let unitdecimal = validText;
- if (colSetting.field === 'unit') {
- //粘贴内容要为下拉列表里所有的单位,不然为空
- if (changeUnits.indexOf(validText) === -1) {
- unitdecimal = '';
- }
- cLData.camount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
- cLData.oamount = ZhCalc.round(sortData[curRow].oamount, findDecimal(unitdecimal)) || 0;
- }
- cLData[colSetting.field] = validText;
- sortData[curRow][colSetting.field] = validText;
- cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
- }
- if (bPaste) {
- data.push(cLData);
- // rowData.push(curRow);
- } else {
- SpreadJsObj.reLoadRowData(info.sheet, curRow);
- }
- }
- if (data.length === 0) {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- }
- console.log(data);
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
- changeList = result;
- SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
- changeSpreadObj.makeSjsFooter();
- changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- });
- },
- valueChanged(e, info) {
- // 防止ctrl+z撤销数据
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- }
- };
- const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
- let changeListData;
- let gclGatherData;
- postData(preUrl + '/defaultBills', {}, function (result) {
- gclGatherModel.loadLedgerData(result.bills);
- gclGatherModel.loadPosData(result.pos);
- gclGatherData = gclGatherModel.gatherGclData();
- gclGatherData = _.filter(gclGatherData, function (item) {
- return item.leafXmjs && item.leafXmjs.length !== 0;
- });
- for (const ggd in gclGatherData) {
- if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
- gclGatherData.splice(ggd, 1);
- }
- gclGatherData[ggd].code = gclGatherData[ggd].b_code;
- }
- // 数组去重
- const dealBillList = result.dealBills;
- for (const db of gclGatherData) {
- const exist_index = dealBillList.findIndex(function (item) {
- return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
- });
- if (exist_index !== -1) {
- dealBillList.splice(exist_index, 1);
- }
- }
- changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
- console.log(changeListData);
- // 先加载台账数据
- let listHtml = '';
- let list_index = 1;
- let gcl_index = 0;
- for (const gcl of changeListData) {
- const unit = gcl.unit !== undefined && gcl.unit !== null ? gcl.unit : '';
- const quantity = gcl.quantity !== 0 && gcl.quantity !== null && gcl.quantity !== undefined ? (unit !== '' ? ZhCalc.round(gcl.quantity, findDecimal(gcl.unit)) : gcl.quantity) : 0;
- const unit_price = gcl.unit_price !== null && gcl.unit_price !== undefined ? gcl.unit_price : 0;
- let gclhtml = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? ' data-gcl="' + gcl_index + '"' : '';
- gcl_index = gclhtml !== '' ? ++gcl_index : gcl_index;
- const lid = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? (gcl.leafXmjs.length !== 0 ? gcl.leafXmjs[0].gcl_id : false) : gcl.id;
- if (lid) {
- listHtml += '<tr data-lid="' + lid + '"' + gclhtml + ' data-index="' + list_index + '" data-bwmx="">' +
- '<td class="text-center">' + list_index + '</td>' +
- '<td>' + gcl.code + '</td>' +
- '<td class="text-left">' + gcl.name + '</td>' +
- '<td class="text-center">' + unit + '</td>' +
- '<td class="text-right">' + (ZhCalc.round(unit_price, unitPriceUnit) ? ZhCalc.round(unit_price, unitPriceUnit) : 0) + '</td>' +
- '<td class="text-right">' + quantity + '</td>' +
- '</tr>';
- list_index++;
- }
- }
- $('#table-list-select').html(listHtml);
- tableDataRemake(changeListData);
- SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
- SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
- SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
- // changeSpreadSheet.options.protectionOptions = {
- // allowSort: true,
- // allowFilter: true
- // };
- // var option = changeSpreadSheet.options.protectionOptions;
- // changeSpreadSheet.rowFilter(new GC.Spread.Sheets.Filter.HideRowFilter(new GC.Spread.Sheets.Range(-1, 0, -1, changeSpreadSetting.cols.length)));
- // // changeSpreadSheet.rowFilter(new GC.Spread.Sheets.Filter.HideRowFilter(new GC.Spread.Sheets.Range(-1, 0, -1, 3)));
- // const filter = changeSpreadSheet.rowFilter();
- // filter.filterButtonVisible(false);
- // filter.filterButtonVisible(0, true);
- // filter.filterButtonVisible(2, true);
- // filter.filterDialogVisibleInfo({
- // sortByValue: true, //SortByValue item is visible.
- // sortByColor: false, //SortByColor item is visible.
- // filterByColor: false, //FilterByColor item is visible.
- // filterByValue: false, //FilterByValue item is visible.
- // listFilterArea: false //ListFilterArea item is visible.
- // });
- // function compareList(obj1, obj2) {
- // console.log(obj1, obj2);
- // var list = ["", '204-1-b', '合计'];
- // var index1 = list.indexOf(obj1), index2 = list.indexOf(obj2);
- // if (index1 > index2) {
- // return 1;
- // } else if (index1 < index2) {
- // return -1;
- // } else {
- // return 0;
- // }
- // }
- // changeSpreadSheet.sortRange(0, 0, changeSpreadSetting.cols.length, 1, true, [{index: 0, ascending: true, compareFunction: compareList}]);
- // changeSpreadSheet.bind(GC.Spread.Sheets.Events.RangeSorting, function (e, info) {
- // info.compareFunction = compareList;
- // });
- // filter.sortColumn(0, true);
- changeSpreadObj.makeSjsFooter();
- changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
- });
- if (!readOnly) {
- $('#add-white-btn').click(changeSpreadObj.add);
- changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
- changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
- changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
- changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
- SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
- changeSpreadSheet.getCell(-1, 10).foreColor('#dc3545');
- let batchInsertObj;
- $.contextMenu.types.batchInsert = function (item, opt, root) {
- const self = this;
- if ($.isFunction(item.icon)) {
- item._icon = item.icon.call(this, this, $t, key, item);
- } else {
- if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
- // to enable font awesome
- item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
- } else {
- item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
- }
- }
- this.addClass(item._icon);
- const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="100" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
- .appendTo(this);
- const $input = $obj.find('input');
- const event = () => {
- if (self.hasClass('context-menu-disabled')) return;
- item.batchInsert($input[0], root);
- };
- $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
- $input.click((e) => {e.stopPropagation();})
- .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
- .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
- };
- // 右键菜单
- $.contextMenu({
- selector: '#change-spread',
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
- return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
- },
- items: {
- 'createList': {
- name: '添加台账清单',
- icon: 'fa-sign-in',
- callback: function (key, opt) {
- $('#addlist').modal('show');
- },
- },
- 'createAdd': {
- name: '添加空白清单',
- icon: 'fa-sign-in',
- callback: function (key, opt) {
- changeSpreadObj.add(changeSpreadSheet);
- },
- },
- 'batchInsert': {
- name: '批量添加空白清单',
- type: 'batchInsert',
- value: '2',
- icon: 'fa-sign-in',
- batchInsert: function (obj, root) {
- if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
- obj.value = obj.max;
- toastr.warning('批量添加不可多于' + obj.max);
- } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
- obj.value = obj.min;
- toastr.warning('批量添加不可少于' + obj.min);
- } else {
- // treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
- changeSpreadObj.batchAdd(obj.value);
- root.$menu.trigger('contextmenu:hide');
- }
- },
- },
- 'delete': {
- name: '删除',
- icon: 'fa-remove',
- callback: function (key, opt) {
- changeSpreadObj.del(changeSpreadSheet);
- },
- disabled: function (key, opt) {
- const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
- const sel = changeSpreadSheet.getSelections()[0];
- changeSpreadObj.resetXmjSpread(select);
- console.log(select, sel);
- if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1 && !_.find(changeUsedData, { id: select.id })) {
- return false;
- } else {
- return true;
- }
- }
- },
- }
- });
- }
- // 清单选中和移除
- $('body').on('click', '#table-list-select tr', function () {
- $('#table-list-select tr').removeClass('table-warning');
- $(this).addClass('table-warning');
- const isCheck = $(this).hasClass('table-success') ? true : false;
- const data_bwmx = $(this).attr('data-bwmx').split('$#$');
- const isDeal = $(this).data('gcl') !== undefined ? true : false;
- let codeHtml = '<tr quantity="'+ $(this).children('td').eq(5).text() +'" gcl_id=""><td colspan="7" class="colspan_1"> </td><td class="colspan_2"><input type="checkbox"></td></tr>';
- if (isDeal) {
- const lid = $(this).data('lid');
- let gcl = _.find(gclGatherData, function (item) {
- return item.leafXmjs && item.leafXmjs[0].gcl_id === lid;
- });
- if (!gcl) {
- gcl = gclGatherData[$(this).data('gcl')];
- }
- codeHtml = '';
- for (const leaf of gcl.leafXmjs) {
- const quantity = leaf.quantity !== undefined && leaf.quantity !== null ? leaf.quantity : 0;
- const gcl_id = leaf.gcl_id ? leaf.gcl_id : '';
- const bwmx = leaf.bwmx !== undefined ? leaf.bwmx : (gcl.leafXmjs.length > 1 && gcl.name ? gcl.name : '');
- const isChecked = data_bwmx.indexOf(
- leaf.code + '!_!' + (leaf.jldy ? leaf.jldy : '') + '!_!' +
- (leaf.dwgc ? leaf.dwgc : '') + '!_!' + (leaf.fbgc ? leaf.fbgc : '') + '!_!' + (leaf.fxgc ? leaf.fxgc : '')
- + '!_!' + (leaf.gcl_id ? leaf.gcl_id : '0') + '!_!' +
- (bwmx !== '' ? bwmx : leaf.jldy ? leaf.jldy : '') + '*;*' + quantity) !== -1 && isCheck ?
- 'checked' : '';
- const isUsed = _.find(changeUsedData, { gcl_id: leaf.gcl_id, bwmx: (bwmx ? bwmx : leaf.jldy ? leaf.jldy : ''), oamount: leaf.quantity });
- const isDisabled = isUsed ? 'disabled ' : '';
- codeHtml += '<tr quantity="' + quantity + '" gcl_id="' + gcl_id + '"><td>' + leaf.code + '</td>' +
- '<td>' + (leaf.jldy ? leaf.jldy: '') + '</td>' +
- '<td>' + (leaf.dwgc ? leaf.dwgc : '') + '</td>' +
- '<td>' + (leaf.fbgc ? leaf.fbgc : '') + '</td>' +
- '<td>' + (leaf.fxgc ? leaf.fxgc : '') + '</td>' +
- '<td>' + bwmx + '</td>' +
- '<td class="text-right">' + (ZhCalc.round(quantity, findDecimal(gcl.unit)) ? ZhCalc.round(quantity, findDecimal(gcl.unit)) : 0) + '</td>' +
- '<td class="text-center"><input type="checkbox" ' + isDisabled + isChecked +
- '></td></tr>';
- }
- } else if (!isDeal && isCheck) {
- codeHtml = '<tr quantity="'+ $(this).children('td').eq(5).text() +'" gcl_id=""><td colspan="7" class="colspan_1"> </td><td class="colspan_2"><input type="checkbox" checked></td></tr>';
- }
- $('#code-list').attr('data-index', $(this).children('td').eq(0).text());
- $('#code-input').val('');
- $('#code-input').siblings('a').hide();
- $('#code-list').html(codeHtml);
- checkSelectAll();
- });
- // 右边项目节选择
- $('body').on('click', '#code-list input', function () {
- let index = $('#code-list').attr('data-index');
- if ($(this).is(':checked')) {
- // 去除其它可能已选的checked
- // $('#code-list input').prop('checked', false);
- $(this).prop('checked', true);
- // 左边表单传值并添加class
- $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
- // 去除部分data-detail值
- let data_bwmx = [];
- $('#code-list input:checked').each(function () {
- const tr = $(this).parents('tr');
- const length = tr.children('td').length;
- const gcl_id = tr.attr('gcl_id');
- const bwmx = length === 8 ?
- tr.children('td').eq(0).text() + '!_!' +
- tr.children('td').eq(1).text() + '!_!' +
- tr.children('td').eq(2).text() + '!_!' +
- tr.children('td').eq(3).text() + '!_!' +
- tr.children('td').eq(4).text() + '!_!' + gcl_id + '!_!' +
- (tr.children('td').eq(5).text() !== '' ? tr.children('td').eq(5).text() : tr.children('td').eq(1).text()) : '0';
- const quantity = tr.attr('quantity');
- const de_qu = bwmx + '*;*' + quantity;
- data_bwmx.push(de_qu);
- });
- data_bwmx = data_bwmx.join('$#$');
- $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
- } else {
- // 判断还有无选中项目节编号
- if ($('#code-list input').is(':checked')) {
- // 去除部分data-detail值
- let data_bwmx = [];
- $('#code-list input:checked').each(function () {
- const tr = $(this).parents('tr');
- const length = tr.children('td').length;
- const gcl_id = tr.attr('gcl_id');
- const bwmx = length === 8 ?
- tr.children('td').eq(0).text() + '!_!' +
- tr.children('td').eq(1).text() + '!_!' +
- tr.children('td').eq(2).text() + '!_!' +
- tr.children('td').eq(3).text() + '!_!' +
- tr.children('td').eq(4).text() + '!_!' + gcl_id + '!_!' +
- (tr.children('td').eq(5).text() !== '' ? tr.children('td').eq(5).text() : tr.children('td').eq(1).text()) : '0';
- const quantity = tr.attr('quantity');
- const de_qu = bwmx + '*;*' + quantity;
- data_bwmx.push(de_qu);
- });
- data_bwmx = data_bwmx.join('$#$');
- $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
- } else {
- $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
- $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
- }
- }
- checkSelectAll();
- });
- // 添加空白清单or签约清单
- $('.add-list-btn').on('click', function () {
- const newLedgerList = remakeChangeSpread();
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'ledger_list', updateData: newLedgerList }, function (result) {
- changeList = result.changeList;
- changeUsedData = result.usedList;
- SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
- changeSpreadObj.makeSjsFooter();
- const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
- changeSpreadObj.resetXmjSpread(select);
- $('#addlist').modal('hide');
- }, function () {
- $('#addlist').modal('hide');
- });
- });
- // 选中input所有值
- $('body').on('focus', ".clist input", function() {
- $(this).select();
- });
- // 取消选中清单
- $('#cancel-list-btn').click(function () {
- // $('#table-list-select tr').removeClass('table-success');
- // $('#table-list-select tr').attr('data-bwmx', '');
- // $('#code-list').html('');
- tableDataRemake(changeListData);
- });
- // 自动编号
- $('.reduction-code').click(function () {
- const code = $(this).attr('data-code');
- $('input[name="code"]').val(code);
- });
- $('#list-input').on('valuechange', function (e, previous) {
- const value = $(this).val();
- let showListData = changeListData;
- if (value !== '') {
- $(this).siblings('a').show();
- showListData = _.filter(changeListData, function (c) {
- return (c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1);
- });
- } else {
- $(this).siblings('a').hide();
- }
- makeListTable(changeListData, showListData);
- $('#table-list-select tr').removeClass('table-warning');
- $('#code-input').val('');
- $('#code-input').siblings('a').hide();
- $('#code-list').html('');
- $('#code-select-all').prop('checked', false);
- });
- $('#code-input').on('valuechange', function (e, previous) {
- const value = $(this).val();
- if (value !== '') {
- $(this).siblings('a').show();
- } else {
- $(this).siblings('a').hide();
- }
- makeCodeTable($(this).val());
- checkSelectAll();
- });
- $('.remove-btn').on('click', function () {
- $(this).hide();
- $(this).siblings('input').val('');
- if ($(this).data('btn') === 'list') {
- makeListTable(changeListData);
- $('#table-list-select tr').removeClass('table-warning');
- $('#code-list').html('');
- } else {
- makeCodeTable();
- }
- checkSelectAll();
- });
- // 全选及取消
- $('#code-select-all').click(function () {
- // 全选checkbox
- let index = $('#code-list').attr('data-index');
- if (index) {
- if ($(this).is(':checked')){
- $('#code-list tr').each(function () {
- if ($(this).css('display') !== 'none') {
- $(this).find('input').prop('checked', true);
- }
- })
- } else {
- $('#code-list tr').each(function () {
- if ($(this).css('display') !== 'none' && $(this).find('input').prop('disabled') !== true) {
- $(this).find('input').prop('checked', false);
- }
- });
- }
- // 判断还有无选中项目节编号
- if ($('#code-list input').is(':checked')) {
- // 去除部分data-detail值
- let data_bwmx = [];
- $('#code-list input:checked').each(function () {
- const tr = $(this).parents('tr');
- const length = tr.children('td').length;
- const gcl_id = tr.attr('gcl_id');
- const bwmx = length === 8 ?
- tr.children('td').eq(0).text() + '!_!' +
- tr.children('td').eq(1).text() + '!_!' +
- tr.children('td').eq(2).text() + '!_!' +
- tr.children('td').eq(3).text() + '!_!' +
- tr.children('td').eq(4).text() + '!_!' + gcl_id + '!_!' +
- (tr.children('td').eq(5).text() !== '' ? tr.children('td').eq(5).text() : tr.children('td').eq(1).text()) : '0';
- const quantity = tr.attr('quantity');
- const de_qu = bwmx + '*;*' + quantity;
- data_bwmx.push(de_qu);
- });
- data_bwmx = data_bwmx.join('$#$');
- $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
- $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
- } else {
- $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
- $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
- }
- }
- });
- // 记录变更信息操作
- $('body').on('valuechange', '#change_form input[type="text"]', function (e, previous) {
- changeInfo[$(this).attr('name')] = $(this).val();
- judgeChange();
- });
- $('body').on('valuechange', '#change_form textarea', function (e, previous) {
- changeInfo[$(this).attr('name')] = $(this).val().replace(/[\r\n]/g, '<br><br>');
- judgeChange();
- });
- $('body').on('change', '#change_form select', function (e, previous) {
- changeInfo[$(this).attr('name')] = $(this).val();
- judgeChange();
- });
- $('body').on('click', '#change_form input[type="radio"]', function (e, previous) {
- changeInfo[$(this).attr('name')] = $(this).val();
- judgeChange();
- });
- $('body').on('click', '#change_form input[type="checkbox"]', function (e, previous) {
- const typecheck = [];
- $.each($('#change_form input[name="type[]"]:checked'), function () {
- typecheck.push($(this).val());
- });
- changeInfo.type = typecheck.join(',');
- judgeChange();
- });
- // 保存修改ajax提交(不刷新页面)
- $('.save_change_btn').on('click', function () {
- // 保存修改modal
- if ($('input[name="code"]').val() === '') {
- toastr.error('申请编号不能为空!');
- return;
- }
- if ($('input[name="name"]').val() === '') {
- toastr.error('工程名称不能为空!');
- return;
- }
- // 换行更改并提交
- changeInfo.content = changeInfo.content.replace(/<br><br>/g, '\r\n');
- changeInfo.basis = changeInfo.basis.replace(/<br><br>/g, '\r\n');
- changeInfo.expr = changeInfo.expr.replace(/<br><br>/g, '\r\n');
- changeInfo.memo = changeInfo.memo.replace(/<br><br>/g, '\r\n');
- // 后改为br
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'info', updateData: changeInfo }, function (result) {
- $('.reduction-code').attr('data-code', $('input[name="code"]').val());
- toastr.success(result);
- $('#show-save-btn').hide();
- $('#sp-btn').show();
- $('.title-main').removeClass('bg-warning');
- changeInfo.content = changeInfo.content.replace(/[\r\n]/g, '<br>');
- changeInfo.basis = changeInfo.basis.replace(/[\r\n]/g, '<br>');
- changeInfo.expr = changeInfo.expr.replace(/[\r\n]/g, '<br>');
- changeInfo.memo = changeInfo.memo.replace(/[\r\n]/g, '<br>');
- back_changeInfo = Object.assign({}, changeInfo);
- });
- return false;
- });
- $('#cancel_change').on('click', function () {
- $('#show-save-btn').hide();
- $('#sp-btn').show();
- $('.title-main').removeClass('bg-warning');
- if (!isObjEqual(changeInfo, back_changeInfo)) {
- changeFormRemake();
- }
- toastr.success('已还原到上次保存状态');
- });
- });
- function checkSelectAll() {
- let check = $('#code-list tr').length > 0 ? true : false;
- $('#code-list tr').each(function () {
- if ($(this).css('display') !== 'none' && !$(this).find('input').is(':checked')) {
- check = false;
- }
- });
- $('#code-select-all').prop('checked', check);
- }
- function checkChangeFrom() {
- let returnFlag = false;
- // 表单判断
- if ($('input[name="code"]').val() === '') {
- toastr.error('申请编号不能为空!');
- returnFlag = true;
- }
- if ($('input[name="name"]').val() === '') {
- toastr.error('工程名称不能为空!');
- returnFlag = true;
- }
- if ($('textarea[name="content"]').val() === '') {
- toastr.error('工程变更理由及内容不能为空!');
- returnFlag = true;
- }
- if (changeList.length === 0) {
- toastr.error('请添加变更清单!');
- returnFlag = true;
- } else {
- for (const [i,cl] of changeList.entries()) {
- if (cl.code === '' || cl.name === '' || cl.oamount === '') {
- toastr.error('变更清单第' + (i+1) + '行未完整填写数据(变更部位、变更详情、单位、单价可空)');
- returnFlag = true;
- }
- }
- }
- if(!checkAuditorFrom ()) {
- returnFlag = true;
- }
- if (returnFlag) {
- return false;
- }
- }
- // 检查上报情况
- function checkAuditorFrom () {
- if ($('#auditList li').length === 0) {
- if(shenpi_status === shenpiConst.sp_status.gdspl) {
- toastr.error('请联系管理员添加审批人');
- } else {
- toastr.error('请先选择审批人,再上报数据');
- }
- return false;
- }
- return true;
- }
- function tableDataRemake(changeListData) {
- $('#table-list-select tr').removeClass('table-warning');
- $('#table-list-select tr').removeClass('table-success');
- $('#table-list-select tr').attr('data-bwmx', '');
- $('#code-list').html('');
- $('#code-list').attr('data-index', '');
- $('#code-input').val('');
- $('#code-select-all').prop('checked', false);
- $('#code-input').siblings('a').hide();
- // 根据已添加的清单显示
- if (changeList.length > 0 && changeList[0]) {
- const removeList = [];
- for (const [index,clinfo] of changeList.entries()) {
- if (clinfo.lid != 0) {
- let listinfo = changeListData.find(function (item) {
- return (item.id !== undefined && item.id == clinfo.lid) || (item.id === undefined && item.leafXmjs !== undefined && item.leafXmjs.length !== 0 && item.leafXmjs[0].gcl_id == clinfo.lid);
- });
- if (listinfo === undefined) {
- // 针对旧数据获取清单信息
- listinfo = changeListData[clinfo.lid - 1];
- if (listinfo === undefined) {
- toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
- // changeList.splice(index, 1);
- removeList.push(clinfo);
- continue;
- }
- $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').addClass('table-success');
- let pushbwmx = '0*;*0';
- if (listinfo.leafXmjs !== undefined) {
- const leafInfo = listinfo.leafXmjs.find(function (item) {
- const flag = (item.bwmx === undefined || item.bwmx === clinfo.bwmx || item.jldy === clinfo.bwmx) && item.gcl_id === clinfo.gcl_id && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
- if (flag && item.code === clinfo.xmj_code) {
- return flag && item.code === clinfo.xmj_code;
- }
- return flag;
- });
- if (leafInfo) {
- pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' +
- (leafInfo.dwgc ? leafInfo.dwgc : '') + '!_!' +
- (leafInfo.fbgc ? leafInfo.fbgc : '') + '!_!' +
- (leafInfo.fxgc ? leafInfo.fxgc : '') + '!_!' +
- (leafInfo.gcl_id ? leafInfo.gcl_id : '') + '!_!' +
- (leafInfo.bwmx !== undefined ? leafInfo.bwmx : (listinfo.leafXmjs.length > 1 && listinfo.name ? listinfo.name : (leafInfo.jldy !== undefined ? leafInfo.jldy : ''))) + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
- } else {
- toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
- // changeList.splice(index, 1);
- removeList.push(clinfo);
- continue;
- }
- } else {
- pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
- }
- const bwmx = $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx');
- if (bwmx) {
- const bwmxArray = bwmx.split('$#$');
- bwmxArray.push(pushbwmx);
- $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
- } else {
- $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
- }
- } else {
- $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').addClass('table-success');
- let pushbwmx = '0*;*0';
- if (listinfo.leafXmjs !== undefined) {
- const leafInfo = listinfo.leafXmjs.find(function (item) {
- const flag = (item.bwmx === undefined || item.bwmx === clinfo.bwmx || item.jldy === clinfo.bwmx) && item.gcl_id === clinfo.gcl_id && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
- if (flag && item.code === clinfo.xmj_code) {
- return flag && item.code === clinfo.xmj_code;
- }
- return flag;
- });
- if (leafInfo) {
- pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' +
- (leafInfo.dwgc ? leafInfo.dwgc : '') + '!_!' +
- (leafInfo.fbgc ? leafInfo.fbgc : '') + '!_!' +
- (leafInfo.fxgc ? leafInfo.fxgc : '') + '!_!' +
- (leafInfo.gcl_id ? leafInfo.gcl_id : '') + '!_!' +
- (leafInfo.bwmx !== undefined ? leafInfo.bwmx : (listinfo.leafXmjs.length > 1 && listinfo.name ? listinfo.name : (leafInfo.jldy !== undefined ? leafInfo.jldy : ''))) + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
- } else {
- toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
- // changeList.splice(index, 1);
- removeList.push(clinfo);
- continue;
- }
- } else {
- pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
- }
- const bwmx = $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx');
- if (bwmx) {
- const bwmxArray = bwmx.split('$#$');
- bwmxArray.push(pushbwmx);
- $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
- } else {
- $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
- }
- }
- }
- }
- if(removeList.length > 0) {
- _.pullAll(changeList, removeList);
- postData(window.location.pathname + '/save', { type:'remove_list', updateData: removeList }, function (result) {
- }, function () {
- });
- }
- }
- }
- // 清单搜索隐藏清单table部分值
- function makeListTable(changeListData, showListData = changeListData) {
- // 先加载台账数据
- let listHtml = '';
- let list_index = 1;
- let gcl_index = 0;
- for (const [index,gcl] of changeListData.entries()) {
- const isShow = _.find(showListData, gcl);
- $('#table-list-select tr').eq(index).css('display', (isShow ? 'table-row' : 'none'));
- }
- }
- // 项目节搜索隐藏code-table部分值
- function makeCodeTable(search = '') {
- if (search === '') {
- $('#code-list tr').css('display', 'table-row');
- return;
- }
- for(let i = 0; i < $('#code-list tr').length; i++) {
- const length = $('#code-list tr').eq(i).children('td').length;
- if (length === 8) {
- const code = $('#code-list tr').eq(i).children('td').eq(0).text();
- const name = $('#code-list tr').eq(i).children('td').eq(1).text();
- const jldy = $('#code-list tr').eq(i).children('td').eq(5).text();
- const isShow = code.indexOf(search) !== -1 || name.indexOf(search) !== -1 || jldy.indexOf(search) !== -1;
- $('#code-list tr').eq(i).css('display', (isShow ? 'table-row' : 'none'));
- } else {
- return;
- }
- }
- }
- function remakeChangeSpread() {
- const newTableList = [];
- // 获取选中的签约清单判断并插入到原有清单中
- $('#table-list-select .table-success').each(function(){
- let code = $(this).children('td').eq(1).text();
- let name = $(this).children('td').eq(2).text();
- let unit = $(this).children('td').eq(3).text();
- let price = $(this).children('td').eq(4).text();
- // let oamount = $(this).children('td').eq(5).text();
- // 根据单位获取数量的位数,并得出
- // let numdecimal = findDecimal(unit);
- // let scnum = makedecimalzero(numdecimal);
- let scnum = 0;
- // let detail = $(this).attr('data-detail') != 0 ? $(this).attr('data-detail').split('_')[1] : '';
- let lid = $(this).data('lid');
- let lindex = $(this).data('index');
- // 原清单和数量改变
- let data_bwmx = $(this).attr('data-bwmx').split('$#$');
- for (const b of data_bwmx) {
- const oamount = b.split('*;*')[1] != '' ? b.split('*;*')[1] : 0;
- let bwmx = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[6] : '';
- let xmj_code = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[0] : '';
- let xmj_jldy = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[1] : '';
- let xmj_dwgc = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[2] : '';
- let xmj_fbgc = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[3] : '';
- let xmj_fxgc = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[4] : '';
- let gcl_id = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[5] : '';
- let trlist = {
- code,
- name,
- bwmx,
- unit,
- unit_price: price,
- oamount,
- camount: scnum,
- detail: '',
- lid,
- xmj_code,
- xmj_jldy,
- xmj_dwgc,
- xmj_fbgc,
- xmj_fxgc,
- gcl_id,
- };
- const radionInfo = changeList.find(function (info) {
- return info.code === code && (info.lid == lid || parseInt(info.lid) === parseInt(lindex)) && gcl_id == info.gcl_id && (info.bwmx === bwmx || info.bwmx === xmj_jldy) && parseInt(info.oamount) === parseInt(oamount);
- });
- if (radionInfo) {
- trlist.camount = radionInfo.camount;
- trlist.detail = radionInfo.detail;
- }
- newTableList.push(trlist);
- }
- });
- // const changeWhiteList = _.filter(changeList, function (item) {
- // return item.lid == 0;
- // });
- // console.log(newTableList);
- // changeList = newTableList.concat(changeWhiteList);
- return newTableList;
- }
- //判断元素是否在数组中,相当于php的in_array();
- function in_array(arr, obj) {
- let i = arr.length;
- while (i--) {
- if (arr[i] == obj) {
- return true;
- }
- }
- return false;
- }
- function isObjEqual(o1,o2){
- var props1 = Object.getOwnPropertyNames(o1);
- var props2 = Object.getOwnPropertyNames(o2);
- if (props1.length != props2.length) {
- return false;
- }
- for (var i = 0,max = props1.length; i < max; i++) {
- var propName = props1[i];
- if (o1[propName] !== o2[propName]) {
- return false;
- }
- }
- return true;
- }
- // 判断是否有更改过
- function judgeChange() {
- let change = false;
- if (!isObjEqual(changeInfo, back_changeInfo)) {
- change = true;
- }
- if (change) {
- $('#show-save-btn').show();
- $('#sp-btn').hide();
- $('.title-main').addClass('bg-warning');
- } else {
- $('#show-save-btn').hide();
- $('#sp-btn').show();
- $('.title-main').removeClass('bg-warning');
- }
- }
- function changeFormRemake() {
- changeInfo = Object.assign({}, back_changeInfo);
- $('#change_form input[name="code"]').val(changeInfo.code);
- $('#change_form input[name="name"]').val(changeInfo.name);
- $('#change_form input[name="peg"]').val(changeInfo.peg);
- $('#change_form input[name="org_name"]').val(changeInfo.org_name);
- $('#change_form input[name="org_code"]').val(changeInfo.org_code);
- $('#change_form input[name="new_name"]').val(changeInfo.new_name);
- $('#change_form input[name="new_code"]').val(changeInfo.new_code);
- $('#change_form textarea[name="content"]').val(changeInfo.content.replace(/<br><br>/g, '\r\n'));
- $('#change_form textarea[name="basis"]').val(changeInfo.basis.replace(/<br><br>/g, '\r\n'));
- $('#change_form textarea[name="expr"]').val(changeInfo.expr.replace(/<br><br>/g, '\r\n'));
- $('#change_form textarea[name="memo"]').val(changeInfo.memo.replace(/<br><br>/g, '\r\n'));
- $('#change_form select[name="type"]').val(changeInfo.type);
- $('#change_form select[name="class"]').val(changeInfo.class);
- $('#change_form select[name="quality"]').val(changeInfo.quality);
- $('#change_form select[name="company"]').val(changeInfo.company);
- $('#change_form input[name="charge"][value="'+ changeInfo.charge +'"]').prop('checked', true);
- $('#change_form input[name="type[]"]').prop('checked', false);
- const typecheck = changeInfo.type.split(',');
- for (const type of typecheck) {
- $('#change_form input[name="type[]"][value="'+ type +'"]').prop('checked', true);
- }
- }
|