123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763 |
- '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;
- }
- }
- }
- }
- let searchCodeList = [];
- $(document).ready(() => {
- let searchGcl;
- autoFlashHeight();
- const gclSpreadSetting = {
- cols: [
- {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 120, formatter: '@'},
- {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 300, formatter: '@'},
- {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 100, formatter: '@'},
- {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 100},
- {title: '数量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 100},
- ],
- emptyRows: 0,
- headRows: 2,
- headRowHeight: [25, 25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- rowHeader:[
- {
- rowHeaderType: 'circle',
- setting: {
- size: 5,
- indent: 16,
- getColor: function (index, data) {
- if (!data) return;
- if (data.cid) {
- return '#dc3545';
- }
- }
- },
- },
- ],
- localCache: {
- key: 'change-add-list-gcl-spread',
- colWidth: true,
- }
- };
- gclSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
- if (data && data.settle_status && data.settle_status === settleStatus.finish) {
- return spreadColor.stage.settle;
- }
- if (data && data.is_change) {
- return '#c3e6cb';
- }
- return defaultColor;
- }
- const gclSpreadObj = {
- resetXmjSpread: function(data = null) {
- const xmjs = [];
- if (data && data.id) {
- xmjs.push({
- deal_id: data.id,
- cid: '',
- is_change: _.findIndex(changeList, { lid: data.id }) !== -1 ? 1 : 0,
- code: '',
- jldy: '',
- dwgc: '',
- fbgc: '',
- fxgc: '',
- bwmx: '',
- quantity: '',
- })
- } else if (data && data.leafXmjs) {
- for (const leaf of data.leafXmjs) {
- xmjs.push({
- gcl_id: leaf.gcl_id,
- mx_id: leaf.mx_id || '',
- is_change: _.findIndex(changeList, { gcl_id: leaf.gcl_id, mx_id: leaf.mx_id || '' }) !== -1 ? 1 : 0,
- cid: leaf.cid || '',
- code: leaf.code,
- jldy: leaf.jldy || '',
- dwgc: leaf.dwgc || '',
- fbgc: leaf.fbgc || '',
- fxgc: leaf.fxgc || '',
- bwmx: leaf.bwmx || '',
- quantity: leaf.quantity ? ZhCalc.round(leaf.quantity, findDecimal(data.unit)).toString() : '0',
- });
- }
- }
- console.log(xmjs, changeList);
- SpreadJsObj.loadSheetData(xmjSpreadSheet, SpreadJsObj.DataType.Data, xmjs);
- checkSelectAll(data);
- },
- selectionChanged: function (e, info) {
- const data = SpreadJsObj.getSelectObject(info.sheet);
- gclSpreadObj.resetXmjSpread(data);
- xmjSearch.searchAndLocate($('#xmj-keyword').val());
- }
- };
- const xmjSpreadSetting = {
- cols: [
- { title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList'},
- {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
- {title: '细目', colSpan: '1', rowSpan: '2', field: 'jldy', hAlign: 0, width: 150, formatter: '@', readOnly: true},
- {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'dwgc', hAlign: 0, width: 150, formatter: '@', readOnly: true},
- {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'fbgc', hAlign: 0, width: 150, readOnly: true},
- {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'fxgc', hAlign: 0, width: 150, readOnly: true},
- {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 150, readOnly: true},
- {title: '数量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 100, readOnly: true},
- ],
- emptyRows: 0,
- headRows: 2,
- headRowHeight: [25, 25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- rowHeader:[
- {
- rowHeaderType: 'circle',
- setting: {
- size: 5,
- indent: 16,
- getColor: function (index, data) {
- if (!data) return;
- if (data.cid) {
- return '#dc3545';
- }
- }
- },
- },
- ],
- };
- const xmjCol = {
- readOnly: {
- isChangeList: function (data) {
- if (!data) return true;
- return readOnly;
- }
- }
- };
- const xmjSpreadObj = {
- buttonClicked: function (e, info) {
- if (info.sheet.zh_setting) {
- const select = SpreadJsObj.getSelectObject(info.sheet);
- const col = info.sheet.zh_setting.cols[info.col];
- const gclInfo = SpreadJsObj.getSelectObject(gclSpreadSheet);
- const gclIndex = changeListData.indexOf(gclInfo);
- if (col.field === 'is_change') {
- if (xmjCol.readOnly.isChangeList(select)) {
- info.sheet.setValue(info.row, info.col, !select || !select.is_change ? 0 : 1);
- return
- }
- if (info.sheet.isEditing()) {
- info.sheet.endEdit(true);
- }
- const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
- if (!gclInfo) {
- info.sheet.setValue(info.row, info.col, 0);
- return;
- }
- if (is_change) {
- const oldCInfo = select.deal_id ? _.find(oldChangeList, { lid: select.deal_id }) : _.find(oldChangeList, { gcl_id: select.gcl_id, mx_id: select.mx_id });
- const data = {};
- if (oldCInfo) {
- data.detail = oldCInfo.detail;
- data.camount = oldCInfo.camount;
- data.spamount = oldCInfo.spamount;
- data.is_valuation = oldCInfo.is_valuation;
- data.delimit = oldCInfo.delimit;
- }
- if (select.deal_id) {
- const newData = {
- lid: select.deal_id,
- code: gclInfo.code,
- name: gclInfo.name,
- unit: gclInfo.unit,
- unit_price: gclInfo.unit_price,
- oamount: gclInfo.quantity ? parseFloat(gclInfo.quantity) : 0,
- oamount2: oldCInfo ? oldCInfo.oamount2 : gclInfo.quantity ? parseFloat(gclInfo.quantity) : 0,
- bwmx: '',
- xmj_code: '',
- xmj_jldy: '',
- xmj_dwgc: '',
- xmj_fbgc: '',
- xmj_fxgc: '',
- gcl_id: '',
- mx_id: '',
- }
- _.assign(data, newData);
- } else if (gclInfo.leafXmjs) {
- const xmjInfo = _.find(gclInfo.leafXmjs, function (item) {
- return item.gcl_id === select.gcl_id && (item.mx_id === undefined || item.mx_id === select.mx_id);
- });
- const newData = {
- lid: gclInfo.leafXmjs[0].gcl_id || select.gcl_id,
- code: gclInfo.b_code,
- name: gclInfo.name,
- unit: gclInfo.unit,
- unit_price: gclInfo.unit_price,
- oamount: xmjInfo.quantity,
- oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
- bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
- xmj_code: xmjInfo.code || '',
- xmj_jldy: xmjInfo.jldy || '',
- xmj_dwgc: xmjInfo.dwgc || '',
- xmj_fbgc: xmjInfo.fbgc || '',
- xmj_fxgc: xmjInfo.fxgc || '',
- gcl_id: select.gcl_id,
- mx_id: select.mx_id || '',
- }
- _.assign(data, newData);
- }
- console.log(data);
- // 更新至服务器
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
- type: 'add-change-list',
- postData: [data]
- }, function (result) {
- changeList = result.changeList;
- select.is_change = 1;
- changeListData[gclIndex].is_change = 1;
- // 如果是已勾选清单,需要另外找值勾选
- if ($('#show-select-btn').is(':checked')) {
- const newGclIndex = gclSpreadSheet.zh_data.indexOf(gclInfo);
- if (newGclIndex !== -1) {
- gclSpreadSheet.zh_data[newGclIndex].is_change = 1;
- SpreadJsObj.reLoadRowData(gclSpreadSheet, newGclIndex);
- }
- } else {
- SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
- }
- checkSelectAll(gclInfo);
- }, function () {
- info.sheet.setValue(info.row, info.col, 0);
- });
- } else {
- const cInfo = select.deal_id ? _.find(changeList, { lid: select.deal_id }) : _.find(changeList, { gcl_id: select.gcl_id, mx_id: select.mx_id });
- if (changeOrder && _.findIndex(oldChangeList, { id: cInfo.id }) !== -1) {
- toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
- info.sheet.setValue(info.row, info.col, 1);
- return
- }
- if (_.find(changeUsedData, {cbid: cInfo.id})) {
- toastr.warning('该清单已被使用,无法取消变更');
- info.sheet.setValue(info.row, info.col, 1);
- return
- } else if (checkIsSettle(cInfo)) {
- toastr.warning('该清单已结算,无法取消变更');
- info.sheet.setValue(info.row, info.col, 1);
- return
- } else {
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
- type: 'del-change-list',
- ids: [cInfo.id],
- }, function (result) {
- changeList = result.changeList;
- select.is_change = 0;
- checkSelectAll(gclInfo);
- if (select.deal_id) {
- changeListData[gclIndex].is_change = 0;
- if ($('#show-select-btn').is(':checked')) {
- const newGclIndex = gclSpreadSheet.zh_data.indexOf(gclInfo);
- if (newGclIndex !== -1) {
- gclSpreadSheet.zh_data[newGclIndex].is_change = 0;
- SpreadJsObj.reLoadRowData(gclSpreadSheet, newGclIndex);
- }
- } else {
- SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
- }
- } else {
- let isChange = false;
- gclInfo.leafXmjs.forEach(function (item) {
- if (_.findIndex(changeList, { gcl_id: item.gcl_id, mx_id: item.mx_id || '' }) !== -1) {
- isChange = true;
- return;
- }
- });
- if (!isChange) {
- changeListData[gclIndex].is_change = 0;
- // 如果是已勾选清单,需要另外找值勾选
- if ($('#show-select-btn').is(':checked')) {
- const newGclIndex = gclSpreadSheet.zh_data.indexOf(gclInfo);
- if (newGclIndex !== -1) {
- gclSpreadSheet.zh_data[newGclIndex].is_change = 0;
- SpreadJsObj.reLoadRowData(gclSpreadSheet, newGclIndex);
- }
- } else {
- SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
- }
- }
- }
- }, function () {
- info.sheet.setValue(info.row, info.col, 1);
- });
- }
- }
- }
- }
- }
- };
- const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
- let changeListData;
- let gclGatherData;
- const gclSpread = SpreadJsObj.createNewSpread($('#gcl-spread')[0]);
- const gclSpreadSheet = gclSpread.getActiveSheet();
- const xmjSpread = SpreadJsObj.createNewSpread($('#xmj-spread')[0]);
- const xmjSpreadSheet = xmjSpread.getActiveSheet();
- sjsSettingObj.setGridSelectStyle(gclSpreadSetting);
- SpreadJsObj.initSheet(gclSpreadSheet, gclSpreadSetting);
- sjsSettingObj.setGridSelectStyle(xmjSpreadSetting);
- SpreadJsObj.initSpreadSettingEvents(xmjSpreadSetting, xmjCol);
- SpreadJsObj.initSheet(xmjSpreadSheet, xmjSpreadSetting);
- postData(preUrl + '/defaultBills', { from: 'batch' }, 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;
- let hadcid = 0;
- for (const xmj of gclGatherData[ggd].leafXmjs) {
- const changeLedger = _.find(result.changeLedgerList, { id: xmj.gcl_id });
- const changePos = _.find(result.changePosList, { id: xmj.mx_id, lid: xmj.gcl_id });
- if (changeLedger || changePos) {
- xmj.cid = 1;
- xmj.ccid = changePos ? changePos.ccid : changeLedger ? changeLedger.ccid : 0;
- hadcid = 1;
- }
- }
- if (hadcid !== 0) gclGatherData[ggd].cid = 1;
- }
- // 数组去重
- // 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.sort(sortByCode);
- for (const gcl of changeListData) {
- gcl.unit = gcl.unit !== undefined && gcl.unit !== null ? gcl.unit : '';
- gcl.quantity = gcl.quantity !== 0 && gcl.quantity !== null && gcl.quantity !== undefined ? (gcl.unit !== '' ? ZhCalc.round(gcl.quantity, findDecimal(gcl.unit)) : gcl.quantity).toString() : '0';
- gcl.unit_price = gcl.unit_price !== null && gcl.unit_price !== undefined ? ZhCalc.round(gcl.unit_price, unitPriceUnit) : 0;
- // 用id值区分签约清单和台账
- if (gcl.id) {
- const cInfo = gcl.id ? _.find(changeList, { lid: gcl.id }) : null;
- gcl.is_change = cInfo ? 1 : 0;
- } else {
- const index = gcl.leafXmjs && gcl.leafXmjs.length !== 0 ? _.findIndex(gcl.leafXmjs, function (item) {
- return _.findIndex(changeList, { gcl_id: item.gcl_id }) !== -1;
- }) : -1;
- gcl.is_change = index !== -1 ? 1 : 0;
- }
- }
- console.log(changeListData);
- SpreadJsObj.loadSheetData(gclSpreadSheet, SpreadJsObj.DataType.Data, changeListData);
- gclSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(gclSpreadSheet));
- });
- gclSpread.bind(spreadNS.Events.SelectionChanged, gclSpreadObj.selectionChanged);
- xmjSpread.bind(spreadNS.Events.ButtonClicked, xmjSpreadObj.buttonClicked)
- const xmjSearch = $.xmjSearch({
- selector: '#xmj-search',
- searchSpread: xmjSpread,
- searchRangeStr: '输入项目节编号、细目、计量单元查找',
- });
- $.divResizer({
- select: '#revise-resize',
- callback: function () {
- gclSpread.refresh();
- let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
- $(".sp-wrap").height(bcontent-30);
- xmjSpread.refresh();
- }
- });
- $.divResizer({
- select: '#revise-right-spr',
- callback: function () {
- gclSpread.refresh();
- xmjSpread.refresh();
- if (searchGcl) searchGcl.spread.refresh();
- }
- });
- $.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();
- gclSpread.refresh();
- xmjSpread.refresh();
- if (searchGcl) searchGcl.spread.refresh();
- }
- });
- gclSpread.refresh();
- xmjSpread.refresh();
- // 展开收起标准节点
- $('a', '#side-menu').bind('click', function (e) {
- e.preventDefault();
- const tab = $(this), tabPanel = $(tab.attr('content'));
- // 展开工具栏、切换标签
- if (!tab.hasClass('active')) {
- const close = $('.active', '#side-menu').length === 0;
- $('a', '#side-menu').removeClass('active');
- tab.addClass('active');
- $('.tab-content .tab-pane').removeClass('active');
- tabPanel.addClass('active');
- showSideTools(tab.hasClass('active'));
- if (tab.attr('content') === '#search') {
- if (!searchGcl) {
- searchGcl = $.listSearch({
- selector: '#search',
- searchSpread: gclSpread,
- searchOver: true,
- searchEmpty: true,
- resultSpreadSetting: {
- cols: [
- {title: '清单编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
- {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
- {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
- {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
- {title: '数量', field: 'quantity', hAlign: 2, width: 50},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- selectedBackColor: '#fffacd',
- readOnly: true,
- },
- afterLocated: function () {
- gclSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(gclSpreadSheet));
- },
- check: function(data, keyword) {
- return !keyword ||
- (data.code && data.code.indexOf(keyword) > -1) ||
- (data.name && data.name.indexOf(keyword) > -1);
- },
- customSearch: [
- {
- key: 'revise', title: '新增部位', valid: true, parent: true,
- check: function (node) {
- if (node.formc || node.cid) {
- return true;
- } else {
- return false;
- }
- }
- }
- ],
- });
- }
- searchGcl.spread.refresh();
- }
- }
- else {// 收起工具栏
- tab.removeClass('active');
- tabPanel.removeClass('active');
- showSideTools(tab.hasClass('active'));
- }
- gclSpread.refresh();
- xmjSpread.refresh();
- });
- // 全选及取消
- $('#code-select-all').click(function () {
- // 全选checkbox
- const data = SpreadJsObj.getSelectObject(gclSpreadSheet);
- if ($(this).is(':checked')){
- const addDatas = [];
- if (data && data.id) {
- if (_.findIndex(changeList, function (item) {
- return item.id && item.id === data.id;
- }) === -1) {
- addDatas.push({
- lid: data.id,
- code: data.code,
- name: data.name || '',
- unit: data.unit || '',
- unit_price: data.unit_price,
- oamount: data.quantity ? parseFloat(data.quantity) : 0,
- oamount2: data.quantity ? parseFloat(data.quantity) : 0,
- bwmx: '',
- xmj_code: '',
- xmj_jldy: '',
- xmj_dwgc: '',
- xmj_fbgc: '',
- xmj_fxgc: '',
- gcl_id: '',
- mx_id: '',
- });
- }
- } else if (data && data.leafXmjs) {
- for (const leaf of data.leafXmjs) {
- if (_.findIndex(changeList, function (item) {
- return item.gcl_id === leaf.gcl_id && item.mx_id === (leaf.mx_id || '');
- }) === -1) {
- addDatas.push({
- lid: leaf.gcl_id,
- code: data.code,
- name: data.name || '',
- unit: data.unit || '',
- unit_price: data.unit_price,
- oamount: leaf.quantity,
- oamount2: leaf.quantity,
- bwmx: leaf.bwmx || leaf.jldy || '',
- xmj_code: leaf.code || '',
- xmj_jldy: leaf.jldy || '',
- xmj_dwgc: leaf.dwgc || '',
- xmj_fbgc: leaf.fbgc || '',
- xmj_fxgc: leaf.fxgc || '',
- gcl_id: leaf.gcl_id,
- mx_id: leaf.mx_id || '',
- });
- }
- }
- }
- console.log(addDatas);
- if (addDatas.length > 0) {
- // 更新至服务器
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
- type: 'add-change-list',
- postData: addDatas,
- }, function (result) {
- changeList = result.changeList;
- const gclIndex = changeListData.indexOf(data);
- console.log(gclIndex, data);
- data.is_change = 1;
- changeListData[gclIndex].is_change = 1;
- SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
- gclSpreadObj.resetXmjSpread(data);
- }, function () {
- $('#code-select-all').prop('checked', false);
- });
- }
- } else {
- const cList = xmjSpreadSheet.zh_data;
- const removeDatas = [];
- let hadContinue = false;
- for (const c of cList) {
- const cInfo = c.deal_id ? _.find(changeList, { lid: c.deal_id }) : _.find(changeList, function (item) {
- return item.gcl_id === c.gcl_id && item.mx_id === (c.mx_id || '');
- });
- if (_.find(changeUsedData, {cbid: cInfo.id})) {
- hadContinue = true;
- continue;
- } else if (checkIsSettle(cInfo)) {
- hadContinue = true;
- continue;
- }
- removeDatas.push(cInfo);
- }
- console.log(removeDatas);
- if (removeDatas.length > 0) {
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
- type: 'del-change-list',
- ids: _.map(removeDatas, 'id'),
- postData: null
- }, function (result) {
- changeList = result.changeList;
- if (!hadContinue) {
- const gclIndex = changeListData.indexOf(data);
- data.is_change = 0;
- changeListData[gclIndex].is_change = 0;
- SpreadJsObj.reLoadRowData(gclSpreadSheet, gclIndex);
- }
- gclSpreadObj.resetXmjSpread(data);
- }, function () {
- $('#code-select-all').prop('checked', true);
- });
- }
- }
- });
- // 选中所有新增部位/清单
- $('#add-all-revise').click(function() {
- const this_cid = window.location.pathname.split('/')[4];
- const addDatas = [];
- const refreshIndexs = [];
- for (const gclInfo of _.filter(changeListData, { cid: 1 })) {
- const leafXmjs = _.filter(gclInfo.leafXmjs, { ccid: this_cid });
- if (leafXmjs.length > 0) {
- gclInfo.is_change = 1;
- refreshIndexs.push(changeListData.indexOf(gclInfo));
- for (const xmj of leafXmjs) {
- if (_.findIndex(changeList, function (item) {
- return item.gcl_id === xmj.gcl_id && item.mx_id === (xmj.mx_id || '');
- }) === -1) {
- addDatas.push({
- lid: xmj.gcl_id,
- code: gclInfo.code,
- name: gclInfo.name || '',
- unit: gclInfo.unit || '',
- unit_price: gclInfo.unit_price,
- oamount: xmj.quantity,
- oamount2: xmj.quantity,
- bwmx: xmj.bwmx || xmj.jldy || '',
- xmj_code: xmj.code || '',
- xmj_jldy: xmj.jldy || '',
- xmj_dwgc: xmj.dwgc || '',
- xmj_fbgc: xmj.fbgc || '',
- xmj_fxgc: xmj.fxgc || '',
- gcl_id: xmj.gcl_id,
- mx_id: xmj.mx_id || '',
- });
- }
- }
- }
- }
- console.log(addDatas);
- if (addDatas.length > 0) {
- // 更新至服务器
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
- type: 'add-change-list',
- postData: addDatas,
- }, function (result) {
- toastr.success('已新增当前变更令新增的所有部位/清单');
- changeList = result.changeList;
- refreshIndexs.forEach(function (index) {
- changeListData[index].is_change = 1;
- SpreadJsObj.reLoadRowData(gclSpreadSheet, index);
- });
- const data = SpreadJsObj.getSelectObject(gclSpreadSheet);
- gclSpreadObj.resetXmjSpread(data);
- });
- } else {
- toastr.warning('未存在当前变更令新增的部位/清单');
- }
- });
- $('#show-select-btn').click(function() {
- if ($(this).is(':checked')) {
- const selectList = changeListData.filter(function (item) {
- return item.is_change === 1;
- });
- SpreadJsObj.loadSheetData(gclSpreadSheet, SpreadJsObj.DataType.Data, selectList);
- } else {
- SpreadJsObj.loadSheetData(gclSpreadSheet, SpreadJsObj.DataType.Data, changeListData);
- }
- gclSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(gclSpreadSheet));
- });
- });
- function checkSelectAll(data) {
- let check = false;
- if (data && data.id && data.is_change) {
- check = true;
- } else if(data && data.leafXmjs) {
- check = data.leafXmjs.length > 0 ? true : false;
- data.leafXmjs.forEach(function (item) {
- const is_change = _.findIndex(changeList, { gcl_id: item.gcl_id, mx_id: item.mx_id || '' }) !== -1
- if (!is_change) {
- check = false;
- return;
- }
- });
- }
- $('#code-select-all').prop('checked', check);
- }
- function findDecimal(unit) {
- let value = precision.other.value;
- const changeUnits = precision;
- for (const d in changeUnits) {
- if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
- value = changeUnits[d].value;
- break;
- }
- }
- return value;
- }
- // 判断是否是已结算清单
- function checkIsSettle(data) {
- const info = data.mx_id ? _.find(settlePos, { lid: data.gcl_id, pid: data.mx_id }) : _.find(settleBills, { lid: data.gcl_id });
- if (info && info.settle_status && info.settle_status === settleStatus.finish) {
- return true;
- }
- return false;
- }
|