stage.js 131 KB

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