| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212 | 
							- 'use strict';
 
- /**
 
-  * 材料调差 - 调差工料
 
-  *
 
-  * @author Mai
 
-  * @date 2019/1/16
 
-  * @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;
 
-             }
 
-         }
 
-     }
 
- }
 
- function loadUpdateMaterials(newMaterial, fields) {
 
-     const newMaterials = newMaterial instanceof Array ? newMaterial : [newMaterial];
 
-     for (const nm of newMaterials) {
 
-         const om = _.find(materialBillsData, {id: nm.id});
 
-         for (const prop in nm) {
 
-             if (!fields || fields.indexOf(prop) >= 0) {
 
-                 om[prop] = nm[prop];
 
-             }
 
-         }
 
-     }
 
- }
 
- function DatePickerCellType() {
 
- }
 
- DatePickerCellType.prototype = new GC.Spread.Sheets.CellTypes.Base();
 
- DatePickerCellType.prototype.createEditorElement = function () {
 
-     //Create input presenter.
 
-     var input = document.createElement("input");
 
-     return input;
 
- };
 
- DatePickerCellType.prototype.activateEditor = function (editorContext, cellStyle, cellRect) {
 
-     //Initialize input editor.
 
-     if (editorContext) {
 
-         const $editor = $(editorContext);
 
-         GC.Spread.Sheets.CellTypes.Base.prototype.activateEditor.apply(this, arguments);
 
-         $editor.datepicker({});
 
-         $editor.css("position", "absolute");
 
-         $editor.attr("gcUIElement", "gcEditingInput");
 
-         $(".ui-datepicker").attr("gcUIElement", "gcEditingInput");
 
-     }
 
- }
 
- DatePickerCellType.prototype.deactivateEditor = function (editorContext) {
 
-     //Remove input editor when end editor status.
 
-     if (editorContext) {
 
-         var element = editorContext;
 
-         // $(element).datepicker().data('datepicker').hide();
 
-         // $(element).datepicker().data('datepicker').destroy();
 
-         $(element).datepicker("hide");
 
-         $(element).datepicker("destroy");
 
-     }
 
-     GC.Spread.Sheets.CellTypes.Base.prototype.deactivateEditor.apply(this, arguments)
 
- };
 
- DatePickerCellType.prototype.setEditorValue = function (editor, value) {
 
-     //Sync value from Cell value to editor value.
 
-     // console.log($(editor), value);
 
-     $(editor).datepicker("setDate", value);
 
-     // $(editor).datepicker().data('datepicker').selectDate(value ? new Date(value) : new Date());
 
- };
 
- DatePickerCellType.prototype.getEditorValue = function (editor, context) {
 
-     // console.log($(editor).datepicker().data('datepicker'), context);
 
-     //Sync value from editor value to cell value.
 
-     // console.log($(editor).datepicker("getDate"));
 
-     // return $(editor).datepicker("getDate");
 
-     return $(editor).val();
 
- };
 
- DatePickerCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect) {
 
-     if (editorContext) {
 
-         const $editor = $(editorContext);
 
-         $editor.css("width", cellRect.width - 1);
 
-         $editor.css("height", cellRect.height - 3);
 
-     }
 
- };
 
- function resetTpTable() {
 
-     $('#tp_set').find('td').eq(1).text(ZhCalc.round(m_tp, materialDecimal.tp));
 
-     $('#tp_set').find('td').eq(2).text(ZhCalc.add(pre_tp, ZhCalc.round(m_tp, materialDecimal.tp)));
 
-     if (materialTax) {
 
-         $('#tax_rate_set').find('td').eq(1).text(ZhCalc.round(m_tax_tp, materialDecimal.tp));
 
-         $('#tax_rate_set').find('td').eq(2).text(ZhCalc.add(m_tax_pre_tp, ZhCalc.round(m_tax_tp, materialDecimal.tp)));
 
-     } else {
 
-         const rate = $('#rateInput').val();
 
-         const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
 
-         const jzbqhs = ZhCalc.add(pre_tp_hs, bqhs);
 
-         $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
 
-         $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
 
-     }
 
-     if (isStageSelf) {
 
-         let html = '';
 
-         for (const ms of materialStageData) {
 
-             const taxHtml = materialTax ? '                                        <td class="text-center">' + (ms.m_tax_tp !== null ? ms.m_tax_tp : '') + '</td>\n' : '';
 
-             html += '<tr><td>第' + ms.order + '期</td><td class="text-center">' + (ms.m_tp !== null ? ms.m_tp : '') + '</td>\n' +
 
-                 taxHtml +
 
-                 '                                </tr>';
 
-         }
 
-         const allTaxHtml = materialTax ? '                                        <td class="text-center">' + m_tax_tp + '</td>\n' : '';
 
-         html += '<tr><td>合计</td><td class="text-center">' + m_tp + '</td>\n' +
 
-             allTaxHtml +
 
-             '                                </tr>';
 
-         $('#materialStageTable').html(html);
 
-     }
 
- }
 
- function getPasteHint (str, row = '') {
 
-     let returnObj = str;
 
-     if (row) {
 
-         returnObj.msg = '工料第' + (row+1) + '行' + str.msg;
 
-     }
 
-     return returnObj;
 
- }
 
- const is_numeric = (value) => {
 
-     if (typeof(value) === 'object') {
 
-         return false;
 
-     } else {
 
-         return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
 
-     }
 
- };
 
- $(document).ready(() => {
 
-     autoFlashHeight();
 
-     const materialSpread = SpreadJsObj.createNewSpread($('#material-spread')[0]);
 
-     const materialSpreadSetting = {
 
-         emptyRows: 0,
 
-         headRows: 2,
 
-         headRowHeight: [25, 32],
 
-         defaultRowHeight: 21,
 
-         headerFont: '12px 微软雅黑',
 
-         font: '12px 微软雅黑',
 
-         readOnly: readOnly,
 
-     };
 
-     let materialSpreadSettingCols = [
 
-         {title: '调差类型', colSpan: '1', rowSpan: '2', field: 't_type', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isUsed', cellType: 'customizeCombo', comboItems: materialType.t_type, cellTypeKey: 1},
 
-         {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.isUsed'},
 
-         {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: 'readOnly.isEdit'},
 
-         {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: 'readOnly.isEdit'},
 
-         {title: '规格', colSpan: '1', rowSpan: '2', field: 'spec', hAlign: 0, width: 150, formatter: '@', readOnly: 'readOnly.isEdit'},
 
-         {title: '工料分类', colSpan: '1', rowSpan: '2', field: 'm_type', hAlign: 1, width: 60, readOnly: 'readOnly.isEdit', cellType: 'customizeCombo', comboItems: materialType.m_type, cellTypeKey: 2},
 
-     ];
 
-     if (materialTax) {
 
-         materialSpreadSettingCols.push({title: '税率(%)', colSpan: '1', rowSpan: '2', field: 'm_tax', hAlign: 2, width: 50, type: 'Number', readOnly: editTaxPermission ? 'readOnly.remark' : 'readOnly.isEdit'});
 
-     }
 
-     materialSpreadSettingCols = _.concat(materialSpreadSettingCols, [
 
-         {title: '上涨 幅度(%)', colSpan: '1', rowSpan: '2', field: 'm_up_risk', hAlign: 2, width: 50, type: 'Number', readOnly: 'readOnly.isEdit'},
 
-         {title: '下跌 幅度(%)', colSpan: '1', rowSpan: '2', field: 'm_down_risk', hAlign: 2, width: 50, type: 'Number', readOnly: 'readOnly.isEdit'},
 
-         {title: '基准价', colSpan: '1', rowSpan: '2', field: 'basic_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit'},
 
-         {title: '基准时间', colSpan: '1', rowSpan: '2', field: 'basic_times', hAlign: 0, width: 70, formatter: '@', readOnly: 'readOnly.isEdit'},
 
-         {title: '本期信息价|单价', colSpan: '3|1', rowSpan: '1|1', field: 'msg_tp', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.msg_tp'},
 
-         {title: '|时间', colSpan: '|1', rowSpan: '|1', field: 'msg_times', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.remark'},
 
-         {title: '|单价差', colSpan: '|1', rowSpan: '|1', field: 'msg_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.msg_spread'},]
 
-     );
 
-     if (materialTax) {
 
-         materialSpreadSettingCols = _.concat(materialSpreadSettingCols, [
 
-             {title: '本期材料调差|有效价差', colSpan: '4|1', rowSpan: '1|1', field: 'm_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.m_spread'},
 
-             {title: '|本期应耗数量', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 90, type: 'Number', readOnly: true},
 
-             {title: '|调差金额', colSpan: '|1', rowSpan: '|1', field: 'm_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true, getValue: 'getValue.m_tp'},
 
-             {title: '|调差金额(材料税)', colSpan: '|1', rowSpan: '|1', field: 'm_tax_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true, getValue: 'getValue.m_tax_tp'},
 
-             {title: '截止上期|调差金额', colSpan: '2|1', rowSpan: '1|1', field: 'pre_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true},
 
-             {title: '|调差金额(材料税)', colSpan: '|1', rowSpan: '|1', field: 'tax_pre_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true},
 
-             {title: '备注', colSpan: '1', rowSpan: '2', field: 'remark', hAlign: 0, width: 50, formatter: '@', cellType: 'ellipsisAutoTip', readOnly: 'readOnly.remark'},
 
-             {title: '是否汇总', colSpan: '1', rowSpan: '2', field: 'is_summary', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isEdit'}
 
-         ])
 
-     } else {
 
-         materialSpreadSettingCols = _.concat(materialSpreadSettingCols, [
 
-             {title: '本期材料调差|有效价差', colSpan: '3|1', rowSpan: '1|1', field: 'm_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.m_spread'},
 
-             {title: '|本期应耗数量', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 90, type: 'Number', readOnly: true},
 
-             {title: '|调差金额', colSpan: '|1', rowSpan: '|1', field: 'm_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true, getValue: 'getValue.m_tp'},
 
-             {title: '截止上期|调差金额', colSpan: '1|1', rowSpan: '1|1', field: 'pre_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true},
 
-             {title: '备注', colSpan: '1', rowSpan: '2', field: 'remark', hAlign: 0, width: 50, formatter: '@', cellType: 'ellipsisAutoTip', readOnly: 'readOnly.remark'},
 
-             {title: '是否汇总', colSpan: '1', rowSpan: '2', field: 'is_summary', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isEdit'}
 
-         ])
 
-     }
 
-     materialSpreadSetting.cols = materialSpreadSettingCols;
 
-     const spCol = _.find(materialSpreadSetting.cols, {field: 'quantity'});
 
-     spCol.readOnly = true;
 
-     spCol.cellType = 'activeImageBtn';
 
-     spCol.normalImg = '#ellipsis-icon';
 
-     spCol.indent = 5;
 
-     spCol.showImage = function (data) {
 
-         // return !readOnly && data.t_type === 2 && data.mid === materialID;
 
-         return data && data.t_type === 2;
 
-     };
 
-     materialSpreadSetting.imageClick = function (data) {
 
-         if (data.t_type === 2) {
 
-             $('#bcyy').modal('show');
 
-             $('#materialbillsId').val(data.id);
 
-             $('#expr').val(data.expr);
 
-             if (!readOnly) {
 
-                 $('#expr').attr('readOnly', false);
 
-                 $('#expr_btn').show();
 
-                 $('#expr_select').show();
 
-             } else {
 
-                 $('#expr').attr('readOnly', true);
 
-                 $('#expr_btn').hide();
 
-                 $('#expr_select').hide();
 
-             }
 
-         }
 
-     };
 
-     const materialBase = {
 
-         isUsed: function (data) {
 
-             if (data.t_type === 2) {
 
-                 return data.mid === materialID;
 
-             } else {
 
-                 const mlInfo = _.find(materialListData, { mb_id: data.id });
 
-                 return data.mid === materialID && mlInfo === undefined;
 
-             }
 
-         },
 
-         isEdit: function (data) {
 
-             // if (data.t_type === 2) {
 
-             //     return data.mid === materialID;
 
-             // } else {
 
-             //     const mlInfo = _.find(materialListData, { mb_id: data.id });
 
-             //     return data.mid === materialID && mlInfo === undefined;
 
-             // }
 
-             return data.mid === materialID;
 
-         },
 
-         // isStage: function (data) {
 
-         //     return data.mid === materialID;
 
-         // }
 
-     }
 
-     const materialCol = {
 
-         getValue: {
 
-             msg_spread: function (data) {
 
-                 return ZhCalc.round(ZhCalc.sub(data.msg_tp, data.basic_price), materialDecimal.up);
 
-             },
 
-             m_spread : function (data) {
 
-                 const msg_spread = materialCol.getValue.msg_spread(data);
 
-                 const cor = msg_spread >= 0 ? ZhCalc.mul(data.basic_price, ZhCalc.div(data.m_up_risk, 100)) : ZhCalc.mul(data.basic_price, ZhCalc.div(data.m_down_risk, 100));
 
-                 return Math.abs(msg_spread) > Math.abs(cor) ? (msg_spread > 0 ? ZhCalc.round(ZhCalc.sub(msg_spread, cor), materialDecimal.up) : ZhCalc.round(ZhCalc.add(msg_spread, cor), materialDecimal.up)) : 0;
 
-             },
 
-             m_tp: function (data) {
 
-                 return ZhCalc.round(ZhCalc.mul(materialCol.getValue.m_spread(data), data.quantity), materialDecimal.tp);
 
-             },
 
-             m_tax_tp: function (data) {
 
-                 const m_tp = ZhCalc.round(ZhCalc.mul(materialCol.getValue.m_spread(data), data.quantity), materialDecimal.tp);
 
-                 return data.m_tax ? ZhCalc.round(ZhCalc.mul(m_tp, (1+ZhCalc.div(data.m_tax, 100))), materialDecimal.tp) : m_tp;
 
-             }
 
-         },
 
-         readOnly: {
 
-             isEdit: function (data) {
 
-                 return !(!readOnly && materialBase.isEdit(data));
 
-             },
 
-             isUsed: function (data) {
 
-                 return !(!readOnly && materialBase.isUsed(data));
 
-             },
 
-             remark: function () {
 
-                 return readOnly;
 
-             },
 
-             msg_tp: function () {
 
-                 return !(!readOnly && months.length === 0);
 
-             }
 
-         },
 
-     };
 
-     const needUpdateArray = ['quantity', 'expr', 'msg_tp', 'msg_times', 'msg_spread', 'm_spread', 'm_tp', 'm_tax_tp', 'is_summary', 'remark'];
 
-     const materialSpreadObj = {
 
-         getMaterialBillsData: function () {
 
-             if (isStageSelf) {
 
-                 // 当前选中nav id
 
-                 const ms_id = $('#myTab').find('.active').data('msid');
 
-                 const msbList = _.filter(materialStageBillsData, { ms_id });
 
-                 for (const mb of materialBillsData) {
 
-                     mb.ms_id = ms_id;
 
-                     const msbInfo = _.find(msbList, { mb_id: mb.mb_id ? mb.mb_id : mb.id });
 
-                     if (msbInfo) {
 
-                         for (const nu of needUpdateArray) {
 
-                             mb[nu] = msbInfo[nu];
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             return materialBillsData;
 
-         },
 
-         updateOneMaterialBill: function (data) {
 
-             const ms_id = $('#myTab').find('.active').data('msid');
 
-             const msbInfo = _.find(materialStageBillsData, { ms_id, mb_id: data.id });
 
-             console.log(msbInfo);
 
-             data.ms_id = ms_id;
 
-             for (const nu of needUpdateArray) {
 
-                 data[nu] = msbInfo[nu];
 
-             }
 
-             return data;
 
-         },
 
-         updateMaterialData: function (datas) {
 
-             if (datas.stageData && datas.stageData.length > 0) {
 
-                 if (datas.stageData.length === materialStageData.length) {
 
-                     // 全体替换
 
-                     materialStageData = datas.stageData;
 
-                 } else {
 
-                     // 替换对应的stage数据
 
-                     for (const s of datas.stageData) {
 
-                         const index = _.findIndex(materialStageData, { id: s.id });
 
-                         materialStageData.splice(index, 1, s);
 
-                     }
 
-                 }
 
-             }
 
-             if (datas.pushStageBillsData && datas.pushStageBillsData.length > 0) {
 
-                 materialStageBillsData = _.concat(materialStageBillsData, datas.pushStageBillsData);
 
-             }
 
-             if (datas.removeStageBillsData && datas.removeStageBillsData.length > 0) {
 
-                 materialStageBillsData = _.remove(materialStageBillsData, function (item) {
 
-                     return _.findIndex(datas.removeStageBillsData, { id: item.mb_id }) === -1
 
-                 })
 
-             }
 
-             if (datas.stageBillsData && datas.stageBillsData.length > 0) {
 
-                 if (datas.stageBillsData.length === materialStageBillsData.length) {
 
-                     // 全体替换
 
-                     materialStageBillsData = datas.stageBillsData;
 
-                 } else {
 
-                     // 替换对应的stage数据
 
-                     for (const s of datas.stageBillsData) {
 
-                         const index = _.findIndex(materialStageBillsData, { id: s.id });
 
-                         materialStageBillsData.splice(index, 1, s);
 
-                     }
 
-                 }
 
-             }
 
-             if (datas.billsData && datas.billsData.length > 0) {
 
-                 if (datas.billsData.length === materialBillsData.length) {
 
-                     // 全体替换
 
-                     materialBillsData = datas.billsData;
 
-                     materialSpreadObj.getMaterialBillsData();
 
-                 } else {
 
-                     for (const b of datas.billsData) {
 
-                         const index = _.findIndex(materialBillsData, {id: b.id});
 
-                         materialBillsData.splice(index, 1, b);
 
-                         materialSpreadObj.updateOneMaterialBill(materialBillsData[index]);
 
-                     }
 
-                 }
 
-             }
 
-         },
 
-         materialSheetReset: function (redo = false) {
 
-             let newMaterialBillsData = _.cloneDeep(materialBillsData);
 
-             if($('#bills0_list').is(':checked')) {
 
-                 newMaterialBillsData = _.filter(materialBillsData, function (item) {
 
-                     return item.quantity !== null && item.quantity !== 0;
 
-                 });
 
-             }
 
-             if (redo) {
 
-                 materialSpread.getActiveSheet().reset();
 
-                 SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
 
-                 SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
 
-             }
 
-             console.log(newMaterialBillsData);
 
-             SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
 
-             materialSpreadObj.refreshActn();
 
-         },
 
-         refreshActn: function (rowCount = 1) {
 
-             const setObjEnable = function (obj, enable) {
 
-                 if (enable) {
 
-                     obj.removeClass('disabled');
 
-                 } else {
 
-                     obj.addClass('disabled');
 
-                 }
 
-             };
 
-             const sheet = materialSpread.getActiveSheet();
 
-             const select = SpreadJsObj.getSelectObject(sheet);
 
-             const selection = sheet.getSelections();
 
-             const sel = selection ? selection[0] : sheet.getSelections()[0];
 
-             const row = sel ? sel.row : -1;
 
-             const first = materialBillsData[row];
 
-             let last = first;
 
-             if (sel.rowCount > 1 && first) {
 
-                 for (let r = 1; r < sel.rowCount; r++) {
 
-                     const rNode = materialBillsData[sel.row + r];
 
-                     if (!rNode) break;
 
-                     last = rNode;
 
-                 }
 
-             }
 
-             const preNode = materialBillsData[row - 1];
 
-             // 还需判断是否已被调差清单调用
 
-             setObjEnable($('#del'), !readOnly && select && materialBase.isUsed(select) && rowCount === 1);
 
-             setObjEnable($('#up-move'), !readOnly && first && preNode && materialBillsData.indexOf(last) > 0 && sel.row + sel.rowCount <= materialBillsData.length && !$('#bills0_list').is(':checked'));
 
-             setObjEnable($('#down-move'), !readOnly && first && materialBillsData.indexOf(last) < materialBillsData.length - 1 && sel.row + sel.rowCount <= materialBillsData.length && !$('#bills0_list').is(':checked'));
 
-         },
 
-         add: function () {
 
-             const sheet = materialSpread.getActiveSheet();
 
-             postData(window.location.pathname + '/save', {type: 'add'}, function (result) {
 
-                 if (result) {
 
-                     materialBillsData.push(result.info);
 
-                     if (isStageSelf) {
 
-                         materialSpreadObj.updateMaterialData(result);
 
-                         materialSpreadObj.getMaterialBillsData();
 
-                     }
 
-                     // sheet.addRows(materialBillsData.length - 1, 1);
 
-                     // SpreadJsObj.reLoadRowData(sheet, materialBillsData.length - 1);
 
-                     let newMaterialBillsData = materialBillsData;
 
-                     if($('#bills0_list').is(':checked')) {
 
-                         newMaterialBillsData = _.filter(materialBillsData, function (item) {
 
-                             return item.quantity !== null && item.quantity !== 0;
 
-                         });
 
-                     }
 
-                     SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
 
-                     // materialSpreadObj.materialSheetReset();
 
-                     sheet.setSelection(newMaterialBillsData.length - 1, 0, 1, 1);
 
-                     console.log(sheet);
 
-                     materialSpreadObj.refreshActn();
 
-                     // 月信息价需要同时添加空白的list
 
-                     if (months.length > 0) {
 
-                         const one_month ={ mb_id: result.info.id, code: '', name: null, origin: null, unit: null, order: result.info.order };
 
-                         for (const m of months) {
 
-                             one_month[m] = null;
 
-                         }
 
-                         monthsList.push(one_month);
 
-                         // const newMonthsList = _.filter(monthsList, function (item) {
 
-                         //     return _.findIndex(newMaterialBillsData, { code: item.code }) !== -1;
 
-                         // });
 
-                         // materialMonthSpread.getActiveSheet().addRows(newMonthsList.length - 1, 1);
 
-                         // SpreadJsObj.reLoadRowData(materialMonthSpread.getActiveSheet(), newMonthsList.length - 1);
 
-                         monthFunGather.monthsListSet();
 
-                         // materialMonthSpreadObj.monthsListSet();
 
-                     }
 
-                 }
 
-             });
 
-         },
 
-         del: function () {
 
-             const sheet = materialSpread.getActiveSheet();
 
-             const select = SpreadJsObj.getSelectObject(sheet);
 
-             const sel = sheet.getSelections();
 
-             postData(window.location.pathname + '/save', {type: 'del', id: select.id}, function (result) {
 
-                 m_tp = result.m_tp;
 
-                 if (materialTax) {
 
-                     m_tax_tp = result.m_tax_tp;
 
-                 }
 
-                 const index = _.findIndex(materialBillsData, { id: select.id });
 
-                 materialBillsData.splice(index, 1);
 
-                 if (isStageSelf) {
 
-                     result.removeStageBillsData = [{ id: select.id }];
 
-                     materialSpreadObj.updateMaterialData(result);
 
-                     materialSpreadObj.getMaterialBillsData();
 
-                 }
 
-                 let newMaterialBillsData = materialBillsData;
 
-                 let newIndex = index;
 
-                 if($('#bills0_list').is(':checked')) {
 
-                     newMaterialBillsData = _.filter(materialBillsData, function (item) {
 
-                         return item.quantity !== null && item.quantity !== 0;
 
-                     });
 
-                     newIndex = _.findIndex(newMaterialBillsData, { id: select.id });
 
-                 }
 
-                 // sheet.deleteRows(newIndex, 1);
 
-                 // sheet.zh_data.splice(newIndex, 1);
 
-                 materialSpreadObj.materialSheetReset(true);
 
-                 resetTpTable();
 
-                 // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
 
-                 sheet.setSelection(newIndex > 0 ? newIndex - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
 
-                 materialSpreadObj.refreshActn();
 
-                 // 月信息价需要同时删除
 
-                 if (months.length > 0) {
 
-                     monthsList.splice(index, 1);
 
-                     materialMonthSpread.getActiveSheet().deleteRows(newIndex, 1);
 
-                     // SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
 
-                 }
 
-             });
 
-         },
 
-         upMove: function () {
 
-             if($('#bills0_list').is(':checked')) {
 
-                 return;
 
-             }
 
-             const data = {
 
-                 type: 'changeOrder',
 
-                 postData: [],
 
-             };
 
-             const sheet = materialSpread.getActiveSheet();
 
-             const selection = sheet.getSelections();
 
-             const row = selection[0].row, count = selection[0].rowCount;
 
-             const first = sheet.zh_data[row];
 
-             if (!first) {
 
-                 materialSpreadObj.refreshActn();
 
-                 return false;
 
-             }
 
-             const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
 
-             for (let iRow = 0; iRow < count; iRow++) {
 
-                 const posData = sheet.zh_data[iRow + row];
 
-                 if (posData) {
 
-                     data.postData.push({id: posData.id, order: sheet.zh_data[iRow + row - 1].order});
 
-                     preUpdate.order = posData.order;
 
-                 }
 
-             }
 
-             console.log(monthsList);
 
-             data.postData.push(preUpdate);
 
-             console.log(data);
 
-             if (data.postData.length > 0) {
 
-                 postData(window.location.pathname + '/save', data, function () {
 
-                     _.forEach(data.postData, function (item) {
 
-                         const cl = _.find(materialBillsData, { id: item.id });
 
-                         cl.order = item.order;
 
-                     });
 
-                     materialBillsData.sort(function (a, b) {
 
-                         return a.order - b.order
 
-                     });
 
-                     SpreadJsObj.reLoadSheetData(sheet);
 
-                     const sel = selection[0];
 
-                     if (sel) {
 
-                         sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
 
-                     }
 
-                     if (months.length > 0) {
 
-                         _.forEach(data.postData, function (item) {
 
-                             const cl = _.find(monthsList, { mb_id: item.id });
 
-                             cl.order = item.order;
 
-                         });
 
-                         monthsList.sort(function (a, b) {
 
-                             return a.order - b.order
 
-                         });
 
-                         const materialMonthSheet = materialMonthSpread.getActiveSheet();
 
-                         SpreadJsObj.reLoadSheetData(materialMonthSheet);
 
-                     }
 
-                     materialSpreadObj.refreshActn();
 
-                 });
 
-             }
 
-         },
 
-         downMove: function () {
 
-             if($('#bills0_list').is(':checked')) {
 
-                 return;
 
-             }
 
-             const data = {
 
-                 type: 'changeOrder',
 
-                 postData: [],
 
-             };
 
-             const sheet = materialSpread.getActiveSheet();
 
-             const selection = sheet.getSelections();
 
-             const row = selection[0].row, count = selection[0].rowCount;
 
-             const first = sheet.zh_data[row];
 
-             if (!first) {
 
-                 materialSpreadObj.refreshActn();
 
-                 return false;
 
-             }
 
-             const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
 
-             for (let iRow = count - 1; iRow >= 0; iRow--) {
 
-                 const posData = sheet.zh_data[iRow + row];
 
-                 if (posData) {
 
-                     data.postData.push({id: posData.id, order: sheet.zh_data[iRow + row + 1].order});
 
-                     nextUpdate.order = posData.order;
 
-                 }
 
-             }
 
-             data.postData.push(nextUpdate);
 
-             console.log(data);
 
-             if (data.postData.length > 0) {
 
-                 postData(window.location.pathname + '/save', data, function () {
 
-                     _.forEach(data.postData, function (item) {
 
-                         const cl = _.find(materialBillsData, { id: item.id });
 
-                         cl.order = item.order;
 
-                     });
 
-                     materialBillsData.sort(function (a, b) {
 
-                         return a.order - b.order
 
-                     });
 
-                     SpreadJsObj.reLoadSheetData(sheet);
 
-                     const sel = selection[0];
 
-                     if (sel) {
 
-                         sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
 
-                     }
 
-                     if (months.length > 0) {
 
-                         _.forEach(data.postData, function (item) {
 
-                             const cl = _.find(monthsList, { mb_id: item.id });
 
-                             cl.order = item.order;
 
-                         });
 
-                         monthsList.sort(function (a, b) {
 
-                             return a.order - b.order
 
-                         });
 
-                         const materialMonthSheet = materialMonthSpread.getActiveSheet();
 
-                         SpreadJsObj.reLoadSheetData(materialMonthSheet);
 
-                     }
 
-                     materialSpreadObj.refreshActn();
 
-                 });
 
-             }
 
-         },
 
-         selectionChanged: function (e, info) {
 
-             const sel = info.sheet.getSelections()[0];
 
-             const col = info.sheet.zh_setting.cols[sel.col];
 
-             materialSpreadObj.refreshActn(sel.rowCount);
 
-             const data = SpreadJsObj.getSelectObject(info.sheet);
 
-             materialSpreadObj.setReadOnly(true);
 
-             // console.log(data);
 
-             setCurBillSourceList(data ? (data.mb_id || data.id) : null, $('#myTab').find('.active').data('msid') || null);
 
-         },
 
-         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 === 'is_summary') {
 
-                     return;
 
-                 }
 
-                 // 未改变值则不提交
 
-                 let validText = (col.type === 'Number' || col.field === 'm_type' || col.field === 't_type') && is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
 
-                 const orgValue = select[col.field];
 
-                 if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
 
-                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                     return;
 
-                 }
 
-                 // 判断部分值是否输入的是数字判断和数据计算
 
-                 if (col.field === 'basic_price') {
 
-                     if (isNaN(validText)) {
 
-                         toastr.error('不能输入其它非数字类型字符');
 
-                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                         return;
 
-                     }
 
-                     let num = parseFloat(validText);
 
-                     const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
 
-                     if (validText !== null && (num < 0 || !reg.test(num))) {
 
-                         toastr.warning('已保留'+ materialDecimal.up +'位小数');
 
-                         validText = ZhCalc.round(num, materialDecimal.up);
 
-                     }
 
-                 }
 
-                 if (col.field === 'msg_tp') {
 
-                     if (isNaN(validText)) {
 
-                         toastr.error('不能输入其它非数字类型字符');
 
-                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                         return;
 
-                     }
 
-                     const num = parseFloat(validText);
 
-                     const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
 
-                     if (validText !== null && (num < 0 || !reg.test(num))) {
 
-                         toastr.warning('已保留'+ materialDecimal.up +'位小数');
 
-                         validText = ZhCalc.round(num, materialDecimal.up);
 
-                     }
 
-                 }
 
-                 if (col.field === 'm_up_risk' || col.field === 'm_down_risk' || col.field === 'm_tax') {
 
-                     // 只能输入正整数
 
-                     if (isNaN(validText)) {
 
-                         toastr.error('不能输入其它非数字类型字符');
 
-                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                         return;
 
-                     }
 
-                     const num = parseFloat(validText);
 
-                     if (validText !== null && (num < 0 || num > 100 || !/^\d+$/.test(num))) {
 
-                         toastr.error('只能输入0-100的正整数');
 
-                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                         return;
 
-                     }
 
-                 }
 
-                 if (col.field === 't_type') {
 
-                     if (validText === 1) {
 
-                         select.quantity = null;
 
-                         select.expr = null;
 
-                         select.m_tp = null;
 
-                     }
 
-                 }
 
-                 select[col.field] = validText;
 
-                 select.msg_spread = materialCol.getValue.msg_spread(select);
 
-                 select.m_spread = materialCol.getValue.m_spread(select);
 
-                 select.m_tp = materialCol.getValue.m_tp(select);
 
-                 select.m_tax_tp = materialCol.getValue.m_tax_tp(select);
 
-                 delete select.waitingLoading;
 
-                 // console.log(select);
 
-                 // 更新至服务器
 
-                 postData(window.location.pathname + '/save', { type:'update', updateData: select, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
 
-                     m_tp = result.m_tp;
 
-                     if (materialTax) {
 
-                         m_tax_tp = result.m_tax_tp;
 
-                     }
 
-                     if (isStageSelf) {
 
-                         materialSpreadObj.updateMaterialData(result);
 
-                     }
 
-                     resetTpTable();
 
-                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                     // 判断如果是更改了编号,名称,单位,月信息价需要跟着改变值
 
-                     if (months.length > 0 && (col.field === 'code' || col.field === 'name' || col.field === 'unit')) {
 
-                         const index = _.findIndex(materialBillsData, { id: select.id });
 
-                         monthsList[index][col.field] = validText;
 
-                         monthFunGather.monthsListSet();
 
-                     }
 
-                 }, function () {
 
-                     select[col.field] = orgValue;
 
-                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                 });
 
-             }
 
-         },
 
-         buttonClicked: function (e, info) {
 
-             if (info.sheet.zh_setting) {
 
-                 const select = SpreadJsObj.getSelectObject(info.sheet);
 
-                 const col = info.sheet.zh_setting.cols[info.col];
 
-                 if (materialCol.readOnly.isEdit(select)) {
 
-                     return;
 
-                 }
 
-                 if (col.field === 'is_summary') {
 
-                     if (info.sheet.isEditing()) {
 
-                         info.sheet.endEdit(true);
 
-                     }
 
-                     select.is_summary = info.sheet.getValue(info.row, info.col) ? 1 : 0;
 
-                     delete select.waitingLoading;
 
-                     // 更新至服务器
 
-                     postData(window.location.pathname + '/save', { type:'update', updateData: select, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
 
-                         m_tp = result.m_tp;
 
-                         if (materialTax) {
 
-                             m_tax_tp = result.m_tax_tp;
 
-                         }
 
-                         if (isStageSelf) {
 
-                             materialSpreadObj.updateMaterialData(result);
 
-                         }
 
-                         resetTpTable();
 
-                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                     }, function () {
 
-                         select.is_summary = info.sheet.getValue(info.row, info.col) ? 0 : 1;
 
-                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                     });
 
-                 }
 
-             }
 
-         },
 
-         deletePress: function (sheet) {
 
-             return;
 
-         },
 
-         clipboardPasted(e, info) {
 
-             const hint = {
 
-                 cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
 
-                 codeEmpty: {type: 'error', msg: '请先输入编号,并且不超过15个字符'},
 
-                 codeUsed: {type: 'error', msg: '该编号已存在,请重新输入。'},
 
-                 codeError: {type: 'error', msg: '编号为纯数字时,不能为小数'},
 
-                 numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
 
-                 riskCan: {type: 'error', msg: '只能粘贴0-100的正整数'},
 
-                 numberCan: {type: 'warning', msg: '已保留'+ materialDecimal.up +'位小数'},
 
-             };
 
-             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(materialSpread.getActiveSheet());
 
-                 SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
 
-                 return;
 
-             }
 
-             if (sortData.length > 0 && range.col + range.colCount > 18) {
 
-                 toastMessageUniq(hint.cellError);
 
-                 SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
 
-                 SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
 
-                 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 materialData = { 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 = (colSetting.type === 'Number' || colSetting.field === 'm_type' || colSetting.field === 't_type') && is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
 
-                     const orgValue = sortData[curRow][colSetting.field];
 
-                     if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
 
-                         sameCol++;
 
-                         if (range.colCount === sameCol)  {
 
-                             bPaste = false;
 
-                         }
 
-                         continue;
 
-                     }
 
-                     if (colSetting.field === 'code' && (validText === '' || validText.length > 15)) {
 
-                         toastMessageUniq(getPasteHint(hint.codeEmpty, hintRow));
 
-                         bPaste = false;
 
-                         continue;
 
-                     }
 
-                     if (colSetting.field === 'code' && validText.toString().indexOf('.') !== -1) {
 
-                         toastMessageUniq(getPasteHint(hint.codeError, hintRow));
 
-                         bPaste = false;
 
-                         continue;
 
-                     }
 
-                     if (colSetting.field === 'code' && _.find(sortData, { code: validText.toString() })) {
 
-                         toastMessageUniq(getPasteHint(hint.codeUsed, hintRow));
 
-                         bPaste = false;
 
-                         continue;
 
-                     }
 
-                     if (colSetting.field === 't_type' || colSetting.field === 'm_type') {
 
-                         continue;
 
-                     }
 
-                     if (colSetting.field === 'basic_price' || colSetting.field === 'msg_tp'
 
-                         || colSetting.field === 'm_up_risk' || colSetting.field === 'm_down_risk') {
 
-                         if (isNaN(validText)) {
 
-                             toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
 
-                             bPaste = false;
 
-                             continue;
 
-                         }
 
-                         const num = parseFloat(validText);
 
-                         if (colSetting.field === 'basic_price' || colSetting.field === 'msg_tp') {
 
-                             const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
 
-                             if (validText !== null && (num < 0 || !reg.test(num))) {
 
-                                 toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
 
-                                 validText = ZhCalc.round(num, materialDecimal.up);
 
-                             }
 
-                         } else if (colSetting.field === 'm_up_risk' || colSetting.field === 'm_down_risk' || colSetting.field === 'm_tax') {
 
-                             if (validText !== null && (num < 0 || num > 100 || !/^\d+$/.test(num))) {
 
-                                 toastMessageUniq(getPasteHint(hint.riskCan, hintRow));
 
-                                 bPaste = false;
 
-                                 continue;
 
-                             }
 
-                         }
 
-                     }
 
-                     materialData[colSetting.field] = validText;
 
-                     sortData[curRow][colSetting.field] = validText;
 
-                 }
 
-                 if (materialData.code === '' || materialData.code === null) {
 
-                     toastMessageUniq(getPasteHint(hint.codeEmpty, hintRow));
 
-                     bPaste = false;
 
-                 }
 
-                 if (bPaste) {
 
-                     materialData.msg_spread = materialCol.getValue.msg_spread(sortData[curRow]);
 
-                     materialData.m_spread = materialCol.getValue.m_spread(sortData[curRow]);
 
-                     materialData.m_tp = materialCol.getValue.m_tp(sortData[curRow]);
 
-                     materialData.m_tax_tp = materialCol.getValue.m_tax_tp(sortData[curRow]);
 
-                     data.push(materialData);
 
-                     // 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, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
 
-                 materialBillsData = result.info;
 
-                 m_tp = result.m_tp;
 
-                 if (materialTax) {
 
-                     m_tax_tp = result.m_tax_tp;
 
-                 }
 
-                 if (isStageSelf) {
 
-                     materialSpreadObj.updateMaterialData(result);
 
-                     materialSpreadObj.getMaterialBillsData();
 
-                 }
 
-                 // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
 
-                 materialSpreadObj.materialSheetReset();
 
-                 // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
 
-                 // for (const row in rowData) {
 
-                 //     materialBillsData.splice(index, 1, result.info[row]);
 
-                 //     SpreadJsObj.reLoadRowData(info.sheet, row);
 
-                 // }
 
-                 if (months.length > 0) {
 
-                     for (const [i,m] of monthsList.entries()) {
 
-                         m.code = materialBillsData[i].code;
 
-                         m.name = materialBillsData[i].name;
 
-                         m.unit = materialBillsData[i].unit;
 
-                         m.origin = materialBillsData[i].origin;
 
-                     }
 
-                     // SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, monthsList);
 
-                     monthFunGather.monthsListSet();
 
-                     // SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
 
-                 }
 
-                 resetTpTable();
 
-                 // materialSpreadObj.refreshActn();
 
-             }, function () {
 
-                 // materialSpreadObj.refreshActn();
 
-                 SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
 
-                 return;
 
-             });
 
-         },
 
-         setReadOnly: function(readOnly) {
 
-             // SpreadJsObj.resetFieldReadOnly(materialSpread.getActiveSheet(), 'msg_spread', 'm_spread', 'm_tp', 'pre_tp', readOnly);
 
-         }
 
-     };
 
-     materialSpread.bind(spreadNS.Events.SelectionChanged, materialSpreadObj.selectionChanged);
 
-     materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
 
-     SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
 
-     materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
 
-     materialSpread.bind(spreadNS.Events.ButtonClicked, materialSpreadObj.buttonClicked);
 
-     const sheet = materialSpread.getActiveSheet();
 
-     sheet.suspendPaint();
 
-     // materialSpreadObj.refreshActn();
 
-     // const basic_range = sheet.getRange(-1, 8, -1, 1);
 
-     // basic_range.cellType(new DatePickerCellType());
 
-     // basic_range.formatter("yyyy-MM-dd");
 
-     // const msg_range = sheet.getRange(-1, 10, -1, 1);
 
-     // msg_range.cellType(new DatePickerCellType());
 
-     // msg_range.formatter("yyyy-MM-dd");
 
-     sheet.resumePaint();
 
-     const static_cols = [
 
-         {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 60, formatter: '@', readOnly: true},
 
-         {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
 
-         {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
 
-         {title: '来源地', colSpan: '1', rowSpan: '2', field: 'origin', hAlign: 0, width: 70, formatter: '@', readOnly: 'readOnly.isEdit'},
 
-         {title: '平均单价', colSpan: '1', rowSpan: '2', field: 'average_msg_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue:'getValue.average_msg_tp'},
 
-     ];
 
-     // 月信息价方法集合
 
-     const monthFunGather = {
 
-         _setMonthHtml: function() {
 
-             let html = '';
 
-             let qihtml = '';
 
-             for (const m of months) {
 
-                 html += '<div class="custom-control custom-checkbox mb-2">\n' +
 
-                     '                            <input type="checkbox" name="del_month" value="' + m + '" class="custom-control-input" id="month_' + m + '">\n' +
 
-                     '                            <label class="custom-control-label" for="month_' + m + '">' + m + '月</label>\n' +
 
-                     '                        </div>';
 
-                 qihtml += parseInt(m.split('-')[1]) + '月,';
 
-             }
 
-             if (months.length > 0) {
 
-                 qihtml = '<span class="mx-2 text-muted">/</span>本期月信息价:' + qihtml;
 
-                 qihtml = qihtml.substring(0, qihtml.length-1);
 
-             }
 
-             $('#show_month').html(html);
 
-             $('#qi-month').html(qihtml);
 
-         },
 
-         _monthHeaderSet: function() {
 
-             const newMonths = [];
 
-             for (const m of months) {
 
-                 const year = m.split('-')[0];
 
-                 const month = parseInt(m.split('-')[1]);
 
-                 let one = _.find(newMonths, { 'year': year });
 
-                 let oneIndex = _.findIndex(newMonths, { 'year': year });
 
-                 if (one) {
 
-                     one.month.push(month);
 
-                     newMonths.splice(oneIndex, 1, one);
 
-                 } else {
 
-                     one = {
 
-                         year: year,
 
-                         month: [ month ],
 
-                     };
 
-                     newMonths.push(one);
 
-                 }
 
-             }
 
-             const pushMonth = [];
 
-             for(const mo of newMonths) {
 
-                 for (let i in mo.month) {
 
-                     i = parseInt(i);
 
-                     const newCols = {
 
-                         title: (i === 0 ? mo.year: '') + '|' + mo.month[i] + '月',
 
-                         colSpan: (i === 0 ? (mo.month.length === 1 ? '0' : mo.month.length) : '') + '|1',
 
-                         rowSpan: i === 0 ? '1|1' : '|1',
 
-                         field: mo.year + '-' + (mo.month[i] < 10 ? '0' + mo.month[i] : mo.month[i]),
 
-                         hAlign: 2, width: 60, type: '@', readOnly: 'readOnly.isEdit'};
 
-                     pushMonth.push(newCols);
 
-                 }
 
-             }
 
-             return pushMonth;
 
-         },
 
-         monthSheetReset: function (ml = monthsList) {
 
-             const monthCols = monthFunGather._monthHeaderSet();
 
-             const newMonthSpreadHeaderCols = static_cols.concat(monthCols);
 
-             materialMonthSpreadSetting.cols = newMonthSpreadHeaderCols;
 
-             // 表头变化需要重新绘制,不然报错;
 
-             materialMonthSpread.getActiveSheet().reset();
 
-             SpreadJsObj.initSpreadSettingEvents(materialMonthSpreadSetting, materialMonthCol);
 
-             SpreadJsObj.initSheet(materialMonthSpread.getActiveSheet(), materialMonthSpreadSetting);
 
-             SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, ml);
 
-             monthFunGather._setMonthHtml();
 
-         },
 
-         monthsListSet: function (ml = materialBillsData, checked = true) {
 
-             if($('#bills0_list').is(':checked') && checked) {
 
-                 ml = _.filter(materialBillsData, function (item) {
 
-                     return item.quantity === null || item.quantity === 0;
 
-                 });
 
-             }
 
-             const newMonthsList = _.filter(monthsList, function (item) {
 
-                 return _.findIndex(ml, { code: item.code }) !== -1;
 
-             });
 
-             monthFunGather.monthSheetReset(newMonthsList);
 
-         }
 
-     };
 
-     const materialMonthSpread = SpreadJsObj.createNewSpread($('#material-month-spread')[0]);
 
-     const materialMonthSpreadSetting = {
 
-         cols: static_cols,
 
-         emptyRows: 0,
 
-         headRows: 2,
 
-         headRowHeight: [25, 25],
 
-         defaultRowHeight: 21,
 
-         headerFont: '12px 微软雅黑',
 
-         font: '12px 微软雅黑',
 
-         readOnly: readOnly,
 
-     };
 
-     if (months.length > 0) {
 
-         const monthCols = monthFunGather._monthHeaderSet();
 
-         const monthSpreadHeaderCols = static_cols.concat(monthCols);
 
-         materialMonthSpreadSetting.cols = monthSpreadHeaderCols;
 
-     }
 
-     const materialMonthCol = {
 
-         getValue: {
 
-             average_msg_tp: function (data) {
 
-                 let msg_tp = 0;
 
-                 let hadnum = 0;
 
-                 for (const m of months) {
 
-                     msg_tp += data[m];
 
-                     if (data[m] !== null && data[m] !== '' && data[m] !== 0) {
 
-                         hadnum++;
 
-                     }
 
-                 }
 
-                 const average_tp = hadnum !== 0 ? ZhCalc.round(ZhCalc.div(msg_tp, hadnum), materialDecimal.up) : ZhCalc.round(ZhCalc.div(msg_tp, months.length), materialDecimal.up);
 
-                 return average_tp;
 
-             },
 
-         },
 
-         readOnly: {
 
-             isEdit: function (data) {
 
-                 return readOnly;
 
-             },
 
-         },
 
-     };
 
-     materialMonthSpread.getActiveSheet().frozenColumnCount(5);
 
-     materialMonthSpread.getActiveSheet().options.frozenlineColor = '#f1f1f1';
 
-     SpreadJsObj.initSpreadSettingEvents(materialMonthSpreadSetting, materialMonthCol);
 
-     SpreadJsObj.initSheet(materialMonthSpread.getActiveSheet(), materialMonthSpreadSetting);
 
-     SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, monthsList);
 
-     const materialMonthSpreadObj = {
 
-         editEnded: function (e, info) {
 
-             if (info.sheet.zh_setting) {
 
-                 const select = SpreadJsObj.getSelectObject(info.sheet);
 
-                 const col = info.sheet.zh_setting.cols[info.col];
 
-                 // 未改变值则不提交
 
-                 let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
 
-                 const orgValue = select[col.field];
 
-                 if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
 
-                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                     return;
 
-                 }
 
-                 if (col.field === 'origin') {
 
-                     select[col.field] = validText;
 
-                     postData(window.location.pathname + '/month/save', { type:'updateOrigin', updateData: { mb_id: select.mb_id, value: validText } }, function (result) {
 
-                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                         materialBillsData = result.materialBillsData;
 
-                         materialSpreadObj.materialSheetReset();
 
-                         // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
 
-                     }, function () {
 
-                         select[col.field] = orgValue;
 
-                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                     });
 
-                 } else {
 
-                     // 判断部分值是否输入的是数字判断和数据计算
 
-                     if (isNaN(validText)) {
 
-                         toastr.error('不能输入其它非数字类型字符');
 
-                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                         return;
 
-                     }
 
-                     const num = parseFloat(validText);
 
-                     const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
 
-                     if (validText !== null && (num < 0 || !reg.test(num))) {
 
-                         toastr.warning('已保留'+ materialDecimal.up +'位小数');
 
-                         validText = ZhCalc.round(num, materialDecimal.up);
 
-                     }
 
-                     select[col.field] = validText;
 
-                     // 更新至服务器
 
-                     postData(window.location.pathname + '/month/save', { type:'update', updateData: { mb_id: select.mb_id, yearmonth: col.field, value: validText } }, function (result) {
 
-                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                         materialBillsData = result.materialBillsData;
 
-                         materialSpreadObj.materialSheetReset();
 
-                         // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
 
-                         m_tp = result.m_tp;
 
-                         if (materialTax) {
 
-                             m_tax_tp = result.m_tax_tp;
 
-                         }
 
-                         resetTpTable();
 
-                     }, function () {
 
-                         select[col.field] = orgValue;
 
-                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                     });
 
-                 }
 
-             }
 
-         },
 
-         deletePress: function (sheet) {
 
-             // if (sheet.zh_setting && sheet.zh_data) {
 
-             //     const sel = sheet.getSelections()[0];
 
-             //     if (!sel) return;
 
-             //
 
-             //     const col = sheet.zh_setting.cols[sel.col];
 
-             //     const select = SpreadJsObj.getSelectObject(sheet);
 
-             //     const orgValue = select[col.field];
 
-             //     if (sel.colCount > 1 || sel.rowCount > 1) {
 
-             //         toastr.warning('请勿同时删除多行或多列数据');
 
-             //     }
 
-             //     console.log(sel, select, col);
 
-             // if (orgValue === null || col.field === 'type' || col.field === 'is_summary') {
 
-             //     return;
 
-             // }
 
-             // select[col.field] = null;
 
-             // select.calc_num = materialExponentCol.getValue.calc_num(select);
 
-             // console.log(select);
 
-             // 更新至服务器
 
-             // postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
 
-             //     ex_tp = result.ex_tp;
 
-             //     ex_expr = result.ex_expr;
 
-             //     resetExTpTable();
 
-             //     SpreadJsObj.reLoadRowData(sheet, sel.row);
 
-             //     materialExponentData.splice(sel.row, 1, select);
 
-             // }, function () {
 
-             //     select[col.field] = orgValue;
 
-             //     SpreadJsObj.reLoadRowData(sheet, sel.row);
 
-             // });
 
-             // }
 
-             return;
 
-         },
 
-         clipboardPasted(e, info) {
 
-             const hint = {
 
-                 cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
 
-                 numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
 
-                 numberCan: {type: 'warning', msg: '已保留'+ materialDecimal.up +'位小数'},
 
-             };
 
-             const range = info.cellRange;
 
-             const sortData = info.sheet.zh_data || [];
 
-             if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
 
-                 toastMessageUniq(hint.cellError);
 
-                 SpreadJsObj.reLoadSheetHeader(materialMonthSpread.getActiveSheet());
 
-                 SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
 
-                 return;
 
-             }
 
-             if (sortData.length > 0 && range.col + range.colCount > 5 + months.length) {
 
-                 toastMessageUniq(hint.cellError);
 
-                 SpreadJsObj.reLoadSheetHeader(materialMonthSpread.getActiveSheet());
 
-                 SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
 
-                 return;
 
-             }
 
-             const data = [];
 
-             let pasteOrigin = false;
 
-             for (let iRow = 0; iRow < range.rowCount; iRow++) {
 
-                 let bPaste = true;
 
-                 const curRow = range.row + iRow;
 
-                 const materialMonthData = sortData[curRow];
 
-                 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) : null);
 
-                     const orgValue = sortData[curRow][colSetting.field];
 
-                     if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
 
-                         sameCol++;
 
-                         if (range.colCount === sameCol)  {
 
-                             bPaste = false;
 
-                         }
 
-                         continue;
 
-                     }
 
-                     if (colSetting.field === 'origin') {
 
-                         pasteOrigin = true;
 
-                     } else {
 
-                         const num = parseFloat(validText);
 
-                         if (isNaN(validText)) {
 
-                             toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
 
-                             bPaste = false;
 
-                             continue;
 
-                         }
 
-                         const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
 
-                         if (validText !== null && (num < 0 || !reg.test(num))) {
 
-                             toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
 
-                             validText = ZhCalc.round(num, materialDecimal.up);
 
-                         }
 
-                     }
 
-                     materialMonthData[colSetting.field] = validText;
 
-                     sortData[curRow][colSetting.field] = validText;
 
-                 }
 
-                 if (bPaste) {
 
-                     data.push(materialMonthData);
 
-                 } else {
 
-                     SpreadJsObj.reLoadRowData(info.sheet, curRow);
 
-                 }
 
-             }
 
-             if (data.length === 0) {
 
-                 SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
 
-                 return;
 
-             }
 
-             // console.log(data);
 
-             if (pasteOrigin) {
 
-                 // 更新至服务器
 
-                 postData(window.location.pathname + '/month/save', { type:'pasteOrigin', updateData: data }, function (result) {
 
-                     SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
 
-                     materialBillsData = result.materialBillsData;
 
-                 }, function () {
 
-                     SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
 
-                     return;
 
-                 });
 
-             } else {
 
-                 // 更新至服务器
 
-                 postData(window.location.pathname + '/month/save', { type:'paste', updateData: data }, function (result) {
 
-                     SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
 
-                     materialBillsData = result.materialBillsData;
 
-                     materialSpreadObj.materialSheetReset();
 
-                     // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
 
-                     m_tp = result.m_tp;
 
-                     if (materialTax) {
 
-                         m_tax_tp = result.m_tax_tp;
 
-                     }
 
-                     resetTpTable();
 
-                 }, function () {
 
-                     SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
 
-                     return;
 
-                 });
 
-             }
 
-         },
 
-     };
 
-     // 应耗来源sjs
 
-     const material_source_cols = [
 
-         {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 100, formatter: '@'},
 
-         {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 150, formatter: '@'},
 
-         {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 70, formatter: '@'},
 
-         {title: '本期应耗', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 100, formatter: '@'},
 
-     ];
 
-     const materialSourceSpread = SpreadJsObj.createNewSpread($('#material-source-spread')[0]);
 
-     const materialSourceSpreadSetting = {
 
-         cols: material_source_cols,
 
-         emptyRows: 0,
 
-         headRows: 1,
 
-         headRowHeight: [32],
 
-         defaultRowHeight: 21,
 
-         headerFont: '12px 微软雅黑',
 
-         font: '12px 微软雅黑',
 
-         readOnly: true,
 
-     };
 
-     SpreadJsObj.initSheet(materialSourceSpread.getActiveSheet(), materialSourceSpreadSetting);
 
-     SpreadJsObj.loadSheetData(materialSourceSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
 
-     let first = true;
 
-     function setListsData(sid = null, ms_id = null) {
 
-         if (first) {
 
-             // 加载清单数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
 
-             postData(window.location.pathname + '/list/load', {sid}, async function (result) {
 
-                 ledger = result.ledger;
 
-                 curLedgerData = result.curLedgerData;
 
-                 pos = result.pos;
 
-                 curPosData = result.curPosData;
 
-                 materialListData2 = result.materialListData;
 
-                 gclList = result.gclList;
 
-                 notJoinList = result.materialNotJoinListData;
 
-                 selfList = result.materialSelfListData;
 
-                 materialChecklistData = result.materialChecklistData;
 
-                 if (isStageSelf) {
 
-                     const newGclGatherListData = [];
 
-                     for (const [index, s] of result.ledgerListData.entries()) {
 
-                         gclGatherModel.loadLedgerData(_.cloneDeep(ledger), s);
 
-                         gclGatherModel.loadPosData(_.cloneDeep(pos), result.posListData[index]);
 
-                         const oneGclGatherData = gclGatherModel.gatherGclData().filter(item => {
 
-                             return item.qc_qty || item.contract_qty || item.qc_minus_qty
 
-                         });
 
-                         newGclGatherListData.push(oneGclGatherData);
 
-                     }
 
-                     gclGatherListData = newGclGatherListData;
 
-                 }
 
-                 // 解析清单汇总数据
 
-                 gclGatherModel.loadLedgerData(_.cloneDeep(ledger), curLedgerData);
 
-                 gclGatherModel.loadPosData(_.cloneDeep(pos), curPosData);
 
-                 gclGatherData = gclGatherModel.gatherGclData();
 
-                 gclGatherData = gclGatherData.filter(item => {
 
-                     return item.qc_qty || item.contract_qty || item.qc_minus_qty
 
-                 });
 
-                 if (openMaterialChecklist) {
 
-                     // 取交集
 
-                     const selfListGcl = _.uniq(_.map(selfList, 'gcl_id'));
 
-                     gclGatherData = _.filter(gclGatherData, function (item) {
 
-                         if (_.find(materialChecklistData, {
 
-                             b_code: item.b_code,
 
-                             name: item.name,
 
-                             unit: item.unit,
 
-                             unit_price: item.unit_price
 
-                         })) {
 
-                             return true;
 
-                         } else {
 
-                             const gcl_ids = item.leafXmjs ? _.uniq(_.map(item.leafXmjs, 'gcl_id')) : [];
 
-                             const jiaoji = _.intersection(gcl_ids, selfListGcl);
 
-                             if (jiaoji.length > 0) {
 
-                                 return true;
 
-                             }
 
-                         }
 
-                     });
 
-                 }
 
-                 // calculateJiaCha(gclGatherData);
 
-                 console.log(gclGatherData);
 
-                 setCurBillSourceList(materialBillsData[0] ? materialBillsData[0].mb_id || materialBillsData[0].id : null, ms_id);
 
-                 first = false;
 
-                 // 判断是否需要更新contract_qty、qc_qty和qc_minus_qty
 
-                 if (!materialIsNewQty && !readOnly && !editForAudit) {
 
-                     let needUpdateList = [];
 
-                     if (materialListData2.length > 0) {
 
-                         if (isStageSelf) {
 
-                             for (const msIndex in materialStageData) {
 
-                                 const materialStageList = _.filter(materialListData2, { ms_id: materialStageData[msIndex].id });
 
-                                 const gclIdList = _.uniq(_.map(materialListData2, 'gcl_id'));
 
-                                 let leafXmjList = [];
 
-                                 for (const id of gclIdList) {
 
-                                     const gcl = _.find(gclGatherListData[msIndex], function (item) {
 
-                                         return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, {gcl_id: id}) !== -1;
 
-                                     });
 
-                                     if (gcl) leafXmjList = [...leafXmjList, ...gcl.leafXmjs];
 
-                                 }
 
-                                 for (const ml of materialStageList) {
 
-                                     const leafXmjInfo = _.find(leafXmjList, function (item) {
 
-                                         return item.gcl_id === ml.gcl_id && item.id === ml.xmj_id && (item.mx_id === undefined || (item.mx_id !== undefined && item.mx_id === ml.mx_id));
 
-                                     });
 
-                                     if (leafXmjInfo) {
 
-                                         needUpdateList.push({ id: ml.id, contract_qty: leafXmjInfo.contract_qty, qc_qty: leafXmjInfo.qc_qty, qc_minus_qty: leafXmjInfo.qc_minus_qty });
 
-                                     }
 
-                                 }
 
-                             }
 
-                         } else {
 
-                             // 找出所有gcl相同的,方便搜索gclGatherData值
 
-                             const gclIdList = _.uniq(_.map(materialListData2, 'gcl_id'));
 
-                             let leafXmjList = [];
 
-                             for (const id of gclIdList) {
 
-                                 const gcl = _.find(gclGatherData, function (item) {
 
-                                     return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, {gcl_id: id}) !== -1;
 
-                                 });
 
-                                 if (gcl) leafXmjList = [...leafXmjList, ...gcl.leafXmjs];
 
-                             }
 
-                             for (const ml of materialListData2) {
 
-                                 const leafXmjInfo = _.find(leafXmjList, function (item) {
 
-                                     return item.gcl_id === ml.gcl_id && item.id === ml.xmj_id && (item.mx_id === undefined || (item.mx_id !== undefined && item.mx_id === ml.mx_id));
 
-                                 });
 
-                                 if (leafXmjInfo) {
 
-                                     needUpdateList.push({ id: ml.id, contract_qty: leafXmjInfo.contract_qty, qc_qty: leafXmjInfo.qc_qty, qc_minus_qty: leafXmjInfo.qc_minus_qty });
 
-                                 }
 
-                             }
 
-                         }
 
-                     }
 
-                     console.log(needUpdateList);
 
-                     postData(window.location.pathname + '/save', { type: 'qty_update', needUpdateList }, function (result) {
 
-                         materialListData2 = result.materialListData;
 
-                     });
 
-                 }
 
-             });
 
-         } else {
 
-             const i = _.findIndex(materialStageData, { sid });
 
-             gclGatherData = gclGatherListData[i];
 
-             gclGatherData = gclGatherData.filter(item => {
 
-                 return item.qc_qty || item.contract_qty || item.qc_minus_qty
 
-             });
 
-             if (openMaterialChecklist) {
 
-                 // 取交集
 
-                 const selfListGcl = _.uniq(_.map(selfList, 'gcl_id'));
 
-                 gclGatherData = _.filter(gclGatherData, function (item) {
 
-                     if (_.find(materialChecklistData, {
 
-                         b_code: item.b_code,
 
-                         name: item.name,
 
-                         unit: item.unit,
 
-                         unit_price: item.unit_price
 
-                     })) {
 
-                         return true;
 
-                     } else {
 
-                         const gcl_ids = item.leafXmjs ? _.uniq(_.map(item.leafXmjs, 'gcl_id')) : [];
 
-                         const jiaoji = _.intersection(gcl_ids, selfListGcl);
 
-                         if (jiaoji.length > 0) {
 
-                             return true;
 
-                         }
 
-                     }
 
-                 });
 
-             }
 
-             // calculateJiaCha(gclGatherData);
 
-             console.log(gclGatherData);
 
-         }
 
-     }
 
-     setListsData(isStageSelf ? materialStageData[0].sid : null, isStageSelf ? materialStageData[0].id : null);
 
-     SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
 
-     SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
 
-     materialSpreadObj.getMaterialBillsData();
 
-     SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
 
-     materialSpreadObj.refreshActn();
 
-     materialMonthSpread.bind(spreadNS.Events.ClipboardPasted, materialMonthSpreadObj.clipboardPasted);
 
-     SpreadJsObj.addDeleteBind(materialMonthSpread, materialMonthSpreadObj.deletePress);
 
-     materialMonthSpread.bind(spreadNS.Events.EditEnded, materialMonthSpreadObj.editEnded);
 
-     // 期切换
 
-     $('#myTab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
 
-         e.preventDefault();
 
-         showWaitingView();
 
-         setTimeout(function () {
 
-             materialSpreadObj.getMaterialBillsData();
 
-             materialSpreadObj.materialSheetReset(true);
 
-             // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
 
-             // 消耗量表格更新
 
-             let html = '';
 
-             calcBase = _.find(calcBaseList, { ms_id: $('#myTab').find('.active').data('msid') }).calcBase;
 
-             for (let iBase = 0; iBase < calcBase.length; iBase++) {
 
-                 if (!calcBase[iBase].cType || (calcBase[iBase].cType && calcBase[iBase].cType === 1 && calcBase[iBase].value)) {
 
-                     html += '<tr><td>' + calcBase[iBase].name + '</td><td>' + calcBase[iBase].code + '</td><td>' + calcBase[iBase].value + '</td></tr>';
 
-                 }
 
-             }
 
-             $('#calcBase').html(html);
 
-             const ms_id = parseInt($('#myTab').find('.active').data('msid'));
 
-             const msInfo = _.find(materialStageData, { id: ms_id });
 
-             setListsData(msInfo.sid, ms_id);
 
-             const data = SpreadJsObj.getSelectObject(materialSpread.getActiveSheet());
 
-             setCurBillSourceList(data ? (data.mb_id || data.id) : null, ms_id);
 
-             closeWaitingView();
 
-         }, 1000);
 
-     });
 
-     // 本条工料应耗来源数据信息
 
-     function setCurBillSourceList(mb_id, ms_id = null) {
 
-         const showSourceList = [];
 
-         if (mb_id) {
 
-             const list = _.filter(materialListData2, function (item) {
 
-                 return item.mb_id === mb_id && item.ms_id === ms_id && (item.is_join === 1 || item.is_join === 2);
 
-             });
 
-             console.log(list);
 
-             if (list.length > 0) {
 
-                 for (const l of list) {
 
-                     const gcl = _.find(gclGatherData, function (item) {
 
-                         return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, { gcl_id: l.gcl_id }) !== -1;
 
-                     });
 
-                     if (gcl) {
 
-                         const index = _.findIndex(showSourceList, { code: gcl.b_code, name: gcl.name, unit: gcl.unit });
 
-                         if (index === -1) {
 
-                             showSourceList.push({
 
-                                 code: gcl.b_code,
 
-                                 name: gcl.name,
 
-                                 unit: gcl.unit,
 
-                                 quantity: ZhCalc.mul(calcQty(l), l.quantity),
 
-                             });
 
-                         } else {
 
-                             showSourceList[index].quantity = ZhCalc.add(showSourceList[index].quantity, ZhCalc.mul(calcQty(l), l.quantity));
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         // 按清单编号排序
 
-         SpreadJsObj.loadSheetData(materialSourceSpread.getActiveSheet(), SpreadJsObj.DataType.Data, showSourceList.sort(sortByCode));
 
-     }
 
-     function calcQty(info) {
 
-         let qty = '';
 
-         switch (qtySource) {
 
-             case qtySourceValueConst.gather_qty: qty = info.gather_qty; break;
 
-             case qtySourceValueConst.contract_qty: qty = info.contract_qty; break;
 
-             case qtySourceValueConst.gather_minus_qty: qty = ZhCalc.add(info.gather_qty, info.qc_minus_qty); break;
 
-             default: throw '未配置计量来源出错';
 
-         }
 
-         if (qtySource !== qtySourceValueConst.contract_qty && info.is_join === 2) {
 
-             qty = info.contract_qty;
 
-         }
 
-         return qty;
 
-     }
 
-     if (!readOnly || editForAudit) {
 
-         $('#expr_select button').on('click', function () {
 
-             const code = $(this).text();
 
-             // $('#expr').val($('#expr').val() + code);
 
-             $('#expr').insertAtCaret(code);
 
-         });
 
-         const ExprObj = {
 
-             _checkExprValid(expr, invalidParam) {
 
-                 if (!expr) return [true, null];
 
-                 const param = [];
 
-                 let num = '', base = '';
 
-                 for (let i = 0, iLen = expr.length; i < iLen; i++) {
 
-                     if (/^[\d\.%]+/.test(expr[i])) {
 
-                         if (base !== '') {
 
-                             param.push({type: 'base', value: base});
 
-                             base = '';
 
-                         }
 
-                         num = num + expr[i];
 
-                     } else if (/^[a-z]/.test(expr[i])) {
 
-                         if (num !== '') {
 
-                             param.push({type: 'num', value: num});
 
-                             num = '';
 
-                         }
 
-                         base = base + expr[i];
 
-                     } else if (expr[i] === '(') {
 
-                         if (num !== '') {
 
-                             param.push({type: 'num', value: num});
 
-                             num = '';
 
-                         }
 
-                         if (base !== '') {
 
-                             param.push({type: 'base', value: base});
 
-                             base = '';
 
-                         }
 
-                         param.push({type: 'left', value: '('});
 
-                     } else if (expr[i] === ')') {
 
-                         if (num !== '') {
 
-                             param.push({type: 'num', value: num});
 
-                             num = '';
 
-                         }
 
-                         if (base !== '') {
 
-                             param.push({type: 'base', value: base});
 
-                             base = '';
 
-                         }
 
-                         param.push({type: 'right', value: ')'});
 
-                     } else if (/^[\+\-*\/]/.test(expr[i])) {
 
-                         if (num !== '') {
 
-                             param.push({type: 'num', value: num});
 
-                             num = '';
 
-                         }
 
-                         if (base !== '') {
 
-                             param.push({type: 'base', value: base});
 
-                             base = '';
 
-                         }
 
-                         param.push({type: 'calc', value: expr[i]});
 
-                     } else {
 
-                         return [false, '输入的表达式含有非法字符: ' + expr[i]];
 
-                     }
 
-                 }
 
-                 if (num !== '') {
 
-                     param.push({type: 'num', value: num});
 
-                     num = '';
 
-                 }
 
-                 if (base !== '') {
 
-                     param.push({type: 'base', value: base});
 
-                     base = '';
 
-                 }
 
-                 if (param.length === 0) return true;
 
-                 if (param.length > 1) {
 
-                     if (param[0].value === '-' && param[1].type === 'num') {
 
-                         param[1].value = '-' + param[1].value;
 
-                         param.shift();
 
-                     }
 
-                 }
 
-                 const iLen = param.length;
 
-                 let iLeftCount = 0, iRightCount = 0;
 
-                 for (const [i, p] of param.entries()) {
 
-                     if (p.type === 'calc') {
 
-                         if (i === 0 || i === iLen - 1)
 
-                             return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字或计算基数'];
 
-                     }
 
-                     if (p.type === 'num') {
 
-                         num = p.value.replace('%', '');
 
-                         if (p.value.length - num.length > 1)
 
-                             return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
 
-                         num = _.toNumber(num);
 
-                         if (num === undefined || num === null || _.isNaN(num))
 
-                             return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
 
-                         if (i > 0) {
 
-                             if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
 
-                                 return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
 
-                             } else if (param[i - 1].value === '/' && num === 0) {
 
-                                 return [false, '输入的表达式非法:请勿除0'];
 
-                             }
 
-                         }
 
-                     }
 
-                     if (p.type === 'base') {
 
-                         const baseParam = _.find(calcBase, {code: p.value});
 
-                         if (!baseParam)
 
-                             return [false, '输入的表达式非法:不存在计算基数' + p.value];
 
-                         if (invalidParam && invalidParam.indexOf(p.value) >= 0)
 
-                             return [false, '不可使用计算基数' + p.value];
 
-                         if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
 
-                             return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
 
-                     }
 
-                     if (p.type === 'left') {
 
-                         iLeftCount += 1;
 
-                         if (i !== 0 && param[i-1].type !== 'calc')
 
-                             return [false, '输入的表达式非法:(前应有运算符'];
 
-                     }
 
-                     if (p.type === 'right') {
 
-                         iRightCount += 1;
 
-                         if (i !== iLen - 1 && param[i+1].type !== 'calc')
 
-                             return [false, '输入的表达式非法:)后应有运算符'];
 
-                         if (iRightCount > iLeftCount)
 
-                             return [false, '输入的表达式非法:")"前无对应的"("'];
 
-                     }
 
-                 }
 
-                 if (iLeftCount > iRightCount)
 
-                     return [false, '输入的表达式非法:"("后无对应的")"'];
 
-                 return [true, ''];
 
-             },
 
-             _checkExpr: function (text) {
 
-                 if (text) {
 
-                     const num = _.toNumber(text);
 
-                     if (num) {
 
-                         console.log(num);
 
-                     } else {
 
-                         const expr = text.replace('=', '').toLowerCase();
 
-                         const [valid, msg] = this._checkExprValid(expr);
 
-                         if (!valid) return [valid, msg];
 
-                     }
 
-                 }
 
-                 return [true, ''];
 
-             },
 
-         };
 
-         $('#expr_btn').click(function () {
 
-             const expr = $('#expr').val();
 
-             // 判断表达式格式
 
-             const [valid, msg] = ExprObj._checkExpr(expr);
 
-             if (!valid) {
 
-                 toastr.error(msg);
 
-                 return false;
 
-             }
 
-             postData(window.location.pathname + '/save', { type:'expr', id: $('#materialbillsId').val(), expr: expr, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
 
-                 m_tp = result.m_tp;
 
-                 if (materialTax) {
 
-                     m_tax_tp = result.m_tax_tp;
 
-                 }
 
-                 const sheet = materialSpread.getActiveSheet();
 
-                 const select = SpreadJsObj.getSelectObject(sheet);
 
-                 const index = _.findIndex(materialBillsData, { id: select.id });
 
-                 let newIndex = index;
 
-                 if (isStageSelf) {
 
-                     materialSpreadObj.updateMaterialData(result);
 
-                     result.info = materialSpreadObj.updateOneMaterialBill(result.info);
 
-                 }
 
-                 if($('#bills0_list').is(':checked')) {
 
-                     const newMaterialBillsData = _.filter(materialBillsData, function (item) {
 
-                         return item.quantity !== null && item.quantity !== 0;
 
-                     });
 
-                     newIndex = _.findIndex(newMaterialBillsData, { id: select.id });
 
-                     // newIndex = newMaterialBillsData.indexOf(select);
 
-                     newMaterialBillsData.splice(newIndex, 1, result.info);
 
-                     sheet.zh_data[newIndex] = result.info;
 
-                 }
 
-                 materialBillsData.splice(index, 1, result.info);
 
-                 sheet.zh_data.splice(newIndex, 1, result.info);
 
-                 SpreadJsObj.reLoadRowData(sheet, newIndex);
 
-                 resetTpTable();
 
-                 $('#bcyy').modal('hide');
 
-             });
 
-         });
 
-     }
 
-     if (!readOnly && !editForAudit) {
 
-         $('#add').click(materialSpreadObj.add);
 
-         $('#del').click(materialSpreadObj.del);
 
-         $('#up-move').click(materialSpreadObj.upMove);
 
-         $('#down-move').click(materialSpreadObj.downMove);
 
-         // 右键菜单
 
-         $.contextMenu({
 
-             selector: '#material-spread',
 
-             build: function ($trigger, e) {
 
-                 const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
 
-                 return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
 
-             },
 
-             items: {
 
-                 'create': {
 
-                     name: '新增材料',
 
-                     icon: 'fa-sign-in',
 
-                     callback: function (key, opt) {
 
-                         materialSpreadObj.add(materialSpread.getActiveSheet());
 
-                     },
 
-                 },
 
-                 'delete': {
 
-                     name: '删除材料',
 
-                     icon: 'fa-remove',
 
-                     callback: function (key, opt) {
 
-                         materialSpreadObj.del(materialSpread.getActiveSheet());
 
-                     },
 
-                     disabled: function (key, opt) {
 
-                         const sheet = materialSpread.getActiveSheet();
 
-                         const select = SpreadJsObj.getSelectObject(sheet);
 
-                         const sel = sheet.getSelections()[0];
 
-                         materialSpreadObj.refreshActn(sel.rowCount);
 
-                         if (!readOnly && select && materialBase.isUsed(select) && sel.rowCount === 1) {
 
-                             return false;
 
-                         } else {
 
-                             return true;
 
-                         }
 
-                     }
 
-                 },
 
-             }
 
-         });
 
-         $('.changeRate').click(function () {
 
-             $('#rateInput').val(parseInt($(this).data('value')));
 
-             $('#rateInput').siblings('.dropdown-menu').hide();
 
-         });
 
-         $('#rateInput').click(function () {
 
-             $(this).siblings('.dropdown-menu').show();
 
-         })
 
-         // 回车提交
 
-         $('#rateInput').on('keypress', function () {
 
-             if(window.event.keyCode === 13) {
 
-                 $(this).blur();
 
-             }
 
-         });
 
-         $('#rateInput').blur(function () {
 
-             const _self = $(this);
 
-             setTimeout(function () {
 
-                 let rate = parseFloat(_self.val());
 
-                 if (_.isNaN(rate)) {
 
-                     toastr.error('请输入0-100之前的整数值');
 
-                     $('#rateInput').val(materialRate);
 
-                     return;
 
-                 }
 
-                 rate = _.round(rate);
 
-                 if(rate < 0 || rate > 100) {
 
-                     toastr.error('请输入0-100之前的整数值');
 
-                     $('#rateInput').val(materialRate);
 
-                     return;
 
-                 }
 
-                 $('#rateInput').siblings('.dropdown-menu').hide();
 
-                 console.log(rate, materialRate);
 
-                 if (rate !== materialRate) {
 
-                     postData(window.location.pathname + '/save', { type:'rate', rate: rate }, function (result) {
 
-                         const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
 
-                         // const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), materialDecimal.tp);
 
-                         const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), materialDecimal.tp);
 
-                         // const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), materialDecimal.tp);
 
-                         $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
 
-                         $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
 
-                         // $('#rate_set').find('td').eq(3).text(exbqhs !== 0 ? exbqhs : '');
 
-                         // $('#rate_set').find('td').eq(4).text(exjzbqhs !== 0 ? exjzbqhs : '');
 
-                         materialRate = rate;
 
-                         $('#rateInput').val(rate);
 
-                     });
 
-                 } else {
 
-                     $('#rateInput').val(rate);
 
-                 }
 
-             }, 500);
 
-         });
 
-         // $('#changeRate').change(function () {
 
-         //     const rate = parseInt($(this).val());
 
-         //     postData(window.location.pathname + '/save', { type:'rate', rate: rate }, function (result) {
 
-         //         const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
 
-         //         const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), materialDecimal.tp);
 
-         //         const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), materialDecimal.tp);
 
-         //         const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), materialDecimal.tp);
 
-         //         $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
 
-         //         $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
 
-         //         $('#rate_set').find('td').eq(3).text(exbqhs !== 0 ? exbqhs : '');
 
-         //         $('#rate_set').find('td').eq(4).text(exjzbqhs !== 0 ? exjzbqhs : '');
 
-         //     });
 
-         // });
 
-         // 创建月信息价
 
-         $('#make-month').click(function() {
 
-             const yearmonth = $('#months').val();
 
-             const result = yearmonth.match(/^(\d{1,4})(-|\/)(\d{1,2})$/);
 
-             if (result === null) {
 
-                 toastr.error('请选择正确的信息价月份');
 
-                 return false;
 
-             }
 
-             //判断是否已存在当前月份
 
-             if (months.indexOf(yearmonth) !== -1) {
 
-                 toastr.error('调差期已创建过本月的信息价');
 
-                 return false;
 
-             }
 
-             postData(window.location.pathname + '/month/save', { type: 'add', updateData: { yearmonth: yearmonth } }, function (data) {
 
-                 months.push(yearmonth);
 
-                 months.sort();
 
-                 monthsList = data.monthsList;
 
-                 monthFunGather.monthsListSet();
 
-                 // 工料表单价显示也要更新
 
-                 materialBillsData = data.materialBillsData;
 
-                 materialSpreadObj.materialSheetReset();
 
-                 // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
 
-                 m_tp = data.m_tp;
 
-                 if (materialTax) {
 
-                     m_tax_tp = data.m_tax_tp;
 
-                 }
 
-                 resetTpTable();
 
-                 $('#add-month').modal('hide');
 
-             });
 
-         });
 
-         // 删除月信息价
 
-         $('#del-month').click(function () {
 
-             const del_month_array = [];
 
-             $("input[name='del_month']:checked").each(function () {
 
-                 del_month_array.push($(this).val());
 
-             });
 
-             if (del_month_array.length === 0) {
 
-                 toastr.error('请选择要移除的月信息价');
 
-                 return false;
 
-             }
 
-             postData(window.location.pathname + '/month/save', { type: 'del', updateData: { del_yearmonth: del_month_array } }, function (data) {
 
-                 for (const dm of del_month_array) {
 
-                     // _.remove(materialMonthSpreadSetting.cols, function (n) {
 
-                     //     return n.field === dm;
 
-                     // });
 
-                     _.remove(months, function (n) {
 
-                         return n === dm;
 
-                     });
 
-                 }
 
-                 monthsList = data.monthsList;
 
-                 monthFunGather.monthsListSet();
 
-                 // 工料表单价显示也要更新
 
-                 materialBillsData = data.materialBillsData;
 
-                 materialSpreadObj.materialSheetReset();
 
-                 // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
 
-                 m_tp = data.m_tp;
 
-                 if (materialTax) {
 
-                     m_tax_tp = data.m_tax_tp;
 
-                 }
 
-                 resetTpTable();
 
-                 $('#remove-month').modal('hide');
 
-             });
 
-         });
 
-         // 导入功能
 
-         let importFile = null;
 
-         $('#upload-xls-file').change(function () {
 
-             const file = this.files[0];
 
-             importFile = file;
 
-         });
 
-         $('#import-bills-btn').click(function() {
 
-             if (!importFile) {
 
-                 toastr.error('请选择excel文件再确定');
 
-                 return;
 
-             }
 
-             const ext = importFile.name.toLowerCase().split('.').splice(-1)[0];
 
-             const imgStr = /(xls|xlsx|XLS|XLSX)$/;
 
-             if (!imgStr.test(ext)) {
 
-                 toastr.error('请导入正确格式的excel文件。');
 
-                 return
 
-             }
 
-             const fileReader = new FileReader();
 
-             fileReader.onload = async function(ev) {
 
-                 try{
 
-                     const data = ev.target.result;
 
-                     let tree = [];
 
-                     const includeSpec = $('#xls-spec').is(':checked');
 
-                     if (/(xls|xlsx|XLS|XLSX)$/.test(ext)) {
 
-                         const workbook = XLSX.read(data, {type: 'binary'}); // 以二进制流方式读取得到整份excel表格对象
 
-                         const jsonData = transExcel(XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]], { defval: null }));
 
-                         console.log(jsonData);
 
-                         if (!(jsonData[0] && jsonData[0].code !== undefined && jsonData[0].code !== null && jsonData[0].unit !== undefined && jsonData[0].name !== undefined &&
 
-                             jsonData[0].spec !== undefined && jsonData[0].msg_tp !== undefined && jsonData[0].msg_times !== undefined)) {
 
-                             throw 'excel必须按指定格式内容上传';
 
-                         }
 
-                         // 去重
 
-                         tree = _.unionWith(jsonData, function (item1, item2) {
 
-                             return item1.code === item2.code && item1.name === item2.name && item1.unit === item2.unit && (!includeSpec || (includeSpec && item1.spec === item2.spec));
 
-                         });
 
-                     }
 
-                     if (tree.length === 0) {
 
-                         throw '该excel不存在导入的数据';
 
-                     }
 
-                     // 判断msg_tp格式,不符合则无法导入,还有excel日期转换问题
 
-                     for (const t of tree) {
 
-                         t.code = t.code.toString();
 
-                         if (t.msg_tp) {
 
-                             if (_.isNumber(t.msg_tp)) {
 
-                                 const num = parseFloat(t.msg_tp);
 
-                                 const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
 
-                                 if (num < 0 || !reg.test(num)) {
 
-                                     t.msg_tp = ZhCalc.round(num, materialDecimal.up);
 
-                                 }
 
-                             } else {
 
-                                 throw '信息价数据存在非数字字符,无法导入';
 
-                             }
 
-                         }
 
-                         if (_.isNumber(t.msg_times)) {
 
-                             t.msg_times = formatDate(t.msg_times, '/');
 
-                         }
 
-                         t.spec = t.spec === null ? '' : t.spec;
 
-                     }
 
-                     console.log(tree);
 
-                     postData(window.location.pathname + '/save', { type:'export', postData: tree, includeSpec, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
 
-                         m_tp = result.m_tp;
 
-                         if (materialTax) {
 
-                             m_tax_tp = result.m_tax_tp;
 
-                         }
 
-                         materialBillsData = result.billsData;
 
-                         if (isStageSelf) {
 
-                             materialStageData = result.stageData;
 
-                             materialStageBillsData = result.stageBillsData;
 
-                         }
 
-                         materialSpreadObj.getMaterialBillsData();
 
-                         materialSpreadObj.materialSheetReset(true);
 
-                         if (months.length > 0) {
 
-                             monthsList = result.monthsList;
 
-                             monthFunGather.monthsListSet();
 
-                         }
 
-                         resetTpTable();
 
-                         if (result.addNum || result.updateNum) {
 
-                             let msg = [];
 
-                             if (result.addNum !== undefined && result.addNum !== 0) {
 
-                                 msg.push('成功导入工料 ' + result.addNum + ' 条');
 
-                             }
 
-                             if (result.updateNum !== undefined && result.updateNum !== 0) {
 
-                                 msg.push('成功更新工料 ' + result.updateNum + ' 条');
 
-                             }
 
-                             toastr.success(msg.length > 1 ? msg.join(',并') : msg[0]);
 
-                         } else {
 
-                             toastr.warning('不存在可导入的信息价数据');
 
-                         }
 
-                         $('#import-info').modal('hide');
 
-                     });
 
-                 } catch (error) {
 
-                     console.log(error);
 
-                     toastr.error(error);
 
-                     return
 
-                 }
 
-             };
 
-             // 以二进制方式打开文件
 
-             fileReader.readAsBinaryString(importFile);
 
-             $('#upload-xls-file').val('');
 
-             importFile = null;
 
-         });
 
-     } else {
 
-         // SpreadJsObj.forbiddenSpreadContextMenu('#material-spread', materialSpread);
 
-     }
 
-     // 筛选调差工料本期应耗数量为0
 
-     $('#bills0_list').click(function () {
 
-         const isCheck = $(this).is(':checked');
 
-         let newMaterialBillsData = materialBillsData;
 
-         if (isCheck) {
 
-             newMaterialBillsData = _.filter(materialBillsData, function (item) {
 
-                 return item.quantity !== null && item.quantity !== 0;
 
-             });
 
-             SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
 
-             SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
 
-         }
 
-         SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
 
-         monthFunGather.monthsListSet(newMaterialBillsData, false);
 
-         materialSpreadObj.refreshActn();
 
-     });
 
-     let gljLib;
 
-     const gljLibCellDoubleClick = function (e, info) {
 
-         if (readOnly || editForAudit) return;
 
-         const gljSheet = info.sheet;
 
-         if (!gljSheet.zh_setting || !gljSheet.zh_tree) { return; }
 
-         const gljTree = gljSheet.zh_tree;
 
-         const gljNode = gljTree.nodes[info.row];
 
-         const sheet = materialSpread.getActiveSheet();
 
-         const select = SpreadJsObj.getSelectObject(sheet);
 
-         if (!gljNode) return;
 
-         if (gljNode && gljNode.is_leaf === 0) {
 
-             toastr.warning('非最底层项目下,不应添加');
 
-             return;
 
-         }
 
-         postData(window.location.pathname + '/save', { type:'add-glj', postData: gljNode, order: select ? select.order : null }, function (result) {
 
-             if (result) {
 
-                 // 比order大的+1
 
-                 const maxData = select ? _.filter(materialBillsData, (item) => { return item.order > select.order }) : [];
 
-                 _.forEach(maxData, function (item) {
 
-                     const cl = _.find(materialBillsData, { id: item.id });
 
-                     cl.order = item.order + 1;
 
-                 });
 
-                 materialBillsData.push(result.info);
 
-                 materialBillsData.sort(function (a, b) {
 
-                     return a.order - b.order
 
-                 });
 
-                 console.log(materialBillsData);
 
-                 if (isStageSelf) {
 
-                     materialSpreadObj.updateMaterialData(result);
 
-                     materialSpreadObj.getMaterialBillsData();
 
-                 }
 
-                 // sheet.addRows(materialBillsData.length - 1, 1);
 
-                 // SpreadJsObj.reLoadRowData(sheet, materialBillsData.length - 1);
 
-                 let newMaterialBillsData = materialBillsData;
 
-                 if($('#bills0_list').is(':checked')) {
 
-                     newMaterialBillsData = _.filter(materialBillsData, function (item) {
 
-                         return item.quantity !== null && item.quantity !== 0;
 
-                     });
 
-                 }
 
-                 SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
 
-                 // materialSpreadObj.materialSheetReset();
 
-                 sheet.setSelection(sheet.zh_data.indexOf(select) + 1, 0, 1, 1);
 
-                 materialSpreadObj.refreshActn();
 
-                 // 月信息价需要同时添加空白的list
 
-                 if (months.length > 0) {
 
-                     const one_month ={ mb_id: result.info.id, code: result.info.code, name: result.info.name, origin: result.info.origin, unit: result.info.unit, order: result.info.order };
 
-                     for (const m of months) {
 
-                         one_month[m] = null;
 
-                     }
 
-                     _.forEach(maxData, function (item) {
 
-                         const cl = _.find(monthsList, { mb_id: item.id });
 
-                         cl.order = item.order + 1;
 
-                     });
 
-                     monthsList.push(one_month);
 
-                     monthsList.sort(function (a, b) {
 
-                         return a.order - b.order
 
-                     });
 
-                     console.log(monthsList);
 
-                     // const newMonthsList = _.filter(monthsList, function (item) {
 
-                     //     return _.findIndex(newMaterialBillsData, { code: item.code }) !== -1;
 
-                     // });
 
-                     // materialMonthSpread.getActiveSheet().addRows(newMonthsList.length - 1, 1);
 
-                     // SpreadJsObj.reLoadRowData(materialMonthSpread.getActiveSheet(), newMonthsList.length - 1);
 
-                     monthFunGather.monthsListSet();
 
-                     // materialMonthSpreadObj.monthsListSet();
 
-                 }
 
-             }
 
-         });
 
-     };
 
-     const gljLibSetting = {
 
-         selector: '#material-tab',
 
-         stdType: 'glj',
 
-         libs: gljLists,
 
-         treeSetting: {
 
-             id: 'glj_id',
 
-             pid: 'glj_pid',
 
-             order: 'order',
 
-             level: 'level',
 
-             rootId: -1,
 
-             keys: ['id', 'list_id', 'glj_id'],
 
-         },
 
-         spreadSetting: {
 
-             cols: [
 
-                 {title: '编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
 
-                 {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
 
-                 {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
 
-                 {title: '参考上涨幅度', field: 'rise_range', hAlign: 1, width: 50, formatter: '@', readOnly: true},
 
-                 {title: '参考下跌幅度', field: 'fall_range', hAlign: 1, width: 50, formatter: '@', readOnly: true},
 
-             ],
 
-             treeCol: 0,
 
-             emptyRows: 0,
 
-             headRows: 1,
 
-             headRowHeight: [32],
 
-             defaultRowHeight: 21,
 
-             headerFont: '12px 微软雅黑',
 
-             font: '12px 微软雅黑',
 
-             headColWidth: [30],
 
-             selectedBackColor: '#fffacd',
 
-         },
 
-         spreadClassCss: 'sjs-material',
 
-         cellDoubleClick: gljLibCellDoubleClick,
 
-         page: 'material',
 
-         tid: window.location.pathname.split('/')[2],
 
-     };
 
-     $.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();
 
-             materialSpread.refresh();
 
-         }
 
-     });
 
-     $.divResizer({
 
-         select: '#right-spr',
 
-         callback: function () {
 
-             materialSpread.refresh();
 
-             materialMonthSpread.refresh();
 
-             if (gljLib) gljLib.spread.refresh();
 
-             const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
 
-             setLocalCache('material_month_' + materialID, width);
 
-         }
 
-     });
 
-     $.divResizer({
 
-         select: '#main-resize',
 
-         callback: function () {
 
-             let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
 
-             $(".sp-wrap").height(bcontent-30);
 
-             const height = $('.bcontent-wrap').height();
 
-             const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
 
-             $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
 
-             updateSjsHeight();
 
-             materialSpread.refresh();
 
-             materialMonthSpread.refresh();
 
-             if (gljLib) gljLib.spread.refresh();
 
-             setLocalCache('material_bills_' + materialID, height);
 
-         }
 
-     });
 
-     // 展开收起月信息价并浏览器记住本期展开收起
 
-     $('a', '.right-nav').bind('click', function () {
 
-         //const main = $('#main-view'), tool = $('#tools-view');
 
-         const tab = $(this), tabPanel = $(tab.attr('content'));
 
-         if (!tab.hasClass('active')) {
 
-             $('a', '.side-menu').removeClass('active');
 
-             $('#right-view .tab-content .tab-pane').removeClass('active');
 
-             tab.addClass('active');
 
-             tabPanel.addClass('active');
 
-             showSideTools(tab.hasClass('active'));
 
-             if (tab.attr('content') === '#month-tab') {
 
-                 const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
 
-                 setLocalCache('material_month_' + materialID, width);
 
-                 materialMonthSpread.refresh();
 
-             } else if (tab.attr('content') === '#material-tab') {
 
-                 if (!gljLib) {
 
-                     gljLib = $.gljLib(gljLibSetting);
 
-                 }
 
-                 updateSjsHeight();
 
-                 gljLib.spread.refresh();
 
-             }
 
-         } else {
 
-             removeLocalCache('material_month_' + materialID);
 
-             tab.removeClass('active');
 
-             tabPanel.removeClass('active');
 
-             showSideTools(tab.hasClass('active'));
 
-         }
 
-         materialSpread.refresh();
 
-         // materialMonthSpread.refresh();
 
-     });
 
-     // 根据浏览器记录展开收起
 
-     if (getLocalCache('material_month_' + materialID) && !isStageSelf) {
 
-         const tab = $('.right-nav a[content="#month-tab"]'), tabPanel = $(tab.attr('content'));
 
-         $('a', '.side-menu').removeClass('active');
 
-         $('#right-view .tab-content .tab-pane').removeClass('active');
 
-         tab.addClass('active');
 
-         tabPanel.addClass('active');
 
-         $('#right-view').width(getLocalCache('material_month_' + materialID) + '%');
 
-         showSideTools(tab.hasClass('active'));
 
-         materialSpread.refresh();
 
-         materialMonthSpread.refresh();
 
-     }
 
-     const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
 
-     if (getLocalCache('material_bills_' + materialID)) {
 
-         $('.bcontent-wrap').height(getLocalCache('material_bills_' + materialID));
 
-         const cHeader = getObjHeight($(".c-header"));
 
-         const bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
 
-         $(".sp-wrap").height(bcontent-30);
 
-         $('.sjs-height-1').height($(window).height()-cHeader-bcontent-90+53);
 
-         $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
 
-         updateSjsHeight();
 
-         materialSpread.refresh();
 
-         materialMonthSpread.refresh();
 
-         if (gljLib) gljLib.spread.refresh();
 
-     } else {
 
-         $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
 
-         updateSjsHeight();
 
-         materialSpread.refresh();
 
-         materialMonthSpread.refresh();
 
-         if (gljLib) gljLib.spread.refresh();
 
-     }
 
-     function updateSjsHeight() {
 
-         $('.sjs-height-material-month').height($('.sjs-height-1').height() - getObjHeight($('.sjs-bar-1')));
 
-         $('.material-table-height').height($('.bcontent-wrap').height() - getObjHeight($('.bc-bar')));
 
-         $('.sjs-material').height($('.sjs-height-1').height() - getObjHeight($('.sjs-bar')));
 
-     }
 
-     function getObjHeight(select) {
 
-         return select.length > 0 ? select.outerHeight() : 0;
 
-     }
 
-     function formatDate(numb, format) {
 
-         const old = numb - 1;
 
-         const t = Math.round((old - Math.floor(old)) * 24 * 60 * 60);
 
-         const time = new Date(1900, 0, old, 0, 0, t);
 
-         const year = time.getFullYear();
 
-         const month = time.getMonth() + 1;
 
-         const date = time.getDate();
 
-         return year + format + (month < 10 ? '0' + month : month) + format + (date < 10 ? '0' + date : date);
 
-     }
 
-     function transExcel(results) {
 
-         const mapInfo = {
 
-             '编号': 'code',
 
-             '名称': 'name',
 
-             '单位': 'unit',
 
-             '规格': 'spec',
 
-             '信息价': 'msg_tp',
 
-             '时间': 'msg_times',
 
-         };
 
-         return results.map(zhObj => {
 
-             const enObj = {}
 
-             const zhKeys = Object.keys(zhObj);
 
-             zhKeys.forEach(zhKey => {
 
-                 const enKey = mapInfo[zhKey];
 
-                 enObj[enKey] = zhObj[zhKey] && _.isString(zhObj[zhKey]) ? _.trim(zhObj[zhKey]) : zhObj[zhKey];
 
-             });
 
-             return enObj
 
-         })
 
-     }
 
- });
 
 
  |