stage.js 141 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982
  1. 'use strict';
  2. /**
  3. * 期计量 - 本期计量台账页面 js
  4. *
  5. * @author Mai
  6. * @date 2018/12/7
  7. * @version
  8. */
  9. const ckBillsSpread = window.location.pathname + '-billsSelect';
  10. function checkTzMeasureType () {
  11. return tender.measure_type === measureType.tz.value;
  12. }
  13. function transExpr(expr) {
  14. return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
  15. }
  16. /**
  17. * 从cookie中读取缓存的列显示设置,没有则取默认
  18. * @returns {*[]}
  19. */
  20. function customColDisplay () {
  21. const defaultSetting = [
  22. { title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true },
  23. { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
  24. { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl'], visible: true },
  25. { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
  26. { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
  27. { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl'], visible: true },
  28. { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp', 'end_gather_percent'], visible: true },
  29. { title: '本期批注', fields: ['postil'], visible: true },
  30. { title: '图册号', fields: ['drawing_code'], visible: true },
  31. { title: '备注', fields: ['memo'], visible: true },
  32. { title: '总额计量', fields: ['is_tp'], visible: true},
  33. ];
  34. if (checkTzMeasureType()) {
  35. defaultSetting.splice(0, 1);
  36. }
  37. const settingStr = Cookies.get(ckColSetting);
  38. return settingStr ? JSON.parse(settingStr) : defaultSetting;
  39. }
  40. /**
  41. * 根据列显示设置,调整setting中的列是否显示
  42. * @param setting
  43. * @param customDisplay
  44. */
  45. function customizeStageTreeSetting(setting, customDisplay) {
  46. for (const cd of customDisplay) {
  47. for (const c of setting.cols) {
  48. if (cd.fields.indexOf(c.field) !== -1) {
  49. c.visible = cd.visible;
  50. }
  51. }
  52. }
  53. }
  54. /**
  55. * 初始化 树结构 列事件
  56. * @param setting
  57. */
  58. function initTreeColSettingEvents(setting) {
  59. const Events = {
  60. readOnly: {
  61. measureData: function (node) {
  62. return node.children && node.children.length > 0;
  63. },
  64. },
  65. };
  66. const getEvent = function (eventName) {
  67. const names = eventName.split('.');
  68. let event = Events;
  69. for (let name of names) {
  70. if (event[name]) {
  71. event = event[name];
  72. } else {
  73. return null;
  74. }
  75. }
  76. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  77. return null;
  78. } else {
  79. return event;
  80. }
  81. };
  82. for (const col of setting.cols) {
  83. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  84. col.readOnly = getEvent(col.readOnly);
  85. }
  86. }
  87. }
  88. // 生成所有附件列表
  89. function getAllList(currPageNum = 1) {
  90. // 每页最多几个附件
  91. const pageCount = 11;
  92. // 附件总数
  93. const total = attData.length;
  94. // 总页数
  95. const pageNum = Math.ceil(total/pageCount);
  96. $('#totalPage').text(pageNum);
  97. $('#currentPage').text(currPageNum);
  98. // 当前页附件内容
  99. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  100. let html = '';
  101. for(const att of currPageAttData) {
  102. html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  103. }
  104. $('#alllist-table').html(html);
  105. }
  106. // 生成当前节点列表
  107. function getNodeList(node) {
  108. let html = '';
  109. for(const att of attData) {
  110. if (node === att.lid) {
  111. html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  112. }
  113. }
  114. $('#nodelist-table').html(html);
  115. }
  116. $(document).ready(() => {
  117. let detail, searchLedger, checkedChanges;
  118. // 界面布局
  119. autoFlashHeight();
  120. // 初始化 台账树结构 数据结构
  121. const stageTreeSetting = {
  122. id: 'ledger_id',
  123. pid: 'ledger_pid',
  124. order: 'order',
  125. level: 'level',
  126. rootId: -1,
  127. keys: ['id', 'tender_id', 'ledger_id'],
  128. stageId: 'id',
  129. };
  130. // 台账树结构计算相关设置
  131. stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil', 'used'];
  132. stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
  133. 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp'];
  134. stageTreeSetting.calcFun = function (node) {
  135. if (node.children && node.children.length === 0) {
  136. node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
  137. node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
  138. node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty);
  139. node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
  140. node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
  141. }
  142. node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
  143. node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
  144. node.end_contract_tp = ZhCalc.add(node.pre_contract_tp, node.contract_tp);
  145. node.end_qc_tp = ZhCalc.add(node.pre_qc_tp, node.qc_tp);
  146. node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
  147. node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
  148. node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
  149. 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);
  150. };
  151. const stageTree = createNewPathTree('stage', stageTreeSetting);
  152. // 初始化 计量单元 数据结构
  153. const stagePosSetting = {
  154. id: 'id', ledgerId: 'lid',
  155. updateFields: ['contract_qty', 'qc_qty', 'postil'],
  156. };
  157. stagePosSetting.calcFun = function (pos) {
  158. pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
  159. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  160. pos.end_contract_qty = ZhCalc.add(pos.pre_contract_qty, pos.contract_qty);
  161. pos.end_qc_qty = ZhCalc.add(pos.pre_qc_qty, pos.qc_qty);
  162. pos.end_gather_qty = ZhCalc.add(pos.pre_gather_qty, pos.gather_qty);
  163. pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
  164. pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2);
  165. };
  166. const stagePos = new StagePosData(stagePosSetting);
  167. class Changes {
  168. constructor(obj) {
  169. const self = this;
  170. this.obj = obj;
  171. // 初始化 清单编号窗口 参数
  172. this.spreadSetting = {
  173. cols: [
  174. {title: '已用', field: '', width: 45, formatter: '@', cellType: 'image', readOnly: true, hAlign: 1, indent: 14, img: function (data) {
  175. if (data.uamount && !checkZero(data.uamount)) {
  176. return $('#icon-ok')[0];
  177. } else {
  178. return null;
  179. }
  180. }},
  181. {title: '变更令号', field: 'p_code', width: 100, formatter: '@', readOnly: true, hAlign: 0, },
  182. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true, hAlign: 0,},
  183. {title: '变更部位', field: 'b_bwmx', width: 100, formatter: '@', readOnly: true, hAlign: 0,},
  184. //{title: '总数量', field: 'b_amount', width: 60, formatter: '@', readOnly: true, hAlign: 2, },
  185. {title: '可变更数量', field: 'vamount', width: 60, readOnly: true, hAlign: 2, getValue: function (data) {return data.vamount ? data.vamount + '' : '0';}},
  186. {title: '本期计量', field: 'uamount', width: 60, formatter: '@', hAlign: 2, type: 'Number', },
  187. ],
  188. emptyRows: 0,
  189. headRows: 1,
  190. headRowHeight: [32],
  191. headerFont: '12px 微软雅黑',
  192. font: '12px 微软雅黑',
  193. getColor: function (sheet, data, row, col, defaultColor) {
  194. if (col.field === 'uamount') {
  195. if (!data.vamount) {
  196. return (data.uamount && math.abs(data.uamount) > 0) ? '#ff6f5c' : defaultColor;
  197. } else if (data.uamount) {
  198. return data.vamount > 0
  199. ? data.uamount > data.vamount ? '#ff6f5c' : defaultColor
  200. : data.uamount < data.vamount ? '#ff6f5c' : defaultColor;
  201. } else {
  202. return defaultColor;
  203. }
  204. } else {
  205. return defaultColor;
  206. }
  207. }
  208. };
  209. this.curChangeId = '';
  210. this.spread = SpreadJsObj.createNewSpread($('#change-spread')[0]);
  211. this.firstView = true;
  212. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  213. // 初次显示,需刷新spread界面,保证界面绘制正确
  214. this.obj.bind('shown.bs.modal', function () {
  215. if (self.firstView) {
  216. self.firstView = false;
  217. self.spread.refresh();
  218. }
  219. });
  220. // 切换变更令,加载右侧明细数据
  221. this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  222. const change = SpreadJsObj.getSelectObject(info.sheet);
  223. self._loadChangeDetail(change);
  224. });
  225. // 填写本期计量
  226. this.spread.bind(spreadNS.Events.EditEnded, function (e, info) {
  227. if (info.sheet.zh_setting) {
  228. const col = info.sheet.zh_setting.cols[info.col];
  229. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  230. const node = sortData[info.row];
  231. node[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  232. // 刷新界面
  233. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  234. }
  235. });
  236. this.spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  237. if (info.sheet.zh_setting) {
  238. const sortData = SpreadJsObj.getSortData(info.sheet);
  239. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  240. const curRow = iRow + info.cellRange.row;
  241. const curCol = info.cellRange.col;
  242. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  243. sortData[curRow][col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
  244. }
  245. SpreadJsObj.reLoadRowData(sheet, info.cellRange.row, sel.cellRange.rowCount);
  246. }
  247. });
  248. SpreadJsObj.addDeleteBind(this.spread, function (sheet) {
  249. if (sheet.zh_setting) {
  250. const sel = sheet.getSelections()[0];
  251. const sortData = SpreadJsObj.getSortData(sheet);
  252. // 仅本期计量可删除
  253. if (sel.col === 5 && sel.colCount === 1) {
  254. const col = sheet.zh_setting.cols[sel.col];
  255. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  256. const data = sortData[iRow];
  257. data[col.field] = null;
  258. }
  259. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  260. }
  261. }
  262. });
  263. // 过滤可变更数量为0
  264. $('#filterEmpty').click(function () {
  265. self._filterChange(!this.checked, $('#matchPos')[0].checked);
  266. });
  267. // 匹配编号
  268. $('#matchPos').click(function () {
  269. self._filterChange(!$('#filterEmpty')[0].checked, this.checked);
  270. });
  271. // 展开收起 变更令详细信息
  272. $('#show-bgl-detail').bind('click', function () {
  273. const detail = $('#bgl-detail'), bgl=$('#bgl'), obj=$(this);
  274. if (detail.hasClass('col-4')) {
  275. detail.attr('class', 'col').hide();
  276. bgl.attr('class', 'col-12');
  277. $('a', obj).attr('title', '展开侧栏');
  278. $('i', obj).attr('class', 'fa fa-chevron-left');
  279. self.spread.refresh();
  280. } else {
  281. detail.attr('class', 'col-4').show();
  282. bgl.attr('class', 'col-8');
  283. $('a', obj).attr('title', '收起侧栏');
  284. $('i', obj).attr('class', 'fa fa-chevron-right');
  285. self.spread.refresh();
  286. }
  287. });
  288. // 添加调用变更令
  289. $('#usg-bg-ok').click(function () {
  290. const data = { target: self.callData, change: [] };
  291. for (const c of self.displayChanges) {
  292. if (c.uamount) {
  293. const vamount = (!c.vamount || checkZero(c.vamount)) ? 0 : c.vamount;
  294. if (vamount > 0 && c.uamount < 0) {
  295. toastr.error('变更令:' + c.code + ' 下,请勿进行负变更');
  296. return;
  297. } else if (vamount < 0 && c.uamount > 0) {
  298. toastr.error('变更令:' + c.code + ' 下,请勿进行正变更');
  299. return;
  300. }
  301. if ((vamount > 0 && c.uamount > vamount) || (vamount < 0 && c.uamount < vamount)) {
  302. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  303. return;
  304. }
  305. data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount });
  306. }
  307. }
  308. // 提交数据到后端
  309. postData(window.location.pathname + '/use-change', data, function(result) {
  310. if (result.pos) {
  311. stagePos.loadCurStageData(result.pos.curStageData);
  312. }
  313. const nodes = stageTree.loadPostStageData(result.bills);
  314. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  315. stagePosSpreadObj.loadCurPosData();
  316. if (detail) {
  317. detail.loadStageChangeUpdateData(result);
  318. } else {
  319. stageIm.loadUpdateChangeData(result)
  320. }
  321. self.obj.modal('hide');
  322. });
  323. })
  324. }
  325. _calculateAmount() {
  326. for (const c of this.changes) {
  327. c.bamount = _.toNumber(c.b_amount);
  328. c.vamount = ZhCalc.sub(c.bamount, c.used_amount);
  329. const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid});
  330. if (uc) {
  331. c.org_uamount = uc.qty;
  332. c.uamount = uc.qty;
  333. c.vamount = ZhCalc.add(c.vamount, c.uamount);
  334. }
  335. }
  336. }
  337. _loadChangeDetail(change) {
  338. if (change) {
  339. if (change.cid === this.curChangeId) { return; }
  340. this.curChangeId = change.cid;
  341. const inputs = $('input[type!=checkbox][type!=radio]', this.obj);
  342. for (const i of inputs) {
  343. const field = $(i).attr('name');
  344. const text = (field && change[field]) ? change[field] : '';
  345. $(i).val(text);
  346. }
  347. const textareas = $('textarea', this.obj);
  348. for (const ta of textareas) {
  349. const field = $(ta).attr('name');
  350. const text = (field && change[field]) ? change[field] : '';
  351. ta.textContent = text;
  352. }
  353. const html = [];
  354. for (const a of change.attachments) {
  355. html.push('<tr>');
  356. html.push('<td>', '<a href="/change/download/file/' + a.id + '">', a.filename + a.fileext, '</a>', '</td>');
  357. html.push('<td>', a.u_name, '</td>');
  358. html.push('</tr>');
  359. }
  360. // 变更类型
  361. if (change.type) {
  362. const cType = change.type.split(',');
  363. $('input[name="type"]').prop("checked", false);
  364. for (const c of cType) {
  365. $('input[name="type"][value='+ c +']').prop("checked", true);
  366. }
  367. }
  368. // 变更类别
  369. $('select[name=class]').val(change.class);
  370. // 变更性质
  371. $('select[name=quality]').val(change.quality);
  372. // 变更单位
  373. $('select[name=company]').html('<option>' + (change.company ? change.company : '') + '</option>');
  374. // 费用承担方
  375. $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
  376. // 附件
  377. $('#attachment').html(html.join(''));
  378. } else {
  379. const inputs = $('input', this.obj);
  380. for (const i of inputs) {
  381. $(i).val('');
  382. }
  383. const textareas = $('textarea', this.obj);
  384. for (const ta of textareas) {
  385. ta.innerText = '';
  386. }
  387. $('#attachment').html('');
  388. }
  389. }
  390. _viewChanges() {
  391. const sheet = this.spread.getActiveSheet();
  392. if (this.changes) {
  393. sheet.setSelection(0, 0, 1, 1);
  394. this._filterChange(!$('#filterEmpty')[0].checked, $('#matchPos')[0].checked);
  395. this._loadChangeDetail(this.changes[0]);
  396. } else {
  397. toastr.error('查询变更令有误,请刷新页面后重试');
  398. }
  399. }
  400. _filterChange(filterEmpty, matchPosName) {
  401. this.displayChanges = [];
  402. for (const c of this.changes) {
  403. const filterVisible = filterEmpty ? (c.vamount ? !checkZero(c.vamount) : false) : true;
  404. const matchVisible = matchPosName && this.callData.pos ? c.b_bwmx === this.callData.pos.name : true;
  405. if ((filterVisible && matchVisible) || (c.org_uamount)) {
  406. this.displayChanges.push(c);
  407. }
  408. }
  409. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), SpreadJsObj.DataType.Data, this.displayChanges);
  410. }
  411. loadChanges(data) {
  412. this.callData = data;
  413. if (this.callData.pos) {
  414. $('#matchPos').parent().show();
  415. } else {
  416. $('#matchPos').parent().hide();
  417. }
  418. const self = this;
  419. $('#b-code-hint').text('当前变更清单:' + data.bills.b_code);
  420. postData(window.location.pathname + '/valid-change', data, function (result) {
  421. self.changes = result.changes;
  422. self.useChanges = result.useChanges;
  423. self._calculateAmount();
  424. self._viewChanges();
  425. self.obj.modal('show');
  426. });
  427. }
  428. }
  429. const changesObj = new Changes($('#use-bg'));
  430. // 初始化 台账 spread
  431. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  432. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  433. // 数量变更列,添加按钮
  434. const col = _.find(ledgerSpreadSetting.cols, {field: 'qc_qty'});
  435. col.readOnly = true;
  436. col.cellType = 'activeImageBtn';
  437. col.normalImg = '#ellipsis-icon';
  438. col.indent = 5;
  439. col.showImage = function (data) {
  440. if (!data || (data.children && data.children.length > 0) || !(data.b_code && data.b_code !== '')) {
  441. return false;
  442. } else {
  443. const nodePos = stagePos.getLedgerPos(data.id);
  444. return !(nodePos && nodePos.length > 0);
  445. }
  446. };
  447. ledgerSpreadSetting.imageClick = function (data) {
  448. if (data.children && data.children.length > 0) return;
  449. const nodePos = stagePos.getLedgerPos(data.id);
  450. if (nodePos && nodePos.length > 0) return;
  451. changesObj.loadChanges({bills: data});
  452. };
  453. ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
  454. ledgerSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  455. if (data) {
  456. const posRange = stagePos.ledgerPos[itemsPre + data.id] || [];
  457. if (posRange.length > 0) {
  458. for (const p of posRange) {
  459. if (p.end_contract_qty > p.quantity) return '#f8d7da';
  460. }
  461. }
  462. if (data.is_tp) {
  463. return data.end_contract_tp > data.total_price ? '#f8d7da' : defaultColor;
  464. } else {
  465. return data.end_contract_qty > data.quantity ? '#f8d7da' : defaultColor;
  466. }
  467. } else {
  468. return defaultColor;
  469. }
  470. };
  471. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  472. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  473. slSpread.getActiveSheet().frozenColumnCount(5);
  474. slSpread.getActiveSheet().options.frozenlineColor = '#93b5e4';
  475. //初始化所有附件列表
  476. getAllList();
  477. // 初始化 计量单元 Spread
  478. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  479. const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
  480. spCol.readOnly = true;
  481. spCol.cellType = 'activeImageBtn';
  482. spCol.normalImg = '#ellipsis-icon';
  483. spCol.indent = 5;
  484. spCol.showImage = function (data) {
  485. return data !== undefined && data !== null;
  486. };
  487. posSpreadSetting.imageClick = function (data) {
  488. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  489. changesObj.loadChanges({bills: node, pos: data});
  490. };
  491. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  492. return data && data.end_contract_qty > data.quantity ? '#f8d7da' : defaultColor;
  493. };
  494. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  495. const errorList = $.cs_errorList({
  496. tabSelector: '#error-list-tab',
  497. selector: '#error-list',
  498. relaSpread: slSpread,
  499. storeKey: 'stage-error-' + stage.id,
  500. afterLocated: function () {
  501. stagePosSpreadObj.loadCurPosData();
  502. },
  503. afterShow: function () {
  504. slSpread.refresh();
  505. if (spSpread) spSpread.refresh();
  506. },
  507. });
  508. const stageTreeSpreadObj = {
  509. loadExprToInput(sheet) {
  510. const sel = sheet.getSelections()[0];
  511. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  512. if (col.type === 'Number') {
  513. const data = SpreadJsObj.getSelectObject(sheet);
  514. if (!data) {
  515. $('#bills-expr').val('').attr('readOnly', true);
  516. return;
  517. }
  518. const nodePos = stagePos.getLedgerPos(data.id);
  519. if (nodePos && nodePos.length > 0) {
  520. $('#bills-expr').val('').attr('readOnly', true);
  521. } else {
  522. $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
  523. if (col.field.indexOf('tp') >= 0) {
  524. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp !== 1);
  525. } else {
  526. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp === 1)
  527. }
  528. }
  529. } else {
  530. $('#bills-expr').val('').attr('readOnly', true);
  531. }
  532. },
  533. refreshTreeNodes: function (sheet, nodes) {
  534. const tree = sheet.zh_tree;
  535. if (!tree) { return }
  536. const rows = [];
  537. for (const node of nodes) {
  538. rows.push(tree.nodes.indexOf(node));
  539. }
  540. SpreadJsObj.reLoadRowsData(sheet, rows);
  541. },
  542. editEnded: function (e, info) {
  543. if (info.sheet.zh_setting) {
  544. const col = info.sheet.zh_setting.cols[info.col];
  545. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  546. const node = sortData[info.row], updateData = {};
  547. const orgValue = node[col.field];
  548. let newValue = trimInvalidChar(info.editingText);
  549. if (orgValue == newValue || ((!orgValue || orgValue === '') && (!newValue || newValue === ''))) {
  550. return;
  551. }
  552. if (col.type === 'Number' && newValue && newValue !== '') {
  553. const num = _.toNumber(newValue);
  554. if (_.isFinite(num)) {
  555. newValue = num;
  556. } else {
  557. try {
  558. newValue = math.evaluate(transExpr(newValue));
  559. } catch(err) {
  560. toastr.error('输入的表达式非法');
  561. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  562. return;
  563. }
  564. }
  565. }
  566. if (col.field.indexOf('_dgn_') > 0) {
  567. if (node.b_code && node.b_code !== '') {
  568. toastr.error('仅项目节可输入项目节数量');
  569. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  570. return;
  571. }
  572. } else if (col.field !== 'postil' && col.field !== 'memo') {
  573. if (node.children && node.children.length > 0) {
  574. toastr.error('清单父项不可计量');
  575. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  576. return;
  577. } else {
  578. const nodePos = stagePos.getLedgerPos(node.id);
  579. if (nodePos && nodePos.length > 0) {
  580. toastr.error('该清单有计量单元,请在计量单元处计量');
  581. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  582. return;
  583. }
  584. }
  585. }
  586. if (col.field === 'memo') {
  587. updateData.main = {
  588. id: node.id
  589. };
  590. updateData.main[col.field] = newValue;
  591. } else if (col.field.indexOf('_dgn_') > 0) {
  592. updateData.dgn = {
  593. id: node.id
  594. };
  595. updateData.dgn[col.field] = newValue;
  596. } else if (col.field !== 'is_tp') {
  597. updateData.stage = {
  598. lid: node.id
  599. };
  600. updateData.stage[col.field] = newValue;
  601. }
  602. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  603. // tag update
  604. const nodes = stageTree.loadPostStageData(data);
  605. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  606. if (detail) {
  607. detail.loadStageLedgerUpdateData(data);
  608. } else {
  609. stageIm.loadUpdateLedgerData(data);
  610. }
  611. }, function () {
  612. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  613. });
  614. }
  615. },
  616. selectionChanged: function (e, info) {
  617. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  618. stagePosSpreadObj.loadCurPosData();
  619. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  620. if (posSearch) {
  621. posSearch.search();
  622. }
  623. }
  624. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  625. stageTreeSpreadObj.loadExprToInput(info.sheet);
  626. },
  627. deletePress(sheet) {
  628. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  629. const tree = sheet.zh_tree;
  630. if (!tree) { return; }
  631. const sel = sheet.getSelections()[0];
  632. const validCols = [];
  633. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  634. const colSetting = sheet.zh_setting.cols[iCol];
  635. if (!colSetting.readOnly && colSetting.field !== 'qc_qty') {
  636. validCols.push(iCol);
  637. }
  638. }
  639. if (validCols.length === 0) { return; }
  640. const sortData = sheet.zh_tree.nodes;
  641. const datas = [], dgnDatas = [], mainDatas = [];
  642. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  643. const node = sortData[iRow];
  644. if (node) {
  645. const data = { lid: node.id }, dgnData = { id: node.id }, mainData = { id: node.id };
  646. let filter = true, filterDgn = true, filterMain = true;
  647. for (const iCol of validCols) {
  648. const colSetting = sheet.zh_setting.cols[iCol];
  649. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  650. if (node.b_code && node.b_code !== '') continue;
  651. } else if (colSetting.field !== 'postil') {
  652. if (node.children && node.children.length > 0) { continue; }
  653. const nodePos = stagePos.getLedgerPos(node.id);
  654. if (nodePos && nodePos.length > 0) { continue; }
  655. }
  656. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  657. if (node[colSetting.field] && node[colSetting.field] !== 0) {
  658. dgnData[colSetting.field] = 0;
  659. filterDgn = false;
  660. }
  661. } else if (colSetting.field === 'memo') {
  662. mainData[colSetting.field] = null;
  663. filterMain = false;
  664. } else {
  665. data[colSetting.field] = null;
  666. filter = false;
  667. }
  668. }
  669. if (!filter) datas.push(data);
  670. if (!filterDgn) dgnDatas.push(dgnData);
  671. if (!filterMain) mainDatas.push(mainData);
  672. }
  673. }
  674. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  675. const bills = {};
  676. if (datas.length > 0) bills.stage = datas;
  677. if (dgnDatas.length > 0) bills.dgn = dgnDatas;
  678. if (mainDatas.length > 0) bills.main = mainDatas;
  679. postData(window.location.href + '/update', {bills: bills}, function (result) {
  680. const nodes = stageTree.loadPostStageData(result);
  681. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  682. if (detail) {
  683. detail.loadStageLedgerUpdateData(result);
  684. } else {
  685. stageIm.loadUpdateLedgerData(result);
  686. }
  687. });
  688. }
  689. }
  690. },
  691. clipboardPasting(e, info) {
  692. if (info.sheet.zh_setting) {
  693. const setting = info.sheet.zh_setting;
  694. const range = info.cellRange;
  695. const stageField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'];
  696. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  697. const col = info.sheet.zh_setting.cols[iCol];
  698. if ((stageField.indexOf(col.field) === -1) && setting.dgnUpFields.indexOf(col.field) === -1
  699. && col.field !== 'memo') {
  700. toastr.error('不可修改此数据');
  701. info.cancel = true;
  702. return;
  703. }
  704. }
  705. }
  706. },
  707. clipboardPasted(e, info) {
  708. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  709. const sheet = info.sheet, setting = info.sheet.zh_setting;
  710. const filterNodes = [], datas = [], dgnDatas = [], mainDatas = [];
  711. let bHint = false;
  712. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  713. const curRow = iRow + info.cellRange.row;
  714. const node = sheet.zh_tree.getItemsByIndex(curRow);
  715. const data = {lid: node.id}, dgnData = {id: node.id}, mainData = {id: node.id};
  716. let filter = true, filterDgn = true, filterMain = true;
  717. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  718. const curCol = info.cellRange.col + iCol;
  719. const col = info.sheet.zh_setting.cols[curCol];
  720. if (col.field === 'contract_tp') {
  721. if (!node.is_tp) continue;
  722. } else if (col.field === 'contract_qty') {
  723. if (node.is_tp) continue;
  724. }
  725. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  726. if (node.b_code && node.b_code !== '') continue;
  727. } else if (col.field !== 'postil') {
  728. if (node.children && node.children.length > 0) continue;
  729. const nodePos = stagePos.getLedgerPos(node.id);
  730. if (nodePos && nodePos.length > 0) continue;
  731. }
  732. const text = trimInvalidChar(sheet.getText(curRow, curCol));
  733. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  734. const num = _.toNumber(text);
  735. if (num) {
  736. dgnData[col.field] = num;
  737. filterDgn = false;
  738. } else {
  739. try {
  740. dgnData[col.field] = math.evaluate(transExpr(text));
  741. filterDgn = false;
  742. } catch(err) {
  743. if (!bHint) {
  744. toastr.warning('粘贴了非法表达式,已过滤');
  745. bHint = true;
  746. }
  747. }
  748. }
  749. } else if (col.field === 'memo') {
  750. mainData.memo = text;
  751. filterMain = false;
  752. } else {
  753. if (col.type === 'Number') {
  754. const num = _.toNumber(text);
  755. if (_.isFinite(num)) {
  756. data[col.field] = num;
  757. filter = false;
  758. } else {
  759. try {
  760. data[col.field] = math.evaluate(transExpr(text));
  761. filter = false;
  762. } catch(err) {
  763. if (!bHint) {
  764. toastr.warning('粘贴了非法表达式,已过滤');
  765. bHint = true;
  766. }
  767. }
  768. }
  769. } else {
  770. data[col.field] = text;
  771. }
  772. }
  773. }
  774. if (filter && filterDgn && filterMain) {
  775. filterNodes.push(node);
  776. } else {
  777. if (!filter) datas.push(data);
  778. if (!filterDgn) dgnDatas.push(dgnData);
  779. if (!filterMain) mainDatas.push(mainData);
  780. }
  781. }
  782. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  783. const updateData = {};
  784. if (datas.length > 0) updateData.stage = datas;
  785. if (dgnDatas.length > 0) updateData.dgn = dgnDatas;
  786. if (mainDatas.length > 0) updateData.main = mainDatas;
  787. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  788. const nodes = stageTree.loadPostStageData(data);
  789. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  790. if (detail) {
  791. detail.loadStageLedgerUpdateData(data);
  792. } else {
  793. stageIm.loadUpdateLedgerData(data);
  794. }
  795. }, function () {
  796. // todo
  797. //stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  798. });
  799. } else {
  800. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  801. }
  802. }
  803. },
  804. measureAllPosInNode(node, ratio = 1) {
  805. const posterity = stageTree.getPosterity(node)
  806. const data = {updateType: 'update', updateData: []};
  807. for (const p of posterity) {
  808. if (p.children && p.children.length > 0) continue;
  809. const posRange = stagePos.getLedgerPos(p.id);
  810. if (posRange && posRange.length > 0) {
  811. for (const pr of posRange) {
  812. if (pr.contract_qty && !checkZero(pr.contract_qty)) continue;
  813. const validValue = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
  814. if (validValue <= 0) continue;
  815. const value = ratio !== 1 ? ZhCalc.mul(pr.quantity, ratio) : pr.quantity;
  816. const pData = {
  817. pid: pr.id,
  818. lid: pr.lid,
  819. contract_qty: validValue > 0 ? (value > validValue ? validValue : value) : (value < validValue ? validValue : value),
  820. };
  821. data.updateData.push(pData);
  822. }
  823. }
  824. if (data.updateData.length > 1000 || _.map(data.updateData, 'lid').length > 500) {
  825. toastr.warning('选中的数据过多,仅计量' + data.updateData.length + '条,请稍后');
  826. break;
  827. }
  828. }
  829. if (data.updateData.length === 0) {
  830. toastr.info('其下全部计量单元均已计量');
  831. return;
  832. }
  833. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  834. if (result.pos) {
  835. stagePos.updateDatas(result.pos.pos);
  836. stagePos.loadCurStageData(result.pos.curStageData);
  837. }
  838. const nodes = stageTree.loadPostStageData(result.ledger);
  839. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  840. stagePosSpreadObj.loadCurPosData();
  841. if (detail) {
  842. detail.loadStagePosUpdateData(result);
  843. } else {
  844. stageIm.loadUpdatePosData(result);
  845. }
  846. toastr.success('已计量' + data.updateData.length + '条');
  847. }, function () {
  848. stagePosSpreadObj.loadCurPosData();
  849. });
  850. },
  851. topRowChanged(e, info) {
  852. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  853. },
  854. editStarting(e, info) {
  855. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  856. const col = info.sheet.zh_setting.cols[info.col];
  857. const node = info.sheet.zh_tree.nodes[info.row];
  858. switch (col.field) {
  859. case 'contract_qty':
  860. case 'qc_qty':
  861. info.cancel = node.is_tp;
  862. break;
  863. case 'contract_tp':
  864. info.cancel = !node.is_tp;
  865. break;
  866. case 'is_tp':
  867. info.cancel = true;
  868. break;
  869. }
  870. },
  871. buttonClicked: function (e, info) {
  872. if (info.sheet.zh_setting) {
  873. const node = SpreadJsObj.getSelectObject(info.sheet);
  874. const col = info.sheet.zh_setting.cols[info.col];
  875. const posRange = stagePos.getLedgerPos(node.id);
  876. if (node.pre_used === 1 || node.unit !== '总额' || (posRange && posRange.length > 0) /*|| !checkZero(node.qc_qty)*/) {
  877. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  878. return;
  879. }
  880. const postIsTp = function () {
  881. const data = { calcType: {id: node.id} };
  882. data.calcType.is_tp = info.sheet.getValue(info.row, info.col) || false;
  883. // 更新至服务器
  884. postData(window.location.pathname + '/update', {bills: data}, function (result) {
  885. const nodes = stageTree.loadPostStageData(result);
  886. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  887. if (detail) {
  888. detail.loadStageLedgerUpdateData(result);
  889. } else {
  890. stageIm.loadUpdateLedgerData(result);
  891. }
  892. });
  893. };
  894. if (col.field === 'is_tp') {
  895. if (info.sheet.isEditing()) {
  896. info.sheet.endEdit(true);
  897. }
  898. if (!checkZero(node.contract_qty) || !checkZero(node.contract_tp)) {
  899. $.msgBox({
  900. id: 'calc-type',
  901. title: '提示',
  902. message: '切换计量模式,已计量数据会被清空。',
  903. ok: {
  904. caption: '确定',
  905. callback: postIsTp,
  906. },
  907. cancel: {
  908. caption: '取消',
  909. callback: function () {
  910. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  911. }
  912. }
  913. });
  914. } else {
  915. postIsTp();
  916. }
  917. }
  918. }
  919. },
  920. };
  921. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  922. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  923. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  924. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  925. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  926. slSpread.bind(spreadNS.Events.EditStarting, stageTreeSpreadObj.editStarting);
  927. slSpread.bind(spreadNS.Events.ButtonClicked, stageTreeSpreadObj.buttonClicked);
  928. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  929. if (!readOnly) {
  930. $('#bills-expr').bind('change mouseleave', function () {
  931. if (this.readOnly) return;
  932. const expr = $(this);
  933. const sheet = slSpread.getActiveSheet();
  934. const select = SpreadJsObj.getSelectObject(sheet);
  935. const field = expr.attr('field'), orgValue = expr.attr('org'), updateData = {};
  936. let newValue = expr.val();
  937. const num = _.toNumber(newValue);
  938. if (num) {
  939. newValue = num;
  940. } else {
  941. try {
  942. newValue = math.evaluate(transExpr(newValue));
  943. } catch(err) {
  944. toastr.error('输入的表达式非法');
  945. return;
  946. }
  947. }
  948. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  949. if (field.indexOf('_dgn_') > 0) {
  950. updateData.dgn = {
  951. id: select.id
  952. };
  953. updateData.dgn[field] = newValue;
  954. } else {
  955. updateData.stage = {
  956. lid: select.id
  957. };
  958. updateData.stage[field] = newValue;
  959. }
  960. // 更新至服务器
  961. postData(window.location.pathname + '/update', {bills: updateData}, function (result) {
  962. const nodes = stageTree.loadPostStageData(result);
  963. expr.val(select[field]);
  964. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  965. });
  966. });
  967. }
  968. stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
  969. const stagePosSpreadObj = {
  970. loadExprToInput(sheet) {
  971. const sel = sheet.getSelections()[0];
  972. if (!sel) return;
  973. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  974. if (col && col.type === 'Number') {
  975. const data = SpreadJsObj.getSelectObject(sheet);
  976. if (data) {
  977. $('#pos-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field])
  978. .attr('row', sel.row).attr('readOnly', readOnly || cell.locked());
  979. } else {
  980. $('#pos-expr').val('').attr('readOnly', true);
  981. }
  982. } else {
  983. $('#pos-expr').val('').attr('readOnly', true);
  984. }
  985. },
  986. /**
  987. * 加载计量单元 根据当前台账选择节点
  988. */
  989. loadCurPosData: function () {
  990. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  991. if (node) {
  992. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  993. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  994. getNodeList(node.id);
  995. // 如果是附件是当前节点,隐藏
  996. if ($('#dqjiedian').hasClass('active')) {
  997. $('#showAttachment').hide();
  998. }
  999. } else {
  1000. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  1001. }
  1002. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  1003. },
  1004. editEnded: function (e, info) {
  1005. if (info.sheet.zh_setting) {
  1006. // 未改变过,则直接跳过
  1007. const sortData = info.sheet.zh_data;
  1008. const posData = sortData ? sortData[info.row] : null;
  1009. const col = info.sheet.zh_setting.cols[info.col];
  1010. const orgText = posData ? posData[col.field] : null;
  1011. const newText = trimInvalidChar(info.editingText);
  1012. if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
  1013. return;
  1014. }
  1015. // 台账模式下,不可新增
  1016. if (checkTzMeasureType() && !posData) {
  1017. toastr.error('台账模式不可新增计量单元数据');
  1018. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1019. return ;
  1020. }
  1021. // 不同节点下,计量单元检查输入
  1022. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1023. const node = stagePosSpreadObj.stageTreeNode;
  1024. if (!node) {
  1025. toastr.warning('数据错误, 请刷新页面后再试');
  1026. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1027. return;
  1028. } else if (newText !== '' && node.children && node.children > 0) {
  1029. toastr.error('父节点不可插入计量单元');
  1030. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1031. return;
  1032. } else if (newText !== '' && !node.b_code || node.b_code === '') {
  1033. toastr.error('项目节不可插入计量单元');
  1034. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1035. return;
  1036. }
  1037. // 生成提交数据
  1038. const data = {};
  1039. if (col.field === 'name') {
  1040. if ((!newText || newText === '') && posData) {
  1041. toastr.error('部位名称不可为空');
  1042. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1043. return;
  1044. } else if (!posData) {
  1045. if (newText !== '') {
  1046. data.updateType = 'add';
  1047. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1048. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1049. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1050. return;
  1051. }
  1052. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1053. data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
  1054. } else {
  1055. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1056. return;
  1057. }
  1058. } else {
  1059. data.updateType = 'update';
  1060. data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
  1061. }
  1062. } else if (!posData) {
  1063. toastr.warning('新增计量单元请先输入名称');
  1064. } else {
  1065. data.updateType = 'update';
  1066. data.updateData = {pid: posData.id, lid: posData.lid};
  1067. if (col.type === 'Number') {
  1068. const num = _.toNumber(newText);
  1069. if (_.isFinite(num)) {
  1070. data.updateData[col.field] = num;
  1071. } else {
  1072. try {
  1073. data.updateData[col.field] = math.evaluate(transExpr(newText));
  1074. } catch(err) {
  1075. toastr.error('输入的表达式非法');
  1076. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1077. return;
  1078. }
  1079. }
  1080. } else {
  1081. data.updateData[col.field] = newText;
  1082. }
  1083. }
  1084. // 提交数据到服务器
  1085. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1086. if (result.pos) {
  1087. stagePos.updateDatas(result.pos.pos);
  1088. stagePos.loadCurStageData(result.pos.curStageData);
  1089. }
  1090. const refreshData = stageTree.loadPostStageData(result.ledger);
  1091. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1092. stagePosSpreadObj.loadCurPosData();
  1093. if (detail) {
  1094. detail.loadStagePosUpdateData(result);
  1095. } else {
  1096. stageIm.loadUpdatePosData(result);
  1097. }
  1098. }, function () {
  1099. stagePosSpreadObj.loadCurPosData();
  1100. });
  1101. }
  1102. },
  1103. editStarting: function (e, info) {
  1104. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1105. },
  1106. clipboardPasting: function (e, info) {
  1107. if (info.sheet.zh_setting) {
  1108. const sortData = info.sheet.zh_data;
  1109. const range = info.cellRange;
  1110. const validField = ['contract_qty', 'qc_qty', 'postil'];
  1111. if (!checkTzMeasureType()) {
  1112. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
  1113. }
  1114. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1115. const col = info.sheet.zh_setting.cols[iCol];
  1116. if (validField.indexOf(col.field) === -1) {
  1117. if (checkTzMeasureType()) {
  1118. toastr.error('不可修改此数据');
  1119. info.cancel = true;
  1120. return;
  1121. } else {
  1122. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  1123. const pos = sortData(iRow);
  1124. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  1125. toastr.error('不可修改此数据');
  1126. info.cancel = true;
  1127. return;
  1128. }
  1129. }
  1130. }
  1131. }
  1132. }
  1133. }
  1134. },
  1135. clipboardPasted: function (e, info) {
  1136. if (info.sheet.zh_setting) {
  1137. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1138. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1139. }
  1140. const data = { updateType: '', updateData: [], };
  1141. const sortData = info.sheet.zh_data;
  1142. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1143. if (sortData && (info.cellRange.row >= sortData.length)) {
  1144. data.updateType = 'add';
  1145. if (info.cellRange.col !== 0) {
  1146. toastr.warning('新增计量单元请先输入名称');
  1147. stagePosSpreadObj.loadCurPosData();
  1148. return;
  1149. }
  1150. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1151. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1152. stagePosSpreadObj.loadCurPosData();
  1153. return;
  1154. }
  1155. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1156. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1157. const curRow = info.cellRange.row + iRow;
  1158. const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
  1159. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1160. const curCol = info.cellRange.col + iCol;
  1161. const colSetting = info.sheet.zh_setting.cols[curCol];
  1162. if (!colSetting) continue;
  1163. newData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1164. if (colSetting.type === 'Number') {
  1165. const num = _.toNumber(newData[colSetting.field]);
  1166. if (num) {
  1167. newData[colSetting.field] = num;
  1168. } else {
  1169. try {
  1170. newData[colSetting.field] = math.evaluate(transExpr(newData[colSetting.field]));
  1171. } catch(err) {
  1172. toastr.error('输入的表达式非法');
  1173. stagePosSpreadObj.loadCurPosData();
  1174. return;
  1175. }
  1176. }
  1177. }
  1178. }
  1179. data.updateData.push(newData);
  1180. }
  1181. } else {
  1182. data.updateType = 'update';
  1183. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1184. const curRow = info.cellRange.row + iRow;
  1185. const curPos = sortData[curRow];
  1186. if (curPos) {
  1187. const newData = {pid: curPos.id, lid: curPos.lid};
  1188. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1189. const curCol = info.cellRange.col + iCol;
  1190. const colSetting = info.sheet.zh_setting.cols[curCol];
  1191. newData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1192. if (colSetting.type === 'Number') {
  1193. const num = _.toNumber(newData[colSetting.field]);
  1194. if (num) {
  1195. newData[colSetting.field] = num;
  1196. } else {
  1197. try {
  1198. newData[colSetting.field] = math.evaluate(transExpr(newData[colSetting.field]));
  1199. } catch(err) {
  1200. toastr.error('输入的表达式非法');
  1201. stagePosSpreadObj.loadCurPosData();
  1202. return;
  1203. }
  1204. }
  1205. }
  1206. }
  1207. data.updateData.push(newData);
  1208. }
  1209. }
  1210. }
  1211. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1212. if (result.pos) {
  1213. stagePos.updateDatas(result.pos.pos);
  1214. stagePos.loadCurStageData(result.pos.curStageData);
  1215. }
  1216. const nodes = stageTree.loadPostStageData(result.ledger);
  1217. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1218. stagePosSpreadObj.loadCurPosData();
  1219. if (detail) {
  1220. detail.loadStagePosUpdateData(result);
  1221. } else {
  1222. stageIm.loadUpdatePosData(result);
  1223. }
  1224. }, function () {
  1225. stagePosSpreadObj.loadCurPosData();
  1226. });
  1227. }
  1228. },
  1229. deletePress: function (sheet) {
  1230. if (sheet.zh_setting && sheet.zh_data) {
  1231. const sortData = sheet.zh_data;
  1232. if (!sortData || sortData.length === 0) { return; }
  1233. const sel = sheet.getSelections()[0];
  1234. const validCols = [];
  1235. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1236. const colSetting = sheet.zh_setting.cols[iCol];
  1237. if (!colSetting.readOnly && colSetting.field !== 'qc_qty') {
  1238. validCols.push(iCol);
  1239. }
  1240. }
  1241. if (validCols.length === 0) { return; }
  1242. const datas = [], posSelects = [];
  1243. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1244. const node = sortData[iRow];
  1245. if (node) {
  1246. const data = {pid: node.id, lid: node.lid};
  1247. for (const iCol of validCols) {
  1248. const colSetting = sheet.zh_setting.cols[iCol];
  1249. if (colSetting.field === 'name') {
  1250. toastr.error('部位名称不能为空');
  1251. return;
  1252. }
  1253. data[colSetting.field] = null;
  1254. }
  1255. datas.push(data);
  1256. posSelects.push(node);
  1257. }
  1258. }
  1259. if (datas.length > 0) {
  1260. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  1261. if (result.pos) {
  1262. stagePos.updateDatas(result.pos.pos);
  1263. stagePos.loadCurStageData(result.pos.curStageData);
  1264. }
  1265. const nodes = stageTree.loadPostStageData(result.ledger);
  1266. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1267. if (detail) {
  1268. detail.loadStagePosUpdateData(result);
  1269. } else {
  1270. stageIm.loadUpdatePosData(result);
  1271. }
  1272. // todo 只加载改变项
  1273. stagePosSpreadObj.loadCurPosData();
  1274. });
  1275. }
  1276. }
  1277. },
  1278. deletePos: function (sheet) {
  1279. const sels = sheet.getSelections();
  1280. const sel = sels ? sels[0] : null;
  1281. if (sheet.zh_data && sel) {
  1282. const data = {updateType: 'delete', updateData: []};
  1283. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  1284. const posData = sheet.zh_data[sel.row + iRow];
  1285. if (posData) {
  1286. data.updateData.push(posData.id);
  1287. }
  1288. }
  1289. if (data.updateData.length > 0) {
  1290. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1291. stagePos.removeDatas(result.pos.pos);
  1292. const refreshData = stageTree.loadPostStageData(result.ledger);
  1293. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1294. stagePosSpreadObj.loadCurPosData();
  1295. if (detail) {
  1296. detail.loadStagePosUpdateData(result);
  1297. } else {
  1298. stageIm.loadUpdatePosData(result);
  1299. }
  1300. });
  1301. }
  1302. }
  1303. },
  1304. selectionChanged: function (e, info) {
  1305. stagePosSpreadObj.loadExprToInput(info.sheet);
  1306. },
  1307. addPegs: function (pegs) {
  1308. if (!pegs || pegs.length <= 0) return;
  1309. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1310. if (!node) return;
  1311. const sheet = spSpread.getActiveSheet();
  1312. const sortData = sheet.zh_data || [];
  1313. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1314. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1315. postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
  1316. if (result.pos) {
  1317. stagePos.updateDatas(result.pos.pos);
  1318. }
  1319. stagePosSpreadObj.loadCurPosData();
  1320. });
  1321. }
  1322. };
  1323. // 加载上下窗口resizer
  1324. $.divResizer({
  1325. select: '#main-resize',
  1326. callback: function () {
  1327. slSpread.refresh();
  1328. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1329. $(".sp-wrap").height(bcontent-30);
  1330. spSpread.refresh();
  1331. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1332. }
  1333. });
  1334. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1335. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change' }, function (result) {
  1336. // 加载树结构
  1337. stageTree.loadDatas(result.ledgerData);
  1338. // stageTree.loadCurStageData(curStageData);
  1339. // stageTree.loadPreStageData(preStageData);
  1340. treeCalc.calculateAll(stageTree);
  1341. // 加载部位明细
  1342. stagePos.loadDatas(result.posData);
  1343. stagePos.calculateAll();
  1344. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  1345. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  1346. stagePosSpreadObj.loadCurPosData();
  1347. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  1348. // 加载中间计量
  1349. stageIm.init(stage, imType);
  1350. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData);
  1351. }, null, true);
  1352. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  1353. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  1354. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  1355. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  1356. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  1357. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  1358. if (!readOnly) {
  1359. $('#pos-expr').bind('change mouseleave', function () {
  1360. if (this.readOnly) return;
  1361. if (document.activeElement.id !== "pos-expr") return;
  1362. const expr = $(this);
  1363. const posSheet = spSpread.getActiveSheet();
  1364. const select = SpreadJsObj.getSelectObject(posSheet);
  1365. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val(), row = expr.attr('row');
  1366. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1367. const data = {pid: select.id, lid: select.lid};
  1368. const num = _.toNumber(newValue);
  1369. if (num) {
  1370. data[field] = num;
  1371. } else {
  1372. try {
  1373. data[field] = math.evaluate(transExpr(newValue));
  1374. } catch (err) {
  1375. toastr.error('输入的表达式非法');
  1376. return;
  1377. }
  1378. }
  1379. // 提交数据到服务器
  1380. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  1381. if (result.pos) {
  1382. stagePos.updateDatas(result.pos.pos);
  1383. stagePos.loadCurStageData(result.pos.curStageData);
  1384. expr.val(select[field]);
  1385. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  1386. }
  1387. const refreshData = stageTree.loadPostStageData(result.ledger);
  1388. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1389. });
  1390. });
  1391. }
  1392. if (!checkTzMeasureType()) {
  1393. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  1394. $.contextMenu({
  1395. selector: '#stage-pos',
  1396. build: function ($trigger, e) {
  1397. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  1398. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1399. },
  1400. items: {
  1401. 'del': {
  1402. name: '删除',
  1403. icon: 'fa-remove',
  1404. disabled: function (key, opt) {
  1405. const sheet = spSpread.getActiveSheet();
  1406. if (sheet.zh_data && !readOnly) {
  1407. const selection = sheet.getSelections();
  1408. if (selection && selection[0]) {
  1409. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1410. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  1411. const posData = sheet.zh_data[selection[0].row + iRow];
  1412. if (posData) {
  1413. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  1414. valid = true;
  1415. break;
  1416. }
  1417. } else {
  1418. valid = true;
  1419. break;
  1420. }
  1421. }
  1422. return valid;
  1423. } else {
  1424. return true;
  1425. }
  1426. } else {
  1427. return true;
  1428. }
  1429. },
  1430. callback: function (key, opt) {
  1431. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  1432. }
  1433. },
  1434. 'merge-peg': {
  1435. name: '合并起讫桩号',
  1436. disabled: function (key, opt) {
  1437. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1438. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  1439. },
  1440. callback: function (key, opt) {
  1441. mergePeg.show();
  1442. }
  1443. }
  1444. }
  1445. })
  1446. } else {
  1447. SpreadJsObj.forbiddenSpreadContextMenu('#stage-pos', spSpread);
  1448. }
  1449. $.subMenu({
  1450. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1451. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1452. key: 'menu.1.0.0',
  1453. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1454. callback: function (info) {
  1455. if (info.mini) {
  1456. $('.panel-title').addClass('fluid');
  1457. $('#sub-menu').removeClass('panel-sidebar');
  1458. } else {
  1459. $('.panel-title').removeClass('fluid');
  1460. $('#sub-menu').addClass('panel-sidebar');
  1461. }
  1462. autoFlashHeight();
  1463. slSpread.refresh();
  1464. spSpread.refresh();
  1465. if (searchLedger) {
  1466. searchLedger.spread.refresh();
  1467. }
  1468. if (detail) {
  1469. detail.spread.refresh();
  1470. }
  1471. if (checkedChanges) checkedChanges.refresh();
  1472. }
  1473. });
  1474. $('#row-view').on('show.bs.modal', function () {
  1475. const html = [], customDisplay = customColDisplay();
  1476. for (const cd of customDisplay) {
  1477. html.push('<tr>');
  1478. html.push('<td>', cd.title, '</td>');
  1479. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  1480. html.push('</tr>');
  1481. }
  1482. $('#row-view-list').html(html.join(''));
  1483. });
  1484. $('#row-view-ok').click(function () {
  1485. const customDisplay = customColDisplay();
  1486. const cvl = $('#row-view-list').children();
  1487. for (const cv of cvl) {
  1488. const title = $(cv).children()[0].innerHTML;
  1489. const check = $('input', cv)[0].checked;
  1490. const cd = customDisplay.find(function (c) {
  1491. return c.title === title;
  1492. });
  1493. cd.visible = check;
  1494. }
  1495. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  1496. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  1497. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  1498. $('#row-view').modal('hide');
  1499. });
  1500. const posSearch = (function () {
  1501. let resultArr = [];
  1502. const search = function () {
  1503. resultArr = [];
  1504. const keyword = $('#pos-search-keyword').val();
  1505. const checkOver = $('#pos-over-search')[0].checked;
  1506. const checkEmpty = $('#pos-empty-search')[0].checked;
  1507. const sortData = spSpread.getActiveSheet().zh_data;
  1508. if (checkOver || checkEmpty) {
  1509. if (sortData) {
  1510. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1511. const sd = sortData[i];
  1512. let match = false;
  1513. if (checkOver) {
  1514. if (sd.end_gather_qty) {
  1515. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  1516. }
  1517. }
  1518. if (checkEmpty) {
  1519. if (sd.quantity) {
  1520. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  1521. }
  1522. }
  1523. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  1524. if (match) {
  1525. resultArr.push({index: i, data: sd});
  1526. }
  1527. }
  1528. }
  1529. } else if (keyword && keyword !== '') {
  1530. if (sortData) {
  1531. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1532. const sd = sortData[i];
  1533. if (sd.name && sd.name.indexOf(keyword) > -1) {
  1534. resultArr.push({index: i, data: sd});
  1535. }
  1536. }
  1537. }
  1538. }
  1539. $('#pos-search-result').html('结果:' + resultArr.length);
  1540. };
  1541. const searchAndLocate = function () {
  1542. search();
  1543. if (resultArr.length > 0) {
  1544. const sheet = spSpread.getActiveSheet();
  1545. const sel = sheet.getSelections()[0];
  1546. const curRow = sel ? sel.row : 0;
  1547. const pos = resultArr[0];
  1548. if (pos.index !== curRow) {
  1549. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  1550. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  1551. }
  1552. }
  1553. };
  1554. const locateNext = function () {
  1555. if (resultArr.length > 0) {
  1556. const sheet = spSpread.getActiveSheet();
  1557. const sel = sheet.getSelections()[0];
  1558. const curRow = sel ? sel.row : 0;
  1559. let next = _.find(resultArr, function (d) {
  1560. return d.index > curRow;
  1561. });
  1562. if (!next) next = resultArr[0];
  1563. if (next.index !== curRow) {
  1564. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1565. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1566. }
  1567. }
  1568. };
  1569. const locatePre = function () {
  1570. if (resultArr.length > 0) {
  1571. const sheet = spSpread.getActiveSheet();
  1572. const sel = sheet.getSelections()[0];
  1573. const curRow = sel ? sel.row : 0;
  1574. let next = _.findLast(resultArr, function (d) {
  1575. return d.index < curRow;
  1576. });
  1577. if (!next) next = resultArr[resultArr.length - 1];
  1578. if (next.index !== curRow) {
  1579. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1580. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1581. }
  1582. }
  1583. };
  1584. return {search, searchAndLocate, locateNext, locatePre};
  1585. })();
  1586. $('#pos-search-keyword').bind('keydown', function(e){
  1587. if (e.keyCode == 13) posSearch.searchAndLocate();
  1588. });
  1589. $('#pos-empty-search').click(function () {
  1590. if (this.checked) {
  1591. $('[for=' + this.id +']').addClass('text-warning');
  1592. } else {
  1593. $('[for=' + this.id +']').removeClass('text-warning');
  1594. }
  1595. if (this.checked) {
  1596. if ($('#pos-over-search')[0].checked) {
  1597. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1598. } else {
  1599. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  1600. }
  1601. } else {
  1602. if ($('#pos-over-search')[0].checked) {
  1603. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  1604. } else {
  1605. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1606. }
  1607. }
  1608. posSearch.searchAndLocate();
  1609. });
  1610. $('#pos-over-search').click(function () {
  1611. if (this.checked) {
  1612. $('[for=' + this.id +']').addClass('text-danger');
  1613. } else {
  1614. $('[for=' + this.id +']').removeClass('text-danger');
  1615. }
  1616. if (this.checked) {
  1617. if ($('#pos-empty-search')[0].checked) {
  1618. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1619. } else {
  1620. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  1621. }
  1622. } else {
  1623. if ($('#pos-empty-search')[0].checked) {
  1624. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  1625. } else {
  1626. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1627. }
  1628. }
  1629. posSearch.searchAndLocate();
  1630. });
  1631. $('#pos-search-next').click(() => {posSearch.locateNext()});
  1632. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  1633. $.divResizer({
  1634. select: '#right-spr',
  1635. callback: function () {
  1636. slSpread.refresh();
  1637. spSpread.refresh();
  1638. if (searchLedger) {
  1639. searchLedger.spread.refresh();
  1640. }
  1641. if (detail) {
  1642. detail.spread.refresh();
  1643. }
  1644. if (checkedChanges) checkedChanges.refresh();
  1645. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1646. }
  1647. });
  1648. // 中间计量加载上下窗口resizer
  1649. $.divResizer({
  1650. select: '#zhongjian-spr',
  1651. callback: function () {
  1652. if (detail) {
  1653. detail.spread.refresh();
  1654. }
  1655. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1656. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1657. }
  1658. });
  1659. // 附件加载上下窗口resizer
  1660. $.divResizer({
  1661. select: '#file-spr',
  1662. callback: function () {
  1663. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1664. }
  1665. });
  1666. // 变更令加载上下窗口resizer
  1667. $.divResizer({
  1668. select: '#change-spr',
  1669. callback: function () {
  1670. if (checkedChanges) checkedChanges.refresh();
  1671. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1672. }
  1673. });
  1674. class Detail {
  1675. constructor (obj) {
  1676. const self = this;
  1677. this.spreadSetting = {
  1678. cols: [
  1679. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  1680. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1681. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  1682. {
  1683. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  1684. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  1685. },
  1686. ],
  1687. headRows: 1,
  1688. emptyRows: 0,
  1689. headRowHeight: [32],
  1690. defaultRowHeight: 21,
  1691. headerFont: '12px 微软雅黑',
  1692. font: '12px 微软雅黑',
  1693. readOnly: readOnly,
  1694. selectedBackColor: '#fffacd',
  1695. };
  1696. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  1697. this.sheet = this.spread.getActiveSheet();
  1698. this.spread.options.allowUserDragFill = true;
  1699. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  1700. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1701. this.detailObj = {
  1702. selectionChanged: function (e, info) {
  1703. self.reLoadDetailData();
  1704. },
  1705. editEnded: function(e, info) {
  1706. if (info.sheet.zh_setting) {
  1707. const col = info.sheet.zh_setting.cols[info.col];
  1708. if (col.field !== 'doc_code') {
  1709. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1710. return;
  1711. }
  1712. const data = SpreadJsObj.getSelectObject(info.sheet);
  1713. if (data) {
  1714. const updateData = {lid: data.lid, pid: data.pid};
  1715. if (data.uuid) {
  1716. updateData.uuid = data.uuid;
  1717. } else {
  1718. updateData.code = data.code;
  1719. updateData.name = data.name;
  1720. updateData.unit = data.unit;
  1721. updateData.unit_price = data.unit_price;
  1722. }
  1723. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  1724. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  1725. stageIm.loadUpdateDetailData(result);
  1726. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1727. }, function () {
  1728. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1729. });
  1730. } else {
  1731. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1732. }
  1733. }
  1734. },
  1735. clipboardPasted: function (e, info) {
  1736. if (info.sheet.zh_setting && info.sheet.zh_data) {
  1737. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  1738. if (info.cellRange.colCount > 1) {
  1739. toastr.warning('请勿同时复制粘贴多列数据');
  1740. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  1741. return;
  1742. }
  1743. if (col.field !== 'doc_code') {
  1744. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  1745. return;
  1746. }
  1747. const datas = [];
  1748. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1749. const curRow = info.cellRange.row + iRow;
  1750. const data = info.sheet.zh_data[curRow];
  1751. if (data) {
  1752. const updateData = {lid: data.lid, pid: data.pid};
  1753. if (data.uuid) {
  1754. updateData.uuid = data.uuid;
  1755. } else {
  1756. updateData.code = data.code;
  1757. updateData.name = data.name;
  1758. updateData.unit = data.unit;
  1759. updateData.unit_price = data.unit_price;
  1760. }
  1761. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  1762. datas.push(updateData);
  1763. }
  1764. }
  1765. if (datas.length > 0) {
  1766. postData(window.location.pathname + '/detail/save', datas, function (result) {
  1767. stageIm.loadUpdateDetailData(result);
  1768. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1769. }, function () {
  1770. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1771. })
  1772. }
  1773. }
  1774. },
  1775. deletePress: function (sheet) {
  1776. if (sheet.zh_setting) {
  1777. const datas = [];
  1778. const sel = sheet.getSelections()[0];
  1779. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1780. const col = sheet.zh_setting.cols[iCol];
  1781. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1782. const data = sheet.zh_data[iRow];
  1783. if (col.field === 'doc_code') {
  1784. const updateData = {lid: data.lid};
  1785. if (data.uuid) {
  1786. updateData.uuid = data.uuid;
  1787. updateData.doc_code = '';
  1788. datas.push(updateData);
  1789. }
  1790. }
  1791. }
  1792. }
  1793. if (datas.length > 0) {
  1794. postData(window.location.pathname + '/detail/save', datas, function (result) {
  1795. stageIm.loadUpdateDetailData(result);
  1796. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  1797. }, function () {
  1798. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  1799. });
  1800. }
  1801. }
  1802. },
  1803. dragFillBlock: function (e, info) {
  1804. info.cancel = true;
  1805. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  1806. const sel = info.sheet.getSelections()[0];
  1807. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  1808. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  1809. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  1810. if (text === '') return;
  1811. const regRst = /(\d+)$/g.exec(text), datas = [];
  1812. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  1813. const curRow = info.fillRange.row + iRow;
  1814. const data = info.sheet.zh_data[curRow];
  1815. if (data) {
  1816. const updateData = {lid: data.lid};
  1817. if (data.uuid) {
  1818. updateData.uuid = data.uuid;
  1819. } else {
  1820. updateData.code = data.code;
  1821. updateData.name = data.name;
  1822. updateData.unit = data.unit;
  1823. updateData.unit_price = data.unit_price;
  1824. }
  1825. if (regRst) {
  1826. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  1827. } else {
  1828. updateData.doc_code = text.replace('\n', '');
  1829. }
  1830. datas.push(updateData);
  1831. }
  1832. }
  1833. if (datas.length > 0) {
  1834. postData(window.location.pathname + '/detail/save', datas, function (result) {
  1835. stageIm.loadUpdateDetailData(result);
  1836. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  1837. }, function () {
  1838. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  1839. })
  1840. }
  1841. },
  1842. };
  1843. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  1844. if (!readOnly) {
  1845. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  1846. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  1847. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  1848. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  1849. }
  1850. this._initImTypeSetRela();
  1851. this._initModifyDetail();
  1852. // 草图相关
  1853. this._initImageRela();
  1854. this.reBuildImData();
  1855. }
  1856. _initImTypeSetRela() {
  1857. const self = this;
  1858. const gatherConfirmPopover = {
  1859. reBind: function (obj, eventName, fun) {
  1860. obj.unbind(eventName);
  1861. obj.bind(eventName, fun);
  1862. },
  1863. check: function (pos, hint, okCallback) {
  1864. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  1865. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  1866. this.reBind(cancelObj, 'click', function () {
  1867. confirmObj.hide();
  1868. });
  1869. this.reBind(okObj, 'click', function () {
  1870. okCallback();
  1871. confirmObj.hide();
  1872. });
  1873. hintObj.text(hint);
  1874. confirmObj.css("top", pos.y).css("left", pos.x).show();
  1875. }
  1876. };
  1877. this.gsTree = stageIm.getGsTree();
  1878. if (stage.im_type === imType.tz.value) {
  1879. $('#type-title-contract').text('本期合同计量金额');
  1880. $('#type-title-qc').text('本期变更计量金额');
  1881. } else {
  1882. $('#type-title-contract').text('本期合同计量数量');
  1883. $('#type-title-qc').text('本期变更计量数量');
  1884. }
  1885. // 选择中间计量模式
  1886. $('div[name="im-type"]').click(function () {
  1887. function chooseType(obj) {
  1888. obj.style.cursor = 'default';
  1889. $(obj).children().addClass('text-primary');
  1890. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  1891. }
  1892. function validType(obj) {
  1893. obj.style.cursor = 'pointer';
  1894. $(obj).children().removeClass('text-primary');
  1895. $('i', obj).remove();
  1896. }
  1897. if (this.style.cursor === 'pointer') {
  1898. const typeArr = $('div[name="im-type"]');
  1899. for (const t of typeArr) {
  1900. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  1901. chooseType(t);
  1902. } else {
  1903. validType(t)
  1904. }
  1905. }
  1906. }
  1907. });
  1908. $('#choose').on('show.bs.modal', function () {
  1909. function chooseType(obj) {
  1910. obj.style.cursor = 'default';
  1911. $(obj).children().addClass('text-primary');
  1912. $('i', obj).remove();
  1913. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  1914. }
  1915. function validType(obj) {
  1916. obj.style.cursor = 'pointer';
  1917. $(obj).children().removeClass('text-primary');
  1918. $('i', obj).remove();
  1919. }
  1920. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  1921. const typeArr = $('div[name="im-type"]');
  1922. for (const t of typeArr) {
  1923. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  1924. chooseType(t);
  1925. } else {
  1926. validType(t)
  1927. }
  1928. }
  1929. });
  1930. // 提交 中间计量模式
  1931. $('#choose-ok').click(() => {
  1932. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  1933. return it.style.cursor !== 'pointer';
  1934. });
  1935. const data = {
  1936. im_type: parseInt($(chooseType).attr('im-type')),
  1937. im_pre: $('#im-pre').val(),
  1938. };
  1939. postData(window.location.pathname + '/detail/build', data, function (result) {
  1940. stage.im_type = data.im_type;
  1941. stage.im_pre = data.im_pre;
  1942. if (stage.im_type === imType.tz.value) {
  1943. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  1944. jlCol.title = '本期计量金额';
  1945. SpreadJsObj.reLoadSheetHeader(self.sheet);
  1946. $('#type-title-contract').text('本期合同计量金额');
  1947. $('#type-title-qc').text('本期变更计量金额');
  1948. } else {
  1949. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  1950. jlCol.title = '本期计量数量';
  1951. SpreadJsObj.reLoadSheetHeader(self.sheet);
  1952. $('#type-title-contract').text('本期合同计量数量');
  1953. $('#type-title-qc').text('本期变更计量数量');
  1954. }
  1955. // 加载生成数据
  1956. self.reBuildImData();
  1957. $('#choose').modal('hide');
  1958. });
  1959. });
  1960. // 显示树结构信息
  1961. $('#choose2').on('shown.bs.modal', function () {
  1962. if (!self.gsSpread) {
  1963. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  1964. const setting = {
  1965. cols: [
  1966. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  1967. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  1968. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  1969. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  1970. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  1971. ],
  1972. headRows: 1,
  1973. emptyRows: 0,
  1974. headRowHeight: [32],
  1975. defaultRowHeight: 21,
  1976. headerFont: '12px 微软雅黑',
  1977. font: '12px 微软雅黑',
  1978. }
  1979. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  1980. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  1981. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  1982. function checkParent(node) {
  1983. const parent = self.gsTree.getParent(node);
  1984. if (parent) {
  1985. return parent.check ? parent.check : checkParent(parent);
  1986. } else {
  1987. return false;
  1988. }
  1989. }
  1990. function checkChildren(node) {
  1991. for (const child of node.children) {
  1992. if (child.check) {
  1993. return true;
  1994. } else if (checkChildren(child)) {
  1995. return true;
  1996. }
  1997. }
  1998. return false;
  1999. }
  2000. if (!$('#im-gather-check')[0].checked) { return; }
  2001. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  2002. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  2003. if (sheet.isEditing()) {
  2004. sheet.endEdit(true);
  2005. }
  2006. }
  2007. if (info.sheet.zh_setting) {
  2008. const col = info.sheet.zh_setting.cols[info.col];
  2009. if (col.field !== 'check') {
  2010. return;
  2011. }
  2012. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  2013. const node = sortData[info.row];
  2014. if (!node.check) {
  2015. if (checkParent(node)) {
  2016. const rect = info.sheet.getCellRect(info.row, info.col);
  2017. gatherConfirmPopover.check({
  2018. x: rect.x + rect.width / 2 + 25,
  2019. y: rect.y + rect.height / 2 + 3,
  2020. }, '父项已勾选,继续将取消父项勾选。', function () {
  2021. node.check = true;
  2022. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  2023. const rows = [self.gsTree.nodes.indexOf(node)];
  2024. for (const p of parents) {
  2025. if (p.check) {
  2026. p.check = false;
  2027. rows.push(self.gsTree.nodes.indexOf(p));
  2028. }
  2029. }
  2030. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2031. });
  2032. } else if (checkChildren(node)) {
  2033. const rect = info.sheet.getCellRect(info.row, info.col);
  2034. gatherConfirmPopover.check({
  2035. x: rect.x + rect.width / 2 + 25,
  2036. y: rect.y + rect.height / 2 + 3,
  2037. }, '子项已勾选,继续将取消子项勾选。', function () {
  2038. node.check = true;
  2039. const posterity = self.gsTree.getPosterity(node);
  2040. const rows = [self.gsTree.nodes.indexOf(node)];
  2041. for (const p of posterity) {
  2042. if (p.check) {
  2043. rows.push(self.gsTree.nodes.indexOf(p));
  2044. p.check = false;
  2045. }
  2046. }
  2047. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2048. });
  2049. } else {
  2050. node.check = true;
  2051. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2052. }
  2053. } else {
  2054. node.check = false;
  2055. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2056. }
  2057. }
  2058. });
  2059. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2060. for (const node of self.gsTree.datas) {
  2061. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2062. }
  2063. SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  2064. self.gsTree.expandByLevel(4);
  2065. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  2066. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  2067. } else {
  2068. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2069. for (const node of self.gsTree.datas) {
  2070. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2071. }
  2072. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  2073. }
  2074. });
  2075. // 提交 高级设置
  2076. $('#choose2-ok').click(() => {
  2077. if (!self.gsTree) { return; }
  2078. const nodes = [];
  2079. for (const node of self.gsTree.datas) {
  2080. if (node.check) {
  2081. nodes.push(node.id);
  2082. }
  2083. }
  2084. const data = {
  2085. im_gather: $('#im-gather-check')[0].checked,
  2086. im_gather_node: nodes.join(','),
  2087. };
  2088. postData(window.location.pathname + '/detail/adv', data, function (result) {
  2089. stage.im_gather = data.im_gather;
  2090. stage.im_gather_node = data.im_gather_node;
  2091. $('#choose2').modal('hide');
  2092. });
  2093. });
  2094. }
  2095. _initModifyDetail() {
  2096. const self = this;
  2097. // 编辑
  2098. $('#edit-detail').click(function () {
  2099. $(this).hide();
  2100. $('#save-detail').show();
  2101. $('#cancel-detail').show();
  2102. $('#detail-show').hide();
  2103. $('#detail-edit').show();
  2104. });
  2105. // 保存
  2106. $('#save-detail').click(() => {
  2107. function check(field, obj, org, update) {
  2108. const newValue = obj.val();
  2109. if (!org[field]) {
  2110. if (newValue !== '') {
  2111. update[field] = newValue;
  2112. }
  2113. } else if (newValue !== org[field]){
  2114. update[field] = newValue;
  2115. }
  2116. }
  2117. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2118. const updateData = {lid: data.lid, pid: data.pid};
  2119. if (data.uuid) {
  2120. updateData.uuid = data.uuid;
  2121. } else {
  2122. updateData.code = data.code;
  2123. updateData.name = data.name;
  2124. updateData.unit = data.unit;
  2125. updateData.unit_price = data.unit_price;
  2126. }
  2127. updateData.bw = $('#bw-name').val();
  2128. updateData.peg = $('#peg').val();
  2129. updateData.xm = $('#xm-name').val();
  2130. updateData.position = $('#position').val();
  2131. updateData.drawing_code = $('#drawing-code').val();
  2132. updateData.calc_memo = $('#calc-memo').val();
  2133. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2134. stageIm.loadUpdateDetailData(result);
  2135. self.reLoadDetailData();
  2136. });
  2137. });
  2138. // 取消
  2139. $('#cancel-detail').click(() => {
  2140. self.reLoadDetailData();
  2141. });
  2142. }
  2143. _initImageRela() {
  2144. const self = this;
  2145. function setdraggrable(){
  2146. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  2147. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  2148. stop: function( event, ui ) {
  2149. }
  2150. });
  2151. }
  2152. // 移动图片
  2153. const moveImageItem = function (ev) {
  2154. const item = this;
  2155. const view = $('.img-view')[0];
  2156. let oEvent = ev;
  2157. // 浏览器有一些图片的默认事件,这里要阻止
  2158. oEvent.preventDefault();
  2159. let disX = oEvent.clientX - item.offsetLeft;
  2160. let disY = oEvent.clientY - item.offsetTop;
  2161. view.onmousemove = function (ev) {
  2162. oEvent = ev;
  2163. oEvent.preventDefault();
  2164. let x = oEvent.clientX -disX;
  2165. let y = oEvent.clientY -disY;
  2166. // 图形移动的边界判断
  2167. x = x <= 0 ? 0 : x;
  2168. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  2169. y = y <= 0 ? 0 : y;
  2170. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  2171. item.style.left = x + 'px';
  2172. item.style.top = y + 'px';
  2173. };
  2174. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  2175. view.onmouseleave = function () {
  2176. view.onmousemove = null;
  2177. view.onmouseup = null;
  2178. };
  2179. // 鼠标弹起后停止移动
  2180. view.onmouseup=function() {
  2181. view.onmousemove = null;
  2182. view.onmouseup = null;
  2183. };
  2184. };
  2185. const removeImageItem = function () {
  2186. $(this).parent().remove();
  2187. };
  2188. // 加载草图组成
  2189. $('#edit-img').on('show.bs.modal', function () {
  2190. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2191. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  2192. const html = [];
  2193. for (const item of items) {
  2194. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  2195. html.push('<div class="img-item" style="' + itemStyle + '">');
  2196. html.push('<div class="img-bar">');
  2197. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  2198. html.push('</div>');
  2199. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  2200. html.push('</div>');
  2201. }
  2202. $('.img-view').html(html.join(''));
  2203. $('.img-bar').click(removeImageItem);
  2204. setdraggrable();
  2205. });
  2206. // 上传图片
  2207. $('#upload-img').click(function () {
  2208. $('#upload-img-file').trigger('click');
  2209. });
  2210. $('#upload-img-file').change(function () {
  2211. const file = this.files[0];
  2212. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  2213. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  2214. if (!imgStr.test(ext)) {
  2215. toastr.error('请上传正确的图片格式文件');
  2216. return
  2217. }
  2218. if ($(this).val()) {
  2219. const formData = new FormData();
  2220. formData.append('file', this.files[0]);
  2221. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  2222. const html = [];
  2223. html.push('<div class="img-item">');
  2224. html.push('<div class="img-bar">');
  2225. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  2226. html.push('</div>');
  2227. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  2228. html.push('</div>');
  2229. $('.img-view').append(html.join(''));
  2230. $('.img-bar').click(removeImageItem);
  2231. setdraggrable();
  2232. $('#upload-img-file').val('');
  2233. });
  2234. }
  2235. });
  2236. // 保存草图修改结果
  2237. $('#edit-img-ok').click(function () {
  2238. // 记录上传的图片的信息
  2239. const items = $('.img-item');
  2240. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2241. if (items.length > 0) {
  2242. const itemInfo = [];
  2243. for (const item of items) {
  2244. const itemData = {
  2245. src: $('img', item).attr('src'),
  2246. left: item.style.left,
  2247. top: item.style.top,
  2248. width: item.style.width,
  2249. height: item.style.height,
  2250. };
  2251. itemInfo.push(itemData);
  2252. }
  2253. // 获取合并好的图片数据
  2254. const canvas = document.createElement('canvas');
  2255. const view = $('.img-view')[0];
  2256. canvas.height = view.clientHeight;
  2257. canvas.width = view.clientWidth;
  2258. const ctx = canvas.getContext('2d');
  2259. ctx.fillStyle = '#ffffff';
  2260. ctx.fillRect(0, 0, canvas.width, canvas.height);
  2261. for (const b of $('.img-item')) {
  2262. const pos = $(b).position();
  2263. const img = $('img', b)[0];
  2264. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  2265. }
  2266. // 生成上传数据
  2267. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid};
  2268. if (data.uuid) {
  2269. updateData.uuid = data.uuid;
  2270. } else {
  2271. updateData.code = data.code;
  2272. updateData.name = data.name;
  2273. updateData.unit = data.unit;
  2274. updateData.unit_price = data.unit_price;
  2275. }
  2276. updateData.img = canvas.toDataURL('image/png');
  2277. updateData.imgInfo = itemInfo;
  2278. postData(window.location.pathname + '/detail/merge-img', updateData, function (result) {
  2279. data.calc_img = result.calc_img;
  2280. data.calc_img_org = result.calc_img_org;
  2281. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2282. $('#show-calc-img').attr('src', calcImgSrc);
  2283. $('#calc-img').attr('src', calcImgSrc);
  2284. $('#view-calc-img').attr('src', calcImgSrc);
  2285. $('#edit-img').modal('hide');
  2286. });
  2287. } else if (data.calc_img) {
  2288. postData(window.location.pathname + '/detail/merge-img', {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid}, function (result) {
  2289. data.calc_img = result.calc_img;
  2290. data.calc_img_org = result.calc_img_org;
  2291. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2292. $('#show-calc-img').attr('src', calcImgSrc);
  2293. $('#calc-img').attr('src', calcImgSrc);
  2294. $('#view-calc-img').attr('src', calcImgSrc);
  2295. $('#edit-img').modal('hide');
  2296. });
  2297. }
  2298. });
  2299. }
  2300. reBuildImData() {
  2301. const imData = stageIm.buildImData();
  2302. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2303. this.reLoadDetailData();
  2304. }
  2305. loadStageLedgerUpdateData(data) {
  2306. const imData = stageIm.loadUpdateLedgerData(data);
  2307. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2308. this.reLoadDetailData();
  2309. }
  2310. loadStagePosUpdateData(data) {
  2311. const imData = stageIm.loadUpdatePosData(data);
  2312. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2313. this.reLoadDetailData();
  2314. }
  2315. loadStageChangeUpdateData(data) {
  2316. const imData = stageIm.loadUpdateChangeData(data);
  2317. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2318. this.reLoadDetailData();
  2319. }
  2320. reLoadDetailData() {
  2321. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  2322. if (data) {
  2323. $('#edit-detail').show();
  2324. $('#modify-img').show();
  2325. } else {
  2326. $('#edit-detail').hide();
  2327. $('#modify-img').hide();
  2328. }
  2329. $('#save-detail').hide();
  2330. $('#cancel-detail').hide();
  2331. $('#detail-show').show();
  2332. $('#detail-edit').hide();
  2333. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  2334. $('#show-contract-jl').text(contractJl);
  2335. $('#contract-jl').val(contractJl);
  2336. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  2337. $('#show-qc-jl').text(qcJl);
  2338. $('#qc-jl').val(qcJl);
  2339. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  2340. $('#show-bgl-code').text(bglCode);
  2341. $('#bgl-code').val(bglCode);
  2342. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  2343. $('#show-bgl-drawing-code').text(bglDrawingCode);
  2344. $('#bgl-drawing-code').val(bglDrawingCode);
  2345. const bwName = data && data.bw ? data.bw : '';
  2346. $('#show-bw-name').text(bwName);
  2347. $('#bw-name').val(bwName);
  2348. const position = data && data.position ? data.position : '';
  2349. $('#show-position').text(position);
  2350. $('#position').val(position);
  2351. const peg = data && data.peg ? data.peg : '';
  2352. $('#show-peg').text(peg);
  2353. $('#peg').val(peg);
  2354. const xmName = data && data.xm ? data.xm: '';
  2355. $('#show-xm-name').text(xmName);
  2356. $('#xm-name').val(xmName);
  2357. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  2358. $('#show-drawing-code').text(drawingCode);
  2359. $('#drawing-code').val(drawingCode);
  2360. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  2361. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  2362. $('#calc-memo').val(calcMemo);
  2363. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2364. $('#show-calc-img').attr('src', calcImgSrc);
  2365. $('#calc-img').attr('src', calcImgSrc);
  2366. $('#view-calc-img').attr('src', calcImgSrc);
  2367. }
  2368. }
  2369. class CheckedChange {
  2370. constructor (setting) {
  2371. const self = this;
  2372. this.changeSpreadSetting = {
  2373. cols: [
  2374. {title: '变更令号', colSpan: '1', rowSpan: '1', field: 'p_code', hAlign: 0, width: 100, formatter: '@'},
  2375. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  2376. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  2377. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  2378. ],
  2379. emptyRows: 0,
  2380. headRows: 1,
  2381. headRowHeight: [32],
  2382. defaultRowHeight: 21,
  2383. headerFont: '12px 微软雅黑',
  2384. font: '12px 微软雅黑',
  2385. readOnly: true,
  2386. };
  2387. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  2388. this.changeSheet = this.changeSpread.getActiveSheet();
  2389. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  2390. this.changeBillsSpreadSetting = {
  2391. cols: [
  2392. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  2393. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, type: 'Number'},
  2394. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2395. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  2396. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@'},
  2397. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@'},
  2398. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  2399. ],
  2400. emptyRows: 0,
  2401. headRows: 1,
  2402. headRowHeight: [32],
  2403. defaultRowHeight: 21,
  2404. headerFont: '12px 微软雅黑',
  2405. font: '12px 微软雅黑',
  2406. readOnly: true
  2407. };
  2408. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  2409. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  2410. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  2411. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  2412. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  2413. if (change.cid === self.curChangeId) { return; }
  2414. self.curChangeId = change.cid;
  2415. if (change.detail) {
  2416. self.loadChangeDetailData();
  2417. } else {
  2418. postData(window.location.pathname + '/change/detail', {cid: change.cid}, function (result) {
  2419. change.detail = result;
  2420. self.analyzeChange(change);
  2421. self.loadChangeDetailData();
  2422. });
  2423. }
  2424. });
  2425. this.changes = null;
  2426. this.reloadChangeData();
  2427. setting.reloadObj.click(function() {
  2428. self.reloadChangeData();
  2429. });
  2430. }
  2431. loadChangeDetailData() {
  2432. const change = SpreadJsObj.getSelectObject(this.changeSheet);
  2433. if (change) {
  2434. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
  2435. } else {
  2436. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
  2437. }
  2438. }
  2439. refresh() {
  2440. this.changeSpread.refresh();
  2441. this.changeBillsSpread.refresh();
  2442. }
  2443. reloadChangeData() {
  2444. const self = this;
  2445. postData(window.location.pathname + '/change/data', null, function (result) {
  2446. self.changes = result.changes;
  2447. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  2448. self.changeSheet.setSelection(0, 0, 1, 1);
  2449. if (self.changes.length > 0) self.analyzeChange(result.changes[0]);
  2450. self.loadChangeDetailData();
  2451. });
  2452. }
  2453. analyzeChange(change) {
  2454. change.bills = change.detail.bills;
  2455. for (const b of change.bills) {
  2456. console.log(b);
  2457. const aub = change.detail.addUsedBills.find(function (x) {
  2458. return x.id === b.id;
  2459. });
  2460. if (aub) {
  2461. b.used_qty = aub.used_qty;
  2462. }
  2463. b.qty = _.toNumber(b.samount);
  2464. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  2465. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  2466. b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
  2467. b.cur_qty = 0;
  2468. for (const p of b.pos) {
  2469. p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
  2470. b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
  2471. }
  2472. }
  2473. }
  2474. }
  2475. // 展开收起附件
  2476. $('a', '.right-nav').bind('click', function () {
  2477. //const main = $('#main-view'), tool = $('#tools-view');
  2478. const tab = $(this), tabPanel = $(tab.attr('content'));
  2479. if (!tab.hasClass('active')) {
  2480. $('a', '.side-menu').removeClass('active');
  2481. $('.tab-content .tab-select-show').removeClass('active');
  2482. tab.addClass('active');
  2483. tabPanel.addClass('active');
  2484. showSideTools(tab.hasClass('active'));
  2485. if (tab.attr('content') === '#search' && !searchLedger) {
  2486. searchLedger = $.billsSearch({
  2487. selector: '#search',
  2488. searchSpread: slSpread,
  2489. searchRangeStr: '项目节编号/名称',
  2490. searchOver: true,
  2491. searchEmpty: true,
  2492. resultSpreadSetting: {
  2493. cols: [
  2494. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@'},
  2495. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  2496. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  2497. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  2498. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2499. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  2500. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  2501. ],
  2502. emptyRows: 0,
  2503. headRows: 1,
  2504. headRowHeight: [32],
  2505. defaultRowHeight: 21,
  2506. headerFont: '12px 微软雅黑',
  2507. font: '12px 微软雅黑',
  2508. selectedBackColor: '#fffacd',
  2509. },
  2510. afterLocated: function () {
  2511. stagePosSpreadObj.loadCurPosData();
  2512. },
  2513. checkLess: function (node) {
  2514. if (node.quantity) {
  2515. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  2516. } else if (node.total_price) {
  2517. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  2518. }
  2519. },
  2520. checkOver: function (node) {
  2521. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  2522. if (posRange.length > 0) {
  2523. for (const p of posRange) {
  2524. if (p.end_contract_qty > p.quantity) return true;
  2525. }
  2526. return false;
  2527. } else if (node.end_gather_qty) {
  2528. return !node.quantity || Math.abs(node.end_gather_qty) > Math.abs(ZhCalc.add(node.quantity, node.end_qc_qty));
  2529. } else if (node.end_gather_tp) {
  2530. return !node.total_price || Math.abs(node.end_gather_tp) > Math.abs(ZhCalc.add(node.total_price, node.end_qc_tp));
  2531. }
  2532. },
  2533. checkEmpty: function (node) {
  2534. if (node.quantity) {
  2535. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  2536. } else if (node.total_price) {
  2537. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  2538. }
  2539. },
  2540. });
  2541. searchLedger.spread.refresh();
  2542. }
  2543. if (tab.attr('content') === '#fujian') {
  2544. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2545. getNodeList(node.id);
  2546. }
  2547. if (tab.attr('content') === '#zhongjian') {
  2548. if (!detail) {
  2549. detail = new Detail($('#detail-spread'));
  2550. detail.spread.refresh();
  2551. $('#zhongjian .sjs-bottom').height('400px');
  2552. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2553. } else {
  2554. detail.spread.refresh();
  2555. $('#zhongjian .sjs-bottom').height('400px');
  2556. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2557. }
  2558. }
  2559. if (tab.attr('content') === '#checked-change') {
  2560. if (!checkedChanges) {
  2561. checkedChanges = new CheckedChange({
  2562. changeObj: $('#cc-spread'),
  2563. changeBillsObj: $('#ccb-spread'),
  2564. reloadObj: $('#refresh-cc'),
  2565. });
  2566. checkedChanges.refresh();
  2567. } else {
  2568. $('#ccb-spread').height('400px');
  2569. checkedChanges.refresh();
  2570. }
  2571. }
  2572. if (tab.attr('content') === '#error-list') {
  2573. errorList.spread.refresh();
  2574. }
  2575. } else {
  2576. tab.removeClass('active');
  2577. tabPanel.removeClass('active');
  2578. showSideTools(tab.hasClass('active'));
  2579. }
  2580. slSpread.refresh();
  2581. spSpread.refresh();
  2582. });
  2583. // 切换附件里节点和所有附件
  2584. $('#fujian .nav-link').on('click', function () {
  2585. const tabPanel = $(this).attr('fujian-content');
  2586. if (tabPanel !== 'syfujian') {
  2587. $('#showPage').hide();
  2588. } else {
  2589. $('#showPage').show();
  2590. }
  2591. $('#showAttachment').hide();
  2592. });
  2593. // 上传附件
  2594. $('#upload-file-btn').click(function () {
  2595. const files = $('#upload-file')[0].files;
  2596. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2597. const formData = new FormData();
  2598. formData.append('lid', node.id);
  2599. for (const file of files) {
  2600. if (file === undefined) {
  2601. toastr.error('未选择上传文件!');
  2602. return false;
  2603. }
  2604. const filesize = file.size;
  2605. if (filesize > 30 * 1024 * 1024) {
  2606. toastr.error('存在上传文件大小过大!');
  2607. return false;
  2608. }
  2609. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  2610. if (whiteList.indexOf(fileext) === -1) {
  2611. toastr.error('只能上传指定格式的附件!');
  2612. return false;
  2613. }
  2614. formData.append('size', filesize);
  2615. formData.append('file[]', file);
  2616. }
  2617. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  2618. $('#upload').modal('hide');
  2619. // 插入到attData中
  2620. attData = data.concat(attData);
  2621. // 重新生成List
  2622. getAllList();
  2623. getNodeList(node.id);
  2624. }, function () {
  2625. toastr.error('附件上传失败');
  2626. });
  2627. $('#upload-file').val('');
  2628. });
  2629. // 获取附件信息
  2630. $('body').on('click', '.list-table a', function () {
  2631. const fid = $(this).attr('file-id');
  2632. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  2633. return;
  2634. }
  2635. const att = attData.find(function (item) {
  2636. return item.id === parseInt(fid);
  2637. });
  2638. $('#edit-att').hide();
  2639. $('#show-att').show();
  2640. if (att !== undefined) {
  2641. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  2642. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  2643. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  2644. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  2645. $('#show-att tr').eq(3).children('td').eq(0).text(att.username);
  2646. $('#show-att tr').eq(3).children('td').eq(1).text(att.in_time);
  2647. $('#show-att tr').eq(4).children('td').text(att.remark);
  2648. if (parseInt(userID) === att.uid) {
  2649. $('#btn-att').show();
  2650. $('#btn-att a').eq(1).show();
  2651. $('#btn-att a').eq(0).hide();
  2652. $('#btn-att a').eq(2).hide();
  2653. $('#btn-att a').eq(3).hide();
  2654. } else {
  2655. $('#btn-att').hide();
  2656. $('#btn-att a').eq(1).hide();
  2657. $('#btn-att a').eq(0).hide();
  2658. $('#btn-att a').eq(2).hide();
  2659. $('#btn-att a').eq(3).hide();
  2660. }
  2661. $('#showAttachment').attr('file-id', fid);
  2662. $('#showAttachment').show();
  2663. } else {
  2664. $('#showAttachment').hide();
  2665. $('#showAttachment').attr('file-id', '');
  2666. toastr.error('附件信息获取失败');
  2667. }
  2668. });
  2669. $('body').on('click', '#btn-att a', function () {
  2670. const content = $(this).attr('content');
  2671. const fid = $('#showAttachment').attr('file-id');
  2672. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2673. if (content === 'edit') {
  2674. $('#btn-att a').eq(1).hide();
  2675. $('#btn-att a').eq(0).show();
  2676. $('#btn-att a').eq(2).show();
  2677. $('#btn-att a').eq(3).show();
  2678. $('#show-att').hide();
  2679. $('#edit-att').show();
  2680. const att = attData.find(function (item) {
  2681. return item.id === parseInt(fid);
  2682. });
  2683. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  2684. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  2685. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  2686. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  2687. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  2688. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  2689. } else if (content === 'cancel') {
  2690. $('#show-att').show();
  2691. $('#edit-att').hide();
  2692. $('#btn-att a').eq(1).show();
  2693. $('#btn-att a').eq(0).hide();
  2694. $('#btn-att a').eq(2).hide();
  2695. $('#btn-att a').eq(3).hide();
  2696. } else if (content === 'save') {
  2697. const formData = new FormData();
  2698. formData.append('id', fid);
  2699. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  2700. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  2701. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  2702. const file = $('#change-att-btn')[0];
  2703. if (file.files[0] !== undefined) {
  2704. const filesize = file.files[0].size;
  2705. formData.append('size', filesize);
  2706. formData.append('file', file.files[0]);
  2707. }
  2708. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  2709. // 替换到attData中
  2710. const att_index = attData.findIndex(function (item) {
  2711. return item.id === parseInt(fid);
  2712. });
  2713. attData.splice(att_index, 1, data);
  2714. // 重新生成List
  2715. getAllList(parseInt($('#currentPage').text()));
  2716. getNodeList(node.id);
  2717. $('#show-att').show();
  2718. $('#edit-att').hide();
  2719. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  2720. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  2721. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  2722. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  2723. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  2724. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  2725. $('#show-att tr').eq(4).children('td').text(data.remark);
  2726. $('#btn-att a').eq(1).show();
  2727. $('#btn-att a').eq(0).hide();
  2728. $('#btn-att a').eq(2).hide();
  2729. $('#btn-att a').eq(3).hide();
  2730. }, function () {
  2731. toastr.error('附件上传失败');
  2732. });
  2733. $('#change-att-btn').val('');
  2734. } else if (content === 'del') {
  2735. const data = {id: fid};
  2736. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  2737. // 删除到attData中
  2738. const att_index = attData.findIndex(function (item) {
  2739. return item.id === parseInt(fid);
  2740. });
  2741. attData.splice(att_index, 1);
  2742. // 重新生成List
  2743. getAllList();
  2744. getNodeList(node.id);
  2745. $('#showAttachment').hide();
  2746. $('#showAttachment').attr('file-id', '');
  2747. });
  2748. }
  2749. });
  2750. // 替换附件
  2751. $('#change-att-btn').on('change', function () {
  2752. const file = $('#change-att-btn')[0].files[0];
  2753. const name = file.name;
  2754. const filename = name.substring(0, name.lastIndexOf("."));
  2755. const fileext = name.substr(name.indexOf("."));
  2756. const filesize = file.size;
  2757. if (filesize > 10 * 1024 * 1024) {
  2758. toastr.error('文件大小过大!');
  2759. $('#change-att-btn').val('');
  2760. return false;
  2761. }
  2762. if (whiteList.indexOf(fileext) === -1) {
  2763. toastr.error('只能上传指定格式的附件!');
  2764. $('#change-att-btn').val('');
  2765. return false;
  2766. }
  2767. $('#edit-att .form-group').eq(0).find('input').val(filename);
  2768. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  2769. });
  2770. // 切换页数
  2771. $('.page-select').on('click', function () {
  2772. const totalPageNum = parseInt($('#totalPage').text());
  2773. const lastPageNum = parseInt($('#currentPage').text());
  2774. const status = $(this).attr('content');
  2775. if (status === 'pre' && lastPageNum > 1) {
  2776. getAllList(lastPageNum-1);
  2777. $('#showAttachment').hide();
  2778. } else if (status === 'next' && lastPageNum < totalPageNum) {
  2779. getAllList(lastPageNum+1);
  2780. $('#showAttachment').hide();
  2781. }
  2782. });
  2783. // 显示层次
  2784. (function (select, sheet) {
  2785. $(select).click(function () {
  2786. if (!sheet.zh_tree) return;
  2787. const tag = $(this).attr('tag');
  2788. const tree = sheet.zh_tree;
  2789. switch (tag) {
  2790. case "1":
  2791. case "2":
  2792. case "3":
  2793. case "4":
  2794. case "5":
  2795. tree.expandByLevel(parseInt(tag));
  2796. SpreadJsObj.refreshTreeRowVisible(sheet);
  2797. break;
  2798. case "last":
  2799. tree.expandByCustom(() => { return true; });
  2800. SpreadJsObj.refreshTreeRowVisible(sheet);
  2801. break;
  2802. case "leafXmj":
  2803. tree.expandToLeafXmj();
  2804. SpreadJsObj.refreshTreeRowVisible(sheet);
  2805. break;
  2806. case "curMeasure":
  2807. tree.expandByCustom(function (node) {
  2808. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  2809. if (node[field]) {
  2810. return true;
  2811. }
  2812. }
  2813. return false;
  2814. });
  2815. SpreadJsObj.refreshTreeRowVisible(sheet);
  2816. break;
  2817. }
  2818. });
  2819. })('a[name=showLevel]', slSpread.getActiveSheet());
  2820. const dataChecker = DataChecker({
  2821. checkUrl: window.location.pathname + '/check',
  2822. completeData: function (data) {
  2823. stagePos.updateDatas({pos: data.source.pos});
  2824. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  2825. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2826. stagePosSpreadObj.loadCurPosData();
  2827. for (const e of data.error) {
  2828. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  2829. }
  2830. },
  2831. errorList: errorList,
  2832. });
  2833. $('[name=stage-start]').submit(function (e) {
  2834. if (checkAuditorFrom()) {
  2835. $(this).parent().parent().parent().modal('hide');
  2836. dataChecker.checkAndPost(this.action, {});
  2837. $('#hide-all').hide();
  2838. }
  2839. return false;
  2840. });
  2841. $('#audit-check0').submit(function (e) {
  2842. if (auditCheck(0)) {
  2843. $(this).parent().parent().modal('hide');
  2844. const data = {
  2845. opinion: $('[name=opinion]', this).val(),
  2846. checkType: parseInt($('[name=checkType]', this).val()),
  2847. };
  2848. dataChecker.checkAndPost(this.action, data);
  2849. $('#hide-all').hide();
  2850. }
  2851. return false;
  2852. });
  2853. $('#audit-check1').submit(function (e) {
  2854. if (auditCheck(1)) {
  2855. $(this).parent().parent().modal('hide');
  2856. const data = {
  2857. opinion: $('[name=opinion]', this).val(),
  2858. checkType: parseInt($('[name=checkType]:checked', this).val()),
  2859. };
  2860. postData(this.action, data, function () {
  2861. window.location.reload();
  2862. });
  2863. $('#hide-all').hide();
  2864. }
  2865. return false;
  2866. });
  2867. $('#audit-check2').submit(function (e) {
  2868. if (auditCheck(0)) {
  2869. $(this).parent().parent().modal('hide');
  2870. const data = {
  2871. opinion: $('[name=opinion]', this).val(),
  2872. checkType: parseInt($('[name=checkType]', this).val()),
  2873. };
  2874. dataChecker.checkAndPost(this.action, data);
  2875. $('#hide-all').hide();
  2876. }
  2877. return false;
  2878. });
  2879. $('#audit-check3').submit(function (e) {
  2880. if (auditCheck(1)) {
  2881. $(this).parent().parent().modal('hide');
  2882. const data = {
  2883. opinion: $('[name=opinion]', this).val(),
  2884. checkType: parseInt($('[name=checkType]:checked', this).val()),
  2885. };
  2886. postData(this.action, data, function () {
  2887. window.location.reload();
  2888. });
  2889. $('#hide-all').hide();
  2890. }
  2891. return false;
  2892. });
  2893. });