stage.js 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025
  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. ];
  33. if (checkTzMeasureType()) {
  34. defaultSetting.splice(0, 1);
  35. }
  36. const settingStr = Cookies.get(ckColSetting);
  37. return settingStr ? JSON.parse(settingStr) : defaultSetting;
  38. }
  39. /**
  40. * 根据列显示设置,调整setting中的列是否显示
  41. * @param setting
  42. * @param customDisplay
  43. */
  44. function customizeStageTreeSetting(setting, customDisplay) {
  45. for (const cd of customDisplay) {
  46. for (const c of setting.cols) {
  47. if (cd.fields.indexOf(c.field) !== -1) {
  48. c.visible = cd.visible;
  49. }
  50. }
  51. }
  52. }
  53. /**
  54. * 初始化 树结构 列事件
  55. * @param setting
  56. */
  57. function initTreeColSettingEvents(setting) {
  58. const Events = {
  59. readOnly: {
  60. measureData: function (node) {
  61. return node.children && node.children.length > 0;
  62. },
  63. },
  64. };
  65. const getEvent = function (eventName) {
  66. const names = eventName.split('.');
  67. let event = Events;
  68. for (let name of names) {
  69. if (event[name]) {
  70. event = event[name];
  71. } else {
  72. return null;
  73. }
  74. }
  75. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  76. return null;
  77. } else {
  78. return event;
  79. }
  80. };
  81. for (const col of setting.cols) {
  82. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  83. col.readOnly = getEvent(col.readOnly);
  84. }
  85. }
  86. }
  87. function needCheckDetail() {
  88. stage.check_detail = true;
  89. $('#check_point').show();
  90. $('#sub-sp-btn').attr('data-target', '#sub-sp3');
  91. $('#sp-done-btn').attr('data-target', '#sub-sp3');
  92. $('#sp-list2-btn').attr('data-target', '#sub-sp3');
  93. }
  94. // 生成所有附件列表
  95. function getAllList(currPageNum = 1) {
  96. // 每页最多几个附件
  97. const pageCount = 11;
  98. // 附件总数
  99. const total = attData.length;
  100. // 总页数
  101. const pageNum = Math.ceil(total/pageCount);
  102. $('#totalPage').text(pageNum);
  103. $('#currentPage').text(currPageNum);
  104. // 当前页附件内容
  105. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  106. let html = '';
  107. for(const att of currPageAttData) {
  108. html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  109. }
  110. $('#alllist-table').html(html);
  111. }
  112. // 生成当前节点列表
  113. function getNodeList(node) {
  114. let html = '';
  115. for(const att of attData) {
  116. if (node === att.lid) {
  117. html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  118. }
  119. }
  120. $('#nodelist-table').html(html);
  121. }
  122. $(document).ready(() => {
  123. // 界面布局
  124. autoFlashHeight();
  125. // 初始化 台账树结构 数据结构
  126. const stageTreeSetting = {
  127. id: 'ledger_id',
  128. pid: 'ledger_pid',
  129. order: 'order',
  130. level: 'level',
  131. rootId: -1,
  132. keys: ['id', 'tender_id', 'ledger_id'],
  133. stageId: 'id',
  134. };
  135. // 台账树结构计算相关设置
  136. stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil'];
  137. stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
  138. 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp'];
  139. stageTreeSetting.calcFun = function (node) {
  140. if (node.children && node.children.length === 0) {
  141. node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
  142. node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
  143. node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty);
  144. node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
  145. node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
  146. }
  147. node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
  148. node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
  149. node.end_contract_tp = ZhCalc.add(node.pre_contract_tp, node.contract_tp);
  150. node.end_qc_tp = ZhCalc.add(node.pre_qc_tp, node.qc_tp);
  151. node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
  152. node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
  153. node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
  154. 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);
  155. };
  156. const stageTree = createNewPathTree('stage', stageTreeSetting);
  157. // 初始化 计量单元 数据结构
  158. const stagePosSetting = {
  159. id: 'id', ledgerId: 'lid',
  160. updateFields: ['contract_qty', 'qc_qty', 'postil'],
  161. };
  162. stagePosSetting.calcFun = function (pos) {
  163. pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
  164. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  165. pos.end_contract_qty = ZhCalc.add(pos.pre_contract_qty, pos.contract_qty);
  166. pos.end_qc_qty = ZhCalc.add(pos.pre_qc_qty, pos.qc_qty);
  167. pos.end_gather_qty = ZhCalc.add(pos.pre_gather_qty, pos.gather_qty);
  168. pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
  169. pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2);
  170. };
  171. const stagePos = new StagePosData(stagePosSetting);
  172. class Changes {
  173. constructor(obj) {
  174. const self = this;
  175. this.obj = obj;
  176. // 初始化 清单编号窗口 参数
  177. this.spreadSetting = {
  178. cols: [
  179. {title: '已用', field: '', width: 45, formatter: '@', cellType: 'image', readOnly: true, hAlign: 1, indent: 14, img: function (data) {
  180. if (data.uamount && !checkZero(data.uamount)) {
  181. return $('#icon-ok')[0];
  182. } else {
  183. return null;
  184. }
  185. }},
  186. {title: '变更令号', field: 'code', width: 100, formatter: '@', readOnly: true, hAlign: 0, },
  187. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true, hAlign: 0,},
  188. {title: '总数量', field: 'b_amount', width: 60, formatter: '@', readOnly: true, hAlign: 2, },
  189. {title: '可变更数量', field: 'vamount', width: 60, readOnly: true, hAlign: 2, getValue: function (data) {return data.vamount ? data.vamount + '' : '0';}},
  190. {title: '本期计量', field: 'uamount', width: 60, formatter: '@', hAlign: 2, type: 'Number', },
  191. ],
  192. emptyRows: 0,
  193. headRows: 1,
  194. headRowHeight: [32],
  195. headerFont: '12px 微软雅黑',
  196. font: '12px 微软雅黑',
  197. getColor: function (sheet, data, col, defaultColor) {
  198. if (col.field === 'uamount') {
  199. if (!data.vamount) {
  200. return (data.uamount && data.uamount > 0) ? '#ff6f5c' : defaultColor;
  201. } else if (data.uamount) {
  202. return data.uamount > data.vamount ? '#ff6f5c' : defaultColor;
  203. } else {
  204. return defaultColor;
  205. }
  206. } else {
  207. return defaultColor;
  208. }
  209. }
  210. };
  211. this.curChangeId = '';
  212. this.spread = SpreadJsObj.createNewSpread($('#change-spread')[0]);
  213. this.firstView = true;
  214. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  215. // 初次显示,需刷新spread界面,保证界面绘制正确
  216. this.obj.bind('shown.bs.modal', function () {
  217. if (self.firstView) {
  218. self.firstView = false;
  219. self.spread.refresh();
  220. }
  221. });
  222. // 切换变更令,加载右侧明细数据
  223. this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  224. const change = SpreadJsObj.getSelectObject(info.sheet);
  225. self._loadChangeDetail(change);
  226. });
  227. // 填写本期计量
  228. this.spread.bind(spreadNS.Events.EditEnded, function (e, info) {
  229. if (info.sheet.zh_setting) {
  230. const col = info.sheet.zh_setting.cols[info.col];
  231. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  232. const node = sortData[info.row];
  233. node[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  234. // 刷新界面
  235. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  236. }
  237. });
  238. this.spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  239. if (info.sheet.zh_setting) {
  240. const sortData = SpreadJsObj.getSortData(info.sheet);
  241. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  242. const curRow = iRow + info.cellRange.row;
  243. const curCol = info.cellRange.col;
  244. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  245. sortData[curRow][col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
  246. }
  247. SpreadJsObj.reLoadRowData(sheet, info.cellRange.row, sel.cellRange.rowCount);
  248. }
  249. });
  250. SpreadJsObj.addDeleteBind(this.spread, function (sheet) {
  251. if (sheet.zh_setting) {
  252. const sel = sheet.getSelections()[0];
  253. const sortData = SpreadJsObj.getSortData(sheet);
  254. // 仅本期计量可删除
  255. if (sel.col === 5 || sel.colCount === 1) {
  256. const col = sheet.zh_setting.cols[sel.col];
  257. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  258. const data = sortData[iRow];
  259. data[col.field] = null;
  260. }
  261. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  262. }
  263. }
  264. });
  265. // 过滤可变更数量为0
  266. $('#filterEmpty').click(function () {
  267. self._filterChange(!this.checked, $('#matchPos')[0].checked);
  268. });
  269. // 匹配编号
  270. $('#matchPos').click(function () {
  271. self._filterChange(!$('#filterEmpty')[0].checked, this.checked);
  272. });
  273. // 展开收起 变更令详细信息
  274. $('#show-bgl-detail').bind('click', function () {
  275. const detail = $('#bgl-detail'), bgl=$('#bgl'), obj=$(this);
  276. if (detail.hasClass('col-4')) {
  277. detail.attr('class', 'col').hide();
  278. bgl.attr('class', 'col-12');
  279. $('a', obj).attr('title', '展开侧栏');
  280. $('i', obj).attr('class', 'fa fa-chevron-left');
  281. self.spread.refresh();
  282. } else {
  283. detail.attr('class', 'col-4').show();
  284. bgl.attr('class', 'col-8');
  285. $('a', obj).attr('title', '收起侧栏');
  286. $('i', obj).attr('class', 'fa fa-chevron-right');
  287. self.spread.refresh();
  288. }
  289. });
  290. // 添加调用变更令
  291. $('#usg-bg-ok').click(function () {
  292. const data = { target: self.callData, change: [] };
  293. for (const c of self.displayChanges) {
  294. if (c.uamount) {
  295. const vamount = (!c.vamount || checkZero(c.vamount)) ? 0 : c.vamount;
  296. if (c.uamount > vamount) {
  297. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  298. return;
  299. }
  300. data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount });
  301. }
  302. }
  303. // 提交数据到后端
  304. postData(window.location.pathname + '/use-change', data, function(result) {
  305. if (result.pos) {
  306. stagePos.loadCurStageData(result.pos.curStageData);
  307. }
  308. const nodes = stageTree.loadPostStageData(result.bills);
  309. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  310. stagePosSpreadObj.loadCurPosData();
  311. needCheckDetail();
  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. changesObj.loadChanges({bills: data});
  440. };
  441. ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
  442. ledgerSpreadSetting.getColor = function (sheet, data, col, defaultColor) {
  443. return data && data.end_contract_qty > data.quantity ? '#f8d7da' : defaultColor;
  444. };
  445. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  446. stageTree.loadDatas(ledgerData);
  447. // stageTree.loadCurStageData(curStageData);
  448. // stageTree.loadPreStageData(preStageData);
  449. // 根据设置 计算 台账树结构
  450. treeCalc.calculateAll(stageTree);
  451. // 绘制界面
  452. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  453. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  454. //初始化所有附件列表
  455. getAllList();
  456. // 初始化 计量单元 Spread
  457. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  458. const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
  459. spCol.readOnly = true;
  460. spCol.cellType = 'activeImageBtn';
  461. spCol.normalImg = '#ellipsis-icon';
  462. spCol.indent = 5;
  463. spCol.showImage = function (data) {
  464. return data !== undefined && data !== null;
  465. };
  466. posSpreadSetting.imageClick = function (data) {
  467. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  468. changesObj.loadChanges({bills: node, pos: data});
  469. };
  470. posSpreadSetting.getColor = function (sheet, data, col, defaultColor) {
  471. return data && data.end_contract_qty > data.quantity ? '#f8d7da' : defaultColor;
  472. };
  473. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  474. const stageTreeSpreadObj = {
  475. loadExprToInput(sheet) {
  476. const sel = sheet.getSelections()[0];
  477. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  478. if (col.type === 'Number') {
  479. const data = SpreadJsObj.getSelectObject(sheet);
  480. if (!data) {
  481. $('#bills-expr').val('').attr('readOnly', true);
  482. return;
  483. }
  484. const nodePos = stagePos.getLedgerPos(data.id);
  485. if (nodePos && nodePos.length > 0) {
  486. $('#bills-expr').val('').attr('readOnly', true);
  487. } else {
  488. $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field])
  489. .attr('readOnly', readOnly || cell.locked());
  490. }
  491. } else {
  492. $('#bills-expr').val('').attr('readOnly', true);
  493. }
  494. },
  495. refreshTreeNodes: function (sheet, nodes) {
  496. const tree = sheet.zh_tree;
  497. if (!tree) { return }
  498. const rows = [];
  499. for (const node of nodes) {
  500. rows.push(tree.nodes.indexOf(node));
  501. }
  502. SpreadJsObj.reLoadRowsData(sheet, rows);
  503. },
  504. editEnded: function (e, info) {
  505. if (info.sheet.zh_setting) {
  506. const col = info.sheet.zh_setting.cols[info.col];
  507. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  508. const node = sortData[info.row], updateData = {};
  509. const orgValue = node[col.field];
  510. let newValue = info.editingText;
  511. if (orgValue == newValue || ((!orgValue || orgValue === '') && (!newValue || newValue === ''))) {
  512. return;
  513. }
  514. if (col.type === 'Number' && newValue && newValue !== '') {
  515. const num = _.toNumber(newValue);
  516. if (num) {
  517. newValue = num;
  518. } else {
  519. try {
  520. newValue = math.evaluate(transExpr(newValue));
  521. } catch(err) {
  522. toastr.error('输入的表达式非法');
  523. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  524. return;
  525. }
  526. }
  527. }
  528. if (col.field.indexOf('_dgn_') > 0) {
  529. if (node.b_code && node.b_code !== '') {
  530. toastr.error('仅项目节可输入设计数量');
  531. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  532. return;
  533. }
  534. } else if (col.field !== 'postil' && col.field !== 'memo') {
  535. if (node.children && node.children.length > 0) {
  536. toastr.error('清单父项不可计量');
  537. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  538. return;
  539. } else {
  540. const nodePos = stagePos.getLedgerPos(node.id);
  541. if (nodePos && nodePos.length > 0) {
  542. toastr.error('该清单有计量单元,请在计量单元处计量');
  543. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  544. return;
  545. }
  546. }
  547. }
  548. if (col.field === 'memo') {
  549. updateData.main = {
  550. id: node.id
  551. };
  552. updateData.main[col.field] = newValue;
  553. } else if (col.field.indexOf('_dgn_') > 0) {
  554. updateData.dgn = {
  555. id: node.id
  556. };
  557. updateData.dgn[col.field] = newValue;
  558. } else {
  559. updateData.stage = {
  560. lid: node.id
  561. };
  562. updateData.stage[col.field] = newValue;
  563. }
  564. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  565. const nodes = stageTree.loadPostStageData(data);
  566. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  567. needCheckDetail();
  568. });
  569. }
  570. },
  571. selectionChanged: function (e, info) {
  572. if (!info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  573. stagePosSpreadObj.loadCurPosData();
  574. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  575. posSearch.search();
  576. }
  577. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  578. stageTreeSpreadObj.loadExprToInput(info.sheet);
  579. },
  580. deletePress(sheet) {
  581. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  582. const tree = sheet.zh_tree;
  583. if (!tree) { return; }
  584. const sel = sheet.getSelections()[0];
  585. const validCols = [];
  586. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  587. if (!sheet.zh_setting.cols[iCol].readOnly) {
  588. validCols.push(iCol);
  589. }
  590. }
  591. if (validCols.length === 0) { return; }
  592. const sortData = sheet.zh_tree.nodes;
  593. const datas = [], dgnDatas = [], mainDatas = [];
  594. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  595. const node = sortData[iRow];
  596. if (node) {
  597. const data = { lid: node.id }, dgnData = { id: node.id }, mainData = { id: node.id };
  598. let filter = true, filterDgn = true, filterMain = true;
  599. for (const iCol of validCols) {
  600. const colSetting = sheet.zh_setting.cols[iCol];
  601. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  602. if (node.b_code && node.b_code !== '') continue;
  603. } else if (colSetting.field !== 'postil') {
  604. if (node.children && node.children.length > 0) { continue; }
  605. const nodePos = stagePos.getLedgerPos(node.id);
  606. if (nodePos && nodePos.length > 0) { continue; }
  607. }
  608. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  609. if (node[colSetting.field] && node[colSetting.field] !== 0) {
  610. dgnData[colSetting.field] = 0;
  611. filterDgn = false;
  612. }
  613. } else if (colSetting.field === 'memo') {
  614. mainData[colSetting.field] = null;
  615. filterMain = false;
  616. } else {
  617. data[colSetting.field] = null;
  618. filter = false;
  619. }
  620. }
  621. if (!filter) datas.push(data);
  622. if (!filterDgn) dgnDatas.push(dgnData);
  623. if (!filterMain) mainDatas.push(mainData);
  624. }
  625. }
  626. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  627. const bills = {};
  628. if (datas.length > 0) bills.stage = datas;
  629. if (dgnDatas.length > 0) bills.dgn = dgnDatas;
  630. if (mainDatas.length > 0) bills.main = mainDatas;
  631. postData(window.location.href + '/update', {bills: bills}, function (result) {
  632. const nodes = stageTree.loadPostStageData(result);
  633. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  634. needCheckDetail();
  635. });
  636. }
  637. }
  638. },
  639. clipboardPasting(e, info) {
  640. if (info.sheet.zh_setting) {
  641. const setting = info.sheet.zh_setting;
  642. const range = info.cellRange;
  643. const stageField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'];
  644. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  645. const col = info.sheet.zh_setting.cols[iCol];
  646. if ((stageField.indexOf(col.field) === -1) && setting.dgnUpFields.indexOf(col.field) === -1
  647. && col.field !== 'memo') {
  648. toastr.error('不可修改此数据');
  649. info.cancel = true;
  650. return;
  651. }
  652. }
  653. }
  654. },
  655. clipboardPasted(e, info) {
  656. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  657. const sheet = info.sheet, setting = info.sheet.zh_setting;
  658. const filterNodes = [], datas = [], dgnDatas = [], mainDatas = [];
  659. let bHint = false;
  660. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  661. const curRow = iRow + info.cellRange.row;
  662. const node = sheet.zh_tree.getItemsByIndex(curRow);
  663. const data = {lid: node.id}, dgnData = {id: node.id}, mainData = {id: node.id};
  664. let filter = true, filterDgn = true, filterMain = true;
  665. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  666. const curCol = info.cellRange.col + iCol;
  667. const col = info.sheet.zh_setting.cols[curCol];
  668. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  669. if (node.b_code && node.b_code !== '') continue;
  670. } else if (col.field !== 'postil') {
  671. if (node.children && node.children.length > 0) continue;
  672. const nodePos = stagePos.getLedgerPos(node.id);
  673. if (nodePos && nodePos.length > 0) continue;
  674. }
  675. const text = sheet.getText(curRow, curCol);
  676. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  677. const num = _.toNumber(text);
  678. if (num) {
  679. dgnData[col.field] = num;
  680. filterDgn = false;
  681. } else {
  682. try {
  683. dgnData[col.field] = math.evaluate(transExpr(text));
  684. filterDgn = false;
  685. } catch(err) {
  686. if (!bHint) {
  687. toastr.warning('粘贴了非法表达式,已过滤');
  688. bHint = true;
  689. }
  690. }
  691. }
  692. } else if (col.field === 'memo') {
  693. mainData.memo = text;
  694. filterMain = false;
  695. } else {
  696. if (col.type === 'Number') {
  697. const num = _.toNumber(text);
  698. if (num) {
  699. data[col.field] = num;
  700. filter = false;
  701. } else {
  702. try {
  703. data[col.field] = math.evaluate(transExpr(text));
  704. filter = false;
  705. } catch(err) {
  706. if (!bHint) {
  707. toastr.warning('粘贴了非法表达式,已过滤');
  708. bHint = true;
  709. }
  710. }
  711. }
  712. } else {
  713. data[col.field] = text;
  714. }
  715. }
  716. }
  717. if (filter && filterDgn && filterMain) {
  718. filterNodes.push(node);
  719. } else {
  720. if (!filter) datas.push(data);
  721. if (!filterDgn) dgnDatas.push(dgnData);
  722. if (!filterMain) mainDatas.push(mainData);
  723. }
  724. }
  725. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  726. const updateData = {};
  727. if (datas.length > 0) updateData.stage = datas;
  728. if (dgnDatas.length > 0) updateData.dgn = dgnDatas;
  729. if (mainDatas.length > 0) updateData.main = mainDatas;
  730. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  731. const nodes = stageTree.loadPostStageData(data);
  732. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  733. needCheckDetail();
  734. });
  735. } else {
  736. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  737. }
  738. }
  739. },
  740. measureAllPosInNode(node, ratio = 1) {
  741. const posterity = stageTree.getPosterity(node)
  742. const data = {updateType: 'update', updateData: []};
  743. for (const p of posterity) {
  744. if (p.children && p.children.length > 0) continue;
  745. const posRange = stagePos.getLedgerPos(p.id);
  746. if (posRange && posRange.length > 0) {
  747. for (const pr of posRange) {
  748. if (pr.contract_qty && !checkZero(pr.contract_qty)) continue;
  749. const validValue = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
  750. if (validValue <= 0) continue;
  751. const value = ratio !== 1 ? ZhCalc.mul(pr.quantity, ratio) : pr.quantity;
  752. const pData = {
  753. pid: pr.id,
  754. lid: pr.lid,
  755. contract_qty: validValue > 0 ? (value > validValue ? validValue : value) : (value < validValue ? validValue : value),
  756. };
  757. data.updateData.push(pData);
  758. }
  759. }
  760. if (data.updateData.length > 1000 || _.map(data.updateData, 'lid').length > 500) {
  761. toastr.warning('选中的数据过多,仅计量' + data.updateData.length + '条,请稍后');
  762. break;
  763. }
  764. }
  765. if (data.updateData.length === 0) {
  766. toastr.info('其下全部计量单元均已计量');
  767. return;
  768. }
  769. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  770. if (result.pos) {
  771. stagePos.updateDatas(result.pos.pos);
  772. stagePos.loadCurStageData(result.pos.curStageData);
  773. }
  774. const nodes = stageTree.loadPostStageData(result.ledger);
  775. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  776. stagePosSpreadObj.loadCurPosData();
  777. needCheckDetail();
  778. toastr.success('已计量' + data.updateData.length + '条');
  779. }, function () {
  780. stagePosSpreadObj.loadCurPosData();
  781. });
  782. },
  783. topRowChanged(e, info) {
  784. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  785. },
  786. };
  787. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  788. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  789. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  790. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  791. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  792. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  793. $.contextMenu({
  794. selector: '#stage-ledger',
  795. build: function ($trigger, e) {
  796. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  797. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  798. },
  799. items: {
  800. 'measureAll': {
  801. name: '计量其下所有计量单元',
  802. icon: 'fa-rocket',
  803. callback: function (key, opt) {
  804. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  805. stageTreeSpreadObj.measureAllPosInNode(node);
  806. },
  807. visible: function (key, opt) {
  808. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  809. return select;
  810. }
  811. },
  812. 'measureAllFiveTenth': {
  813. name: '计量其下所有计量单元(计量50%)',
  814. icon: 'fa-plane',
  815. callback: function (key, opt) {
  816. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  817. stageTreeSpreadObj.measureAllPosInNode(node, 0.5);
  818. },
  819. visible: function (key, opt) {
  820. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  821. return select;
  822. }
  823. },
  824. 'measureAllOneTenth': {
  825. name: '计量其下所有计量单元(计量10%)',
  826. icon: 'fa-car',
  827. callback: function (key, opt) {
  828. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  829. stageTreeSpreadObj.measureAllPosInNode(node, 0.1);
  830. },
  831. visible: function (key, opt) {
  832. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  833. return select;
  834. }
  835. },
  836. 'hint1': {
  837. name: '最多计量200条清单下1000条计量单元',
  838. className: 'text-danger',
  839. visible: function (key, opt) {
  840. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  841. return select;
  842. },
  843. disabled: function (key, opt) {
  844. return true;
  845. }
  846. },
  847. 'hint1_1': {
  848. name: '(计数以清单为准,会计完清单下全部部位)',
  849. className: 'text-danger',
  850. visible: function (key, opt) {
  851. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  852. return select;
  853. },
  854. disabled: function (key, opt) {
  855. return true;
  856. }
  857. },
  858. 'hint2': {
  859. name: '可再次使用该功能计量剩下的节点',
  860. className: 'text-danger',
  861. visible: function (key, opt) {
  862. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  863. return select;
  864. },
  865. disabled: function (key, opt) {
  866. return true;
  867. }
  868. },
  869. 'hint2_2': {
  870. name: '(凡是计量的部位,不论计量多少,均不再计量)',
  871. className: 'text-danger',
  872. visible: function (key, opt) {
  873. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  874. return select;
  875. },
  876. disabled: function (key, opt) {
  877. return true;
  878. }
  879. },
  880. 'hint3': {
  881. name: '如提示数据过多后,未成功,请缩小范围再试',
  882. className: 'text-danger',
  883. visible: function (key, opt) {
  884. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  885. return select;
  886. },
  887. disabled: function (key, opt) {
  888. return true;
  889. }
  890. },
  891. 'hint4': {
  892. name: '该功能仅供测试用,请勿滥用,可能导致服务挂掉',
  893. className: 'text-danger',
  894. visible: function (key, opt) {
  895. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  896. return select;
  897. },
  898. disabled: function (key, opt) {
  899. return true;
  900. }
  901. },
  902. }
  903. });
  904. if (!readOnly) {
  905. $('#bills-expr').bind('change mouseleave', function () {
  906. if (this.readOnly) return;
  907. const expr = $(this);
  908. const sheet = slSpread.getActiveSheet();
  909. const select = SpreadJsObj.getSelectObject(sheet);
  910. const field = expr.attr('field'), orgValue = expr.attr('org'), updateData = {};
  911. let newValue = expr.val();
  912. const num = _.toNumber(newValue);
  913. if (num) {
  914. newValue = num;
  915. } else {
  916. try {
  917. newValue = math.evaluate(transExpr(newValue));
  918. } catch(err) {
  919. toastr.error('输入的表达式非法');
  920. return;
  921. }
  922. }
  923. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  924. if (field.indexOf('_dgn_') > 0) {
  925. updateData.dgn = {
  926. id: select.id
  927. };
  928. updateData.dgn[field] = newValue;
  929. } else {
  930. updateData.stage = {
  931. lid: select.id
  932. };
  933. updateData.stage[field] = newValue;
  934. }
  935. // 更新至服务器
  936. postData(window.location.pathname + '/update', {bills: updateData}, function (result) {
  937. const nodes = stageTree.loadPostStageData(result);
  938. expr.val(select[field]);
  939. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  940. });
  941. });
  942. }
  943. stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
  944. const stagePosSpreadObj = {
  945. loadExprToInput(sheet) {
  946. const sel = sheet.getSelections()[0];
  947. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  948. if (col.type === 'Number') {
  949. const data = SpreadJsObj.getSelectObject(sheet);
  950. if (data) {
  951. $('#pos-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field])
  952. .attr('row', sel.row).attr('readOnly', readOnly || cell.locked());
  953. } else {
  954. $('#pos-expr').val('').attr('readOnly', true);
  955. }
  956. } else {
  957. $('#pos-expr').val('').attr('readOnly', true);
  958. }
  959. },
  960. /**
  961. * 加载计量单元 根据当前台账选择节点
  962. */
  963. loadCurPosData: function () {
  964. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  965. if (node) {
  966. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  967. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  968. getNodeList(node.id);
  969. // 如果是附件是当前节点,隐藏
  970. if ($('#dqjiedian').hasClass('active')) {
  971. $('#showAttachment').hide();
  972. }
  973. } else {
  974. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  975. }
  976. },
  977. editEnded: function (e, info) {
  978. if (info.sheet.zh_setting) {
  979. // 未改变过,则直接跳过
  980. const sortData = info.sheet.zh_data;
  981. const posData = sortData ? sortData[info.row] : null;
  982. const col = info.sheet.zh_setting.cols[info.col];
  983. const orgText = posData ? posData[col.field] : null;
  984. if (orgText === info.editingText || ((!orgText || orgText === '') && (info.editingText === ''))) {
  985. return;
  986. }
  987. // 台账模式下,不可新增
  988. if (checkTzMeasureType() && !posData) {
  989. toastr.error('台账模式不可新增计量单元数据');
  990. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  991. return ;
  992. }
  993. // 不同节点下,计量单元检查输入
  994. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  995. const node = stagePosSpreadObj.stageTreeNode;
  996. if (!node) {
  997. toastr.warning('数据错误, 请刷新页面后再试');
  998. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  999. return;
  1000. } else if (info.editingText !== '' && node.children && node.children > 0) {
  1001. toastr.error('父节点不可插入计量单元');
  1002. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1003. return;
  1004. } else if (info.editingText !== '' && !node.b_code || node.b_code === '') {
  1005. toastr.error('项目节不可插入计量单元');
  1006. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1007. return;
  1008. }
  1009. // 生成提交数据
  1010. const data = {};
  1011. if (col.field === 'name') {
  1012. if ((!info.editingText || info.editingText === '') && posData) {
  1013. toastr.error('部位名称不可为空');
  1014. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1015. return;
  1016. } else if (!posData) {
  1017. if (info.editingText !== '') {
  1018. data.updateType = 'add';
  1019. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1020. data.updateData = {name: info.editingText, lid: node.id, tid: tender.id, porder: order};
  1021. } else {
  1022. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1023. return;
  1024. }
  1025. } else {
  1026. data.updateType = 'update';
  1027. data.updateData = {pid: posData.id, lid: posData.lid, name: info.editingText};
  1028. }
  1029. } else if (!posData) {
  1030. toastr.warning('新增部位请先输入名称');
  1031. } else {
  1032. data.updateType = 'update';
  1033. data.updateData = {pid: posData.id, lid: posData.lid};
  1034. if (col.type === 'Number') {
  1035. const num = _.toNumber(info.editingText);
  1036. if (num) {
  1037. data.updateData[col.field] = num;
  1038. } else {
  1039. try {
  1040. data.updateData[col.field] = math.evaluate(transExpr(info.editingText));
  1041. } catch(err) {
  1042. toastr.error('输入的表达式非法');
  1043. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1044. return;
  1045. }
  1046. }
  1047. } else {
  1048. data.updateData[col.field] = info.editingText;
  1049. }
  1050. }
  1051. // 提交数据到服务器
  1052. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1053. if (result.pos) {
  1054. stagePos.updateDatas(result.pos.pos);
  1055. stagePos.loadCurStageData(result.pos.curStageData);
  1056. }
  1057. const refreshData = stageTree.loadPostStageData(result.ledger);
  1058. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1059. stagePosSpreadObj.loadCurPosData();
  1060. needCheckDetail();
  1061. }, function () {
  1062. stagePosSpreadObj.loadCurPosData();
  1063. });
  1064. }
  1065. },
  1066. editStarting: function (e, info) {
  1067. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1068. },
  1069. clipboardPasting: function (e, info) {
  1070. if (info.sheet.zh_setting) {
  1071. const sortData = info.sheet.zh_data;
  1072. const range = info.cellRange;
  1073. const validField = ['contract_qty', 'qc_qty', 'postil'];
  1074. if (!checkTzMeasureType()) {
  1075. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty');
  1076. }
  1077. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1078. const col = info.sheet.zh_setting.cols[iCol];
  1079. if (validField.indexOf(col.field) === -1) {
  1080. if (checkTzMeasureType()) {
  1081. toastr.error('不可修改此数据');
  1082. info.cancel = true;
  1083. return;
  1084. } else {
  1085. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  1086. const pos = sortData(iRow);
  1087. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  1088. toastr.error('不可修改此数据');
  1089. info.cancel = true;
  1090. return;
  1091. }
  1092. }
  1093. }
  1094. }
  1095. }
  1096. }
  1097. },
  1098. clipboardPasted: function (e, info) {
  1099. const self = this;
  1100. if (info.sheet.zh_setting) {
  1101. const data = { updateType: '', updateData: [], };
  1102. const sortData = info.sheet.zh_data;
  1103. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1104. if (sortData && (info.cellRange.row >= sortData.length)) {
  1105. data.updateType = 'add';
  1106. if (info.cellRange.col !== 0) {
  1107. toastr.warning('新增部位请先输入名称');
  1108. self.loadCurPosData();
  1109. return;
  1110. }
  1111. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1112. const curRow = info.cellRange.row + iRow;
  1113. const newData = {lid: node.id};
  1114. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1115. const curCol = info.cellRange.col + iCol;
  1116. const colSetting = info.sheet.zh_setting.cols[curCol];
  1117. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  1118. if (col.type === 'Number') {
  1119. const num = _.toNumber(newData[colSetting.field]);
  1120. if (num) {
  1121. newData[colSetting.field] = num;
  1122. } else {
  1123. try {
  1124. newData[colSetting.field] = math.evaluate(transExpr(newData[colSetting.field]));
  1125. } catch(err) {
  1126. toastr.error('输入的表达式非法');
  1127. self.loadCurPosData();
  1128. return;
  1129. }
  1130. }
  1131. }
  1132. }
  1133. data.updateData.push(newData);
  1134. }
  1135. } else {
  1136. data.updateType = 'update';
  1137. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1138. const curRow = info.cellRange.row + iRow;
  1139. const curPos = sortData[curRow];
  1140. if (curPos) {
  1141. const newData = {pid: curPos.id, lid: curPos.lid};
  1142. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1143. const curCol = info.cellRange.col + iCol;
  1144. const colSetting = info.sheet.zh_setting.cols[curCol];
  1145. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  1146. if (col.type === 'Number') {
  1147. const num = _.toNumber(newData[colSetting.field]);
  1148. if (num) {
  1149. newData[colSetting.field] = num;
  1150. } else {
  1151. try {
  1152. newData[colSetting.field] = math.evaluate(transExpr(newData[colSetting.field]));
  1153. } catch(err) {
  1154. toastr.error('输入的表达式非法');
  1155. self.loadCurPosData();
  1156. return;
  1157. }
  1158. }
  1159. }
  1160. }
  1161. data.updateData.push(newData);
  1162. }
  1163. }
  1164. }
  1165. console.log(data);
  1166. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1167. if (result.pos) {
  1168. stagePos.updateDatas(result.pos.pos);
  1169. stagePos.loadCurStageData(result.pos.curStageData);
  1170. }
  1171. const nodes = stageTree.loadPostStageData(result.ledger);
  1172. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1173. stagePosSpreadObj.loadCurPosData();
  1174. needCheckDetail();
  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. if (!sheet.zh_setting.cols[iCol].readOnly) {
  1188. validCols.push(iCol);
  1189. }
  1190. }
  1191. if (validCols.length === 0) { return; }
  1192. const datas = [], posSelects = [];
  1193. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1194. const node = sortData[iRow];
  1195. if (node) {
  1196. const data = {pid: node.id, lid: node.lid};
  1197. for (const iCol of validCols) {
  1198. const colSetting = sheet.zh_setting.cols[iCol];
  1199. if (colSetting.field === 'name') {
  1200. toastr.error('部位名称不能为空');
  1201. return;
  1202. }
  1203. data[colSetting.field] = null;
  1204. }
  1205. datas.push(data);
  1206. posSelects.push(node);
  1207. }
  1208. }
  1209. if (datas.length > 0) {
  1210. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  1211. if (result.pos) {
  1212. stagePos.updateDatas(result.pos.pos);
  1213. stagePos.loadCurStageData(result.pos.curStageData);
  1214. }
  1215. const nodes = stageTree.loadPostStageData(result.ledger);
  1216. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1217. needCheckDetail();
  1218. // todo 只加载改变项
  1219. stagePosSpreadObj.loadCurPosData();
  1220. });
  1221. }
  1222. }
  1223. },
  1224. deletePos: function (sheet) {
  1225. const sels = sheet.getSelections();
  1226. const sel = sels ? sels[0] : null;
  1227. if (sheet.zh_data && sel) {
  1228. const data = {updateType: 'delete', updateData: []};
  1229. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  1230. const posData = sheet.zh_data[sel.row + iRow];
  1231. if (posData) {
  1232. data.updateData.push(posData.id);
  1233. }
  1234. }
  1235. if (data.updateData.length > 0) {
  1236. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1237. stagePos.removeDatas(result.pos.pos);
  1238. const refreshData = stageTree.loadPostStageData(result.ledger);
  1239. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1240. stagePosSpreadObj.loadCurPosData();
  1241. needCheckDetail();
  1242. });
  1243. }
  1244. }
  1245. },
  1246. selectionChanged: function (e, info) {
  1247. stagePosSpreadObj.loadExprToInput(info.sheet);
  1248. }
  1249. };
  1250. // 加载上下窗口resizer
  1251. $.divResizer({
  1252. select: '#main-resize',
  1253. callback: function () {
  1254. slSpread.refresh();
  1255. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1256. $(".sp-wrap").height(bcontent-40);
  1257. spSpread.refresh();
  1258. }
  1259. });
  1260. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1261. console.time('loadPosFromServer');
  1262. postData(window.location.pathname + '/pos', null, function (result) {
  1263. console.timeEnd('loadPosFromServer');
  1264. console.log('pos: ' + result.length);
  1265. stagePos.loadDatas(result);
  1266. stagePos.calculateAll();
  1267. stagePosSpreadObj.loadCurPosData();
  1268. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  1269. }, null, true);
  1270. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  1271. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  1272. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  1273. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  1274. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  1275. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  1276. if (!readOnly) {
  1277. $('#pos-expr').bind('change mouseleave', function () {
  1278. if (this.readOnly) return;
  1279. const expr = $(this);
  1280. const posSheet = spSpread.getActiveSheet();
  1281. const select = SpreadJsObj.getSelectObject(posSheet);
  1282. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val(), row = expr.attr('row');
  1283. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1284. const data = {pid: select.id, lid: select.lid};
  1285. const num = _.toNumber(newValue);
  1286. if (num) {
  1287. data[field] = num;
  1288. } else {
  1289. try {
  1290. data[field] = math.evaluate(transExpr(newValue));
  1291. } catch (err) {
  1292. toastr.error('输入的表达式非法');
  1293. return;
  1294. }
  1295. }
  1296. // 提交数据到服务器
  1297. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  1298. if (result.pos) {
  1299. stagePos.updateDatas(result.pos.pos);
  1300. stagePos.loadCurStageData(result.pos.curStageData);
  1301. expr.val(select[field]);
  1302. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  1303. }
  1304. const refreshData = stageTree.loadPostStageData(result.ledger);
  1305. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1306. });
  1307. });
  1308. }
  1309. if (!checkTzMeasureType()) {
  1310. $.contextMenu({
  1311. selector: '#stage-pos',
  1312. build: function ($trigger, e) {
  1313. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  1314. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1315. },
  1316. items: {
  1317. 'del': {
  1318. name: '删除',
  1319. icon: 'fa-remove',
  1320. disabled: function (key, opt) {
  1321. const sheet = spSpread.getActiveSheet();
  1322. if (sheet.zh_data && !readOnly) {
  1323. const selection = sheet.getSelections();
  1324. if (selection && selection[0]) {
  1325. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1326. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  1327. const posData = sheet.zh_data[selection[0].row + iRow];
  1328. if (posData) {
  1329. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  1330. valid = true;
  1331. break;
  1332. }
  1333. } else {
  1334. valid = true;
  1335. break;
  1336. }
  1337. }
  1338. return valid;
  1339. } else {
  1340. return true;
  1341. }
  1342. } else {
  1343. return true;
  1344. }
  1345. },
  1346. callback: function (key, opt) {
  1347. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  1348. }
  1349. }
  1350. }
  1351. })
  1352. } else {
  1353. $.contextMenu({
  1354. selector: '#stage-pos',
  1355. build: function ($trigger, e) {
  1356. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  1357. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1358. },
  1359. items: {
  1360. 'debug': {
  1361. name: 'debug',
  1362. callback: function (key, opt) {
  1363. console.log(SpreadJsObj.getSelectObject(spSpread.getActiveSheet()));
  1364. }
  1365. }
  1366. }
  1367. })
  1368. }
  1369. $.subMenu({
  1370. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1371. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1372. //key: 'stage.memu.1.0.0',
  1373. callback: function (info) {
  1374. if (info.mini) {
  1375. $('.panel-title').addClass('fluid');
  1376. $('#sub-menu').removeClass('panel-sidebar');
  1377. } else {
  1378. $('.panel-title').removeClass('fluid');
  1379. $('#sub-menu').addClass('panel-sidebar');
  1380. }
  1381. autoFlashHeight();
  1382. slSpread.refresh();
  1383. spSpread.refresh();
  1384. }
  1385. });
  1386. $('#row-view').on('show.bs.modal', function () {
  1387. const html = [], customDisplay = customColDisplay();
  1388. for (const cd of customDisplay) {
  1389. html.push('<tr>');
  1390. html.push('<td>', cd.title, '</td>');
  1391. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  1392. html.push('</tr>');
  1393. }
  1394. $('#row-view-list').html(html.join(''));
  1395. });
  1396. $('#row-view-ok').click(function () {
  1397. const customDisplay = customColDisplay();
  1398. const cvl = $('#row-view-list').children();
  1399. for (const cv of cvl) {
  1400. const title = $(cv).children()[0].innerHTML;
  1401. const check = $('input', cv)[0].checked;
  1402. const cd = customDisplay.find(function (c) {
  1403. return c.title === title;
  1404. });
  1405. cd.visible = check;
  1406. }
  1407. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  1408. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  1409. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  1410. $('#row-view').modal('hide');
  1411. });
  1412. class SearchLedger {
  1413. constructor(obj, mainSpread) {
  1414. const self = this;
  1415. this.obj = obj;
  1416. this.mainSpread = mainSpread;
  1417. this.spreadSetting = {
  1418. cols: [
  1419. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@'},
  1420. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  1421. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@'},
  1422. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  1423. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  1424. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  1425. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  1426. ],
  1427. emptyRows: 0,
  1428. headRows: 1,
  1429. headRowHeight: [32],
  1430. defaultRowHeight: 21,
  1431. headerFont: '12px 微软雅黑',
  1432. font: '12px 微软雅黑',
  1433. readOnly: true
  1434. };
  1435. this.spread = SpreadJsObj.createNewSpread($('#search-result', this.obj)[0]);
  1436. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1437. $('#keyword', this.obj).bind('keydown', function(e) {
  1438. if (e.keyCode == 13) self.searchText();
  1439. });
  1440. $('#searchLedger', this.obj).bind('click', () => {self.searchText()});
  1441. $('#over', this.obj).bind('change', () => {self.searchOver()});
  1442. $('#empty', this.obj).bind('change', () => {self.searchLess()});
  1443. this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1444. const sheet = info.sheet;
  1445. const data = sheet.zh_data;
  1446. if (!data) { return }
  1447. const curBills = data[info.row];
  1448. if (!curBills) { return }
  1449. SpreadJsObj.locateTreeNode(self.mainSpread.getActiveSheet(), curBills.ledger_id, true);
  1450. stagePosSpreadObj.loadCurPosData();
  1451. });
  1452. }
  1453. calculateCompletePercent() {
  1454. if (!this.searchResult) return;
  1455. for (const sr of this.searchResult) {
  1456. const base = ZhCalc.add(sr.total_price, sr.end_qc_tp);
  1457. sr.complete_percent = base !== 0 ? ZhCalc.mul(ZhCalc.div(sr.end_gather_tp, base), 100, 2) : 0;
  1458. }
  1459. }
  1460. searchText() {
  1461. const keyword = $('#keyword', this.obj).val();
  1462. if (keyword !== '') {
  1463. $('#over', this.obj)[0].checked = false;
  1464. $('#empty', this.obj)[0].checked = false;
  1465. this.searchResult = [];
  1466. const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
  1467. for (const node of sortData) {
  1468. if ((node.code && node.code.indexOf(keyword) > -1) ||
  1469. node.b_code && node.b_code.indexOf(keyword) > -1 ||
  1470. node.name && node.name.indexOf(keyword) > -1) {
  1471. const data = JSON.parse(JSON.stringify(node));
  1472. data.visible = true;
  1473. this.searchResult.push(data);
  1474. }
  1475. }
  1476. this.calculateCompletePercent();
  1477. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
  1478. }
  1479. }
  1480. searchOver() {
  1481. this.searchResult = [];
  1482. const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
  1483. for (const node of sortData) {
  1484. if (node.children && node.children.length > 0) continue;
  1485. if (node.end_gather_qty) {
  1486. if (!node.quantity || Math.abs(node.end_gather_qty) > Math.abs(ZhCalc.add(node.quantity, node.end_qc_qty))) {
  1487. const data = JSON.parse(JSON.stringify(node));
  1488. data.visible = true;
  1489. this.searchResult.push(data);
  1490. }
  1491. } else if (node.end_gather_tp) {
  1492. if (!node.total_price || Math.abs(node.end_gather_tp) > Math.abs(ZhCalc.add(node.total_price, node.end_qc_tp))) {
  1493. const data = JSON.parse(JSON.stringify(node));
  1494. data.visible = true;
  1495. this.searchResult.push(data);
  1496. }
  1497. }
  1498. }
  1499. this.calculateCompletePercent();
  1500. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
  1501. }
  1502. searchEmpty() {
  1503. this.searchResult = [];
  1504. const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
  1505. for (const node of sortData) {
  1506. if (node.children && node.children.length > 0) continue;
  1507. if (node.quantity) {
  1508. if (!node.end_gather_qty || checkZero(node.end_gather_qty)) {
  1509. const data = JSON.parse(JSON.stringify(node));
  1510. data.visible = true;
  1511. this.searchResult.push(data);
  1512. }
  1513. } else if (node.total_price) {
  1514. if (!node.end_gather_tp || checkZero(node.end_gather_tp)) {
  1515. const data = JSON.parse(JSON.stringify(node));
  1516. data.visible = true;
  1517. this.searchResult.push(data);
  1518. }
  1519. }
  1520. }
  1521. this.calculateCompletePercent();
  1522. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
  1523. }
  1524. searchLess() {
  1525. this.searchResult = [];
  1526. const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
  1527. for (const node of sortData) {
  1528. if (node.children && node.children.length > 0) continue;
  1529. if (node.quantity) {
  1530. if (ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0) {
  1531. const data = JSON.parse(JSON.stringify(node));
  1532. data.visible = true;
  1533. this.searchResult.push(data);
  1534. }
  1535. } else if (node.total_price) {
  1536. if (ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0) {
  1537. const data = JSON.parse(JSON.stringify(node));
  1538. data.visible = true;
  1539. this.searchResult.push(data);
  1540. }
  1541. }
  1542. }
  1543. this.calculateCompletePercent();
  1544. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
  1545. }
  1546. }
  1547. let searchLedger;
  1548. const posSearch = (function () {
  1549. let resultArr = [];
  1550. const search = function () {
  1551. resultArr = [];
  1552. const keyword = $('#pos-search-keyword').val();
  1553. const checkOver = $('#pos-over-search')[0].checked;
  1554. const checkEmpty = $('#pos-empty-search')[0].checked;
  1555. const sortData = spSpread.getActiveSheet().zh_data;
  1556. if (checkOver || checkEmpty) {
  1557. if (sortData) {
  1558. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1559. const sd = sortData[i];
  1560. let match = false;
  1561. if (checkOver) {
  1562. if (sd.end_gather_qty) {
  1563. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  1564. }
  1565. }
  1566. if (checkEmpty) {
  1567. if (sd.quantity) {
  1568. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  1569. }
  1570. }
  1571. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  1572. if (match) {
  1573. resultArr.push({index: i, data: sd});
  1574. }
  1575. }
  1576. }
  1577. } else if (keyword && keyword !== '') {
  1578. if (sortData) {
  1579. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1580. const sd = sortData[i];
  1581. if (sd.name && sd.name.indexOf(keyword) > -1) {
  1582. resultArr.push({index: i, data: sd});
  1583. }
  1584. }
  1585. }
  1586. }
  1587. $('#pos-search-result').html('结果:' + resultArr.length);
  1588. };
  1589. const searchAndLocate = function () {
  1590. search();
  1591. if (resultArr.length > 0) {
  1592. const sheet = spSpread.getActiveSheet();
  1593. const sel = sheet.getSelections()[0];
  1594. const curRow = sel ? sel.row : 0;
  1595. const pos = resultArr[0];
  1596. if (pos.index !== curRow) {
  1597. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  1598. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  1599. }
  1600. }
  1601. };
  1602. const locateNext = function () {
  1603. if (resultArr.length > 0) {
  1604. const sheet = spSpread.getActiveSheet();
  1605. const sel = sheet.getSelections()[0];
  1606. const curRow = sel ? sel.row : 0;
  1607. let next = _.find(resultArr, function (d) {
  1608. return d.index > curRow;
  1609. });
  1610. if (!next) next = resultArr[0];
  1611. if (next.index !== curRow) {
  1612. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1613. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1614. }
  1615. }
  1616. };
  1617. const locatePre = 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 = _.findLast(resultArr, function (d) {
  1623. return d.index < curRow;
  1624. });
  1625. if (!next) next = resultArr[resultArr.length - 1];
  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. return {search, searchAndLocate, locateNext, locatePre};
  1633. })();
  1634. $('#pos-search-keyword').bind('keydown', function(e){
  1635. if (e.keyCode == 13) posSearch.searchAndLocate();
  1636. });
  1637. $('#pos-empty-search').click(function () {
  1638. if (this.checked) {
  1639. $('[for=' + this.id +']').addClass('text-warning');
  1640. } else {
  1641. $('[for=' + this.id +']').removeClass('text-warning');
  1642. }
  1643. if (this.checked) {
  1644. if ($('#pos-over-search')[0].checked) {
  1645. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1646. } else {
  1647. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  1648. }
  1649. } else {
  1650. if ($('#pos-over-search')[0].checked) {
  1651. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  1652. } else {
  1653. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1654. }
  1655. }
  1656. posSearch.searchAndLocate();
  1657. });
  1658. $('#pos-over-search').click(function () {
  1659. if (this.checked) {
  1660. $('[for=' + this.id +']').addClass('text-danger');
  1661. } else {
  1662. $('[for=' + this.id +']').removeClass('text-danger');
  1663. }
  1664. if (this.checked) {
  1665. if ($('#pos-empty-search')[0].checked) {
  1666. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1667. } else {
  1668. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  1669. }
  1670. } else {
  1671. if ($('#pos-empty-search')[0].checked) {
  1672. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  1673. } else {
  1674. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1675. }
  1676. }
  1677. posSearch.searchAndLocate();
  1678. });
  1679. $('#pos-search-next').click(() => {posSearch.locateNext()});
  1680. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  1681. $.divResizer({
  1682. select: '#right-spr',
  1683. callback: function () {
  1684. slSpread.refresh();
  1685. spSpread.refresh();
  1686. if (searchLedger) {
  1687. searchLedger.spread.refresh();
  1688. }
  1689. }
  1690. });
  1691. // 展开收起附件
  1692. $('a', '.right-nav').bind('click', function () {
  1693. //const main = $('#main-view'), tool = $('#tools-view');
  1694. const tab = $(this), tabPanel = $(tab.attr('content'));
  1695. const showTools = function (show) {
  1696. const left = $('#main-view'), right = $('#tools-view'), parent = left.parent();
  1697. if (show) {
  1698. right.show();
  1699. autoFlashHeight();
  1700. /**
  1701. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1702. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1703. * 故需要通过最终的parent.width再计算一次left.width
  1704. *
  1705. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1706. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1707. *
  1708. */
  1709. //left.css('width', parent.width() - right.outerWidth());
  1710. //left.css('width', parent.width() - right.outerWidth());
  1711. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1712. left.css('width', percent + '%');
  1713. } else {
  1714. right.hide();
  1715. left.css('width', '100%');
  1716. }
  1717. };
  1718. if (!tab.hasClass('active')) {
  1719. $('a', '.side-menu').removeClass('active');
  1720. $('.tab-content .tab-select-show').removeClass('active');
  1721. tab.addClass('active');
  1722. tabPanel.addClass('active');
  1723. showTools(tab.hasClass('active'));
  1724. if (tab.attr('content') === '#search' && !searchLedger) {
  1725. searchLedger = new SearchLedger($('#search'), slSpread);
  1726. searchLedger.spread.refresh();
  1727. }
  1728. if (tab.attr('content') === '#fujian') {
  1729. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1730. getNodeList(node.id);
  1731. }
  1732. } else {
  1733. tab.removeClass('active');
  1734. tabPanel.removeClass('active');
  1735. showTools(tab.hasClass('active'));
  1736. }
  1737. slSpread.refresh();
  1738. spSpread.refresh();
  1739. });
  1740. // 切换附件里节点和所有附件
  1741. $('#fujian .nav-link').on('click', function () {
  1742. const tabPanel = $(this).attr('fujian-content');
  1743. if (tabPanel !== 'syfujian') {
  1744. $('#showPage').hide();
  1745. } else {
  1746. $('#showPage').show();
  1747. }
  1748. $('#showAttachment').hide();
  1749. });
  1750. // 上传附件
  1751. $('#upload-file-btn').click(function () {
  1752. const files = $('#upload-file')[0].files;
  1753. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1754. const formData = new FormData();
  1755. formData.append('lid', node.id);
  1756. for (const file of files) {
  1757. if (file === undefined) {
  1758. toastr.error('未选择上传文件!');
  1759. return false;
  1760. }
  1761. const filesize = file.size;
  1762. if (filesize > 10 * 1024 * 1024) {
  1763. toastr.error('存在上传文件大小过大!');
  1764. return false;
  1765. }
  1766. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  1767. if (whiteList.indexOf(fileext) === -1) {
  1768. toastr.error('只能上传指定格式的附件!');
  1769. return false;
  1770. }
  1771. formData.append('size', filesize);
  1772. formData.append('file[]', file);
  1773. }
  1774. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  1775. $('#upload').modal('hide');
  1776. // 插入到attData中
  1777. attData = data.concat(attData);
  1778. // 重新生成List
  1779. getAllList();
  1780. getNodeList(node.id);
  1781. }, function () {
  1782. toastr.error('附件上传失败');
  1783. });
  1784. $('#upload-file').val('');
  1785. });
  1786. // 获取附件信息
  1787. $('body').on('click', '.list-table a', function () {
  1788. const fid = $(this).attr('file-id');
  1789. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  1790. return;
  1791. }
  1792. const att = attData.find(function (item) {
  1793. return item.id === parseInt(fid);
  1794. });
  1795. $('#edit-att').hide();
  1796. $('#show-att').show();
  1797. if (att !== undefined) {
  1798. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  1799. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  1800. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  1801. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  1802. $('#show-att tr').eq(3).children('td').eq(0).text(att.username);
  1803. $('#show-att tr').eq(3).children('td').eq(1).text(att.in_time);
  1804. $('#show-att tr').eq(4).children('td').text(att.remark);
  1805. if (parseInt(userID) === att.uid) {
  1806. $('#btn-att').show();
  1807. $('#btn-att a').eq(1).show();
  1808. $('#btn-att a').eq(0).hide();
  1809. $('#btn-att a').eq(2).hide();
  1810. $('#btn-att a').eq(3).hide();
  1811. } else {
  1812. $('#btn-att').hide();
  1813. $('#btn-att a').eq(1).hide();
  1814. $('#btn-att a').eq(0).hide();
  1815. $('#btn-att a').eq(2).hide();
  1816. $('#btn-att a').eq(3).hide();
  1817. }
  1818. $('#showAttachment').attr('file-id', fid);
  1819. $('#showAttachment').show();
  1820. } else {
  1821. $('#showAttachment').hide();
  1822. $('#showAttachment').attr('file-id', '');
  1823. toastr.error('附件信息获取失败');
  1824. }
  1825. });
  1826. $('body').on('click', '#btn-att a', function () {
  1827. const content = $(this).attr('content');
  1828. const fid = $('#showAttachment').attr('file-id');
  1829. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1830. if (content === 'edit') {
  1831. $('#btn-att a').eq(1).hide();
  1832. $('#btn-att a').eq(0).show();
  1833. $('#btn-att a').eq(2).show();
  1834. $('#btn-att a').eq(3).show();
  1835. $('#show-att').hide();
  1836. $('#edit-att').show();
  1837. const att = attData.find(function (item) {
  1838. return item.id === parseInt(fid);
  1839. });
  1840. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  1841. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  1842. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  1843. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  1844. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  1845. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  1846. } else if (content === 'cancel') {
  1847. $('#show-att').show();
  1848. $('#edit-att').hide();
  1849. $('#btn-att a').eq(1).show();
  1850. $('#btn-att a').eq(0).hide();
  1851. $('#btn-att a').eq(2).hide();
  1852. $('#btn-att a').eq(3).hide();
  1853. } else if (content === 'save') {
  1854. const formData = new FormData();
  1855. formData.append('id', fid);
  1856. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  1857. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  1858. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  1859. const file = $('#change-att-btn')[0];
  1860. if (file.files[0] !== undefined) {
  1861. const filesize = file.files[0].size;
  1862. formData.append('size', filesize);
  1863. formData.append('file', file.files[0]);
  1864. }
  1865. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  1866. // 替换到attData中
  1867. const att_index = attData.findIndex(function (item) {
  1868. return item.id === parseInt(fid);
  1869. });
  1870. attData.splice(att_index, 1, data);
  1871. // 重新生成List
  1872. getAllList(parseInt($('#currentPage').text()));
  1873. getNodeList(node.id);
  1874. $('#show-att').show();
  1875. $('#edit-att').hide();
  1876. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  1877. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  1878. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  1879. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  1880. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  1881. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  1882. $('#show-att tr').eq(4).children('td').text(data.remark);
  1883. $('#btn-att a').eq(1).show();
  1884. $('#btn-att a').eq(0).hide();
  1885. $('#btn-att a').eq(2).hide();
  1886. $('#btn-att a').eq(3).hide();
  1887. }, function () {
  1888. toastr.error('附件上传失败');
  1889. });
  1890. $('#change-att-btn').val('');
  1891. } else if (content === 'del') {
  1892. const data = {id: fid};
  1893. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  1894. // 删除到attData中
  1895. const att_index = attData.findIndex(function (item) {
  1896. return item.id === parseInt(fid);
  1897. });
  1898. attData.splice(att_index, 1);
  1899. // 重新生成List
  1900. getAllList();
  1901. getNodeList(node.id);
  1902. $('#showAttachment').hide();
  1903. $('#showAttachment').attr('file-id', '');
  1904. });
  1905. }
  1906. });
  1907. // 替换附件
  1908. $('#change-att-btn').on('change', function () {
  1909. const file = $('#change-att-btn')[0].files[0];
  1910. const name = file.name;
  1911. const filename = name.substring(0, name.lastIndexOf("."));
  1912. const fileext = name.substr(name.indexOf("."));
  1913. const filesize = file.size;
  1914. if (filesize > 10 * 1024 * 1024) {
  1915. toastr.error('文件大小过大!');
  1916. $('#change-att-btn').val('');
  1917. return false;
  1918. }
  1919. if (whiteList.indexOf(fileext) === -1) {
  1920. toastr.error('只能上传指定格式的附件!');
  1921. $('#change-att-btn').val('');
  1922. return false;
  1923. }
  1924. $('#edit-att .form-group').eq(0).find('input').val(filename);
  1925. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  1926. });
  1927. // 切换页数
  1928. $('.page-select').on('click', function () {
  1929. const totalPageNum = $('#totalPage').text();
  1930. const lastPageNum = $('#currentPage').text();
  1931. const status = $(this).attr('content');
  1932. if (status === 'pre' && lastPageNum > 1) {
  1933. getAllList(parseInt(lastPageNum)-1);
  1934. $('#showAttachment').hide();
  1935. } else if (status === 'next' && lastPageNum < totalPageNum) {
  1936. getAllList(parseInt(lastPageNum)+1);
  1937. $('#showAttachment').hide();
  1938. }
  1939. });
  1940. // 显示层次
  1941. (function (select, sheet) {
  1942. $(select).click(function () {
  1943. if (!sheet.zh_tree) return;
  1944. const tag = $(this).attr('tag');
  1945. const tree = sheet.zh_tree;
  1946. switch (tag) {
  1947. case "1":
  1948. case "2":
  1949. case "3":
  1950. case "4":
  1951. case "5":
  1952. tree.expandByLevel(parseInt(tag));
  1953. SpreadJsObj.refreshTreeRowVisible(sheet);
  1954. break;
  1955. case "last":
  1956. tree.expandByCustom(() => { return true; });
  1957. SpreadJsObj.refreshTreeRowVisible(sheet);
  1958. break;
  1959. case "leafXmj":
  1960. tree.expandToLeafXmj();
  1961. SpreadJsObj.refreshTreeRowVisible(sheet);
  1962. break;
  1963. case "curMeasure":
  1964. tree.expandByCustom(function (node) {
  1965. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  1966. if (node[field]) {
  1967. return true;
  1968. }
  1969. }
  1970. return false;
  1971. });
  1972. SpreadJsObj.refreshTreeRowVisible(sheet);
  1973. break;
  1974. }
  1975. });
  1976. })('a[name=showLevel]', slSpread.getActiveSheet());
  1977. });