stage.js 145 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024
  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, tenderInfo.decimal);
  1350. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData);
  1351. errorList.loadHisErrorData();
  1352. }, null, true);
  1353. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  1354. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  1355. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  1356. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  1357. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  1358. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  1359. if (!readOnly) {
  1360. $('#pos-expr').bind('change mouseleave', function () {
  1361. if (this.readOnly) return;
  1362. if (document.activeElement.id !== "pos-expr") return;
  1363. const expr = $(this);
  1364. const posSheet = spSpread.getActiveSheet();
  1365. const select = SpreadJsObj.getSelectObject(posSheet);
  1366. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val(), row = expr.attr('row');
  1367. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1368. const data = {pid: select.id, lid: select.lid};
  1369. const num = _.toNumber(newValue);
  1370. if (num) {
  1371. data[field] = num;
  1372. } else {
  1373. try {
  1374. data[field] = math.evaluate(transExpr(newValue));
  1375. } catch (err) {
  1376. toastr.error('输入的表达式非法');
  1377. return;
  1378. }
  1379. }
  1380. // 提交数据到服务器
  1381. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  1382. if (result.pos) {
  1383. stagePos.updateDatas(result.pos.pos);
  1384. stagePos.loadCurStageData(result.pos.curStageData);
  1385. expr.val(select[field]);
  1386. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  1387. }
  1388. const refreshData = stageTree.loadPostStageData(result.ledger);
  1389. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1390. });
  1391. });
  1392. }
  1393. if (!checkTzMeasureType()) {
  1394. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  1395. $.contextMenu({
  1396. selector: '#stage-pos',
  1397. build: function ($trigger, e) {
  1398. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  1399. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1400. },
  1401. items: {
  1402. 'del': {
  1403. name: '删除',
  1404. icon: 'fa-remove',
  1405. disabled: function (key, opt) {
  1406. const sheet = spSpread.getActiveSheet();
  1407. if (sheet.zh_data && !readOnly) {
  1408. const selection = sheet.getSelections();
  1409. if (selection && selection[0]) {
  1410. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1411. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  1412. const posData = sheet.zh_data[selection[0].row + iRow];
  1413. if (posData) {
  1414. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  1415. valid = true;
  1416. break;
  1417. }
  1418. } else {
  1419. valid = true;
  1420. break;
  1421. }
  1422. }
  1423. return valid;
  1424. } else {
  1425. return true;
  1426. }
  1427. } else {
  1428. return true;
  1429. }
  1430. },
  1431. callback: function (key, opt) {
  1432. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  1433. }
  1434. },
  1435. 'merge-peg': {
  1436. name: '合并起讫桩号',
  1437. disabled: function (key, opt) {
  1438. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1439. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  1440. },
  1441. callback: function (key, opt) {
  1442. mergePeg.show();
  1443. }
  1444. }
  1445. }
  1446. })
  1447. } else {
  1448. SpreadJsObj.forbiddenSpreadContextMenu('#stage-pos', spSpread);
  1449. }
  1450. $.subMenu({
  1451. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1452. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1453. key: 'menu.1.0.0',
  1454. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1455. callback: function (info) {
  1456. if (info.mini) {
  1457. $('.panel-title').addClass('fluid');
  1458. $('#sub-menu').removeClass('panel-sidebar');
  1459. } else {
  1460. $('.panel-title').removeClass('fluid');
  1461. $('#sub-menu').addClass('panel-sidebar');
  1462. }
  1463. autoFlashHeight();
  1464. slSpread.refresh();
  1465. spSpread.refresh();
  1466. if (searchLedger) {
  1467. searchLedger.spread.refresh();
  1468. }
  1469. if (detail) {
  1470. detail.spread.refresh();
  1471. }
  1472. if (checkedChanges) checkedChanges.refresh();
  1473. }
  1474. });
  1475. $('#row-view').on('show.bs.modal', function () {
  1476. const html = [], customDisplay = customColDisplay();
  1477. for (const cd of customDisplay) {
  1478. html.push('<tr>');
  1479. html.push('<td>', cd.title, '</td>');
  1480. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  1481. html.push('</tr>');
  1482. }
  1483. $('#row-view-list').html(html.join(''));
  1484. });
  1485. $('#row-view-ok').click(function () {
  1486. const customDisplay = customColDisplay();
  1487. const cvl = $('#row-view-list').children();
  1488. for (const cv of cvl) {
  1489. const title = $(cv).children()[0].innerHTML;
  1490. const check = $('input', cv)[0].checked;
  1491. const cd = customDisplay.find(function (c) {
  1492. return c.title === title;
  1493. });
  1494. cd.visible = check;
  1495. }
  1496. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  1497. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  1498. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  1499. $('#row-view').modal('hide');
  1500. });
  1501. const posSearch = (function () {
  1502. let resultArr = [];
  1503. const search = function () {
  1504. resultArr = [];
  1505. const keyword = $('#pos-search-keyword').val();
  1506. const checkOver = $('#pos-over-search')[0].checked;
  1507. const checkEmpty = $('#pos-empty-search')[0].checked;
  1508. const sortData = spSpread.getActiveSheet().zh_data;
  1509. if (checkOver || checkEmpty) {
  1510. if (sortData) {
  1511. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1512. const sd = sortData[i];
  1513. let match = false;
  1514. if (checkOver) {
  1515. if (sd.end_gather_qty) {
  1516. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  1517. }
  1518. }
  1519. if (checkEmpty) {
  1520. if (sd.quantity) {
  1521. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  1522. }
  1523. }
  1524. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  1525. if (match) {
  1526. resultArr.push({index: i, data: sd});
  1527. }
  1528. }
  1529. }
  1530. } else if (keyword && keyword !== '') {
  1531. if (sortData) {
  1532. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1533. const sd = sortData[i];
  1534. if (sd.name && sd.name.indexOf(keyword) > -1) {
  1535. resultArr.push({index: i, data: sd});
  1536. }
  1537. }
  1538. }
  1539. }
  1540. $('#pos-search-result').html('结果:' + resultArr.length);
  1541. };
  1542. const searchAndLocate = function () {
  1543. search();
  1544. if (resultArr.length > 0) {
  1545. const sheet = spSpread.getActiveSheet();
  1546. const sel = sheet.getSelections()[0];
  1547. const curRow = sel ? sel.row : 0;
  1548. const pos = resultArr[0];
  1549. if (pos.index !== curRow) {
  1550. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  1551. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  1552. }
  1553. }
  1554. };
  1555. const locateNext = function () {
  1556. if (resultArr.length > 0) {
  1557. const sheet = spSpread.getActiveSheet();
  1558. const sel = sheet.getSelections()[0];
  1559. const curRow = sel ? sel.row : 0;
  1560. let next = _.find(resultArr, function (d) {
  1561. return d.index > curRow;
  1562. });
  1563. if (!next) next = resultArr[0];
  1564. if (next.index !== curRow) {
  1565. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1566. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1567. }
  1568. }
  1569. };
  1570. const locatePre = function () {
  1571. if (resultArr.length > 0) {
  1572. const sheet = spSpread.getActiveSheet();
  1573. const sel = sheet.getSelections()[0];
  1574. const curRow = sel ? sel.row : 0;
  1575. let next = _.findLast(resultArr, function (d) {
  1576. return d.index < curRow;
  1577. });
  1578. if (!next) next = resultArr[resultArr.length - 1];
  1579. if (next.index !== curRow) {
  1580. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1581. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1582. }
  1583. }
  1584. };
  1585. return {search, searchAndLocate, locateNext, locatePre};
  1586. })();
  1587. $('#pos-search-keyword').bind('keydown', function(e){
  1588. if (e.keyCode == 13) posSearch.searchAndLocate();
  1589. });
  1590. $('#pos-empty-search').click(function () {
  1591. if (this.checked) {
  1592. $('[for=' + this.id +']').addClass('text-warning');
  1593. } else {
  1594. $('[for=' + this.id +']').removeClass('text-warning');
  1595. }
  1596. if (this.checked) {
  1597. if ($('#pos-over-search')[0].checked) {
  1598. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1599. } else {
  1600. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  1601. }
  1602. } else {
  1603. if ($('#pos-over-search')[0].checked) {
  1604. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  1605. } else {
  1606. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1607. }
  1608. }
  1609. posSearch.searchAndLocate();
  1610. });
  1611. $('#pos-over-search').click(function () {
  1612. if (this.checked) {
  1613. $('[for=' + this.id +']').addClass('text-danger');
  1614. } else {
  1615. $('[for=' + this.id +']').removeClass('text-danger');
  1616. }
  1617. if (this.checked) {
  1618. if ($('#pos-empty-search')[0].checked) {
  1619. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1620. } else {
  1621. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  1622. }
  1623. } else {
  1624. if ($('#pos-empty-search')[0].checked) {
  1625. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  1626. } else {
  1627. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1628. }
  1629. }
  1630. posSearch.searchAndLocate();
  1631. });
  1632. $('#pos-search-next').click(() => {posSearch.locateNext()});
  1633. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  1634. $.divResizer({
  1635. select: '#right-spr',
  1636. callback: function () {
  1637. slSpread.refresh();
  1638. spSpread.refresh();
  1639. if (searchLedger) {
  1640. searchLedger.spread.refresh();
  1641. }
  1642. if (detail) {
  1643. detail.spread.refresh();
  1644. }
  1645. if (checkedChanges) checkedChanges.refresh();
  1646. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1647. }
  1648. });
  1649. // 中间计量加载上下窗口resizer
  1650. $.divResizer({
  1651. select: '#zhongjian-spr',
  1652. callback: function () {
  1653. if (detail) {
  1654. detail.spread.refresh();
  1655. }
  1656. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1657. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1658. }
  1659. });
  1660. // 附件加载上下窗口resizer
  1661. $.divResizer({
  1662. select: '#file-spr',
  1663. callback: function () {
  1664. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1665. }
  1666. });
  1667. // 变更令加载上下窗口resizer
  1668. $.divResizer({
  1669. select: '#change-spr',
  1670. callback: function () {
  1671. if (checkedChanges) checkedChanges.refresh();
  1672. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1673. }
  1674. });
  1675. class Detail {
  1676. constructor (obj) {
  1677. const self = this;
  1678. this.spreadSetting = {
  1679. cols: [
  1680. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  1681. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1682. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  1683. {
  1684. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  1685. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  1686. },
  1687. ],
  1688. headRows: 1,
  1689. emptyRows: 0,
  1690. headRowHeight: [32],
  1691. defaultRowHeight: 21,
  1692. headerFont: '12px 微软雅黑',
  1693. font: '12px 微软雅黑',
  1694. readOnly: readOnly,
  1695. selectedBackColor: '#fffacd',
  1696. };
  1697. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  1698. this.sheet = this.spread.getActiveSheet();
  1699. this.spread.options.allowUserDragFill = true;
  1700. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  1701. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1702. this.detailObj = {
  1703. selectionChanged: function (e, info) {
  1704. self.reLoadDetailData();
  1705. },
  1706. editEnded: function(e, info) {
  1707. if (info.sheet.zh_setting) {
  1708. const col = info.sheet.zh_setting.cols[info.col];
  1709. if (col.field !== 'doc_code') {
  1710. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1711. return;
  1712. }
  1713. const data = SpreadJsObj.getSelectObject(info.sheet);
  1714. if (data) {
  1715. const updateData = {lid: data.lid, pid: data.pid};
  1716. if (data.uuid) {
  1717. updateData.uuid = data.uuid;
  1718. } else {
  1719. updateData.code = data.code;
  1720. updateData.name = data.name;
  1721. updateData.unit = data.unit;
  1722. updateData.unit_price = data.unit_price;
  1723. updateData.pos_name = data.pos_name;
  1724. }
  1725. if (data.custom_define.indexOf('doc_code') === -1) {
  1726. updateData.custom_define = data.custom_define;
  1727. updateData.custom_define.push('doc_code');
  1728. updateData.custom_define = updateData.custom_define.join(',');
  1729. }
  1730. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  1731. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  1732. stageIm.loadUpdateDetailData(result);
  1733. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1734. }, function () {
  1735. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1736. });
  1737. } else {
  1738. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1739. }
  1740. }
  1741. },
  1742. clipboardPasted: function (e, info) {
  1743. if (info.sheet.zh_setting && info.sheet.zh_data) {
  1744. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  1745. if (info.cellRange.colCount > 1) {
  1746. toastr.warning('请勿同时复制粘贴多列数据');
  1747. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  1748. return;
  1749. }
  1750. if (col.field !== 'doc_code') {
  1751. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  1752. return;
  1753. }
  1754. const datas = [];
  1755. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1756. const curRow = info.cellRange.row + iRow;
  1757. const data = info.sheet.zh_data[curRow];
  1758. if (data) {
  1759. const updateData = {lid: data.lid, pid: data.pid};
  1760. if (data.uuid) {
  1761. updateData.uuid = data.uuid;
  1762. } else {
  1763. updateData.code = data.code;
  1764. updateData.name = data.name;
  1765. updateData.unit = data.unit;
  1766. updateData.unit_price = data.unit_price;
  1767. updateData.pos_name = data.pos_name;
  1768. }
  1769. if (data.custom_define.indexOf('doc_code') === -1) {
  1770. updateData.custom_define = data.custom_define;
  1771. updateData.custom_define.push('doc_code');
  1772. updateData.custom_define = updateData.custom_define.join(',');
  1773. }
  1774. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  1775. datas.push(updateData);
  1776. }
  1777. }
  1778. if (datas.length > 0) {
  1779. postData(window.location.pathname + '/detail/save', datas, function (result) {
  1780. stageIm.loadUpdateDetailData(result);
  1781. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1782. }, function () {
  1783. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1784. })
  1785. }
  1786. }
  1787. },
  1788. deletePress: function (sheet) {
  1789. if (sheet.zh_setting) {
  1790. const datas = [];
  1791. const sel = sheet.getSelections()[0];
  1792. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1793. const col = sheet.zh_setting.cols[iCol];
  1794. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1795. const data = sheet.zh_data[iRow];
  1796. if (col.field === 'doc_code') {
  1797. const updateData = {lid: data.lid};
  1798. if (data.uuid) {
  1799. updateData.uuid = data.uuid;
  1800. updateData.custom_define = data.custom_define;
  1801. updateData.doc_code = '';
  1802. datas.push(updateData);
  1803. }
  1804. }
  1805. }
  1806. }
  1807. if (datas.length > 0) {
  1808. postData(window.location.pathname + '/detail/save', datas, function (result) {
  1809. stageIm.loadUpdateDetailData(result);
  1810. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  1811. }, function () {
  1812. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  1813. });
  1814. }
  1815. }
  1816. },
  1817. dragFillBlock: function (e, info) {
  1818. info.cancel = true;
  1819. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  1820. const sel = info.sheet.getSelections()[0];
  1821. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  1822. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  1823. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  1824. if (text === '') return;
  1825. const regRst = /(\d+)$/g.exec(text), datas = [];
  1826. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  1827. const curRow = info.fillRange.row + iRow;
  1828. const data = info.sheet.zh_data[curRow];
  1829. if (data) {
  1830. const updateData = {lid: data.lid};
  1831. if (data.uuid) {
  1832. updateData.uuid = data.uuid;
  1833. } else {
  1834. updateData.code = data.code;
  1835. updateData.name = data.name;
  1836. updateData.unit = data.unit;
  1837. updateData.unit_price = data.unit_price;
  1838. updateData.pos_name = data.pos_name;
  1839. }
  1840. if (regRst) {
  1841. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  1842. } else {
  1843. updateData.doc_code = text.replace('\n', '');
  1844. }
  1845. if (data.custom_define.indexOf('doc_code') === -1) {
  1846. updateData.custom_define = data.custom_define;
  1847. updateData.custom_define.push('doc_code');
  1848. updateData.custom_define = updateData.custom_define.join(',');
  1849. }
  1850. datas.push(updateData);
  1851. }
  1852. }
  1853. if (datas.length > 0) {
  1854. postData(window.location.pathname + '/detail/save', datas, function (result) {
  1855. stageIm.loadUpdateDetailData(result);
  1856. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  1857. }, function () {
  1858. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  1859. })
  1860. }
  1861. },
  1862. };
  1863. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  1864. if (!readOnly) {
  1865. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  1866. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  1867. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  1868. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  1869. }
  1870. this._initImTypeSetRela();
  1871. this._initModifyDetail();
  1872. // 草图相关
  1873. this._initImageRela();
  1874. this.reBuildImData();
  1875. }
  1876. _initImTypeSetRela() {
  1877. const self = this;
  1878. const gatherConfirmPopover = {
  1879. reBind: function (obj, eventName, fun) {
  1880. obj.unbind(eventName);
  1881. obj.bind(eventName, fun);
  1882. },
  1883. check: function (pos, hint, okCallback) {
  1884. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  1885. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  1886. this.reBind(cancelObj, 'click', function () {
  1887. confirmObj.hide();
  1888. });
  1889. this.reBind(okObj, 'click', function () {
  1890. okCallback();
  1891. confirmObj.hide();
  1892. });
  1893. hintObj.text(hint);
  1894. confirmObj.css("top", pos.y).css("left", pos.x).show();
  1895. }
  1896. };
  1897. this.gsTree = stageIm.getGsTree();
  1898. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  1899. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  1900. jlCol.title = '本期计量金额';
  1901. SpreadJsObj.reLoadSheetHeader(self.sheet);
  1902. $('#type-title-contract').text('本期合同计量金额');
  1903. $('#type-title-qc').text('本期变更计量金额');
  1904. } else {
  1905. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  1906. jlCol.title = '本期计量数量';
  1907. SpreadJsObj.reLoadSheetHeader(self.sheet);
  1908. $('#type-title-contract').text('本期合同计量数量');
  1909. $('#type-title-qc').text('本期变更计量数量');
  1910. }
  1911. if (stage.im_type === imType.bb.value) {
  1912. $('#show-jldy').parent().show();
  1913. $('#jldy').parent().show();
  1914. $('#show-xm-name').parent().hide();
  1915. $('#xm-name').parent().hide();
  1916. } else {
  1917. $('#show-jldy').parent().hide();
  1918. $('#jldy').parent().hide();
  1919. $('#show-xm-name').parent().show();
  1920. $('#xm-name').parent().show();
  1921. }
  1922. // 选择中间计量模式
  1923. $('div[name="im-type"]').click(function () {
  1924. function chooseType(obj) {
  1925. obj.style.cursor = 'default';
  1926. $(obj).children().addClass('text-primary');
  1927. $(obj).addClass('border-primary');
  1928. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  1929. }
  1930. function validType(obj) {
  1931. obj.style.cursor = 'pointer';
  1932. $(obj).children().removeClass('text-primary');
  1933. $(obj).removeClass('border-primary');
  1934. $('i', obj).remove();
  1935. }
  1936. if (this.style.cursor === 'pointer') {
  1937. const typeArr = $('div[name="im-type"]');
  1938. for (const t of typeArr) {
  1939. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  1940. chooseType(t);
  1941. } else {
  1942. validType(t)
  1943. }
  1944. }
  1945. }
  1946. });
  1947. $('#choose').on('show.bs.modal', function () {
  1948. function chooseType(obj) {
  1949. obj.style.cursor = 'default';
  1950. $(obj).children().addClass('text-primary');
  1951. $('i', obj).remove();
  1952. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  1953. }
  1954. function validType(obj) {
  1955. obj.style.cursor = 'pointer';
  1956. $(obj).children().removeClass('text-primary');
  1957. $('i', obj).remove();
  1958. }
  1959. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  1960. const typeArr = $('div[name="im-type"]');
  1961. for (const t of typeArr) {
  1962. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  1963. chooseType(t);
  1964. } else {
  1965. validType(t)
  1966. }
  1967. }
  1968. });
  1969. // 提交 中间计量模式
  1970. $('#choose-ok').click(() => {
  1971. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  1972. return it.style.cursor !== 'pointer';
  1973. });
  1974. const data = {
  1975. im_type: parseInt($(chooseType).attr('im-type')),
  1976. im_pre: $('#im-pre').val(),
  1977. };
  1978. postData(window.location.pathname + '/detail/build', data, function (result) {
  1979. stage.im_type = data.im_type;
  1980. stage.im_pre = data.im_pre;
  1981. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  1982. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  1983. jlCol.title = '本期计量金额';
  1984. SpreadJsObj.reLoadSheetHeader(self.sheet);
  1985. $('#type-title-contract').text('本期合同计量金额');
  1986. $('#type-title-qc').text('本期变更计量金额');
  1987. } else {
  1988. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  1989. jlCol.title = '本期计量数量';
  1990. SpreadJsObj.reLoadSheetHeader(self.sheet);
  1991. $('#type-title-contract').text('本期合同计量数量');
  1992. $('#type-title-qc').text('本期变更计量数量');
  1993. }
  1994. if (stage.im_type === imType.bb.value) {
  1995. $('#show-jldy').parent().show();
  1996. $('#jldy').parent().show();
  1997. $('#show-xm-name').parent().hide();
  1998. $('#xm-name').parent().hide();
  1999. } else {
  2000. $('#show-jldy').parent().hide();
  2001. $('#jldy').parent().hide();
  2002. $('#show-xm-name').parent().show();
  2003. $('#xm-name').parent().show();
  2004. }
  2005. // 加载生成数据
  2006. self.reBuildImData();
  2007. $('#choose').modal('hide');
  2008. });
  2009. });
  2010. // 显示树结构信息
  2011. $('#choose2').on('shown.bs.modal', function () {
  2012. if (!self.gsSpread) {
  2013. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  2014. const setting = {
  2015. cols: [
  2016. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  2017. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  2018. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2019. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  2020. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  2021. ],
  2022. headRows: 1,
  2023. emptyRows: 0,
  2024. headRowHeight: [32],
  2025. defaultRowHeight: 21,
  2026. headerFont: '12px 微软雅黑',
  2027. font: '12px 微软雅黑',
  2028. };
  2029. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  2030. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  2031. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  2032. function checkParent(node) {
  2033. const parent = self.gsTree.getParent(node);
  2034. if (parent) {
  2035. return parent.check ? parent.check : checkParent(parent);
  2036. } else {
  2037. return false;
  2038. }
  2039. }
  2040. function checkChildren(node) {
  2041. for (const child of node.children) {
  2042. if (child.check) {
  2043. return true;
  2044. } else if (checkChildren(child)) {
  2045. return true;
  2046. }
  2047. }
  2048. return false;
  2049. }
  2050. if (!$('#im-gather-check')[0].checked) { return; }
  2051. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  2052. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  2053. if (sheet.isEditing()) {
  2054. sheet.endEdit(true);
  2055. }
  2056. }
  2057. if (info.sheet.zh_setting) {
  2058. const col = info.sheet.zh_setting.cols[info.col];
  2059. if (col.field !== 'check') {
  2060. return;
  2061. }
  2062. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  2063. const node = sortData[info.row];
  2064. if (!node.check) {
  2065. if (checkParent(node)) {
  2066. const rect = info.sheet.getCellRect(info.row, info.col);
  2067. gatherConfirmPopover.check({
  2068. x: rect.x + rect.width / 2 + 25,
  2069. y: rect.y + rect.height / 2 + 3,
  2070. }, '父项已勾选,继续将取消父项勾选。', function () {
  2071. node.check = true;
  2072. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  2073. const rows = [self.gsTree.nodes.indexOf(node)];
  2074. for (const p of parents) {
  2075. if (p.check) {
  2076. p.check = false;
  2077. rows.push(self.gsTree.nodes.indexOf(p));
  2078. }
  2079. }
  2080. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2081. });
  2082. } else if (checkChildren(node)) {
  2083. const rect = info.sheet.getCellRect(info.row, info.col);
  2084. gatherConfirmPopover.check({
  2085. x: rect.x + rect.width / 2 + 25,
  2086. y: rect.y + rect.height / 2 + 3,
  2087. }, '子项已勾选,继续将取消子项勾选。', function () {
  2088. node.check = true;
  2089. const posterity = self.gsTree.getPosterity(node);
  2090. const rows = [self.gsTree.nodes.indexOf(node)];
  2091. for (const p of posterity) {
  2092. if (p.check) {
  2093. rows.push(self.gsTree.nodes.indexOf(p));
  2094. p.check = false;
  2095. }
  2096. }
  2097. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2098. });
  2099. } else {
  2100. node.check = true;
  2101. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2102. }
  2103. } else {
  2104. node.check = false;
  2105. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2106. }
  2107. }
  2108. });
  2109. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2110. for (const node of self.gsTree.datas) {
  2111. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2112. }
  2113. SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  2114. self.gsTree.expandByLevel(4);
  2115. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  2116. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  2117. } else {
  2118. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2119. for (const node of self.gsTree.datas) {
  2120. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2121. }
  2122. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  2123. }
  2124. });
  2125. // 提交 高级设置
  2126. $('#choose2-ok').click(() => {
  2127. if (!self.gsTree) { return; }
  2128. const nodes = [];
  2129. for (const node of self.gsTree.datas) {
  2130. if (node.check) {
  2131. nodes.push(node.id);
  2132. }
  2133. }
  2134. const data = {
  2135. im_gather: $('#im-gather-check')[0].checked,
  2136. im_gather_node: nodes.join(','),
  2137. };
  2138. postData(window.location.pathname + '/detail/adv', data, function (result) {
  2139. stage.im_gather = data.im_gather;
  2140. stage.im_gather_node = data.im_gather_node;
  2141. $('#choose2').modal('hide');
  2142. });
  2143. });
  2144. }
  2145. _initModifyDetail() {
  2146. const self = this;
  2147. // 编辑
  2148. $('#edit-detail').click(function () {
  2149. $(this).hide();
  2150. $('#save-detail').show();
  2151. $('#cancel-detail').show();
  2152. $('#detail-show').hide();
  2153. $('#detail-edit').show();
  2154. });
  2155. // 保存
  2156. $('#save-detail').click(() => {
  2157. function check(field, obj, org, update) {
  2158. const newValue = obj.val();
  2159. if (!org[field]) {
  2160. if (newValue !== '') {
  2161. update[field] = newValue;
  2162. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  2163. }
  2164. } else if (newValue !== org[field]){
  2165. update[field] = newValue;
  2166. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  2167. }
  2168. }
  2169. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2170. const updateData = {lid: data.lid, pid: data.pid};
  2171. if (data.uuid) {
  2172. updateData.uuid = data.uuid;
  2173. updateData.custom_define = data.custom_define;
  2174. } else {
  2175. updateData.code = data.code;
  2176. updateData.name = data.name;
  2177. updateData.unit = data.unit;
  2178. updateData.unit_price = data.unit_price;
  2179. updateData.pos_name = data.pos_name;
  2180. updateData.custom_define = [];
  2181. }
  2182. check('bw', $('#bw-name'), data, updateData);
  2183. check('peg', $('#peg'), data, updateData);
  2184. check('xm', $('#xm'), data, updateData);
  2185. check('position', $('#position'), data, updateData);
  2186. check('jldy', $('#jldy'), data, updateData);
  2187. check('drawing_code', $('#drawing_code'), data, updateData);
  2188. check('calc-memo', $('#calc-memo'), data, updateData);
  2189. updateData.custom_define = updateData.custom_define.join(',');
  2190. // updateData.bw = $('#bw-name').val();
  2191. // updateData.peg = $('#peg').val();
  2192. // updateData.xm = $('#xm-name').val();
  2193. // updateData.position = $('#position').val();
  2194. // updateData.jldy = $('#jldy').val();
  2195. // updateData.drawing_code = $('#drawing-code').val();
  2196. // updateData.calc_memo = $('#calc-memo').val();
  2197. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2198. stageIm.loadUpdateDetailData(result);
  2199. self.reLoadDetailData();
  2200. });
  2201. });
  2202. // 取消
  2203. $('#cancel-detail').click(() => {
  2204. self.reLoadDetailData();
  2205. });
  2206. }
  2207. _initImageRela() {
  2208. const self = this;
  2209. function setdraggrable(){
  2210. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  2211. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  2212. stop: function( event, ui ) {
  2213. }
  2214. });
  2215. }
  2216. // 移动图片
  2217. const moveImageItem = function (ev) {
  2218. const item = this;
  2219. const view = $('.img-view')[0];
  2220. let oEvent = ev;
  2221. // 浏览器有一些图片的默认事件,这里要阻止
  2222. oEvent.preventDefault();
  2223. let disX = oEvent.clientX - item.offsetLeft;
  2224. let disY = oEvent.clientY - item.offsetTop;
  2225. view.onmousemove = function (ev) {
  2226. oEvent = ev;
  2227. oEvent.preventDefault();
  2228. let x = oEvent.clientX -disX;
  2229. let y = oEvent.clientY -disY;
  2230. // 图形移动的边界判断
  2231. x = x <= 0 ? 0 : x;
  2232. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  2233. y = y <= 0 ? 0 : y;
  2234. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  2235. item.style.left = x + 'px';
  2236. item.style.top = y + 'px';
  2237. };
  2238. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  2239. view.onmouseleave = function () {
  2240. view.onmousemove = null;
  2241. view.onmouseup = null;
  2242. };
  2243. // 鼠标弹起后停止移动
  2244. view.onmouseup=function() {
  2245. view.onmousemove = null;
  2246. view.onmouseup = null;
  2247. };
  2248. };
  2249. const removeImageItem = function () {
  2250. $(this).parent().remove();
  2251. };
  2252. // 加载草图组成
  2253. $('#edit-img').on('show.bs.modal', function () {
  2254. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2255. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  2256. const html = [];
  2257. for (const item of items) {
  2258. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  2259. html.push('<div class="img-item" style="' + itemStyle + '">');
  2260. html.push('<div class="img-bar">');
  2261. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  2262. html.push('</div>');
  2263. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  2264. html.push('</div>');
  2265. }
  2266. $('.img-view').html(html.join(''));
  2267. $('.img-bar').click(removeImageItem);
  2268. setdraggrable();
  2269. });
  2270. // 上传图片
  2271. $('#upload-img').click(function () {
  2272. $('#upload-img-file').trigger('click');
  2273. });
  2274. $('#upload-img-file').change(function () {
  2275. const file = this.files[0];
  2276. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  2277. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  2278. if (!imgStr.test(ext)) {
  2279. toastr.error('请上传正确的图片格式文件');
  2280. return
  2281. }
  2282. if ($(this).val()) {
  2283. const formData = new FormData();
  2284. formData.append('file', this.files[0]);
  2285. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  2286. const html = [];
  2287. html.push('<div class="img-item">');
  2288. html.push('<div class="img-bar">');
  2289. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  2290. html.push('</div>');
  2291. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  2292. html.push('</div>');
  2293. $('.img-view').append(html.join(''));
  2294. $('.img-bar').click(removeImageItem);
  2295. setdraggrable();
  2296. $('#upload-img-file').val('');
  2297. });
  2298. }
  2299. });
  2300. // 保存草图修改结果
  2301. $('#edit-img-ok').click(function () {
  2302. // 记录上传的图片的信息
  2303. const items = $('.img-item');
  2304. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2305. if (items.length > 0) {
  2306. const itemInfo = [];
  2307. for (const item of items) {
  2308. const itemData = {
  2309. src: $('img', item).attr('src'),
  2310. left: item.style.left,
  2311. top: item.style.top,
  2312. width: item.style.width,
  2313. height: item.style.height,
  2314. };
  2315. itemInfo.push(itemData);
  2316. }
  2317. // 获取合并好的图片数据
  2318. const canvas = document.createElement('canvas');
  2319. const view = $('.img-view')[0];
  2320. canvas.height = view.clientHeight;
  2321. canvas.width = view.clientWidth;
  2322. const ctx = canvas.getContext('2d');
  2323. ctx.fillStyle = '#ffffff';
  2324. ctx.fillRect(0, 0, canvas.width, canvas.height);
  2325. for (const b of $('.img-item')) {
  2326. const pos = $(b).position();
  2327. const img = $('img', b)[0];
  2328. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  2329. }
  2330. // 生成上传数据
  2331. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid};
  2332. if (data.uuid) {
  2333. updateData.uuid = data.uuid;
  2334. } else {
  2335. updateData.code = data.code;
  2336. updateData.name = data.name;
  2337. updateData.unit = data.unit;
  2338. updateData.unit_price = data.unit_price;
  2339. updateData.pos_name = data.pos_name;
  2340. }
  2341. if (data.custom_define.indexOf('calc_img') === -1) {
  2342. updateData.custom_define = data.custom_define;
  2343. updateData.custom_define.push('calc_img');
  2344. updateData.custom_define = updateData.custom_define.join(',');
  2345. }
  2346. updateData.img = canvas.toDataURL('image/png');
  2347. updateData.imgInfo = itemInfo;
  2348. postData(window.location.pathname + '/detail/merge-img', updateData, function (result) {
  2349. data.calc_img = result.calc_img;
  2350. data.calc_img_org = result.calc_img_org;
  2351. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2352. $('#show-calc-img').attr('src', calcImgSrc);
  2353. $('#calc-img').attr('src', calcImgSrc);
  2354. $('#view-calc-img').attr('src', calcImgSrc);
  2355. $('#edit-img').modal('hide');
  2356. });
  2357. } else if (data.calc_img) {
  2358. postData(window.location.pathname + '/detail/merge-img', {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid}, function (result) {
  2359. data.calc_img = result.calc_img;
  2360. data.calc_img_org = result.calc_img_org;
  2361. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2362. $('#show-calc-img').attr('src', calcImgSrc);
  2363. $('#calc-img').attr('src', calcImgSrc);
  2364. $('#view-calc-img').attr('src', calcImgSrc);
  2365. $('#edit-img').modal('hide');
  2366. });
  2367. }
  2368. });
  2369. }
  2370. reBuildImData() {
  2371. const imData = stageIm.buildImData();
  2372. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2373. this.reLoadDetailData();
  2374. }
  2375. loadStageLedgerUpdateData(data) {
  2376. const imData = stageIm.loadUpdateLedgerData(data);
  2377. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2378. this.reLoadDetailData();
  2379. }
  2380. loadStagePosUpdateData(data) {
  2381. const imData = stageIm.loadUpdatePosData(data);
  2382. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2383. this.reLoadDetailData();
  2384. }
  2385. loadStageChangeUpdateData(data) {
  2386. const imData = stageIm.loadUpdateChangeData(data);
  2387. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2388. this.reLoadDetailData();
  2389. }
  2390. reLoadDetailData() {
  2391. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  2392. if (data) {
  2393. $('#edit-detail').show();
  2394. $('#modify-img').show();
  2395. } else {
  2396. $('#edit-detail').hide();
  2397. $('#modify-img').hide();
  2398. }
  2399. $('#save-detail').hide();
  2400. $('#cancel-detail').hide();
  2401. $('#detail-show').show();
  2402. $('#detail-edit').hide();
  2403. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  2404. $('#show-contract-jl').text(contractJl);
  2405. $('#contract-jl').val(contractJl);
  2406. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  2407. $('#show-qc-jl').text(qcJl);
  2408. $('#qc-jl').val(qcJl);
  2409. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  2410. $('#show-bgl-code').text(bglCode);
  2411. $('#bgl-code').val(bglCode);
  2412. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  2413. $('#show-bgl-drawing-code').text(bglDrawingCode);
  2414. $('#bgl-drawing-code').val(bglDrawingCode);
  2415. const bwName = data && data.bw ? data.bw : '';
  2416. $('#show-bw-name').text(bwName);
  2417. $('#bw-name').val(bwName);
  2418. const position = data && data.position ? data.position : '';
  2419. $('#show-position').text(position);
  2420. $('#position').val(position);
  2421. const peg = data && data.peg ? data.peg : '';
  2422. $('#show-peg').text(peg);
  2423. $('#peg').val(peg);
  2424. const xmName = data && data.xm ? data.xm: '';
  2425. $('#show-xm-name').text(xmName);
  2426. $('#xm-name').val(xmName);
  2427. const jldy = data && data.jldy ? data.jldy: '';
  2428. $('#show-jldy').text(jldy);
  2429. $('#jldy').val(jldy);
  2430. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  2431. $('#show-drawing-code').text(drawingCode);
  2432. $('#drawing-code').val(drawingCode);
  2433. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  2434. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  2435. $('#calc-memo').val(calcMemo);
  2436. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2437. $('#show-calc-img').attr('src', calcImgSrc);
  2438. $('#calc-img').attr('src', calcImgSrc);
  2439. $('#view-calc-img').attr('src', calcImgSrc);
  2440. }
  2441. }
  2442. class CheckedChange {
  2443. constructor (setting) {
  2444. const self = this;
  2445. this.changeSpreadSetting = {
  2446. cols: [
  2447. {title: '变更令号', colSpan: '1', rowSpan: '1', field: 'p_code', hAlign: 0, width: 100, formatter: '@'},
  2448. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  2449. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  2450. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  2451. ],
  2452. emptyRows: 0,
  2453. headRows: 1,
  2454. headRowHeight: [32],
  2455. defaultRowHeight: 21,
  2456. headerFont: '12px 微软雅黑',
  2457. font: '12px 微软雅黑',
  2458. readOnly: true,
  2459. };
  2460. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  2461. this.changeSheet = this.changeSpread.getActiveSheet();
  2462. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  2463. this.changeBillsSpreadSetting = {
  2464. cols: [
  2465. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  2466. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, type: 'Number'},
  2467. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2468. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  2469. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@'},
  2470. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@'},
  2471. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  2472. ],
  2473. emptyRows: 0,
  2474. headRows: 1,
  2475. headRowHeight: [32],
  2476. defaultRowHeight: 21,
  2477. headerFont: '12px 微软雅黑',
  2478. font: '12px 微软雅黑',
  2479. readOnly: true
  2480. };
  2481. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  2482. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  2483. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  2484. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  2485. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  2486. if (change.cid === self.curChangeId) { return; }
  2487. self.curChangeId = change.cid;
  2488. if (change.detail) {
  2489. self.loadChangeDetailData();
  2490. } else {
  2491. postData(window.location.pathname + '/change/detail', {cid: change.cid}, function (result) {
  2492. change.detail = result;
  2493. self.analyzeChange(change);
  2494. self.loadChangeDetailData();
  2495. });
  2496. }
  2497. });
  2498. this.changes = null;
  2499. this.reloadChangeData();
  2500. setting.reloadObj.click(function() {
  2501. self.reloadChangeData();
  2502. });
  2503. }
  2504. loadChangeDetailData() {
  2505. const change = SpreadJsObj.getSelectObject(this.changeSheet);
  2506. if (change) {
  2507. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
  2508. } else {
  2509. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
  2510. }
  2511. }
  2512. refresh() {
  2513. this.changeSpread.refresh();
  2514. this.changeBillsSpread.refresh();
  2515. }
  2516. reloadChangeData() {
  2517. const self = this;
  2518. postData(window.location.pathname + '/change/data', null, function (result) {
  2519. self.changes = result.changes;
  2520. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  2521. self.changeSheet.setSelection(0, 0, 1, 1);
  2522. if (self.changes.length > 0) self.analyzeChange(result.changes[0]);
  2523. self.loadChangeDetailData();
  2524. });
  2525. }
  2526. analyzeChange(change) {
  2527. change.bills = change.detail.bills;
  2528. for (const b of change.bills) {
  2529. console.log(b);
  2530. const aub = change.detail.addUsedBills.find(function (x) {
  2531. return x.id === b.id;
  2532. });
  2533. if (aub) {
  2534. b.used_qty = aub.used_qty;
  2535. }
  2536. b.qty = _.toNumber(b.samount);
  2537. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  2538. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  2539. b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
  2540. b.cur_qty = 0;
  2541. for (const p of b.pos) {
  2542. p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
  2543. b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
  2544. }
  2545. }
  2546. }
  2547. }
  2548. // 展开收起附件
  2549. $('a', '.right-nav').bind('click', function () {
  2550. //const main = $('#main-view'), tool = $('#tools-view');
  2551. const tab = $(this), tabPanel = $(tab.attr('content'));
  2552. if (!tab.hasClass('active')) {
  2553. $('a', '.side-menu').removeClass('active');
  2554. $('.tab-content .tab-select-show').removeClass('active');
  2555. tab.addClass('active');
  2556. tabPanel.addClass('active');
  2557. showSideTools(tab.hasClass('active'));
  2558. if (tab.attr('content') === '#search' && !searchLedger) {
  2559. searchLedger = $.billsSearch({
  2560. selector: '#search',
  2561. searchSpread: slSpread,
  2562. searchRangeStr: '项目节编号/名称',
  2563. searchOver: true,
  2564. searchEmpty: true,
  2565. resultSpreadSetting: {
  2566. cols: [
  2567. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@'},
  2568. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  2569. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  2570. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  2571. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2572. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  2573. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  2574. ],
  2575. emptyRows: 0,
  2576. headRows: 1,
  2577. headRowHeight: [32],
  2578. defaultRowHeight: 21,
  2579. headerFont: '12px 微软雅黑',
  2580. font: '12px 微软雅黑',
  2581. selectedBackColor: '#fffacd',
  2582. },
  2583. afterLocated: function () {
  2584. stagePosSpreadObj.loadCurPosData();
  2585. },
  2586. checkLess: function (node) {
  2587. if (node.quantity) {
  2588. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  2589. } else if (node.total_price) {
  2590. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  2591. }
  2592. },
  2593. checkOver: function (node) {
  2594. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  2595. if (posRange.length > 0) {
  2596. for (const p of posRange) {
  2597. if (p.end_contract_qty > p.quantity) return true;
  2598. }
  2599. return false;
  2600. } else if (node.end_gather_qty) {
  2601. return !node.quantity || Math.abs(node.end_gather_qty) > Math.abs(ZhCalc.add(node.quantity, node.end_qc_qty));
  2602. } else if (node.end_gather_tp) {
  2603. return !node.total_price || Math.abs(node.end_gather_tp) > Math.abs(ZhCalc.add(node.total_price, node.end_qc_tp));
  2604. }
  2605. },
  2606. checkEmpty: function (node) {
  2607. if (node.quantity) {
  2608. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  2609. } else if (node.total_price) {
  2610. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  2611. }
  2612. },
  2613. });
  2614. searchLedger.spread.refresh();
  2615. }
  2616. if (tab.attr('content') === '#fujian') {
  2617. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2618. getNodeList(node.id);
  2619. }
  2620. if (tab.attr('content') === '#zhongjian') {
  2621. if (!detail) {
  2622. detail = new Detail($('#detail-spread'));
  2623. detail.spread.refresh();
  2624. $('#zhongjian .sjs-bottom').height('400px');
  2625. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2626. } else {
  2627. detail.spread.refresh();
  2628. $('#zhongjian .sjs-bottom').height('400px');
  2629. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2630. }
  2631. }
  2632. if (tab.attr('content') === '#checked-change') {
  2633. if (!checkedChanges) {
  2634. checkedChanges = new CheckedChange({
  2635. changeObj: $('#cc-spread'),
  2636. changeBillsObj: $('#ccb-spread'),
  2637. reloadObj: $('#refresh-cc'),
  2638. });
  2639. checkedChanges.refresh();
  2640. } else {
  2641. $('#ccb-spread').height('400px');
  2642. checkedChanges.refresh();
  2643. }
  2644. }
  2645. if (tab.attr('content') === '#error-list') {
  2646. errorList.spread.refresh();
  2647. }
  2648. } else {
  2649. tab.removeClass('active');
  2650. tabPanel.removeClass('active');
  2651. showSideTools(tab.hasClass('active'));
  2652. }
  2653. slSpread.refresh();
  2654. spSpread.refresh();
  2655. });
  2656. // 切换附件里节点和所有附件
  2657. $('#fujian .nav-link').on('click', function () {
  2658. const tabPanel = $(this).attr('fujian-content');
  2659. if (tabPanel !== 'syfujian') {
  2660. $('#showPage').hide();
  2661. } else {
  2662. $('#showPage').show();
  2663. }
  2664. $('#showAttachment').hide();
  2665. });
  2666. // 上传附件
  2667. $('#upload-file-btn').click(function () {
  2668. const files = $('#upload-file')[0].files;
  2669. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2670. const formData = new FormData();
  2671. formData.append('lid', node.id);
  2672. for (const file of files) {
  2673. if (file === undefined) {
  2674. toastr.error('未选择上传文件!');
  2675. return false;
  2676. }
  2677. const filesize = file.size;
  2678. if (filesize > 30 * 1024 * 1024) {
  2679. toastr.error('存在上传文件大小过大!');
  2680. return false;
  2681. }
  2682. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  2683. if (whiteList.indexOf(fileext) === -1) {
  2684. toastr.error('只能上传指定格式的附件!');
  2685. return false;
  2686. }
  2687. formData.append('size', filesize);
  2688. formData.append('file[]', file);
  2689. }
  2690. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  2691. $('#upload').modal('hide');
  2692. // 插入到attData中
  2693. attData = data.concat(attData);
  2694. // 重新生成List
  2695. getAllList();
  2696. getNodeList(node.id);
  2697. }, function () {
  2698. toastr.error('附件上传失败');
  2699. });
  2700. $('#upload-file').val('');
  2701. });
  2702. // 获取附件信息
  2703. $('body').on('click', '.list-table a', function () {
  2704. const fid = $(this).attr('file-id');
  2705. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  2706. return;
  2707. }
  2708. const att = attData.find(function (item) {
  2709. return item.id === parseInt(fid);
  2710. });
  2711. $('#edit-att').hide();
  2712. $('#show-att').show();
  2713. if (att !== undefined) {
  2714. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  2715. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  2716. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  2717. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  2718. $('#show-att tr').eq(3).children('td').eq(0).text(att.username);
  2719. $('#show-att tr').eq(3).children('td').eq(1).text(att.in_time);
  2720. $('#show-att tr').eq(4).children('td').text(att.remark);
  2721. if (parseInt(userID) === att.uid) {
  2722. $('#btn-att').show();
  2723. $('#btn-att a').eq(1).show();
  2724. $('#btn-att a').eq(0).hide();
  2725. $('#btn-att a').eq(2).hide();
  2726. $('#btn-att a').eq(3).hide();
  2727. } else {
  2728. $('#btn-att').hide();
  2729. $('#btn-att a').eq(1).hide();
  2730. $('#btn-att a').eq(0).hide();
  2731. $('#btn-att a').eq(2).hide();
  2732. $('#btn-att a').eq(3).hide();
  2733. }
  2734. $('#showAttachment').attr('file-id', fid);
  2735. $('#showAttachment').show();
  2736. } else {
  2737. $('#showAttachment').hide();
  2738. $('#showAttachment').attr('file-id', '');
  2739. toastr.error('附件信息获取失败');
  2740. }
  2741. });
  2742. $('body').on('click', '#btn-att a', function () {
  2743. const content = $(this).attr('content');
  2744. const fid = $('#showAttachment').attr('file-id');
  2745. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2746. if (content === 'edit') {
  2747. $('#btn-att a').eq(1).hide();
  2748. $('#btn-att a').eq(0).show();
  2749. $('#btn-att a').eq(2).show();
  2750. $('#btn-att a').eq(3).show();
  2751. $('#show-att').hide();
  2752. $('#edit-att').show();
  2753. const att = attData.find(function (item) {
  2754. return item.id === parseInt(fid);
  2755. });
  2756. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  2757. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  2758. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  2759. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  2760. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  2761. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  2762. } else if (content === 'cancel') {
  2763. $('#show-att').show();
  2764. $('#edit-att').hide();
  2765. $('#btn-att a').eq(1).show();
  2766. $('#btn-att a').eq(0).hide();
  2767. $('#btn-att a').eq(2).hide();
  2768. $('#btn-att a').eq(3).hide();
  2769. } else if (content === 'save') {
  2770. const formData = new FormData();
  2771. formData.append('id', fid);
  2772. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  2773. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  2774. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  2775. const file = $('#change-att-btn')[0];
  2776. if (file.files[0] !== undefined) {
  2777. const filesize = file.files[0].size;
  2778. formData.append('size', filesize);
  2779. formData.append('file', file.files[0]);
  2780. }
  2781. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  2782. // 替换到attData中
  2783. const att_index = attData.findIndex(function (item) {
  2784. return item.id === parseInt(fid);
  2785. });
  2786. attData.splice(att_index, 1, data);
  2787. // 重新生成List
  2788. getAllList(parseInt($('#currentPage').text()));
  2789. getNodeList(node.id);
  2790. $('#show-att').show();
  2791. $('#edit-att').hide();
  2792. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  2793. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  2794. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  2795. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  2796. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  2797. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  2798. $('#show-att tr').eq(4).children('td').text(data.remark);
  2799. $('#btn-att a').eq(1).show();
  2800. $('#btn-att a').eq(0).hide();
  2801. $('#btn-att a').eq(2).hide();
  2802. $('#btn-att a').eq(3).hide();
  2803. }, function () {
  2804. toastr.error('附件上传失败');
  2805. });
  2806. $('#change-att-btn').val('');
  2807. } else if (content === 'del') {
  2808. const data = {id: fid};
  2809. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  2810. // 删除到attData中
  2811. const att_index = attData.findIndex(function (item) {
  2812. return item.id === parseInt(fid);
  2813. });
  2814. attData.splice(att_index, 1);
  2815. // 重新生成List
  2816. getAllList();
  2817. getNodeList(node.id);
  2818. $('#showAttachment').hide();
  2819. $('#showAttachment').attr('file-id', '');
  2820. });
  2821. }
  2822. });
  2823. // 替换附件
  2824. $('#change-att-btn').on('change', function () {
  2825. const file = $('#change-att-btn')[0].files[0];
  2826. const name = file.name;
  2827. const filename = name.substring(0, name.lastIndexOf("."));
  2828. const fileext = name.substr(name.indexOf("."));
  2829. const filesize = file.size;
  2830. if (filesize > 10 * 1024 * 1024) {
  2831. toastr.error('文件大小过大!');
  2832. $('#change-att-btn').val('');
  2833. return false;
  2834. }
  2835. if (whiteList.indexOf(fileext) === -1) {
  2836. toastr.error('只能上传指定格式的附件!');
  2837. $('#change-att-btn').val('');
  2838. return false;
  2839. }
  2840. $('#edit-att .form-group').eq(0).find('input').val(filename);
  2841. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  2842. });
  2843. // 切换页数
  2844. $('.page-select').on('click', function () {
  2845. const totalPageNum = parseInt($('#totalPage').text());
  2846. const lastPageNum = parseInt($('#currentPage').text());
  2847. const status = $(this).attr('content');
  2848. if (status === 'pre' && lastPageNum > 1) {
  2849. getAllList(lastPageNum-1);
  2850. $('#showAttachment').hide();
  2851. } else if (status === 'next' && lastPageNum < totalPageNum) {
  2852. getAllList(lastPageNum+1);
  2853. $('#showAttachment').hide();
  2854. }
  2855. });
  2856. // 显示层次
  2857. (function (select, sheet) {
  2858. $(select).click(function () {
  2859. if (!sheet.zh_tree) return;
  2860. const tag = $(this).attr('tag');
  2861. const tree = sheet.zh_tree;
  2862. switch (tag) {
  2863. case "1":
  2864. case "2":
  2865. case "3":
  2866. case "4":
  2867. case "5":
  2868. tree.expandByLevel(parseInt(tag));
  2869. SpreadJsObj.refreshTreeRowVisible(sheet);
  2870. break;
  2871. case "last":
  2872. tree.expandByCustom(() => { return true; });
  2873. SpreadJsObj.refreshTreeRowVisible(sheet);
  2874. break;
  2875. case "leafXmj":
  2876. tree.expandToLeafXmj();
  2877. SpreadJsObj.refreshTreeRowVisible(sheet);
  2878. break;
  2879. case "curMeasure":
  2880. tree.expandByCustom(function (node) {
  2881. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  2882. if (node[field]) {
  2883. return true;
  2884. }
  2885. }
  2886. return false;
  2887. });
  2888. SpreadJsObj.refreshTreeRowVisible(sheet);
  2889. break;
  2890. }
  2891. });
  2892. })('a[name=showLevel]', slSpread.getActiveSheet());
  2893. const dataChecker = DataChecker({
  2894. checkUrl: window.location.pathname + '/check',
  2895. completeData: function (data) {
  2896. stagePos.updateDatas({pos: data.source.pos});
  2897. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  2898. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2899. stagePosSpreadObj.loadCurPosData();
  2900. for (const e of data.error) {
  2901. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  2902. }
  2903. },
  2904. errorList: errorList,
  2905. });
  2906. $('[name=stage-start]').submit(function (e) {
  2907. if (checkAuditorFrom()) {
  2908. $(this).parent().parent().parent().modal('hide');
  2909. dataChecker.checkAndPost(this.action, {});
  2910. $('#hide-all').hide();
  2911. }
  2912. return false;
  2913. });
  2914. $('#audit-check0').submit(function (e) {
  2915. $(this).parent().parent().modal('hide');
  2916. const data = {
  2917. opinion: $('[name=opinion]', this).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  2918. checkType: parseInt($('[name=checkType]', this).val()),
  2919. };
  2920. dataChecker.checkAndPost(this.action, data);
  2921. $('#hide-all').hide();
  2922. return false;
  2923. });
  2924. $('#audit-check2').submit(function (e) {
  2925. $(this).parent().parent().modal('hide');
  2926. const data = {
  2927. opinion: $('[name=opinion]', this).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  2928. checkType: parseInt($('[name=checkType]', this).val()),
  2929. };
  2930. dataChecker.checkAndPost(this.action, data);
  2931. $('#hide-all').hide();
  2932. return false;
  2933. });
  2934. });