| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757 | 
							- 'use strict';
 
- /**
 
-  * 期计量 - 本期计量台账页面 js
 
-  *
 
-  * @author Mai
 
-  * @date 2018/12/7
 
-  * @version
 
-  */
 
- const ckBillsSpread = window.location.pathname + '-billsSelect';
 
- function checkTzMeasureType () {
 
-     return tender.measure_type === measureType.tz.value;
 
- }
 
- function transExpr(expr) {
 
-     return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
 
- }
 
- /**
 
-  * 从cookie中读取缓存的列显示设置,没有则取默认
 
-  * @returns {*[]}
 
-  */
 
- function customColDisplay () {
 
-     const defaultSetting = [
 
-         { title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true },
 
-         { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
 
-         { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl'], visible: true },
 
-         { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
 
-         { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
 
-         { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl'], visible: true },
 
-         { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp', 'end_gather_percent'], visible: true },
 
-         { title: '本期批注', fields: ['postil'], visible: true },
 
-         { title: '图册号', fields: ['drawing_code'], visible: true },
 
-         { title: '备注', fields: ['memo'], visible: true },
 
-         { title: '总额计量', fields: ['is_tp'], visible: true},
 
-     ];
 
-     if (checkTzMeasureType()) {
 
-         defaultSetting.splice(0, 1);
 
-     }
 
-     const settingStr = Cookies.get(ckColSetting);
 
-     return settingStr ? JSON.parse(settingStr) : defaultSetting;
 
- }
 
- /**
 
-  * 根据列显示设置,调整setting中的列是否显示
 
-  * @param setting
 
-  * @param customDisplay
 
-  */
 
- function customizeStageTreeSetting(setting, customDisplay) {
 
-     for (const cd of customDisplay) {
 
-         for (const c of setting.cols) {
 
-             if (cd.fields.indexOf(c.field) !== -1) {
 
-                 c.visible = cd.visible;
 
-             }
 
-         }
 
-     }
 
- }
 
- /**
 
-  * 初始化 树结构 列事件
 
-  * @param setting
 
-  */
 
- function initTreeColSettingEvents(setting) {
 
-     const Events = {
 
-         readOnly: {
 
-             measureData: function (node) {
 
-                 return node.children && node.children.length > 0;
 
-             },
 
-         },
 
-     };
 
-     const getEvent = function (eventName) {
 
-         const names = eventName.split('.');
 
-         let event = Events;
 
-         for (let name of names) {
 
-             if (event[name]) {
 
-                 event = event[name];
 
-             } else {
 
-                 return null;
 
-             }
 
-         }
 
-         if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
 
-             return null;
 
-         } else {
 
-             return event;
 
-         }
 
-     };
 
-     for (const col of setting.cols) {
 
-         if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
 
-             col.readOnly = getEvent(col.readOnly);
 
-         }
 
-     }
 
- }
 
- // 生成所有附件列表
 
- function getAllList(currPageNum = 1) {
 
-     // 每页最多几个附件
 
-     const pageCount = 11;
 
-     // 附件总数
 
-     const total = attData.length;
 
-     // 总页数
 
-     const pageNum = Math.ceil(total/pageCount);
 
-     $('#totalPage').text(pageNum);
 
-     $('#currentPage').text(currPageNum);
 
-     // 当前页附件内容
 
-     const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
 
-     let html = '';
 
-     for(const att of currPageAttData) {
 
-         html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
 
-     }
 
-     $('#alllist-table').html(html);
 
- }
 
- // 生成当前节点列表
 
- function getNodeList(node) {
 
-     let html = '';
 
-     for(const att of attData) {
 
-         if (node === att.lid) {
 
-             html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
 
-         }
 
-     }
 
-     $('#nodelist-table').html(html);
 
- }
 
- $(document).ready(() => {
 
-     let detail, searchLedger;
 
-     // 界面布局
 
-     autoFlashHeight();
 
-     // 初始化 台账树结构 数据结构
 
-     const stageTreeSetting = {
 
-         id: 'ledger_id',
 
-         pid: 'ledger_pid',
 
-         order: 'order',
 
-         level: 'level',
 
-         rootId: -1,
 
-         keys: ['id', 'tender_id', 'ledger_id'],
 
-         stageId: 'id',
 
-     };
 
-     // 台账树结构计算相关设置
 
-     stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil', 'used'];
 
-     stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
 
-         'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp'];
 
-     stageTreeSetting.calcFun = function (node) {
 
-         if (node.children && node.children.length === 0) {
 
-             node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
 
-             node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
 
-             node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty);
 
-             node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
 
-             node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
 
-         }
 
-         node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
 
-         node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
 
-         node.end_contract_tp = ZhCalc.add(node.pre_contract_tp, node.contract_tp);
 
-         node.end_qc_tp = ZhCalc.add(node.pre_qc_tp, node.qc_tp);
 
-         node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
 
-         node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
 
-         node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
 
-         node.final_dgn_price = ZhCalc.round(ZhCalc.div(node.end_gather_tp, ZhCalc.add(node.deal_dgn_qty1, node.c_dgn_qty1)), tenderInfo.decimal.up);
 
-     };
 
-     const stageTree = createNewPathTree('stage', stageTreeSetting);
 
-     // 初始化 计量单元 数据结构
 
-     const stagePosSetting = {
 
-         id: 'id', ledgerId: 'lid',
 
-         updateFields: ['contract_qty', 'qc_qty', 'postil'],
 
-     };
 
-     stagePosSetting.calcFun = function (pos) {
 
-         pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
 
-         pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
 
-         pos.end_contract_qty = ZhCalc.add(pos.pre_contract_qty, pos.contract_qty);
 
-         pos.end_qc_qty = ZhCalc.add(pos.pre_qc_qty, pos.qc_qty);
 
-         pos.end_gather_qty = ZhCalc.add(pos.pre_gather_qty, pos.gather_qty);
 
-         pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
 
-         pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2);
 
-     };
 
-     const stagePos = new StagePosData(stagePosSetting);
 
-     class Changes {
 
-         constructor(obj) {
 
-             const self = this;
 
-             this.obj = obj;
 
-             // 初始化 清单编号窗口 参数
 
-             this.spreadSetting = {
 
-                 cols: [
 
-                     {title: '已用', field: '', width: 45, formatter: '@', cellType: 'image', readOnly: true, hAlign: 1, indent: 14, img: function (data) {
 
-                         if (data.uamount && !checkZero(data.uamount)) {
 
-                             return $('#icon-ok')[0];
 
-                         } else {
 
-                             return null;
 
-                         }
 
-                     }},
 
-                     {title: '变更令号', field: 'code', width: 100, formatter: '@', readOnly: true, hAlign: 0, },
 
-                     {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true, hAlign: 0,},
 
-                     {title: '变更部位', field: 'b_bwmx', width: 100, formatter: '@', readOnly: true, hAlign: 0,},
 
-                     //{title: '总数量', field: 'b_amount', width: 60, formatter: '@', readOnly: true, hAlign: 2, },
 
-                     {title: '可变更数量', field: 'vamount', width: 60, readOnly: true, hAlign: 2, getValue: function (data) {return data.vamount ? data.vamount + '' : '0';}},
 
-                     {title: '本期计量', field: 'uamount', width: 60, formatter: '@', hAlign: 2, type: 'Number', },
 
-                 ],
 
-                 emptyRows: 0,
 
-                 headRows: 1,
 
-                 headRowHeight: [32],
 
-                 headerFont: '12px 微软雅黑',
 
-                 font: '12px 微软雅黑',
 
-                 getColor: function (sheet, data, col, defaultColor) {
 
-                     if (col.field === 'uamount') {
 
-                         if (!data.vamount) {
 
-                             return (data.uamount && data.uamount > 0) ? '#ff6f5c' : defaultColor;
 
-                         } else if (data.uamount) {
 
-                             return data.uamount > data.vamount ? '#ff6f5c' : defaultColor;
 
-                         } else {
 
-                             return defaultColor;
 
-                         }
 
-                     } else {
 
-                         return defaultColor;
 
-                     }
 
-                 }
 
-             };
 
-             this.curChangeId = '';
 
-             this.spread = SpreadJsObj.createNewSpread($('#change-spread')[0]);
 
-             this.firstView = true;
 
-             SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
 
-             // 初次显示,需刷新spread界面,保证界面绘制正确
 
-             this.obj.bind('shown.bs.modal', function () {
 
-                 if (self.firstView) {
 
-                     self.firstView = false;
 
-                     self.spread.refresh();
 
-                 }
 
-             });
 
-             // 切换变更令,加载右侧明细数据
 
-             this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
 
-                 const change = SpreadJsObj.getSelectObject(info.sheet);
 
-                 self._loadChangeDetail(change);
 
-             });
 
-             // 填写本期计量
 
-             this.spread.bind(spreadNS.Events.EditEnded, function (e, info) {
 
-                 if (info.sheet.zh_setting) {
 
-                     const col = info.sheet.zh_setting.cols[info.col];
 
-                     const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
 
-                     const node = sortData[info.row];
 
-                     node[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
 
-                     // 刷新界面
 
-                     SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
 
-                 }
 
-             });
 
-             this.spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
 
-                 if (info.sheet.zh_setting) {
 
-                     const sortData = SpreadJsObj.getSortData(info.sheet);
 
-                     for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
 
-                         const curRow = iRow + info.cellRange.row;
 
-                         const curCol = info.cellRange.col;
 
-                         const col = info.sheet.zh_setting.cols[info.cellRange.col];
 
-                         sortData[curRow][col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
 
-                     }
 
-                     SpreadJsObj.reLoadRowData(sheet, info.cellRange.row, sel.cellRange.rowCount);
 
-                 }
 
-             });
 
-             SpreadJsObj.addDeleteBind(this.spread, function (sheet) {
 
-                 if (sheet.zh_setting) {
 
-                     const sel = sheet.getSelections()[0];
 
-                     const sortData = SpreadJsObj.getSortData(sheet);
 
-                     // 仅本期计量可删除
 
-                     if (sel.col === 5 && sel.colCount === 1) {
 
-                         const col = sheet.zh_setting.cols[sel.col];
 
-                         for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
 
-                             const data = sortData[iRow];
 
-                             data[col.field] = null;
 
-                         }
 
-                         SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
 
-                     }
 
-                 }
 
-             });
 
-             // 过滤可变更数量为0
 
-             $('#filterEmpty').click(function () {
 
-                 self._filterChange(!this.checked, $('#matchPos')[0].checked);
 
-             });
 
-             // 匹配编号
 
-             $('#matchPos').click(function () {
 
-                 self._filterChange(!$('#filterEmpty')[0].checked, this.checked);
 
-             });
 
-             // 展开收起 变更令详细信息
 
-             $('#show-bgl-detail').bind('click', function () {
 
-                 const detail = $('#bgl-detail'), bgl=$('#bgl'), obj=$(this);
 
-                 if (detail.hasClass('col-4')) {
 
-                     detail.attr('class', 'col').hide();
 
-                     bgl.attr('class', 'col-12');
 
-                     $('a', obj).attr('title', '展开侧栏');
 
-                     $('i', obj).attr('class', 'fa fa-chevron-left');
 
-                     self.spread.refresh();
 
-                 } else {
 
-                     detail.attr('class', 'col-4').show();
 
-                     bgl.attr('class', 'col-8');
 
-                     $('a', obj).attr('title', '收起侧栏');
 
-                     $('i', obj).attr('class', 'fa fa-chevron-right');
 
-                     self.spread.refresh();
 
-                 }
 
-             });
 
-             // 添加调用变更令
 
-             $('#usg-bg-ok').click(function () {
 
-                 const data = { target: self.callData, change: [] };
 
-                 for (const c of self.displayChanges) {
 
-                     if (c.uamount) {
 
-                         const vamount = (!c.vamount || checkZero(c.vamount)) ? 0 : c.vamount;
 
-                         if (c.uamount > vamount) {
 
-                             toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
 
-                             return;
 
-                         }
 
-                         data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount });
 
-                     }
 
-                 }
 
-                 // 提交数据到后端
 
-                 postData(window.location.pathname + '/use-change', data, function(result) {
 
-                     if (result.pos) {
 
-                         stagePos.loadCurStageData(result.pos.curStageData);
 
-                     }
 
-                     const nodes = stageTree.loadPostStageData(result.bills);
 
-                     stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
 
-                     stagePosSpreadObj.loadCurPosData();
 
-                     if (detail) {
 
-                         detail.loadStageChangeUpdateData(result);
 
-                     } else {
 
-                         stageIm.loadUpdateChangeData(result)
 
-                     }
 
-                     self.obj.modal('hide');
 
-                 });
 
-             })
 
-         }
 
-         _calculateAmount() {
 
-             for (const c of this.changes) {
 
-                 c.bamount = _.toNumber(c.b_amount);
 
-                 c.vamount = ZhCalc.sub(c.bamount, c.used_amount);
 
-                 const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid});
 
-                 if (uc) {
 
-                     c.org_uamount = uc.qty;
 
-                     c.uamount = uc.qty;
 
-                     c.vamount = ZhCalc.add(c.vamount, c.uamount);
 
-                 }
 
-             }
 
-         }
 
-         _loadChangeDetail(change) {
 
-             if (change) {
 
-                 if (change.cid === this.curChangeId) { return; }
 
-                 this.curChangeId = change.cid;
 
-                 const inputs = $('input[type!=checkbox][type!=radio]', this.obj);
 
-                 for (const i of inputs) {
 
-                     const field = $(i).attr('name');
 
-                     const text = (field && change[field]) ? change[field] : '';
 
-                     $(i).val(text);
 
-                 }
 
-                 const textareas = $('textarea', this.obj);
 
-                 for (const ta of textareas) {
 
-                     const field = $(ta).attr('name');
 
-                     const text = (field && change[field]) ? change[field] : '';
 
-                     ta.textContent = text;
 
-                 }
 
-                 const html = [];
 
-                 for (const a of change.attachments) {
 
-                     html.push('<tr>');
 
-                     html.push('<td>', '<a href="/change/download/file/' + a.id + '">', a.filename + a.fileext, '</a>', '</td>');
 
-                     html.push('<td>', a.u_name, '</td>');
 
-                     html.push('</tr>');
 
-                 }
 
-                 // 变更类型
 
-                 if (change.type) {
 
-                     const cType = change.type.split(',');
 
-                     $('input[name="type"]').prop("checked", false);
 
-                     for (const c of cType) {
 
-                         $('input[name="type"][value='+ c +']').prop("checked", true);
 
-                     }
 
-                 }
 
-                 // 变更类别
 
-                 $('select[name=class]').val(change.class);
 
-                 // 变更性质
 
-                 $('select[name=quality]').val(change.quality);
 
-                 // 变更单位
 
-                 $('select[name=company]').html('<option>' + (change.company ? change.company : '') + '</option>');
 
-                 // 费用承担方
 
-                 $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
 
-                 // 附件
 
-                 $('#attachment').html(html.join(''));
 
-             } else {
 
-                 const inputs = $('input', this.obj);
 
-                 for (const i of inputs) {
 
-                     $(i).val('');
 
-                 }
 
-                 const textareas = $('textarea', this.obj);
 
-                 for (const ta of textareas) {
 
-                     ta.innerText = '';
 
-                 }
 
-                 $('#attachment').html('');
 
-             }
 
-         }
 
-         _viewChanges() {
 
-             const sheet = this.spread.getActiveSheet();
 
-             if (this.changes) {
 
-                 sheet.setSelection(0, 0, 1, 1);
 
-                 this._filterChange(!$('#filterEmpty')[0].checked, $('#matchPos')[0].checked);
 
-                 this._loadChangeDetail(this.changes[0]);
 
-             } else {
 
-                 toastr.error('查询变更令有误,请刷新页面后重试');
 
-             }
 
-         }
 
-         _filterChange(filterEmpty, matchPosName) {
 
-             this.displayChanges = [];
 
-             for (const c of this.changes) {
 
-                 const filterVisible = filterEmpty ? (c.vamount ? !checkZero(c.vamount) : false) : true;
 
-                 const matchVisible = matchPosName && this.callData.pos ? c.b_bwmx === this.callData.pos.name : true;
 
-                 if ((filterVisible && matchVisible) || (c.org_uamount)) {
 
-                     this.displayChanges.push(c);
 
-                 }
 
-             }
 
-             SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), SpreadJsObj.DataType.Data, this.displayChanges);
 
-         }
 
-         loadChanges(data) {
 
-             this.callData = data;
 
-             if (this.callData.pos) {
 
-                 $('#matchPos').parent().show();
 
-             } else {
 
-                 $('#matchPos').parent().hide();
 
-             }
 
-             const self = this;
 
-             $('#b-code-hint').text('当前变更清单:' + data.bills.b_code);
 
-             postData(window.location.pathname + '/valid-change', data, function (result) {
 
-                 self.changes = result.changes;
 
-                 self.useChanges = result.useChanges;
 
-                 self._calculateAmount();
 
-                 self._viewChanges();
 
-                 self.obj.modal('show');
 
-             });
 
-         }
 
-     }
 
-     const changesObj = new Changes($('#use-bg'));
 
-     // 初始化 台账 spread
 
-     const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
 
-     customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
 
-     // 数量变更列,添加按钮
 
-     const col = _.find(ledgerSpreadSetting.cols, {field: 'qc_qty'});
 
-     col.readOnly = true;
 
-     col.cellType = 'activeImageBtn';
 
-     col.normalImg = '#ellipsis-icon';
 
-     col.indent = 5;
 
-     col.showImage = function (data) {
 
-         if (!data || (data.children && data.children.length > 0) || !(data.b_code && data.b_code !== '')) {
 
-             return false;
 
-         } else {
 
-             const nodePos = stagePos.getLedgerPos(data.id);
 
-             return !(nodePos && nodePos.length > 0);
 
-         }
 
-     };
 
-     ledgerSpreadSetting.imageClick = function (data) {
 
-         if (data.children && data.children.length > 0) return;
 
-         const nodePos = stagePos.getLedgerPos(data.id);
 
-         if (nodePos && nodePos.length > 0) return;
 
-         changesObj.loadChanges({bills: data});
 
-     };
 
-     ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
 
-     ledgerSpreadSetting.getColor = function (sheet, data, col, defaultColor) {
 
-         return data && data.end_contract_qty > data.quantity ? '#f8d7da' : defaultColor;
 
-     };
 
-     SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
 
-     slSpread.getActiveSheet().frozenColumnCount(5);
 
-     slSpread.getActiveSheet().options.frozenlineColor = '#93b5e4';
 
-     //初始化所有附件列表
 
-     getAllList();
 
-     // 初始化 计量单元 Spread
 
-     const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
 
-     const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
 
-     spCol.readOnly = true;
 
-     spCol.cellType = 'activeImageBtn';
 
-     spCol.normalImg = '#ellipsis-icon';
 
-     spCol.indent = 5;
 
-     spCol.showImage = function (data) {
 
-         return data !== undefined && data !== null;
 
-     };
 
-     posSpreadSetting.imageClick = function (data) {
 
-         const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
 
-         changesObj.loadChanges({bills: node, pos: data});
 
-     };
 
-     posSpreadSetting.getColor = function (sheet, data, col, defaultColor) {
 
-         return data && data.end_contract_qty > data.quantity ? '#f8d7da' : defaultColor;
 
-     };
 
-     SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
 
-     const stageTreeSpreadObj = {
 
-         loadExprToInput(sheet) {
 
-             const sel = sheet.getSelections()[0];
 
-             const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
 
-             if (col.type === 'Number') {
 
-                 const data = SpreadJsObj.getSelectObject(sheet);
 
-                 if (!data) {
 
-                     $('#bills-expr').val('').attr('readOnly', true);
 
-                     return;
 
-                 }
 
-                 const nodePos = stagePos.getLedgerPos(data.id);
 
-                 if (nodePos && nodePos.length > 0) {
 
-                     $('#bills-expr').val('').attr('readOnly', true);
 
-                 } else {
 
-                     $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field])
 
-                         .attr('readOnly', readOnly || cell.locked());
 
-                 }
 
-             } else {
 
-                 $('#bills-expr').val('').attr('readOnly', true);
 
-             }
 
-         },
 
-         refreshTreeNodes: function (sheet, nodes) {
 
-             const tree = sheet.zh_tree;
 
-             if (!tree) { return }
 
-             const rows = [];
 
-             for (const node of nodes) {
 
-                 rows.push(tree.nodes.indexOf(node));
 
-             }
 
-             SpreadJsObj.reLoadRowsData(sheet, rows);
 
-         },
 
-         editEnded: function (e, info) {
 
-             if (info.sheet.zh_setting) {
 
-                 const col = info.sheet.zh_setting.cols[info.col];
 
-                 const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
 
-                 const node = sortData[info.row], updateData = {};
 
-                 const orgValue = node[col.field];
 
-                 let newValue = trimInvalidChar(info.editingText);
 
-                 if (orgValue == newValue || ((!orgValue || orgValue === '') && (!newValue || newValue === ''))) {
 
-                     return;
 
-                 }
 
-                 if (col.type === 'Number' && newValue && newValue !== '') {
 
-                     const num = _.toNumber(newValue);
 
-                     if (_.isFinite(num)) {
 
-                         newValue = num;
 
-                     } else {
 
-                         try {
 
-                             newValue = math.evaluate(transExpr(newValue));
 
-                         } catch(err) {
 
-                             toastr.error('输入的表达式非法');
 
-                             SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                             return;
 
-                         }
 
-                     }
 
-                 }
 
-                 if (col.field.indexOf('_dgn_') > 0) {
 
-                     if (node.b_code && node.b_code !== '') {
 
-                         toastr.error('仅项目节可输入项目节数量');
 
-                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                         return;
 
-                     }
 
-                 } else if (col.field !== 'postil' && col.field !== 'memo') {
 
-                     if (node.children && node.children.length > 0) {
 
-                         toastr.error('清单父项不可计量');
 
-                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                         return;
 
-                     } else {
 
-                         const nodePos = stagePos.getLedgerPos(node.id);
 
-                         if (nodePos && nodePos.length > 0) {
 
-                             toastr.error('该清单有计量单元,请在计量单元处计量');
 
-                             SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                             return;
 
-                         }
 
-                     }
 
-                 }
 
-                 if (col.field === 'memo') {
 
-                     updateData.main = {
 
-                         id: node.id
 
-                     };
 
-                     updateData.main[col.field] = newValue;
 
-                 } else if (col.field.indexOf('_dgn_') > 0) {
 
-                     updateData.dgn = {
 
-                         id: node.id
 
-                     };
 
-                     updateData.dgn[col.field] = newValue;
 
-                 } else if (col.field !== 'is_tp') {
 
-                     updateData.stage = {
 
-                         lid: node.id
 
-                     };
 
-                     updateData.stage[col.field] = newValue;
 
-                 }
 
-                 postData(window.location.href + '/update', {bills: updateData}, function (data) {
 
-                     // tag update
 
-                     const nodes = stageTree.loadPostStageData(data);
 
-                     stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
 
-                     if (detail) {
 
-                         detail.loadStageLedgerUpdateData(data);
 
-                     } else {
 
-                         stageIm.loadUpdateLedgerData(data);
 
-                     }
 
-                 }, function () {
 
-                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                 });
 
-             }
 
-         },
 
-         selectionChanged: function (e, info) {
 
-             if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
 
-                 stagePosSpreadObj.loadCurPosData();
 
-                 SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
 
-                 if (posSearch) {
 
-                     posSearch.search();
 
-                 }
 
-             }
 
-             SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
 
-             stageTreeSpreadObj.loadExprToInput(info.sheet);
 
-         },
 
-         deletePress(sheet) {
 
-             if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
 
-                 const tree = sheet.zh_tree;
 
-                 if (!tree) { return; }
 
-                 const sel = sheet.getSelections()[0];
 
-                 const validCols = [];
 
-                 for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
 
-                     const colSetting = sheet.zh_setting.cols[iCol];
 
-                     if (!colSetting.readOnly && colSetting.field !== 'qc_qty') {
 
-                         validCols.push(iCol);
 
-                     }
 
-                 }
 
-                 if (validCols.length === 0) { return; }
 
-                 const sortData = sheet.zh_tree.nodes;
 
-                 const datas = [], dgnDatas = [], mainDatas = [];
 
-                 for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
 
-                     const node = sortData[iRow];
 
-                     if (node) {
 
-                         const data = { lid: node.id }, dgnData = { id: node.id }, mainData = { id: node.id };
 
-                         let filter = true, filterDgn = true, filterMain = true;
 
-                         for (const iCol of validCols) {
 
-                             const colSetting = sheet.zh_setting.cols[iCol];
 
-                             if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
 
-                                 if (node.b_code && node.b_code !== '') continue;
 
-                             } else if (colSetting.field !== 'postil') {
 
-                                 if (node.children && node.children.length > 0) { continue; }
 
-                                 const nodePos = stagePos.getLedgerPos(node.id);
 
-                                 if (nodePos && nodePos.length > 0) { continue; }
 
-                             }
 
-                             if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
 
-                                 if (node[colSetting.field] && node[colSetting.field] !== 0) {
 
-                                     dgnData[colSetting.field] = 0;
 
-                                     filterDgn = false;
 
-                                 }
 
-                             } else if (colSetting.field === 'memo') {
 
-                                 mainData[colSetting.field] = null;
 
-                                 filterMain = false;
 
-                             } else {
 
-                                 data[colSetting.field] = null;
 
-                                 filter = false;
 
-                             }
 
-                         }
 
-                         if (!filter) datas.push(data);
 
-                         if (!filterDgn) dgnDatas.push(dgnData);
 
-                         if (!filterMain) mainDatas.push(mainData);
 
-                     }
 
-                 }
 
-                 if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
 
-                     const bills = {};
 
-                     if (datas.length > 0) bills.stage = datas;
 
-                     if (dgnDatas.length > 0) bills.dgn = dgnDatas;
 
-                     if (mainDatas.length > 0) bills.main = mainDatas;
 
-                     postData(window.location.href + '/update', {bills: bills}, function (result) {
 
-                         const nodes = stageTree.loadPostStageData(result);
 
-                         stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
 
-                         if (detail) {
 
-                             detail.loadStageLedgerUpdateData(result);
 
-                         } else {
 
-                             stageIm.loadUpdateLedgerData(result);
 
-                         }
 
-                     });
 
-                 }
 
-             }
 
-         },
 
-         clipboardPasting(e, info) {
 
-             if (info.sheet.zh_setting) {
 
-                 const setting = info.sheet.zh_setting;
 
-                 const range = info.cellRange;
 
-                 const stageField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'];
 
-                 for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
 
-                     const col = info.sheet.zh_setting.cols[iCol];
 
-                     if ((stageField.indexOf(col.field) === -1) && setting.dgnUpFields.indexOf(col.field) === -1
 
-                         && col.field !== 'memo') {
 
-                         toastr.error('不可修改此数据');
 
-                         info.cancel = true;
 
-                         return;
 
-                     }
 
-                 }
 
-             }
 
-         },
 
-         clipboardPasted(e, info) {
 
-             if (info.sheet.zh_setting && info.sheet.zh_tree) {
 
-                 const sheet = info.sheet, setting = info.sheet.zh_setting;
 
-                 const filterNodes = [], datas = [], dgnDatas = [], mainDatas = [];
 
-                 let bHint = false;
 
-                 for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
 
-                     const curRow = iRow + info.cellRange.row;
 
-                     const node = sheet.zh_tree.getItemsByIndex(curRow);
 
-                     const data = {lid: node.id}, dgnData = {id: node.id}, mainData = {id: node.id};
 
-                     let filter = true, filterDgn = true, filterMain = true;
 
-                     for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
 
-                         const curCol = info.cellRange.col + iCol;
 
-                         const col = info.sheet.zh_setting.cols[curCol];
 
-                         if (setting.dgnUpFields.indexOf(col.field) !== -1) {
 
-                             if (node.b_code && node.b_code !== '') continue;
 
-                         } else if (col.field !== 'postil') {
 
-                             if (node.children && node.children.length > 0) continue;
 
-                             const nodePos = stagePos.getLedgerPos(node.id);
 
-                             if (nodePos && nodePos.length > 0) continue;
 
-                         }
 
-                         const text = trimInvalidChar(sheet.getText(curRow, curCol));
 
-                         if (setting.dgnUpFields.indexOf(col.field) !== -1) {
 
-                             const num = _.toNumber(text);
 
-                             if (num) {
 
-                                 dgnData[col.field] = num;
 
-                                 filterDgn = false;
 
-                             } else {
 
-                                 try {
 
-                                     dgnData[col.field] = math.evaluate(transExpr(text));
 
-                                     filterDgn = false;
 
-                                 } catch(err) {
 
-                                     if (!bHint) {
 
-                                         toastr.warning('粘贴了非法表达式,已过滤');
 
-                                         bHint = true;
 
-                                     }
 
-                                 }
 
-                             }
 
-                         } else if (col.field === 'memo') {
 
-                             mainData.memo = text;
 
-                             filterMain = false;
 
-                         } else {
 
-                             if (col.type === 'Number') {
 
-                                 const num = _.toNumber(text);
 
-                                 if (_.isFinite(num)) {
 
-                                     data[col.field] = num;
 
-                                     filter = false;
 
-                                 } else {
 
-                                     try {
 
-                                         data[col.field] = math.evaluate(transExpr(text));
 
-                                         filter = false;
 
-                                     } catch(err) {
 
-                                         if (!bHint) {
 
-                                             toastr.warning('粘贴了非法表达式,已过滤');
 
-                                             bHint = true;
 
-                                         }
 
-                                     }
 
-                                 }
 
-                             } else {
 
-                                 data[col.field] = text;
 
-                             }
 
-                         }
 
-                     }
 
-                     if (filter && filterDgn && filterMain) {
 
-                         filterNodes.push(node);
 
-                     } else {
 
-                         if (!filter) datas.push(data);
 
-                         if (!filterDgn) dgnDatas.push(dgnData);
 
-                         if (!filterMain) mainDatas.push(mainData);
 
-                     }
 
-                 }
 
-                 if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
 
-                     const updateData = {};
 
-                     if (datas.length > 0) updateData.stage = datas;
 
-                     if (dgnDatas.length > 0) updateData.dgn = dgnDatas;
 
-                     if (mainDatas.length > 0) updateData.main = mainDatas;
 
-                     postData(window.location.href + '/update', {bills: updateData}, function (data) {
 
-                         const nodes = stageTree.loadPostStageData(data);
 
-                         stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
 
-                         if (detail) {
 
-                             detail.loadStageLedgerUpdateData(data);
 
-                         } else {
 
-                             stageIm.loadUpdateLedgerData(data);
 
-                         }
 
-                     }, function () {
 
-                         // todo
 
-                         //stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
 
-                     });
 
-                 } else {
 
-                     stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
 
-                 }
 
-             }
 
-         },
 
-         measureAllPosInNode(node, ratio = 1) {
 
-             const posterity = stageTree.getPosterity(node)
 
-             const data = {updateType: 'update', updateData: []};
 
-             for (const p of posterity) {
 
-                 if (p.children && p.children.length > 0) continue;
 
-                 const posRange = stagePos.getLedgerPos(p.id);
 
-                 if (posRange && posRange.length > 0) {
 
-                     for (const pr of posRange) {
 
-                         if (pr.contract_qty && !checkZero(pr.contract_qty)) continue;
 
-                         const validValue = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
 
-                         if (validValue <= 0) continue;
 
-                         const value = ratio !== 1 ? ZhCalc.mul(pr.quantity, ratio) : pr.quantity;
 
-                         const pData = {
 
-                             pid: pr.id,
 
-                             lid: pr.lid,
 
-                             contract_qty: validValue > 0 ? (value > validValue ? validValue : value) : (value < validValue ? validValue : value),
 
-                         };
 
-                         data.updateData.push(pData);
 
-                     }
 
-                 }
 
-                 if (data.updateData.length > 1000 || _.map(data.updateData, 'lid').length > 500) {
 
-                     toastr.warning('选中的数据过多,仅计量' + data.updateData.length + '条,请稍后');
 
-                     break;
 
-                 }
 
-             }
 
-             if (data.updateData.length === 0) {
 
-                 toastr.info('其下全部计量单元均已计量');
 
-                 return;
 
-             }
 
-             postData(window.location.pathname + '/update', {pos: data}, function (result) {
 
-                 if (result.pos) {
 
-                     stagePos.updateDatas(result.pos.pos);
 
-                     stagePos.loadCurStageData(result.pos.curStageData);
 
-                 }
 
-                 const nodes = stageTree.loadPostStageData(result.ledger);
 
-                 stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
 
-                 stagePosSpreadObj.loadCurPosData();
 
-                 if (detail) {
 
-                     detail.loadStagePosUpdateData(result);
 
-                 } else {
 
-                     stageIm.loadUpdatePosData(result);
 
-                 }
 
-                 toastr.success('已计量' + data.updateData.length + '条');
 
-             }, function () {
 
-                 stagePosSpreadObj.loadCurPosData();
 
-             });
 
-         },
 
-         topRowChanged(e, info) {
 
-             SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
 
-         },
 
-         editStarting(e, info) {
 
-             if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
 
-             const col = info.sheet.zh_setting.cols[info.col];
 
-             const node = info.sheet.zh_tree.nodes[info.row];
 
-             switch (col.field) {
 
-                 case 'contract_qty':
 
-                 case 'qc_qty':
 
-                     info.cancel = node.is_tp;
 
-                     break;
 
-                 case 'contract_tp':
 
-                     info.cancel = !node.is_tp;
 
-                     break;
 
-                 case 'is_tp':
 
-                     info.cancel = true;
 
-                     break;
 
-             }
 
-         },
 
-         buttonClicked: function (e, info) {
 
-             if (info.sheet.zh_setting) {
 
-                 const node = SpreadJsObj.getSelectObject(info.sheet);
 
-                 const col = info.sheet.zh_setting.cols[info.col];
 
-                 const posRange = stagePos.getLedgerPos(node.id);
 
-                 if (node.pre_used === 1 || node.unit !== '总额' || (posRange && posRange.length > 0) /*|| !checkZero(node.qc_qty)*/) {
 
-                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                     return;
 
-                 }
 
-                 const postIsTp = function () {
 
-                     const data = { calcType: {id: node.id} };
 
-                     data.calcType.is_tp = info.sheet.getValue(info.row, info.col) || false;
 
-                     // 更新至服务器
 
-                     postData(window.location.pathname + '/update', {bills: data}, function (result) {
 
-                         const nodes = stageTree.loadPostStageData(result);
 
-                         stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
 
-                         if (detail) {
 
-                             detail.loadStageLedgerUpdateData(result);
 
-                         } else {
 
-                             stageIm.loadUpdateLedgerData(result);
 
-                         }
 
-                     });
 
-                 };
 
-                 if (col.field === 'is_tp') {
 
-                     if (info.sheet.isEditing) {
 
-                         info.sheet.endEdit(true);
 
-                     }
 
-                     if (!checkZero(node.contract_qty) || !checkZero(node.contract_tp)) {
 
-                         $.msgBox({
 
-                             id: 'calc-type',
 
-                             title: '提示',
 
-                             message: '切换计量模式,已计量数据会被清空。',
 
-                             ok: {
 
-                                 caption: '确定',
 
-                                 callback: postIsTp,
 
-                             },
 
-                             cancel: {
 
-                                 caption: '取消',
 
-                                 callback: function () {
 
-                                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                                 }
 
-                             }
 
-                         });
 
-                     } else {
 
-                         postIsTp();
 
-                     }
 
-                 }
 
-             }
 
-         },
 
-     };
 
-     slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
 
-     slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
 
-     slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
 
-     slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
 
-     slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
 
-     slSpread.bind(spreadNS.Events.EditStarting, stageTreeSpreadObj.editStarting);
 
-     slSpread.bind(spreadNS.Events.ButtonClicked, stageTreeSpreadObj.buttonClicked);
 
-     SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
 
-     if (!readOnly) {
 
-         $('#bills-expr').bind('change mouseleave', function () {
 
-             if (this.readOnly) return;
 
-             const expr = $(this);
 
-             const sheet = slSpread.getActiveSheet();
 
-             const select = SpreadJsObj.getSelectObject(sheet);
 
-             const field = expr.attr('field'), orgValue = expr.attr('org'), updateData = {};
 
-             let newValue = expr.val();
 
-             const num = _.toNumber(newValue);
 
-             if (num) {
 
-                 newValue = num;
 
-             } else {
 
-                 try {
 
-                     newValue = math.evaluate(transExpr(newValue));
 
-                 } catch(err) {
 
-                     toastr.error('输入的表达式非法');
 
-                     return;
 
-                 }
 
-             }
 
-             if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
 
-             if (field.indexOf('_dgn_') > 0) {
 
-                 updateData.dgn = {
 
-                     id: select.id
 
-                 };
 
-                 updateData.dgn[field] = newValue;
 
-             } else {
 
-                 updateData.stage = {
 
-                     lid: select.id
 
-                 };
 
-                 updateData.stage[field] = newValue;
 
-             }
 
-             // 更新至服务器
 
-             postData(window.location.pathname + '/update', {bills: updateData}, function (result) {
 
-                 const nodes = stageTree.loadPostStageData(result);
 
-                 expr.val(select[field]);
 
-                 stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
 
-             });
 
-         });
 
-     }
 
-     stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
 
-     const stagePosSpreadObj = {
 
-         loadExprToInput(sheet) {
 
-             const sel = sheet.getSelections()[0];
 
-             const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
 
-             if (col.type === 'Number') {
 
-                 const data = SpreadJsObj.getSelectObject(sheet);
 
-                 if (data) {
 
-                     $('#pos-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field])
 
-                         .attr('row', sel.row).attr('readOnly', readOnly || cell.locked());
 
-                 } else {
 
-                     $('#pos-expr').val('').attr('readOnly', true);
 
-                 }
 
-             } else {
 
-                 $('#pos-expr').val('').attr('readOnly', true);
 
-             }
 
-         },
 
-         /**
 
-          * 加载计量单元 根据当前台账选择节点
 
-          */
 
-         loadCurPosData: function () {
 
-             const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
 
-             if (node) {
 
-                 const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
 
-                 SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
 
-                 getNodeList(node.id);
 
-                 // 如果是附件是当前节点,隐藏
 
-                 if ($('#dqjiedian').hasClass('active')) {
 
-                     $('#showAttachment').hide();
 
-                 }
 
-             } else {
 
-                 SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
 
-             }
 
-         },
 
-         editEnded: function (e, info) {
 
-             if (info.sheet.zh_setting) {
 
-                 // 未改变过,则直接跳过
 
-                 const sortData = info.sheet.zh_data;
 
-                 const posData = sortData ? sortData[info.row] : null;
 
-                 const col = info.sheet.zh_setting.cols[info.col];
 
-                 const orgText = posData ? posData[col.field] : null;
 
-                 const newText = trimInvalidChar(info.editingText);
 
-                 if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
 
-                     return;
 
-                 }
 
-                 // 台账模式下,不可新增
 
-                 if (checkTzMeasureType() && !posData) {
 
-                     toastr.error('台账模式不可新增计量单元数据');
 
-                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                     return ;
 
-                 }
 
-                 // 不同节点下,计量单元检查输入
 
-                 //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
 
-                 const node = stagePosSpreadObj.stageTreeNode;
 
-                 if (!node) {
 
-                     toastr.warning('数据错误, 请刷新页面后再试');
 
-                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                     return;
 
-                 } else if (newText !== '' && node.children && node.children > 0) {
 
-                     toastr.error('父节点不可插入计量单元');
 
-                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                     return;
 
-                 } else if (newText !== '' && !node.b_code || node.b_code === '') {
 
-                     toastr.error('项目节不可插入计量单元');
 
-                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                     return;
 
-                 }
 
-                 // 生成提交数据
 
-                 const data = {};
 
-                 if (col.field === 'name') {
 
-                     if ((!newText || newText === '') && posData) {
 
-                         toastr.error('部位名称不可为空');
 
-                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                         return;
 
-                     } else if (!posData) {
 
-                         if (newText !== '') {
 
-                             data.updateType = 'add';
 
-                             const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
 
-                             data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
 
-                         } else {
 
-                             SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                             return;
 
-                         }
 
-                     } else {
 
-                         data.updateType = 'update';
 
-                         data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
 
-                     }
 
-                 } else if (!posData) {
 
-                     toastr.warning('新增部位请先输入名称');
 
-                 } else {
 
-                     data.updateType = 'update';
 
-                     data.updateData = {pid: posData.id, lid: posData.lid};
 
-                     if (col.type === 'Number') {
 
-                         const num = _.toNumber(newText);
 
-                         if (_.isFinite(num)) {
 
-                             data.updateData[col.field] = num;
 
-                         } else {
 
-                             try {
 
-                                 data.updateData[col.field] = math.evaluate(transExpr(newText));
 
-                             } catch(err) {
 
-                                 toastr.error('输入的表达式非法');
 
-                                 SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                                 return;
 
-                             }
 
-                         }
 
-                     } else {
 
-                         data.updateData[col.field] = newText;
 
-                     }
 
-                 }
 
-                 // 提交数据到服务器
 
-                 postData(window.location.pathname + '/update', {pos: data}, function (result) {
 
-                     if (result.pos) {
 
-                         stagePos.updateDatas(result.pos.pos);
 
-                         stagePos.loadCurStageData(result.pos.curStageData);
 
-                     }
 
-                     const refreshData = stageTree.loadPostStageData(result.ledger);
 
-                     stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
 
-                     stagePosSpreadObj.loadCurPosData();
 
-                     if (detail) {
 
-                         detail.loadStagePosUpdateData(result);
 
-                     } else {
 
-                         stageIm.loadUpdatePosData(result);
 
-                     }
 
-                 }, function () {
 
-                     stagePosSpreadObj.loadCurPosData();
 
-                 });
 
-             }
 
-         },
 
-         editStarting: function (e, info) {
 
-             stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
 
-         },
 
-         clipboardPasting: function (e, info) {
 
-             if (info.sheet.zh_setting) {
 
-                 const sortData = info.sheet.zh_data;
 
-                 const range = info.cellRange;
 
-                 const validField = ['contract_qty', 'qc_qty', 'postil'];
 
-                 if (!checkTzMeasureType()) {
 
-                     validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty');
 
-                 }
 
-                 for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
 
-                     const col = info.sheet.zh_setting.cols[iCol];
 
-                     if (validField.indexOf(col.field) === -1) {
 
-                         if (checkTzMeasureType()) {
 
-                             toastr.error('不可修改此数据');
 
-                             info.cancel = true;
 
-                             return;
 
-                         } else {
 
-                             for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
 
-                                 const pos = sortData(iRow);
 
-                                 if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
 
-                                     toastr.error('不可修改此数据');
 
-                                     info.cancel = true;
 
-                                     return;
 
-                                 }
 
-                             }
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-         },
 
-         clipboardPasted: function (e, info) {
 
-             const self = this;
 
-             if (info.sheet.zh_setting) {
 
-                 const data = { updateType: '', updateData: [], };
 
-                 const sortData = info.sheet.zh_data;
 
-                 const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
 
-                 if (sortData && (info.cellRange.row >= sortData.length)) {
 
-                     data.updateType = 'add';
 
-                     if (info.cellRange.col !== 0) {
 
-                         toastr.warning('新增部位请先输入名称');
 
-                         self.loadCurPosData();
 
-                         return;
 
-                     }
 
-                     const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
 
-                     for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
 
-                         const curRow = info.cellRange.row + iRow;
 
-                         const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
 
-                         for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
 
-                             const curCol = info.cellRange.col + iCol;
 
-                             const colSetting = info.sheet.zh_setting.cols[curCol];
 
-                             newData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
 
-                             if (colSetting.type === 'Number') {
 
-                                 const num = _.toNumber(newData[colSetting.field]);
 
-                                 if (num) {
 
-                                     newData[colSetting.field] = num;
 
-                                 } else {
 
-                                     try {
 
-                                         newData[colSetting.field] = math.evaluate(transExpr(newData[colSetting.field]));
 
-                                     } catch(err) {
 
-                                         toastr.error('输入的表达式非法');
 
-                                         self.loadCurPosData();
 
-                                         return;
 
-                                     }
 
-                                 }
 
-                             }
 
-                         }
 
-                         data.updateData.push(newData);
 
-                     }
 
-                 } else {
 
-                     data.updateType = 'update';
 
-                     for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
 
-                         const curRow = info.cellRange.row + iRow;
 
-                         const curPos = sortData[curRow];
 
-                         if (curPos) {
 
-                             const newData = {pid: curPos.id, lid: curPos.lid};
 
-                             for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
 
-                                 const curCol = info.cellRange.col + iCol;
 
-                                 const colSetting = info.sheet.zh_setting.cols[curCol];
 
-                                 newData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
 
-                                 if (colSetting.type === 'Number') {
 
-                                     const num = _.toNumber(newData[colSetting.field]);
 
-                                     if (num) {
 
-                                         newData[colSetting.field] = num;
 
-                                     } else {
 
-                                         try {
 
-                                             newData[colSetting.field] = math.evaluate(transExpr(newData[colSetting.field]));
 
-                                         } catch(err) {
 
-                                             toastr.error('输入的表达式非法');
 
-                                             self.loadCurPosData();
 
-                                             return;
 
-                                         }
 
-                                     }
 
-                                 }
 
-                             }
 
-                             data.updateData.push(newData);
 
-                         }
 
-                     }
 
-                 }
 
-                 postData(window.location.pathname + '/update', {pos: data}, function (result) {
 
-                     if (result.pos) {
 
-                         stagePos.updateDatas(result.pos.pos);
 
-                         stagePos.loadCurStageData(result.pos.curStageData);
 
-                     }
 
-                     const nodes = stageTree.loadPostStageData(result.ledger);
 
-                     stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
 
-                     stagePosSpreadObj.loadCurPosData();
 
-                     if (detail) {
 
-                         detail.loadStagePosUpdateData(result);
 
-                     } else {
 
-                         stageIm.loadUpdatePosData(result);
 
-                     }
 
-                 }, function () {
 
-                     stagePosSpreadObj.loadCurPosData();
 
-                 });
 
-             }
 
-         },
 
-         deletePress: function (sheet) {
 
-             if (sheet.zh_setting && sheet.zh_data) {
 
-                 const sortData = sheet.zh_data;
 
-                 if (!sortData || sortData.length === 0) { return; }
 
-                 const sel = sheet.getSelections()[0];
 
-                 const validCols = [];
 
-                 for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
 
-                     const colSetting = sheet.zh_setting.cols[iCol];
 
-                     if (!colSetting.readOnly && colSetting.field !== 'qc_qty') {
 
-                         validCols.push(iCol);
 
-                     }
 
-                 }
 
-                 if (validCols.length === 0) { return; }
 
-                 const datas = [], posSelects = [];
 
-                 for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
 
-                     const node = sortData[iRow];
 
-                     if (node) {
 
-                         const data = {pid: node.id, lid: node.lid};
 
-                         for (const iCol of validCols) {
 
-                             const colSetting = sheet.zh_setting.cols[iCol];
 
-                             if (colSetting.field === 'name') {
 
-                                 toastr.error('部位名称不能为空');
 
-                                 return;
 
-                             }
 
-                             data[colSetting.field] = null;
 
-                         }
 
-                         datas.push(data);
 
-                         posSelects.push(node);
 
-                     }
 
-                 }
 
-                 if (datas.length > 0) {
 
-                     postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
 
-                         if (result.pos) {
 
-                             stagePos.updateDatas(result.pos.pos);
 
-                             stagePos.loadCurStageData(result.pos.curStageData);
 
-                         }
 
-                         const nodes = stageTree.loadPostStageData(result.ledger);
 
-                         stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
 
-                         if (detail) {
 
-                             detail.loadStagePosUpdateData(result);
 
-                         } else {
 
-                             stageIm.loadUpdatePosData(result);
 
-                         }
 
-                         // todo 只加载改变项
 
-                         stagePosSpreadObj.loadCurPosData();
 
-                     });
 
-                 }
 
-             }
 
-         },
 
-         deletePos: function (sheet) {
 
-             const sels = sheet.getSelections();
 
-             const sel = sels ? sels[0] : null;
 
-             if (sheet.zh_data && sel) {
 
-                 const data = {updateType: 'delete', updateData: []};
 
-                 for (let iRow = 0; iRow < sel.rowCount; iRow++) {
 
-                     const posData = sheet.zh_data[sel.row + iRow];
 
-                     if (posData) {
 
-                         data.updateData.push(posData.id);
 
-                     }
 
-                 }
 
-                 if (data.updateData.length > 0) {
 
-                     postData(window.location.pathname + '/update', {pos: data}, function (result) {
 
-                         stagePos.removeDatas(result.pos.pos);
 
-                         const refreshData = stageTree.loadPostStageData(result.ledger);
 
-                         stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
 
-                         stagePosSpreadObj.loadCurPosData();
 
-                         if (detail) {
 
-                             detail.loadStagePosUpdateData(result);
 
-                         } else {
 
-                             stageIm.loadUpdatePosData(result);
 
-                         }
 
-                     });
 
-                 }
 
-             }
 
-         },
 
-         selectionChanged: function (e, info) {
 
-             stagePosSpreadObj.loadExprToInput(info.sheet);
 
-         }
 
-     };
 
-     // 加载上下窗口resizer
 
-     $.divResizer({
 
-         select: '#main-resize',
 
-         callback: function () {
 
-             slSpread.refresh();
 
-             let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
 
-             $(".sp-wrap").height(bcontent-40);
 
-             spSpread.refresh();
 
-         }
 
-     });
 
-     // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
 
-     postData(window.location.pathname + '/load', null, function (result) {
 
-         // 加载树结构
 
-         stageTree.loadDatas(result.ledgerData);
 
-         // stageTree.loadCurStageData(curStageData);
 
-         // stageTree.loadPreStageData(preStageData);
 
-         treeCalc.calculateAll(stageTree);
 
-         SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
 
-         SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
 
-         // 加载部位明细
 
-         stagePos.loadDatas(result.posData);
 
-         stagePos.calculateAll();
 
-         stagePosSpreadObj.loadCurPosData();
 
-         SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
 
-         // 加载中间计量
 
-         stageIm.init(stage, imType);
 
-         stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData);
 
-     }, null, true);
 
-     spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
 
-     spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
 
-     spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
 
-     spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
 
-     spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
 
-     SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
 
-     if (!readOnly) {
 
-         $('#pos-expr').bind('change mouseleave', function () {
 
-             if (this.readOnly) return;
 
-             const expr = $(this);
 
-             const posSheet = spSpread.getActiveSheet();
 
-             const select = SpreadJsObj.getSelectObject(posSheet);
 
-             const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val(), row = expr.attr('row');
 
-             if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
 
-             const data = {pid: select.id, lid: select.lid};
 
-             const num = _.toNumber(newValue);
 
-             if (num) {
 
-                 data[field] = num;
 
-             } else {
 
-                 try {
 
-                     data[field] = math.evaluate(transExpr(newValue));
 
-                 } catch (err) {
 
-                     toastr.error('输入的表达式非法');
 
-                     return;
 
-                 }
 
-             }
 
-             // 提交数据到服务器
 
-             postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
 
-                 if (result.pos) {
 
-                     stagePos.updateDatas(result.pos.pos);
 
-                     stagePos.loadCurStageData(result.pos.curStageData);
 
-                     expr.val(select[field]);
 
-                     SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
 
-                 }
 
-                 const refreshData = stageTree.loadPostStageData(result.ledger);
 
-                 stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
 
-             });
 
-         });
 
-     }
 
-     if (!checkTzMeasureType()) {
 
-         $.contextMenu({
 
-             selector: '#stage-pos',
 
-             build: function ($trigger, e) {
 
-                 const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
 
-                 return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
 
-             },
 
-             items: {
 
-                 'del': {
 
-                     name: '删除',
 
-                     icon: 'fa-remove',
 
-                     disabled: function (key, opt) {
 
-                         const sheet = spSpread.getActiveSheet();
 
-                         if (sheet.zh_data && !readOnly) {
 
-                             const selection = sheet.getSelections();
 
-                             if (selection && selection[0]) {
 
-                                 let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
 
-                                 for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
 
-                                     const posData = sheet.zh_data[selection[0].row + iRow];
 
-                                     if (posData) {
 
-                                         if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
 
-                                             valid = true;
 
-                                             break;
 
-                                         }
 
-                                     } else {
 
-                                         valid = true;
 
-                                         break;
 
-                                     }
 
-                                 }
 
-                                 return valid;
 
-                             } else {
 
-                                 return true;
 
-                             }
 
-                         } else {
 
-                             return true;
 
-                         }
 
-                     },
 
-                     callback: function (key, opt) {
 
-                         stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
 
-                     }
 
-                 }
 
-             }
 
-         })
 
-     } else {
 
-         $.contextMenu({
 
-             selector: '#stage-pos',
 
-             build: function ($trigger, e) {
 
-                 const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
 
-                 return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
 
-             }
 
-         })
 
-     }
 
-     $.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();
 
-             slSpread.refresh();
 
-             spSpread.refresh();
 
-             if (searchLedger) {
 
-                 searchLedger.spread.refresh();
 
-             }
 
-             if (detail) {
 
-                 detail.spread.refresh();
 
-             }
 
-         }
 
-     });
 
-     $('#row-view').on('show.bs.modal', function () {
 
-         const html = [], customDisplay = customColDisplay();
 
-         for (const cd of customDisplay) {
 
-             html.push('<tr>');
 
-             html.push('<td>', cd.title, '</td>');
 
-             html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
 
-             html.push('</tr>');
 
-         }
 
-         $('#row-view-list').html(html.join(''));
 
-     });
 
-     $('#row-view-ok').click(function () {
 
-         const customDisplay = customColDisplay();
 
-         const cvl = $('#row-view-list').children();
 
-         for (const cv of cvl) {
 
-             const title = $(cv).children()[0].innerHTML;
 
-             const check = $('input', cv)[0].checked;
 
-             const cd = customDisplay.find(function (c) {
 
-                 return c.title === title;
 
-             });
 
-             cd.visible = check;
 
-         }
 
-         customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
 
-         SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
 
-         Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
 
-         $('#row-view').modal('hide');
 
-     });
 
-     class SearchLedger {
 
-         constructor(obj, mainSpread) {
 
-             const self = this;
 
-             this.obj = obj;
 
-             this.mainSpread = mainSpread;
 
-             this.spreadSetting = {
 
-                 cols: [
 
-                     {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@'},
 
-                     {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
 
-                     {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
 
-                     {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
 
-                     {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
 
-                     {title: '数量', field: 'quantity', hAlign: 2, width: 50},
 
-                     {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
 
-                 ],
 
-                 emptyRows: 0,
 
-                 headRows: 1,
 
-                 headRowHeight: [32],
 
-                 defaultRowHeight: 21,
 
-                 headerFont: '12px 微软雅黑',
 
-                 font: '12px 微软雅黑',
 
-                 readOnly: true
 
-             };
 
-             this.spread = SpreadJsObj.createNewSpread($('#search-result', this.obj)[0]);
 
-             SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
 
-             $('#keyword', this.obj).bind('keydown', function(e) {
 
-                 if (e.keyCode == 13) self.searchText();
 
-             });
 
-             $('#searchLedger', this.obj).bind('click', () => {self.searchText()});
 
-             $('#over', this.obj).bind('change', () => {self.searchOver()});
 
-             $('#empty', this.obj).bind('change', () => {self.searchLess()});
 
-             this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
 
-                 const sheet = info.sheet;
 
-                 const data = sheet.zh_data;
 
-                 if (!data) { return }
 
-                 const curBills = data[info.row];
 
-                 if (!curBills) { return }
 
-                 SpreadJsObj.locateTreeNode(self.mainSpread.getActiveSheet(), curBills.ledger_id, true);
 
-                 stagePosSpreadObj.loadCurPosData();
 
-             });
 
-         }
 
-         calculateCompletePercent() {
 
-             if (!this.searchResult) return;
 
-             for (const sr of this.searchResult) {
 
-                 const base = ZhCalc.add(sr.total_price, sr.end_qc_tp);
 
-                 sr.complete_percent = base !== 0 ? ZhCalc.mul(ZhCalc.div(sr.end_gather_tp, base), 100, 2) : 0;
 
-             }
 
-         }
 
-         searchText() {
 
-             const keyword = $('#keyword', this.obj).val();
 
-             if (keyword !== '') {
 
-                 $('#over', this.obj)[0].checked = false;
 
-                 $('#empty', this.obj)[0].checked = false;
 
-                 this.searchResult = [];
 
-                 const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
 
-                 for (const node of sortData) {
 
-                     if ((node.code && node.code.indexOf(keyword) > -1) ||
 
-                         node.b_code && node.b_code.indexOf(keyword) > -1 ||
 
-                         node.name && node.name.indexOf(keyword) > -1) {
 
-                         const data = JSON.parse(JSON.stringify(node));
 
-                         data.visible = true;
 
-                         this.searchResult.push(data);
 
-                     }
 
-                 }
 
-                 this.calculateCompletePercent();
 
-                 SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
 
-             }
 
-         }
 
-         searchOver() {
 
-             this.searchResult = [];
 
-             const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
 
-             for (const node of sortData) {
 
-                 if (node.children && node.children.length > 0) continue;
 
-                 if (node.end_gather_qty) {
 
-                     if (!node.quantity || Math.abs(node.end_gather_qty) > Math.abs(ZhCalc.add(node.quantity, node.end_qc_qty))) {
 
-                         const data = JSON.parse(JSON.stringify(node));
 
-                         data.visible = true;
 
-                         this.searchResult.push(data);
 
-                     }
 
-                 } else if (node.end_gather_tp) {
 
-                     if (!node.total_price || Math.abs(node.end_gather_tp) > Math.abs(ZhCalc.add(node.total_price, node.end_qc_tp))) {
 
-                         const data = JSON.parse(JSON.stringify(node));
 
-                         data.visible = true;
 
-                         this.searchResult.push(data);
 
-                     }
 
-                 }
 
-             }
 
-             this.calculateCompletePercent();
 
-             SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
 
-         }
 
-         searchEmpty() {
 
-             this.searchResult = [];
 
-             const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
 
-             for (const node of sortData) {
 
-                 if (node.children && node.children.length > 0) continue;
 
-                 if (node.quantity) {
 
-                     if (!node.end_gather_qty || checkZero(node.end_gather_qty)) {
 
-                         const data = JSON.parse(JSON.stringify(node));
 
-                         data.visible = true;
 
-                         this.searchResult.push(data);
 
-                     }
 
-                 } else if (node.total_price) {
 
-                     if (!node.end_gather_tp || checkZero(node.end_gather_tp)) {
 
-                         const data = JSON.parse(JSON.stringify(node));
 
-                         data.visible = true;
 
-                         this.searchResult.push(data);
 
-                     }
 
-                 }
 
-             }
 
-             this.calculateCompletePercent();
 
-             SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
 
-         }
 
-         searchLess() {
 
-             this.searchResult = [];
 
-             const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
 
-             for (const node of sortData) {
 
-                 if (node.children && node.children.length > 0) continue;
 
-                 if (node.quantity) {
 
-                     if (ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0) {
 
-                         const data = JSON.parse(JSON.stringify(node));
 
-                         data.visible = true;
 
-                         this.searchResult.push(data);
 
-                     }
 
-                 } else if (node.total_price) {
 
-                     if (ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0) {
 
-                         const data = JSON.parse(JSON.stringify(node));
 
-                         data.visible = true;
 
-                         this.searchResult.push(data);
 
-                     }
 
-                 }
 
-             }
 
-             this.calculateCompletePercent();
 
-             SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
 
-         }
 
-     }
 
-     const posSearch = (function () {
 
-         let resultArr = [];
 
-         const search = function () {
 
-             resultArr = [];
 
-             const keyword = $('#pos-search-keyword').val();
 
-             const checkOver = $('#pos-over-search')[0].checked;
 
-             const checkEmpty = $('#pos-empty-search')[0].checked;
 
-             const sortData = spSpread.getActiveSheet().zh_data;
 
-             if (checkOver || checkEmpty) {
 
-                 if (sortData) {
 
-                     for (let i = 0, iLength = sortData.length; i < iLength; i++) {
 
-                         const sd = sortData[i];
 
-                         let match = false;
 
-                         if (checkOver) {
 
-                             if (sd.end_gather_qty) {
 
-                                 if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
 
-                             }
 
-                         }
 
-                         if (checkEmpty) {
 
-                             if (sd.quantity) {
 
-                                 if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
 
-                             }
 
-                         }
 
-                         if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
 
-                         if (match) {
 
-                             resultArr.push({index: i, data: sd});
 
-                         }
 
-                     }
 
-                 }
 
-             } else if (keyword && keyword !== '') {
 
-                 if (sortData) {
 
-                     for (let i = 0, iLength = sortData.length; i < iLength; i++) {
 
-                         const sd = sortData[i];
 
-                         if (sd.name && sd.name.indexOf(keyword) > -1) {
 
-                             resultArr.push({index: i, data: sd});
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             $('#pos-search-result').html('结果:' + resultArr.length);
 
-         };
 
-         const searchAndLocate = function () {
 
-             search();
 
-             if (resultArr.length > 0) {
 
-                 const sheet = spSpread.getActiveSheet();
 
-                 const sel = sheet.getSelections()[0];
 
-                 const curRow = sel ? sel.row : 0;
 
-                 const pos = resultArr[0];
 
-                 if (pos.index !== curRow) {
 
-                     sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
 
-                     sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
 
-                 }
 
-             }
 
-         };
 
-         const locateNext = function () {
 
-             if (resultArr.length > 0) {
 
-                 const sheet = spSpread.getActiveSheet();
 
-                 const sel = sheet.getSelections()[0];
 
-                 const curRow = sel ? sel.row : 0;
 
-                 let next = _.find(resultArr, function (d) {
 
-                     return d.index > curRow;
 
-                 });
 
-                 if (!next) next = resultArr[0];
 
-                 if (next.index !== curRow) {
 
-                     sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
 
-                     sheet.showRow(next.index, spreadNS.VerticalPosition.center);
 
-                 }
 
-             }
 
-         };
 
-         const locatePre = function () {
 
-             if (resultArr.length > 0) {
 
-                 const sheet = spSpread.getActiveSheet();
 
-                 const sel = sheet.getSelections()[0];
 
-                 const curRow = sel ? sel.row : 0;
 
-                 let next = _.findLast(resultArr, function (d) {
 
-                     return d.index < curRow;
 
-                 });
 
-                 if (!next) next = resultArr[resultArr.length - 1];
 
-                 if (next.index !== curRow) {
 
-                     sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
 
-                     sheet.showRow(next.index, spreadNS.VerticalPosition.center);
 
-                 }
 
-             }
 
-         };
 
-         return {search, searchAndLocate, locateNext, locatePre};
 
-     })();
 
-     $('#pos-search-keyword').bind('keydown', function(e){
 
-         if (e.keyCode == 13) posSearch.searchAndLocate();
 
-     });
 
-     $('#pos-empty-search').click(function () {
 
-         if (this.checked) {
 
-             $('[for=' + this.id +']').addClass('text-warning');
 
-         } else {
 
-             $('[for=' + this.id +']').removeClass('text-warning');
 
-         }
 
-         if (this.checked) {
 
-             if ($('#pos-over-search')[0].checked) {
 
-                 $('#pos-search-keyword').attr('placeholder', '按名称查询');
 
-             } else {
 
-                 $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
 
-             }
 
-         } else {
 
-             if ($('#pos-over-search')[0].checked) {
 
-                 $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
 
-             } else {
 
-                 $('#pos-search-keyword').attr('placeholder', '按名称查询');
 
-             }
 
-         }
 
-         posSearch.searchAndLocate();
 
-     });
 
-     $('#pos-over-search').click(function () {
 
-         if (this.checked) {
 
-             $('[for=' + this.id +']').addClass('text-danger');
 
-         } else {
 
-             $('[for=' + this.id +']').removeClass('text-danger');
 
-         }
 
-         if (this.checked) {
 
-             if ($('#pos-empty-search')[0].checked) {
 
-                 $('#pos-search-keyword').attr('placeholder', '按名称查询');
 
-             } else {
 
-                 $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
 
-             }
 
-         } else {
 
-             if ($('#pos-empty-search')[0].checked) {
 
-                 $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
 
-             } else {
 
-                 $('#pos-search-keyword').attr('placeholder', '按名称查询');
 
-             }
 
-         }
 
-         posSearch.searchAndLocate();
 
-     });
 
-     $('#pos-search-next').click(() => {posSearch.locateNext()});
 
-     $('#pos-search-pre').click(() => {posSearch.locatePre()});
 
-     $.divResizer({
 
-         select: '#right-spr',
 
-         callback: function () {
 
-             slSpread.refresh();
 
-             spSpread.refresh();
 
-             if (searchLedger) {
 
-                 searchLedger.spread.refresh();
 
-             }
 
-             if (detail) {
 
-                 detail.spread.refresh();
 
-             }
 
-         }
 
-     });
 
-     class Detail {
 
-         constructor (obj) {
 
-             const self = this;
 
-             this.spreadSetting = {
 
-                 cols: [
 
-                     {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
 
-                     {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
 
-                     {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
 
-                     {
 
-                         title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
 
-                         colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
 
-                     },
 
-                 ],
 
-                 headRows: 1,
 
-                 emptyRows: 0,
 
-                 headRowHeight: [32],
 
-                 defaultRowHeight: 21,
 
-                 headerFont: '12px 微软雅黑',
 
-                 font: '12px 微软雅黑',
 
-                 readOnly: readOnly,
 
-             };
 
-             this.spread = SpreadJsObj.createNewSpread(obj[0]);
 
-             this.sheet = this.spread.getActiveSheet();
 
-             this.spread.options.allowUserDragFill = true;
 
-             this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
 
-             SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
 
-             this.detailObj = {
 
-                 selectionChanged: function (e, info) {
 
-                     self.reLoadDetailData();
 
-                 },
 
-                 editEnded: function(e, info) {
 
-                     if (info.sheet.zh_setting) {
 
-                         const col = info.sheet.zh_setting.cols[info.col];
 
-                         if (col.field !== 'doc_code') {
 
-                             SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                             return;
 
-                         }
 
-                         const data = SpreadJsObj.getSelectObject(info.sheet);
 
-                         if (data) {
 
-                             const updateData = {lid: data.lid, pid: data.pid};
 
-                             if (data.uuid) {
 
-                                 updateData.uuid = data.uuid;
 
-                             } else {
 
-                                 updateData.code = data.code;
 
-                                 updateData.name = data.name;
 
-                                 updateData.unit = data.unit;
 
-                                 updateData.unit_price = data.unit_price;
 
-                             }
 
-                             updateData.doc_code = info.editingText === null ? '' : info.editingText;
 
-                             postData(window.location.pathname + '/detail/save', updateData, function (result) {
 
-                                 stageIm.loadUpdateDetailData(result);
 
-                                 SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                             }, function () {
 
-                                 SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                             });
 
-                         } else {
 
-                             SpreadJsObj.reLoadRowData(info.sheet, info.row);
 
-                         }
 
-                     }
 
-                 },
 
-                 clipboardPasted: function (e, info) {
 
-                     if (info.sheet.zh_setting && info.sheet.zh_data) {
 
-                         const col = info.sheet.zh_setting.cols[info.cellRange.col];
 
-                         if (info.cellRange.colCount > 1) {
 
-                             toastr.warning('请勿同时复制粘贴多列数据');
 
-                             SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
 
-                             return;
 
-                         }
 
-                         if (col.field !== 'doc_code') {
 
-                             SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
 
-                             return;
 
-                         }
 
-                         const datas = [];
 
-                         for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
 
-                             const curRow = info.cellRange.row + iRow;
 
-                             const data = info.sheet.zh_data[curRow];
 
-                             if (data) {
 
-                                 const updateData = {lid: data.lid, pid: data.pid};
 
-                                 if (data.uuid) {
 
-                                     updateData.uuid = data.uuid;
 
-                                 } else {
 
-                                     updateData.code = data.code;
 
-                                     updateData.name = data.name;
 
-                                     updateData.unit = data.unit;
 
-                                     updateData.unit_price = data.unit_price;
 
-                                 }
 
-                                 updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
 
-                                 datas.push(updateData);
 
-                             }
 
-                         }
 
-                         if (datas.length > 0) {
 
-                             postData(window.location.pathname + '/detail/save', datas, function (result) {
 
-                                 stageIm.loadUpdateDetailData(result);
 
-                                 SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
 
-                             }, function () {
 
-                                 SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
 
-                             })
 
-                         }
 
-                     }
 
-                 },
 
-                 deletePress: function (sheet) {
 
-                     if (sheet.zh_setting) {
 
-                         const datas = [];
 
-                         const sel = sheet.getSelections()[0];
 
-                         for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
 
-                             const col = sheet.zh_setting.cols[iCol];
 
-                             for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
 
-                                 const data = sheet.zh_data[iRow];
 
-                                 if (col.field === 'doc_code') {
 
-                                     const updateData = {lid: data.lid};
 
-                                     if (data.uuid) {
 
-                                         updateData.uuid = data.uuid;
 
-                                         updateData.doc_code = '';
 
-                                         datas.push(updateData);
 
-                                     }
 
-                                 }
 
-                             }
 
-                         }
 
-                         if (datas.length > 0) {
 
-                             postData(window.location.pathname + '/detail/save', datas, function (result) {
 
-                                 stageIm.loadUpdateDetailData(result);
 
-                                 SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
 
-                             }, function () {
 
-                                 SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
 
-                             });
 
-                         }
 
-                     }
 
-                 },
 
-                 dragFillBlock: function (e, info) {
 
-                     info.cancel = true;
 
-                     if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
 
-                     const sel = info.sheet.getSelections()[0];
 
-                     const col = info.sheet.zh_setting.cols[info.fillRange.col];
 
-                     if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
 
-                     const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
 
-                     if (text === '') return;
 
-                     const regRst = /(\d+)$/g.exec(text), datas = [];
 
-                     for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
 
-                         const curRow = info.fillRange.row + iRow;
 
-                         const data = info.sheet.zh_data[curRow];
 
-                         if (data) {
 
-                             const updateData = {lid: data.lid};
 
-                             if (data.uuid) {
 
-                                 updateData.uuid = data.uuid;
 
-                             } else {
 
-                                 updateData.code = data.code;
 
-                                 updateData.name = data.name;
 
-                                 updateData.unit = data.unit;
 
-                                 updateData.unit_price = data.unit_price;
 
-                             }
 
-                             if (regRst) {
 
-                                 updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
 
-                             } else {
 
-                                 updateData.doc_code = text.replace('\n', '');
 
-                             }
 
-                             datas.push(updateData);
 
-                         }
 
-                     }
 
-                     if (datas.length > 0) {
 
-                         postData(window.location.pathname + '/detail/save', datas, function (result) {
 
-                             stageIm.loadUpdateDetailData(result);
 
-                             SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
 
-                         }, function () {
 
-                             SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
 
-                         })
 
-                     }
 
-                 },
 
-             };
 
-             this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
 
-             if (!readOnly) {
 
-                 this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
 
-                 this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
 
-                 this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
 
-                 SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
 
-             }
 
-             this._initImTypeSetRela();
 
-             this._initModifyDetail();
 
-             // 草图相关
 
-             this._initImageRela();
 
-             this.reBuildImData();
 
-         }
 
-         _initImTypeSetRela() {
 
-             const self = this;
 
-             const gatherConfirmPopover = {
 
-                 reBind: function (obj, eventName, fun) {
 
-                     obj.unbind(eventName);
 
-                     obj.bind(eventName, fun);
 
-                 },
 
-                 check: function (pos, hint, okCallback) {
 
-                     const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
 
-                     const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
 
-                     this.reBind(cancelObj, 'click', function () {
 
-                         confirmObj.hide();
 
-                     });
 
-                     this.reBind(okObj, 'click', function () {
 
-                         okCallback();
 
-                         confirmObj.hide();
 
-                     });
 
-                     hintObj.text(hint);
 
-                     confirmObj.css("top", pos.y).css("left", pos.x).show();
 
-                 }
 
-             };
 
-             this.gsTree = stageIm.getGsTree();
 
-             if (stage.im_type === imType.tz.value) {
 
-                 $('#type-title-contract').text('本期合同计量金额');
 
-                 $('#type-title-qc').text('本期变更计量金额');
 
-             } else {
 
-                 $('#type-title-contract').text('本期合同计量数量');
 
-                 $('#type-title-qc').text('本期变更计量数量');
 
-             }
 
-             // 选择中间计量模式
 
-             $('div[name="im-type"]').click(function () {
 
-                 function chooseType(obj) {
 
-                     obj.style.cursor = 'default';
 
-                     $(obj).children().addClass('text-primary');
 
-                     $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
 
-                 }
 
-                 function validType(obj) {
 
-                     obj.style.cursor = 'pointer';
 
-                     $(obj).children().removeClass('text-primary');
 
-                     $('i', obj).remove();
 
-                 }
 
-                 if (this.style.cursor === 'pointer') {
 
-                     const typeArr = $('div[name="im-type"]');
 
-                     for (const t of typeArr) {
 
-                         if ($(t).attr('im-type') === $(this).attr('im-type')) {
 
-                             chooseType(t);
 
-                         } else {
 
-                             validType(t)
 
-                         }
 
-                     }
 
-                 }
 
-             });
 
-             $('#choose').on('show.bs.modal', function () {
 
-                 function chooseType(obj) {
 
-                     obj.style.cursor = 'default';
 
-                     $(obj).children().addClass('text-primary');
 
-                     $('i', obj).remove();
 
-                     $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
 
-                 }
 
-                 function validType(obj) {
 
-                     obj.style.cursor = 'pointer';
 
-                     $(obj).children().removeClass('text-primary');
 
-                     $('i', obj).remove();
 
-                 }
 
-                 $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
 
-                 const typeArr = $('div[name="im-type"]');
 
-                 for (const t of typeArr) {
 
-                     if (parseInt($(t).attr('im-type')) === stage.im_type) {
 
-                         chooseType(t);
 
-                     } else {
 
-                         validType(t)
 
-                     }
 
-                 }
 
-             });
 
-             // 提交 中间计量模式
 
-             $('#choose-ok').click(() => {
 
-                 const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
 
-                     return it.style.cursor !== 'pointer';
 
-                 });
 
-                 const data = {
 
-                     im_type: parseInt($(chooseType).attr('im-type')),
 
-                     im_pre: $('#im-pre').val(),
 
-                 };
 
-                 postData(window.location.pathname + '/detail/build', data, function (result) {
 
-                     stage.im_type = data.im_type;
 
-                     stage.im_pre = data.im_pre;
 
-                     if (stage.im_type === imType.tz.value) {
 
-                         const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
 
-                         jlCol.title = '本期计量金额';
 
-                         SpreadJsObj.reLoadSheetHeader(self.sheet);
 
-                         $('#type-title-contract').text('本期合同计量金额');
 
-                         $('#type-title-qc').text('本期变更计量金额');
 
-                     } else {
 
-                         const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
 
-                         jlCol.title = '本期计量数量';
 
-                         SpreadJsObj.reLoadSheetHeader(self.sheet);
 
-                         $('#type-title-contract').text('本期合同计量数量');
 
-                         $('#type-title-qc').text('本期变更计量数量');
 
-                     }
 
-                     // 加载生成数据
 
-                     self.reBuildImData();
 
-                     $('#choose').modal('hide');
 
-                 });
 
-             });
 
-             // 显示树结构信息
 
-             $('#choose2').on('shown.bs.modal', function () {
 
-                 if (!self.gsSpread) {
 
-                     self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
 
-                     SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), {
 
-                         cols: [
 
-                             {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
 
-                             {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
 
-                             {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
 
-                             {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
 
-                             {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
 
-                         ],
 
-                         headRows: 1,
 
-                         emptyRows: 0,
 
-                         headRowHeight: [32],
 
-                         defaultRowHeight: 21,
 
-                         headerFont: '12px 微软雅黑',
 
-                         font: '12px 微软雅黑',
 
-                     });
 
-                     self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
 
-                         function checkParent(node) {
 
-                             const parent = self.gsTree.getParent(node);
 
-                             if (parent) {
 
-                                 return parent.check ? parent.check : checkParent(parent);
 
-                             } else {
 
-                                 return false;
 
-                             }
 
-                         }
 
-                         function checkChildren(node) {
 
-                             for (const child of node.children) {
 
-                                 if (child.check) {
 
-                                     return true;
 
-                                 } else if (checkChildren(child)) {
 
-                                     return true;
 
-                                 }
 
-                             }
 
-                             return false;
 
-                         }
 
-                         if (!$('#im-gather-check')[0].checked) { return; }
 
-                         const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
 
-                         if (cellType instanceof  spreadNS.CellTypes.CheckBox) {
 
-                             if (sheet.isEditing()) {
 
-                                 sheet.endEdit(true);
 
-                             }
 
-                         }
 
-                         if (info.sheet.zh_setting) {
 
-                             const col = info.sheet.zh_setting.cols[info.col];
 
-                             if (col.field !== 'check') {
 
-                                 return;
 
-                             }
 
-                             const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
 
-                             const node = sortData[info.row];
 
-                             if (!node.check) {
 
-                                 if (checkParent(node)) {
 
-                                     const rect = info.sheet.getCellRect(info.row, info.col);
 
-                                     gatherConfirmPopover.check({
 
-                                         x: rect.x + rect.width / 2 + 25,
 
-                                         y: rect.y + rect.height / 2 + 3,
 
-                                     }, '父项已勾选,继续将取消父项勾选。', function () {
 
-                                         node.check = true;
 
-                                         const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
 
-                                         const rows = [self.gsTree.nodes.indexOf(node)];
 
-                                         for (const p of parents) {
 
-                                             if (p.check) {
 
-                                                 p.check = false;
 
-                                                 rows.push(self.gsTree.nodes.indexOf(p));
 
-                                             }
 
-                                         }
 
-                                         SpreadJsObj.reLoadRowsData(info.sheet, rows);
 
-                                     });
 
-                                 } else if (checkChildren(node)) {
 
-                                     const rect = info.sheet.getCellRect(info.row, info.col);
 
-                                     gatherConfirmPopover.check({
 
-                                         x: rect.x + rect.width / 2 + 25,
 
-                                         y: rect.y + rect.height / 2 + 3,
 
-                                     }, '子项已勾选,继续将取消子项勾选。', function () {
 
-                                         node.check = true;
 
-                                         const posterity = self.gsTree.getPosterity(node);
 
-                                         const rows = [self.gsTree.nodes.indexOf(node)];
 
-                                         for (const p of posterity) {
 
-                                             if (p.check) {
 
-                                                 rows.push(self.gsTree.nodes.indexOf(p));
 
-                                                 p.check = false;
 
-                                             }
 
-                                         }
 
-                                         SpreadJsObj.reLoadRowsData(info.sheet, rows);
 
-                                     });
 
-                                 } else {
 
-                                     node.check = true;
 
-                                     SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
 
-                                 }
 
-                             } else {
 
-                                 node.check = false;
 
-                                 SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
 
-                             }
 
-                         }
 
-                     });
 
-                     const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
 
-                     for (const node of self.gsTree.datas) {
 
-                         node.check = gatherNodes.indexOf(node.id + '') !== -1;
 
-                     }
 
-                     SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
 
-                     self.gsTree.expandByLevel(4);
 
-                     SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
 
-                     SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
 
-                 } else {
 
-                     const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
 
-                     for (const node of self.gsTree.datas) {
 
-                         node.check = gatherNodes.indexOf(node.id + '') !== -1;
 
-                     }
 
-                     SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
 
-                 }
 
-             });
 
-             // 提交 高级设置
 
-             $('#choose2-ok').click(() => {
 
-                 if (!self.gsTree) { return; }
 
-                 const nodes = [];
 
-                 for (const node of self.gsTree.datas) {
 
-                     if (node.check) {
 
-                         nodes.push(node.id);
 
-                     }
 
-                 }
 
-                 const data = {
 
-                     im_gather: $('#im-gather-check')[0].checked,
 
-                     im_gather_node: nodes.join(','),
 
-                 };
 
-                 postData(window.location.pathname + '/detail/adv', data, function (result) {
 
-                     stage.im_gather = data.im_gather;
 
-                     stage.im_gather_node = data.im_gather_node;
 
-                     $('#choose2').modal('hide');
 
-                 });
 
-             });
 
-         }
 
-         _initModifyDetail() {
 
-             const self = this;
 
-             // 编辑
 
-             $('#edit-detail').click(function () {
 
-                 $(this).hide();
 
-                 $('#save-detail').show();
 
-                 $('#cancel-detail').show();
 
-                 $('#detail-show').hide();
 
-                 $('#detail-edit').show();
 
-             });
 
-             // 保存
 
-             $('#save-detail').click(() => {
 
-                 function check(field, obj, org, update) {
 
-                     const newValue = obj.val();
 
-                     if (!org[field]) {
 
-                         if (newValue !== '') {
 
-                             update[field] = newValue;
 
-                         }
 
-                     } else if (newValue !== org[field]){
 
-                         update[field] = newValue;
 
-                     }
 
-                 }
 
-                 const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
 
-                 const updateData = {lid: data.lid, pid: data.pid};
 
-                 if (data.uuid) {
 
-                     updateData.uuid = data.uuid;
 
-                 } else {
 
-                     updateData.code = data.code;
 
-                     updateData.name = data.name;
 
-                     updateData.unit = data.unit;
 
-                     updateData.unit_price = data.unit_price;
 
-                 }
 
-                 updateData.bw = $('#bw-name').val();
 
-                 updateData.peg = $('#peg').val();
 
-                 updateData.xm = $('#xm-name').val();
 
-                 updateData.drawing_code = $('#drawing-code').val();
 
-                 updateData.calc_memo = $('#calc-memo').val();
 
-                 postData(window.location.pathname + '/detail/save', updateData, function (result) {
 
-                     stageIm.loadUpdateDetailData(result);
 
-                     self.reLoadDetailData();
 
-                 });
 
-             });
 
-             // 取消
 
-             $('#cancel-detail').click(() => {
 
-                 self.reLoadDetailData();
 
-             });
 
-         }
 
-         _initImageRela() {
 
-             const self = this;
 
-             function setdraggrable(){
 
-                 $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
 
-                     }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
 
-                     stop: function( event, ui ) {
 
-                     }
 
-                 });
 
-             }
 
-             // 移动图片
 
-             const moveImageItem = function (ev) {
 
-                 const item = this;
 
-                 const view = $('.img-view')[0];
 
-                 let oEvent = ev;
 
-                 // 浏览器有一些图片的默认事件,这里要阻止
 
-                 oEvent.preventDefault();
 
-                 let disX = oEvent.clientX - item.offsetLeft;
 
-                 let disY = oEvent.clientY - item.offsetTop;
 
-                 view.onmousemove = function (ev) {
 
-                     oEvent = ev;
 
-                     oEvent.preventDefault();
 
-                     let x = oEvent.clientX -disX;
 
-                     let y = oEvent.clientY -disY;
 
-                     // 图形移动的边界判断
 
-                     x = x <= 0 ? 0 : x;
 
-                     x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
 
-                     y = y <= 0 ? 0 : y;
 
-                     y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
 
-                     item.style.left = x + 'px';
 
-                     item.style.top = y + 'px';
 
-                 };
 
-                 // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
 
-                 view.onmouseleave = function () {
 
-                     view.onmousemove = null;
 
-                     view.onmouseup = null;
 
-                 };
 
-                 // 鼠标弹起后停止移动
 
-                 view.onmouseup=function() {
 
-                     view.onmousemove = null;
 
-                     view.onmouseup = null;
 
-                 };
 
-             };
 
-             const removeImageItem = function () {
 
-                 $(this).parent().remove();
 
-             };
 
-             // 加载草图组成
 
-             $('#edit-img').on('show.bs.modal', function () {
 
-                 const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
 
-                 const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
 
-                 const html = [];
 
-                 for (const item of items) {
 
-                     const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
 
-                     html.push('<div class="img-item" style="' + itemStyle + '">');
 
-                     html.push('<div class="img-bar">');
 
-                     html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
 
-                     html.push('</div>');
 
-                     html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
 
-                     html.push('</div>');
 
-                 }
 
-                 $('.img-view').html(html.join(''));
 
-                 $('.img-bar').click(removeImageItem);
 
-                 setdraggrable();
 
-             });
 
-             // 上传图片
 
-             $('#upload-img').click(function () {
 
-                 $('#upload-img-file').trigger('click');
 
-             });
 
-             $('#upload-img-file').change(function () {
 
-                 const file = this.files[0];
 
-                 const ext = file.name.toLowerCase().split('.').splice(-1)[0];
 
-                 const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
 
-                 if (!imgStr.test(ext)) {
 
-                     toastr.error('请上传正确的图片格式文件');
 
-                     return
 
-                 }
 
-                 if ($(this).val()) {
 
-                     const formData = new FormData();
 
-                     formData.append('file', this.files[0]);
 
-                     postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
 
-                         const html = [];
 
-                         html.push('<div class="img-item">');
 
-                         html.push('<div class="img-bar">');
 
-                         html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
 
-                         html.push('</div>');
 
-                         html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
 
-                         html.push('</div>');
 
-                         $('.img-view').append(html.join(''));
 
-                         $('.img-bar').click(removeImageItem);
 
-                         setdraggrable();
 
-                         $('#upload-img-file').val('');
 
-                     });
 
-                 }
 
-             });
 
-             // 保存草图修改结果
 
-             $('#edit-img-ok').click(function () {
 
-                 // 记录上传的图片的信息
 
-                 const items = $('.img-item');
 
-                 const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
 
-                 if (items.length > 0) {
 
-                     const itemInfo = [];
 
-                     for (const item of items) {
 
-                         const itemData = {
 
-                             src: $('img', item).attr('src'),
 
-                             left: item.style.left,
 
-                             top: item.style.top,
 
-                             width: item.style.width,
 
-                             height: item.style.height,
 
-                         };
 
-                         itemInfo.push(itemData);
 
-                     }
 
-                     // 获取合并好的图片数据
 
-                     const canvas = document.createElement('canvas');
 
-                     const view = $('.img-view')[0];
 
-                     canvas.height = view.clientHeight;
 
-                     canvas.width = view.clientWidth;
 
-                     const ctx = canvas.getContext('2d');
 
-                     ctx.fillStyle = '#ffffff';
 
-                     ctx.fillRect(0, 0, canvas.width, canvas.height);
 
-                     for (const b of $('.img-item')) {
 
-                         const pos = $(b).position();
 
-                         const img = $('img', b)[0];
 
-                         ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
 
-                     }
 
-                     // 生成上传数据
 
-                     const updateData = {updateType: 'update', lid: data.lid, pid: data.pid};
 
-                     if (data.uuid) {
 
-                         updateData.uuid = data.uuid;
 
-                     } else {
 
-                         updateData.code = data.code;
 
-                         updateData.name = data.name;
 
-                         updateData.unit = data.unit;
 
-                         updateData.unit_price = data.unit_price;
 
-                     }
 
-                     updateData.img = canvas.toDataURL('image/jpeg');
 
-                     updateData.imgInfo = itemInfo;
 
-                     postData(window.location.pathname + '/detail/merge-img', updateData, function (result) {
 
-                         data.calc_img = result.calc_img;
 
-                         data.calc_img_org = result.calc_img_org;
 
-                         const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
 
-                         $('#show-calc-img').attr('src', calcImgSrc);
 
-                         $('#calc-img').attr('src', calcImgSrc);
 
-                         $('#view-calc-img').attr('src', calcImgSrc);
 
-                         $('#edit-img').modal('hide');
 
-                     });
 
-                 } else if (data.calc_img) {
 
-                     postData(window.location.pathname + '/detail/merge-img', {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid}, function (result) {
 
-                         data.calc_img = result.calc_img;
 
-                         data.calc_img_org = result.calc_img_org;
 
-                         const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
 
-                         $('#show-calc-img').attr('src', calcImgSrc);
 
-                         $('#calc-img').attr('src', calcImgSrc);
 
-                         $('#view-calc-img').attr('src', calcImgSrc);
 
-                         $('#edit-img').modal('hide');
 
-                     });
 
-                 }
 
-             });
 
-         }
 
-         reBuildImData() {
 
-             const imData = stageIm.buildImData();
 
-             SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
 
-             this.reLoadDetailData();
 
-         }
 
-         loadStageLedgerUpdateData(data) {
 
-             const imData = stageIm.loadUpdateLedgerData(data);
 
-             SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
 
-             this.reLoadDetailData();
 
-         }
 
-         loadStagePosUpdateData(data) {
 
-             const imData = stageIm.loadUpdatePosData(data);
 
-             SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
 
-             this.reLoadDetailData();
 
-         }
 
-         loadStageChangeUpdateData(data) {
 
-             const imData = stageIm.loadUpdateChangeData(data);
 
-             SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
 
-             this.reLoadDetailData();
 
-         }
 
-         reLoadDetailData() {
 
-             const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
 
-             if (data) {
 
-                 $('#edit-detail').show();
 
-                 $('#modify-img').show();
 
-             } else {
 
-                 $('#edit-detail').hide();
 
-                 $('#modify-img').hide();
 
-             }
 
-             $('#save-detail').hide();
 
-             $('#cancel-detail').hide();
 
-             $('#detail-show').show();
 
-             $('#detail-edit').hide();
 
-             const contractJl = data && data.contract_jl ? data.contract_jl : '';
 
-             $('#show-contract-jl').text(contractJl);
 
-             $('#contract-jl').val(contractJl);
 
-             const qcJl = data && data.qc_jl ? data.qc_jl : '';
 
-             $('#show-qc-jl').text(qcJl);
 
-             $('#qc-jl').val(qcJl);
 
-             const bglCode = data && data.bgl_code ? data.bgl_code : '';
 
-             $('#show-bgl-code').text(bglCode);
 
-             $('#bgl-code').val(bglCode);
 
-             const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
 
-             $('#show-bgl-drawing-code').text(bglDrawingCode);
 
-             $('#bgl-drawing-code').val(bglDrawingCode);
 
-             const bwName = data && data.bw ? data.bw : '';
 
-             $('#show-bw-name').text(bwName);
 
-             $('#bw-name').val(bwName);
 
-             const peg = data && data.peg ? data.peg : '';
 
-             $('#show-peg').text(peg);
 
-             $('#peg').val(peg);
 
-             const xmName = data && data.xm ? data.xm: '';
 
-             $('#show-xm-name').text(xmName);
 
-             $('#xm-name').val(xmName);
 
-             const drawingCode = data && data.drawing_code ? data.drawing_code: '';
 
-             $('#show-drawing-code').text(drawingCode);
 
-             $('#drawing-code').val(drawingCode);
 
-             const calcMemo = data && data.calc_memo ? data.calc_memo: '';
 
-             $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
 
-             $('#calc-memo').val(calcMemo);
 
-             const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
 
-             $('#show-calc-img').attr('src', calcImgSrc);
 
-             $('#calc-img').attr('src', calcImgSrc);
 
-             $('#view-calc-img').attr('src', calcImgSrc);
 
-         }
 
-     }
 
-     // 展开收起附件
 
-     $('a', '.right-nav').bind('click', function () {
 
-         //const main = $('#main-view'), tool = $('#tools-view');
 
-         const tab = $(this), tabPanel = $(tab.attr('content'));
 
-         const showTools = function (show) {
 
-             const left = $('#main-view'), right = $('#tools-view'), parent = left.parent();
 
-             if (show) {
 
-                 right.show();
 
-                 autoFlashHeight();
 
-                 /**
 
-                  * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
 
-                  * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
 
-                  * 故需要通过最终的parent.width再计算一次left.width
 
-                  *
 
-                  * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
 
-                  * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
 
-                  *
 
-                  */
 
-                     //left.css('width', parent.width() - right.outerWidth());
 
-                     //left.css('width', parent.width() - right.outerWidth());
 
-                 const percent = 100 - right.outerWidth() /parent.width() * 100;
 
-                 left.css('width', percent + '%');
 
-             } else {
 
-                 right.hide();
 
-                 left.css('width', '100%');
 
-             }
 
-         };
 
-         if (!tab.hasClass('active')) {
 
-             $('a', '.side-menu').removeClass('active');
 
-             $('.tab-content .tab-select-show').removeClass('active');
 
-             tab.addClass('active');
 
-             tabPanel.addClass('active');
 
-             showTools(tab.hasClass('active'));
 
-             if (tab.attr('content') === '#search' && !searchLedger) {
 
-                 searchLedger = new SearchLedger($('#search'), slSpread);
 
-                 searchLedger.spread.refresh();
 
-             }
 
-             if (tab.attr('content') === '#fujian') {
 
-                 const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
 
-                 getNodeList(node.id);
 
-             }
 
-             if (tab.attr('content') === '#zhongjian') {
 
-                 if (!detail) {
 
-                     detail = new Detail($('#detail-spread'));
 
-                     detail.spread.refresh();
 
-                 }
 
-             }
 
-         } else {
 
-             tab.removeClass('active');
 
-             tabPanel.removeClass('active');
 
-             showTools(tab.hasClass('active'));
 
-         }
 
-         slSpread.refresh();
 
-         spSpread.refresh();
 
-     });
 
-     // 切换附件里节点和所有附件
 
-     $('#fujian .nav-link').on('click', function () {
 
-         const tabPanel = $(this).attr('fujian-content');
 
-         if (tabPanel !== 'syfujian') {
 
-             $('#showPage').hide();
 
-         } else {
 
-             $('#showPage').show();
 
-         }
 
-         $('#showAttachment').hide();
 
-     });
 
-     // 上传附件
 
-     $('#upload-file-btn').click(function () {
 
-         const files = $('#upload-file')[0].files;
 
-         const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
 
-         const formData = new FormData();
 
-         formData.append('lid', node.id);
 
-         for (const file of files) {
 
-             if (file === undefined) {
 
-                 toastr.error('未选择上传文件!');
 
-                 return false;
 
-             }
 
-             const filesize = file.size;
 
-             if (filesize > 10 * 1024 * 1024) {
 
-                 toastr.error('存在上传文件大小过大!');
 
-                 return false;
 
-             }
 
-             const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
 
-             if (whiteList.indexOf(fileext) === -1) {
 
-                 toastr.error('只能上传指定格式的附件!');
 
-                 return false;
 
-             }
 
-             formData.append('size', filesize);
 
-             formData.append('file[]', file);
 
-         }
 
-         postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
 
-             $('#upload').modal('hide');
 
-             // 插入到attData中
 
-             attData = data.concat(attData);
 
-             // 重新生成List
 
-             getAllList();
 
-             getNodeList(node.id);
 
-         }, function () {
 
-             toastr.error('附件上传失败');
 
-         });
 
-         $('#upload-file').val('');
 
-     });
 
-     // 获取附件信息
 
-     $('body').on('click', '.list-table a', function () {
 
-         const fid = $(this).attr('file-id');
 
-         if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
 
-             return;
 
-         }
 
-         const att = attData.find(function (item) {
 
-             return item.id === parseInt(fid);
 
-         });
 
-         $('#edit-att').hide();
 
-         $('#show-att').show();
 
-         if (att !== undefined) {
 
-             $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
 
-             const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
 
-             $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
 
-             $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
 
-             $('#show-att tr').eq(3).children('td').eq(0).text(att.username);
 
-             $('#show-att tr').eq(3).children('td').eq(1).text(att.in_time);
 
-             $('#show-att tr').eq(4).children('td').text(att.remark);
 
-             if (parseInt(userID) === att.uid) {
 
-                 $('#btn-att').show();
 
-                 $('#btn-att a').eq(1).show();
 
-                 $('#btn-att a').eq(0).hide();
 
-                 $('#btn-att a').eq(2).hide();
 
-                 $('#btn-att a').eq(3).hide();
 
-             } else {
 
-                 $('#btn-att').hide();
 
-                 $('#btn-att a').eq(1).hide();
 
-                 $('#btn-att a').eq(0).hide();
 
-                 $('#btn-att a').eq(2).hide();
 
-                 $('#btn-att a').eq(3).hide();
 
-             }
 
-             $('#showAttachment').attr('file-id', fid);
 
-             $('#showAttachment').show();
 
-         } else {
 
-             $('#showAttachment').hide();
 
-             $('#showAttachment').attr('file-id', '');
 
-             toastr.error('附件信息获取失败');
 
-         }
 
-     });
 
-     $('body').on('click', '#btn-att a', function () {
 
-         const content = $(this).attr('content');
 
-         const fid = $('#showAttachment').attr('file-id');
 
-         const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
 
-         if (content === 'edit') {
 
-             $('#btn-att a').eq(1).hide();
 
-             $('#btn-att a').eq(0).show();
 
-             $('#btn-att a').eq(2).show();
 
-             $('#btn-att a').eq(3).show();
 
-             $('#show-att').hide();
 
-             $('#edit-att').show();
 
-             const att = attData.find(function (item) {
 
-                 return item.id === parseInt(fid);
 
-             });
 
-             $('#edit-att .form-group').eq(0).find('input').val(att.filename);
 
-             $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
 
-             const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
 
-             $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
 
-             $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
 
-             $('#edit-att .form-group').eq(3).find('input').val(att.remark);
 
-         } else if (content === 'cancel') {
 
-             $('#show-att').show();
 
-             $('#edit-att').hide();
 
-             $('#btn-att a').eq(1).show();
 
-             $('#btn-att a').eq(0).hide();
 
-             $('#btn-att a').eq(2).hide();
 
-             $('#btn-att a').eq(3).hide();
 
-         } else if (content === 'save') {
 
-             const formData = new FormData();
 
-             formData.append('id', fid);
 
-             formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
 
-             formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
 
-             formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
 
-             const file = $('#change-att-btn')[0];
 
-             if (file.files[0] !== undefined) {
 
-                 const filesize = file.files[0].size;
 
-                 formData.append('size', filesize);
 
-                 formData.append('file', file.files[0]);
 
-             }
 
-             postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
 
-                 // 替换到attData中
 
-                 const att_index = attData.findIndex(function (item) {
 
-                     return item.id === parseInt(fid);
 
-                 });
 
-                 attData.splice(att_index, 1, data);
 
-                 // 重新生成List
 
-                 getAllList(parseInt($('#currentPage').text()));
 
-                 getNodeList(node.id);
 
-                 $('#show-att').show();
 
-                 $('#edit-att').hide();
 
-                 $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
 
-                 const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
 
-                 $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
 
-                 $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
 
-                 $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
 
-                 $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
 
-                 $('#show-att tr').eq(4).children('td').text(data.remark);
 
-                 $('#btn-att a').eq(1).show();
 
-                 $('#btn-att a').eq(0).hide();
 
-                 $('#btn-att a').eq(2).hide();
 
-                 $('#btn-att a').eq(3).hide();
 
-             }, function () {
 
-                 toastr.error('附件上传失败');
 
-             });
 
-             $('#change-att-btn').val('');
 
-         } else if (content === 'del') {
 
-             const data = {id: fid};
 
-             postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
 
-                 // 删除到attData中
 
-                 const att_index = attData.findIndex(function (item) {
 
-                     return item.id === parseInt(fid);
 
-                 });
 
-                 attData.splice(att_index, 1);
 
-                 // 重新生成List
 
-                 getAllList();
 
-                 getNodeList(node.id);
 
-                 $('#showAttachment').hide();
 
-                 $('#showAttachment').attr('file-id', '');
 
-             });
 
-         }
 
-     });
 
-     // 替换附件
 
-     $('#change-att-btn').on('change', function () {
 
-         const file = $('#change-att-btn')[0].files[0];
 
-         const name = file.name;
 
-         const filename = name.substring(0, name.lastIndexOf("."));
 
-         const fileext = name.substr(name.indexOf("."));
 
-         const filesize = file.size;
 
-         if (filesize > 10 * 1024 * 1024) {
 
-             toastr.error('文件大小过大!');
 
-             $('#change-att-btn').val('');
 
-             return false;
 
-         }
 
-         if (whiteList.indexOf(fileext) === -1) {
 
-             toastr.error('只能上传指定格式的附件!');
 
-             $('#change-att-btn').val('');
 
-             return false;
 
-         }
 
-         $('#edit-att .form-group').eq(0).find('input').val(filename);
 
-         $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
 
-     });
 
-     // 切换页数
 
-     $('.page-select').on('click', function () {
 
-         const totalPageNum = $('#totalPage').text();
 
-         const lastPageNum = $('#currentPage').text();
 
-         const status = $(this).attr('content');
 
-         if (status === 'pre' && lastPageNum > 1) {
 
-             getAllList(parseInt(lastPageNum)-1);
 
-             $('#showAttachment').hide();
 
-         } else if (status === 'next' && lastPageNum < totalPageNum) {
 
-             getAllList(parseInt(lastPageNum)+1);
 
-             $('#showAttachment').hide();
 
-         }
 
-     });
 
-     // 显示层次
 
-     (function (select, sheet) {
 
-         $(select).click(function () {
 
-             if (!sheet.zh_tree) return;
 
-             const tag = $(this).attr('tag');
 
-             const tree = sheet.zh_tree;
 
-             switch (tag) {
 
-                 case "1":
 
-                 case "2":
 
-                 case "3":
 
-                 case "4":
 
-                 case "5":
 
-                     tree.expandByLevel(parseInt(tag));
 
-                     SpreadJsObj.refreshTreeRowVisible(sheet);
 
-                     break;
 
-                 case "last":
 
-                     tree.expandByCustom(() => { return true; });
 
-                     SpreadJsObj.refreshTreeRowVisible(sheet);
 
-                     break;
 
-                 case "leafXmj":
 
-                     tree.expandToLeafXmj();
 
-                     SpreadJsObj.refreshTreeRowVisible(sheet);
 
-                     break;
 
-                 case "curMeasure":
 
-                     tree.expandByCustom(function (node) {
 
-                         for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
 
-                             if (node[field]) {
 
-                                 return true;
 
-                             }
 
-                         }
 
-                         return false;
 
-                     });
 
-                     SpreadJsObj.refreshTreeRowVisible(sheet);
 
-                     break;
 
-             }
 
-         });
 
-     })('a[name=showLevel]', slSpread.getActiveSheet());
 
- });
 
 
  |