sr_detail.js 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347
  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 relaTender.measure_type === measureType.tz.value;
  12. }
  13. function transExpr(expr) {
  14. return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
  15. }
  16. function getExprInfo (field) {
  17. const exprField = [
  18. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  19. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  20. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  21. {qty: 'contract_qty', expr: 'contract_expr'},
  22. ];
  23. return _.find(exprField, {qty: field});
  24. }
  25. /**
  26. * 从cookie中读取缓存的列显示设置,没有则取默认
  27. * @returns {*[]}
  28. */
  29. function customColDisplay () {
  30. const defaultSetting = [
  31. { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
  32. { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl'], visible: true },
  33. { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
  34. { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
  35. { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl'], visible: true },
  36. { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp', 'end_gather_percent', 'end_final_1_percent'], visible: true },
  37. { title: '本期批注', fields: ['postil'], visible: true },
  38. { title: '图册号', fields: ['drawing_code'], visible: true },
  39. { title: '备注', fields: ['memo'], visible: true },
  40. { title: '总额计量', fields: ['is_tp'], visible: true},
  41. ];
  42. if (!checkTzMeasureType()) {
  43. defaultSetting.unshift({ title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true }, { title: '台账', fields: ['quantity', 'total_price'], visible: true});
  44. }
  45. const settingStr = Cookies.get(ckColSetting);
  46. if (settingStr) {
  47. const customSetting = JSON.parse(settingStr);
  48. for (const ds of defaultSetting) {
  49. const cs = customSetting.find(x => {return x.title === ds.title});
  50. if (cs) ds.visible = cs.visible;
  51. }
  52. }
  53. return defaultSetting;
  54. }
  55. /**
  56. * 根据列显示设置,调整setting中的列是否显示
  57. * @param setting
  58. * @param customDisplay
  59. */
  60. function customizeStageTreeSetting(setting, customDisplay) {
  61. for (const cd of customDisplay) {
  62. for (const c of setting.cols) {
  63. if (cd.fields.indexOf(c.field) !== -1) {
  64. c.visible = cd.visible;
  65. }
  66. }
  67. }
  68. }
  69. // 生成所有附件列表
  70. function getAllList(currPageNum = 1) {
  71. // 每页最多几个附件
  72. const pageCount = 20;
  73. // 附件总数
  74. const total = attData.length;
  75. // 总页数
  76. const pageNum = Math.ceil(total/pageCount);
  77. $('#totalPage').text(pageNum);
  78. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  79. // 当前页附件内容
  80. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  81. currPageFileData = currPageAttData;
  82. let html = '';
  83. for(const att of currPageAttData) {
  84. html += `<tr>
  85. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  86. <td>
  87. <div class="d-flex">
  88. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  89. <a href="/tender/${relaTender.id}/measure/stage/${relaStage.order}/download/file/${att.id}" class="col-1 pl-0 att-file-btn"><i class="fa fa-download"></i></a>
  90. </div>
  91. </td><td>${att.username}</td></tr>`
  92. }
  93. $('#alllist-table').html(html);
  94. $('#alllist-table').on('click', 'tr', function() {
  95. $('#alllist-table tr').removeClass('bg-light')
  96. $(this).addClass('bg-light')
  97. })
  98. }
  99. // 生成当前节点列表
  100. function getNodeList(node) {
  101. let html = '';
  102. for(const att of attData) {
  103. if (node === att.lid) {
  104. html += `<tr>
  105. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  106. <td>
  107. <div class="d-flex">
  108. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  109. <a href="/tender/${relaTender.id}/measure/stage/${relaStage.order}/download/file/${att.id}" class="col-1 pl-0 att-file-btn"><i class="fa fa-download"></i></a>
  110. </div>
  111. </td><td>${att.username}</td></tr>`
  112. }
  113. }
  114. $('#nodelist-table').html(html);
  115. $('#nodelist-table').on('click', 'tr', function() {
  116. $('#nodelist-table tr').removeClass('bg-light');
  117. $(this).addClass('bg-light');
  118. })
  119. }
  120. function getGxbyText(data) {
  121. const def = thirdParty.gxby.find(function (x) {
  122. return x.value === data.gxby_status;
  123. });
  124. return def ? def.name : '';
  125. }
  126. function getDaglText(data) {
  127. const def = thirdParty.dagl.find(function (x) {
  128. return x.value === data.dagl_status;
  129. });
  130. return def ? def.name : '';
  131. }
  132. function getHintMsg () {
  133. return {
  134. invalidExpr: {type: 'warning', msg: '粘贴了非法表达式,已过滤'},
  135. disableChange: {type: 'error', msg: '不可修改此数据'},
  136. }
  137. }
  138. let currPageFileData = [];
  139. $(document).ready(() => {
  140. let detail, searchLedger;
  141. // 界面布局
  142. autoFlashHeight();
  143. // 初始化 台账树结构 数据结构
  144. removeLocalCache('bills-fold');
  145. const stageTreeSetting = {
  146. id: 'ledger_id',
  147. pid: 'ledger_pid',
  148. order: 'order',
  149. level: 'level',
  150. rootId: -1,
  151. keys: ['id', 'tender_id', 'ledger_id'],
  152. stageId: 'id',
  153. autoExpand: 3,
  154. // markFoldKey: 'bills-fold',
  155. // markFoldSubKey: window.location.pathname.split('/')[2],
  156. markExpandKey: 'stage-bills-expand',
  157. markExpandSubKey: window.location.pathname.split('/')[2],
  158. };
  159. // 台账树结构计算相关设置
  160. stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'qc_minus_qty', 'postil', 'used', 'contract_expr'];
  161. stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
  162. 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp', 'final_1_tp', 'end_final_1_tp'];
  163. stageTreeSetting.calcFun = function (node) {
  164. if (!node.children || node.children.length === 0) {
  165. node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
  166. node.end_gather_qty = ZhCalc.add(node.end_contract_qty, node.end_qc_qty);
  167. node.end_qc_minus_qty = ZhCalc.add(node.pre_qc_minus_qty, node.qc_minus_qty);
  168. node.final_1_qty = ZhCalc.add(node.end_qc_minus_qty, node.quantity);
  169. node.final_1_tp = ZhCalc.mul(node.final_1_qty, node.unit_price, tenderInfo.decimal.tp);
  170. node.deal_final_1_qty = ZhCalc.add(node.end_qc_minus_qty, node.deal_qty);
  171. node.end_final_1_qty = ZhCalc.add(node.end_qc_qty, node.final_1_qty);
  172. }
  173. node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
  174. node.end_contract_tp = ZhCalc.add(node.pre_contract_tp, node.contract_tp);
  175. node.end_qc_tp = ZhCalc.add(node.pre_qc_tp, node.qc_tp);
  176. node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
  177. node.end_gather_tp = ZhCalc.add(node.end_contract_tp, node.end_qc_tp);
  178. node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
  179. node.end_final_1_tp = ZhCalc.add(node.end_qc_tp, node.final_1_tp);
  180. if (!node.children || node.children.length === 0) {
  181. if (node.end_contract_qty) {
  182. node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp));
  183. } else {
  184. node.end_correct_tp = node.end_gather_tp;
  185. }
  186. }
  187. node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
  188. node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2);
  189. 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);
  190. node.end_final_1_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_1_tp), 100, 2);
  191. node.end_correct_1_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_1_tp), 100, 2);
  192. };
  193. const stageTree = createNewPathTree('stage', stageTreeSetting);
  194. // 初始化 计量单元 数据结构
  195. const stagePosSetting = { id: 'id', ledgerId: 'lid' };
  196. stagePosSetting.calcFun = function (pos) {
  197. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  198. pos.end_gather_qty = ZhCalc.add(pos.end_contract_qty, pos.end_qc_qty);
  199. pos.end_qc_minus_qty = ZhCalc.add(pos.pre_qc_minus_qty, pos.qc_minus_qty);
  200. pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
  201. pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2);
  202. pos.estimate_qty = !checkZero(pos.real_qty)
  203. ? ZhCalc.sub(ZhCalc.sub(pos.real_qty, pos.quantity), pos.end_qc_qty)
  204. : null;
  205. pos.final_1_qty = ZhCalc.add(pos.end_qc_minus_qty, pos.quantity);
  206. pos.deal_final_1_qty = ZhCalc.add(pos.end_qc_minus_qty, pos.deal_qty);
  207. pos.end_final_1_qty = ZhCalc.add(pos.end_qc_qty, pos.final_1_qty);
  208. };
  209. const stagePos = new StagePosData(stagePosSetting);
  210. // 初始化 台账 spread
  211. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  212. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  213. const ratioCol = ledgerSpreadSetting.cols.find(x => {return x.field === 'end_final_1_percent' || x.field === 'end_correct_1_percent'});
  214. if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_1_percent' : 'end_final_1_percent';
  215. ledgerSpreadSetting.imageClick = function (data, hitinfo) {
  216. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  217. if (col.field === 'dagl') data.dagl_url && window.open(data.dagl_url);
  218. if (col.field === 'gxby') data.gxby_url && window.open(data.gxby_url);
  219. };
  220. ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
  221. ledgerSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  222. if (data) {
  223. if (col.field === 'gxby') {
  224. const def = thirdParty.gxby.find(function (x) {
  225. return x.value === data.gxby_status;
  226. });
  227. if (def && def.color) return def.color;
  228. } else if (col.field === 'dagl') {
  229. const def = thirdParty.dagl.find(function (x) {
  230. return x.value === data.dagl_status;
  231. });
  232. if (def && def.color) return def.color;
  233. }
  234. return checkUtils.billsOver(data, checkTzMeasureType(), stagePos) ? '#f8d7da' : defaultColor;
  235. } else {
  236. return defaultColor;
  237. }
  238. };
  239. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  240. sjsSettingObj.set3FCols(ledgerSpreadSetting.cols, [
  241. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  242. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  243. ]);
  244. if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
  245. ledgerSpreadSetting.headColWidth = [50];
  246. ledgerSpreadSetting.rowHeader = [
  247. {
  248. rowHeaderType: 'tag',
  249. setting: {
  250. indent: 14,
  251. tagSize: 0.8,
  252. tagFont: '8px 微软雅黑',
  253. getColor: function (index, data) {
  254. if (!data) return;
  255. return billsTag.getBillsTagsColor(data.id);
  256. },
  257. getTagHtml: function (index, data) {
  258. if (!data) return;
  259. const getHtml = function (list) {
  260. if (!list || list.length === 0) return '';
  261. const html = [];
  262. for (const l of list) {
  263. html.push('<div class="row mr-1">');
  264. html.push(`<div class="col-auto pr-1 ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
  265. html.push('<div class="col p-0">', '<p>', l.comment, '</p>', '</div>');
  266. html.push('</div>');
  267. }
  268. return html.join('');
  269. };
  270. return getHtml(billsTag.getBillsTagsInfo(data.id));
  271. }
  272. },
  273. },
  274. ];
  275. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  276. slSpread.getActiveSheet().frozenColumnCount(5);
  277. slSpread.getActiveSheet().options.frozenlineColor = '#93b5e4';
  278. //初始化所有附件列表
  279. getAllList();
  280. // 初始化 计量单元 Spread
  281. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  282. const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
  283. spCol.cellType = 'activeImageBtn';
  284. spCol.normalImg = '#ellipsis-icon';
  285. spCol.indent = 5;
  286. spCol.showImage = function (data) {
  287. return data !== undefined && data !== null;
  288. };
  289. posSpreadSetting.imageClick = function (data, hitinfo) {
  290. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  291. if (col.field === 'dagl') data.dagl_url && window.open(data.dagl_url);
  292. if (col.field === 'gxby') data.gxby_url && window.open(data.gxby_url);
  293. };
  294. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  295. if (data) {
  296. if (col.field === 'gxby') {
  297. const def = thirdParty.gxby.find(function (x) {
  298. return x.value === data.gxby_status;
  299. });
  300. if (def && def.color) return def.color;
  301. } else if (col.field === 'dagl') {
  302. const def = thirdParty.dagl.find(function (x) {
  303. return x.value === data.dagl_status;
  304. });
  305. if (def && def.color) return def.color;
  306. }
  307. }
  308. if (checkTzMeasureType()) {
  309. return checkUtils.posOver(data) ? '#f8d7da' : defaultColor;
  310. }
  311. };
  312. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  313. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  314. sjsSettingObj.set3FCols(posSpreadSetting.cols, [
  315. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  316. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  317. ]);
  318. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  319. const billsTag = $.billsTag({
  320. selector: '#bills-tag',
  321. relaSpread: slSpread,
  322. updateUrl: window.location.pathname + '/tag',
  323. readOnly: true,
  324. afterModify: function (nodes) {
  325. SpreadJsObj.repaintNodesRowHeader(slSpread.getActiveSheet(), nodes);
  326. },
  327. afterLocated: function () {
  328. stagePosSpreadObj.loadCurPosData();
  329. },
  330. afterShow: function () {
  331. slSpread.refresh();
  332. if (spSpread) spSpread.refresh();
  333. },
  334. });
  335. const stageTreeSpreadObj = {
  336. loadExprToInput(sheet) {
  337. const sel = sheet.getSelections()[0];
  338. const col = sheet.zh_setting.cols[sel.col];
  339. if (col.type === 'Number') {
  340. const data = SpreadJsObj.getSelectObject(sheet);
  341. if (!data) {
  342. $('#bills-expr').val('');
  343. return;
  344. }
  345. const nodePos = stagePos.getLedgerPos(data.id);
  346. if (nodePos && nodePos.length > 0) {
  347. $('#bills-expr').val('');
  348. } else {
  349. const exprInfo = getExprInfo(col.field);
  350. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  351. $('#bills-expr').val(value).attr('field', col.field).attr('org', data[col.field]);
  352. }
  353. } else {
  354. $('#bills-expr').val('');
  355. }
  356. },
  357. selectionChanged: function (e, info) {
  358. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  359. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  360. stagePosSpreadObj.loadCurPosData();
  361. if (posSearch) {
  362. posSearch.search();
  363. }
  364. }
  365. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  366. stageTreeSpreadObj.loadExprToInput(info.sheet);
  367. },
  368. topRowChanged(e, info) {
  369. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  370. },
  371. };
  372. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  373. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  374. stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
  375. $.contextMenu({
  376. selector: '#stage-ledger',
  377. build: function ($trigger, e) {
  378. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  379. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  380. },
  381. items: {
  382. 'locateZjjl': {
  383. name: '定位至中间计量',
  384. icon: 'fa-sign-in',
  385. callback: function (key, opt) {
  386. if (!detail) {
  387. detail = new Detail($('#detail-spread'));
  388. }
  389. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  390. const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
  391. if (leafUsedBills) {
  392. if (!$('#zhongjian').hasClass('active')) {
  393. const tab = $('#zhongjiantab'), tabPanel = $(tab.attr('content'));
  394. $('a', '.side-menu').removeClass('active');
  395. $('.tab-content .tab-select-show').removeClass('active');
  396. tab.addClass('active');
  397. tabPanel.addClass('active');
  398. showSideTools(tab.hasClass('active'));
  399. slSpread.refresh();
  400. spSpread.refresh();
  401. }
  402. const relaXmj = stageIm.getRelaXmj(leafUsedBills);
  403. const im = stageIm.getRelaImData4Rela(relaXmj, leafUsedBills, usedPos);
  404. SpreadJsObj.locateData(detail.sheet, im);
  405. detail.spread.refresh();
  406. $('#zhongjian .sjs-bottom').height('400px');
  407. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  408. detail.reLoadDetailData();
  409. } else {
  410. toastr.error('无可定位中间计量');
  411. }
  412. },
  413. },
  414. tagSpr: '----',
  415. tag: {
  416. name: '书签',
  417. callback: function (key, opt, menu, e) {
  418. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  419. addTag.do(node);
  420. },
  421. disabled: function (key, opt) {
  422. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  423. return !node;
  424. }
  425. },
  426. showSpr: '----',
  427. showLast: {
  428. name: '显示至最底层',
  429. callback: function (key, opt, menu, e) {
  430. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  431. setTimeout(() => {
  432. showWaitingView();
  433. stageTree.expandByCustom(x => {
  434. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  435. });
  436. SpreadJsObj.refreshTreeRowVisible(slSpread.getActiveSheet());
  437. closeWaitingView();
  438. }, 100);
  439. },
  440. },
  441. exportSpr: '----',
  442. exportSelectNodeXlsx: {
  443. name: '导出选中节点至Excel',
  444. callback: function (key, opt, menu, e) {
  445. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  446. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + `计量台账(${node.name || ''}).xlsx`, [node]);
  447. },
  448. disabled: function (key, opt) {
  449. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  450. return !node;
  451. }
  452. },
  453. }
  454. });
  455. const stagePosSpreadObj = {
  456. loadExprToInput(sheet) {
  457. const sel = sheet.getSelections()[0];
  458. if (!sel) return;
  459. const col = sheet.zh_setting.cols[sel.col];
  460. if (col && col.type === 'Number') {
  461. const data = SpreadJsObj.getSelectObject(sheet);
  462. if (data) {
  463. const exprInfo = getExprInfo(col.field);
  464. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  465. $('#pos-expr').val(value);
  466. } else {
  467. $('#pos-expr').val('');
  468. }
  469. } else {
  470. $('#pos-expr').val('');
  471. }
  472. },
  473. /**
  474. * 加载计量单元 根据当前台账选择节点
  475. */
  476. loadCurPosData: function () {
  477. const sheet = slSpread.getActiveSheet();
  478. const node = SpreadJsObj.getSelectObject(sheet);
  479. if (node) {
  480. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  481. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  482. getNodeList(node.id);
  483. // 如果是附件是当前节点,隐藏
  484. // if ($('#dqjiedian').hasClass('active')) {
  485. // $('#showAttachment').hide();
  486. // }
  487. } else {
  488. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  489. }
  490. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  491. },
  492. selectionChanged: function (e, info) {
  493. stagePosSpreadObj.loadExprToInput(info.sheet);
  494. },
  495. };
  496. // 加载上下窗口resizer
  497. $.divResizer({
  498. select: '#main-resize',
  499. callback: function () {
  500. slSpread.refresh();
  501. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  502. $(".sp-wrap").height(bcontent-30);
  503. spSpread.refresh();
  504. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  505. }
  506. });
  507. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  508. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change;tag;sumDeal' }, function (result) {
  509. for (const l of result.ledgerData) {
  510. if (!l.is_leaf) continue;
  511. const sd = result.sumDeal.find(x => { return x.code === l.b_code && x.name === l.name && x.unit === l.unit; });
  512. l.unit_price = sd ? sd.unit_price : 0;
  513. l.deal_tp = ZhCalc.mul(l.unit_price, l.deal_qty, tenderInfo.decimal.tp);
  514. l.sgfh_tp = ZhCalc.mul(l.unit_price, l.sgfh_qty, tenderInfo.decimal.tp);
  515. l.sjcl_tp = ZhCalc.mul(l.unit_price, l.sjcl_qty, tenderInfo.decimal.tp);
  516. l.qtcl_tp = ZhCalc.mul(l.unit_price, l.qtcl_qty, tenderInfo.decimal.tp);
  517. l.total_price = ZhCalc.mul(l.unit_price, l.quantity, tenderInfo.decimal.tp);
  518. }
  519. // 加载树结构
  520. stageTree.loadDatas(result.ledgerData);
  521. treeCalc.calculateAll(stageTree);
  522. for (const t of result.tags) {
  523. t.node = stageTree.datas.find(x => {return x.id === t.lid});
  524. }
  525. billsTag.loadDatas(result.tags);
  526. // 加载部位明细
  527. stagePos.loadDatas(result.posData);
  528. stagePos.calculateAll();
  529. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  530. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  531. stagePosSpreadObj.loadCurPosData();
  532. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  533. // 加载中间计量
  534. stageIm.init(relaStage, imType, tenderInfo.decimal);
  535. stageIm.loadData4Rela(result.ledgerData, result.posData, result.detailData, result.changeData, result.detailAtt);
  536. }, null, true);
  537. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  538. $.subMenu({
  539. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  540. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  541. key: 'menu.1.0.0',
  542. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  543. callback: function (info) {
  544. if (info.mini) {
  545. $('.panel-title').addClass('fluid');
  546. $('#sub-menu').removeClass('panel-sidebar');
  547. } else {
  548. $('.panel-title').removeClass('fluid');
  549. $('#sub-menu').addClass('panel-sidebar');
  550. }
  551. autoFlashHeight();
  552. slSpread.refresh();
  553. spSpread.refresh();
  554. if (searchLedger) searchLedger.spread.refresh();
  555. if (detail) detail.spread.refresh();
  556. }
  557. });
  558. const posSearch = (function () {
  559. let resultArr = [];
  560. const search = function () {
  561. resultArr = [];
  562. const keyword = $('#pos-search-keyword').val();
  563. const checkOver = $('#pos-over-search')[0].checked;
  564. const checkEmpty = $('#pos-empty-search')[0].checked;
  565. const sortData = spSpread.getActiveSheet().zh_data;
  566. if (checkOver || checkEmpty) {
  567. if (sortData) {
  568. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  569. const sd = sortData[i];
  570. let match = false;
  571. if (checkOver) {
  572. if (sd.end_gather_qty) {
  573. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  574. }
  575. }
  576. if (checkEmpty) {
  577. if (sd.quantity) {
  578. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  579. }
  580. }
  581. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  582. if (match) {
  583. resultArr.push({index: i, data: sd});
  584. }
  585. }
  586. }
  587. } else if (keyword && keyword !== '') {
  588. if (sortData) {
  589. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  590. const sd = sortData[i];
  591. if (sd.name && sd.name.indexOf(keyword) > -1) {
  592. resultArr.push({index: i, data: sd});
  593. }
  594. }
  595. }
  596. }
  597. $('#pos-search-result').html('结果:' + resultArr.length);
  598. };
  599. const searchAndLocate = function () {
  600. search();
  601. if (resultArr.length > 0) {
  602. const sheet = spSpread.getActiveSheet();
  603. const sel = sheet.getSelections()[0];
  604. const curRow = sel ? sel.row : 0;
  605. const pos = resultArr[0];
  606. if (pos.index !== curRow) {
  607. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  608. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  609. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  610. }
  611. }
  612. };
  613. const locateNext = function () {
  614. if (resultArr.length > 0) {
  615. const sheet = spSpread.getActiveSheet();
  616. const sel = sheet.getSelections()[0];
  617. const curRow = sel ? sel.row : 0;
  618. let next = _.find(resultArr, function (d) {
  619. return d.index > curRow;
  620. });
  621. if (!next) next = resultArr[0];
  622. if (next.index !== curRow) {
  623. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  624. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  625. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  626. }
  627. }
  628. };
  629. const locatePre = function () {
  630. if (resultArr.length > 0) {
  631. const sheet = spSpread.getActiveSheet();
  632. const sel = sheet.getSelections()[0];
  633. const curRow = sel ? sel.row : 0;
  634. let next = _.findLast(resultArr, function (d) {
  635. return d.index < curRow;
  636. });
  637. if (!next) next = resultArr[resultArr.length - 1];
  638. if (next.index !== curRow) {
  639. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  640. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  641. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  642. }
  643. }
  644. };
  645. return {search, searchAndLocate, locateNext, locatePre};
  646. })();
  647. $('#pos-search-keyword').bind('keydown', function(e){
  648. if (e.keyCode == 13) posSearch.searchAndLocate();
  649. });
  650. $('#pos-empty-search').click(function () {
  651. if (this.checked) {
  652. $('[for=' + this.id +']').addClass('text-warning');
  653. } else {
  654. $('[for=' + this.id +']').removeClass('text-warning');
  655. }
  656. if (this.checked) {
  657. if ($('#pos-over-search')[0].checked) {
  658. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  659. } else {
  660. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  661. }
  662. } else {
  663. if ($('#pos-over-search')[0].checked) {
  664. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  665. } else {
  666. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  667. }
  668. }
  669. posSearch.searchAndLocate();
  670. });
  671. $('#pos-over-search').click(function () {
  672. if (this.checked) {
  673. $('[for=' + this.id +']').addClass('text-danger');
  674. } else {
  675. $('[for=' + this.id +']').removeClass('text-danger');
  676. }
  677. if (this.checked) {
  678. if ($('#pos-empty-search')[0].checked) {
  679. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  680. } else {
  681. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  682. }
  683. } else {
  684. if ($('#pos-empty-search')[0].checked) {
  685. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  686. } else {
  687. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  688. }
  689. }
  690. posSearch.searchAndLocate();
  691. });
  692. $('#pos-search-next').click(() => {posSearch.locateNext()});
  693. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  694. $.divResizer({
  695. select: '#right-spr',
  696. callback: function () {
  697. slSpread.refresh();
  698. spSpread.refresh();
  699. if (searchLedger) {
  700. searchLedger.spread.refresh();
  701. }
  702. if (detail) {
  703. detail.spread.refresh();
  704. }
  705. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  706. }
  707. });
  708. // 中间计量加载上下窗口resizer
  709. $.divResizer({
  710. select: '#zhongjian-spr',
  711. callback: function () {
  712. if (detail) {
  713. detail.spread.refresh();
  714. }
  715. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  716. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  717. }
  718. });
  719. // 附件加载上下窗口resizer
  720. $.divResizer({
  721. select: '#file-spr',
  722. callback: function () {
  723. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  724. }
  725. });
  726. class Detail {
  727. constructor (obj) {
  728. const self = this;
  729. this.spreadSetting = {
  730. cols: [
  731. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  732. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@'},
  733. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  734. {
  735. title: relaStage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  736. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@'
  737. },
  738. {
  739. title: '附件', colSpan: '1', rowSpan: '1', field: 'attachment', hAlign: 0, width: 60, readOnly: true, cellType: 'imageBtn',
  740. normalImg: '#rela-file-icon', hoverImg: '#rela-file-hover', getValue: function (data) {
  741. return data.attachment ? data.attachment.length : 0;
  742. }
  743. },
  744. ],
  745. headRows: 1,
  746. emptyRows: 0,
  747. headRowHeight: [32],
  748. headColWidth: [30],
  749. defaultRowHeight: 21,
  750. headerFont: '12px 微软雅黑',
  751. font: '12px 微软雅黑',
  752. readOnly: true,
  753. selectedBackColor: '#fffacd',
  754. imageClick: function (data) {
  755. self.makeAttTable(data);
  756. $('#im-file').modal('show');
  757. }
  758. };
  759. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  760. this.sheet = this.spread.getActiveSheet();
  761. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  762. this.detailObj = {
  763. selectionChanged: function (e, info) {
  764. self.reLoadDetailData();
  765. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  766. self.loadLocateInfo();
  767. }
  768. },
  769. };
  770. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  771. this._initImTypeSetRela();
  772. this._initLocateRela();
  773. this._initAttRela();
  774. this.reBuildImData();
  775. }
  776. makeAttTable (data) {
  777. let html = [];
  778. if (data.attachment) {
  779. for (const att of data.attachment) {
  780. const delHtml = (parseInt(att.uid) === userID && att.renew)
  781. ? '<a class="delete-att text-danger ml-1" href="javascript:void(0);" data-imid="'+ data.att_uuid +'" data-attid="'+ att.file_id +'" title="删除"><i class="fa fa-remove "></i></a>'
  782. : '';
  783. const viewHtml = att.viewpath ? `<a class="ml-1" href="${att.viewpath}" target="_blank" title="预览"><i class="fa fa-eye"></i></a>` : '';
  784. const downloadHtml = '<a href="'+ window.location.pathname + '/im-file/download?im_id='+ data.att_uuid +'&file_id='+ att.file_id +'" title="下载"><i class="fa fa-download "></i></a>';
  785. html.push('<tr><td style="width: 200px">' + att.filename + att.fileext + '</td><td>' + att.username + '</td><td>' + att.in_time + '</td>',
  786. '<td>', downloadHtml, viewHtml, delHtml, '</td></tr>');
  787. }
  788. }
  789. $('#im-attList').html(html.join(''));
  790. }
  791. _initAttRela() {
  792. // 上传附件
  793. const self = this;
  794. $('#upload-im-file').change(function () {
  795. const files = this.files;
  796. const sels = self.sheet.getSelections();
  797. const select = SpreadJsObj.getSelectObject(self.sheet);
  798. if (!select) return;
  799. const formData = new FormData();
  800. const baseInfo = {};
  801. if (select.att_uuid) {
  802. baseInfo.uuid = select.att_uuid;
  803. } else {
  804. baseInfo.im_type = select.im_type;
  805. baseInfo.lid = select.lid;
  806. baseInfo.pid = select.pid;
  807. baseInfo.code = select.code;
  808. baseInfo.name = select.name;
  809. baseInfo.unit = select.unit;
  810. baseInfo.unit_price = select.unit_price;
  811. baseInfo.pos_name = select.pos_name;
  812. }
  813. formData.append('base', JSON.stringify(baseInfo));
  814. for (const file of files) {
  815. if (file === undefined) {
  816. toast('未选择上传文件!', 'error');
  817. return false;
  818. }
  819. const filesize = file.size;
  820. if (filesize > 30 * 1024 * 1024) {
  821. toast('存在上传文件大小过大!', 'error');
  822. return false;
  823. }
  824. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  825. if (whiteList.indexOf(fileext) === -1) {
  826. toast('只能上传指定格式的附件!', 'error');
  827. return false;
  828. }
  829. formData.append('size', filesize);
  830. formData.append('file[]', file);
  831. }
  832. postDataWithFile(window.location.pathname + '/im-file/upload', formData, function (data) {
  833. stageIm.loadUpdateDetailAtt(data);
  834. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  835. self.makeAttTable(select);
  836. $('#upload-im-file').val('');
  837. });
  838. });
  839. // 删除附件
  840. $('body').on('click', '.delete-att' ,function () {
  841. const sels = self.sheet.getSelections();
  842. const select = SpreadJsObj.getSelectObject(self.sheet);
  843. if (!select) return;
  844. const uuid = $(this).attr('data-imid');
  845. const file_id = $(this).attr('data-attid');
  846. postData(window.location.pathname + '/im-file/del', { uuid, file_id }, function (result) {
  847. stageIm.loadUpdateDetailAtt(result);
  848. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  849. self.makeAttTable(select);
  850. });
  851. });
  852. }
  853. _initImTypeSetRela() {
  854. const self = this;
  855. const gatherConfirmPopover = {
  856. reBind: function (obj, eventName, fun) {
  857. obj.unbind(eventName);
  858. obj.bind(eventName, fun);
  859. },
  860. check: function (pos, hint, okCallback) {
  861. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  862. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  863. this.reBind(cancelObj, 'click', function () {
  864. confirmObj.hide();
  865. });
  866. this.reBind(okObj, 'click', function () {
  867. okCallback();
  868. confirmObj.hide();
  869. });
  870. hintObj.text(hint);
  871. confirmObj.css("top", pos.y).css("left", pos.x).show();
  872. }
  873. };
  874. this.gsTree = stageIm.getGsTree();
  875. if (relaStage.im_type === imType.tz.value || relaStage.im_type === imType.bb.value) {
  876. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  877. jlCol.title = '本期计量金额';
  878. SpreadJsObj.reLoadSheetHeader(self.sheet);
  879. $('[name=type-title-contract]').text('本期合同计量金额');
  880. $('[name=type-title-qc]').text('本期变更计量金额');
  881. if ($('#show-qc-minus-jl').length > 0) {
  882. $('#show-qc-minus-jl').parent().hide();
  883. $('#qc-minus-jl').parent().hide();
  884. }
  885. } else {
  886. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  887. jlCol.title = '本期计量数量';
  888. SpreadJsObj.reLoadSheetHeader(self.sheet);
  889. $('[name=type-title-contract]').text('本期合同计量数量');
  890. $('[name=type-title-qc]').text('本期变更计量数量');
  891. if ($('#show-qc-minus-jl').length > 0) {
  892. $('#show-qc-minus-jl').parent().show();
  893. $('#qc-minus-jl').parent().show();
  894. }
  895. }
  896. if (relaStage.im_type === imType.bb.value || relaStage.im_type === imType.bw.value) {
  897. $('#show-jldy').parent().show();
  898. $('#jldy').parent().show();
  899. $('#show-xm-name').parent().hide();
  900. $('#xm-name').parent().hide();
  901. } else {
  902. $('#show-jldy').parent().hide();
  903. $('#jldy').parent().hide();
  904. $('#show-xm-name').parent().show();
  905. $('#xm-name').parent().show();
  906. }
  907. }
  908. _initLocateRela() {
  909. const self = this;
  910. $('#im-locate2bills').click(function () {
  911. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  912. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  913. if (select && select.source) {
  914. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  915. stagePosSpreadObj.loadCurPosData();
  916. }
  917. });
  918. $('#im-locate-pre').click(function () {
  919. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  920. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  921. if (select && select.source) {
  922. const targetIndex = Math.max(curIndex-1, 1);
  923. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  924. stagePosSpreadObj.loadCurPosData();
  925. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  926. }
  927. });
  928. $('#im-locate-next').click(function () {
  929. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  930. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  931. if (select && select.source) {
  932. const targetIndex = Math.min(curIndex+1, select.source.length);
  933. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  934. stagePosSpreadObj.loadCurPosData();
  935. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  936. }
  937. });
  938. }
  939. loadLocateInfo() {
  940. const select = SpreadJsObj.getSelectObject(this.sheet);
  941. if (select && select.source.length > 1) {
  942. $('#im-locate2bills').next().show();
  943. } else {
  944. $('#im-locate2bills').next().hide();
  945. }
  946. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  947. }
  948. reLoadDetailData() {
  949. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  950. $('#detail-show').show();
  951. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  952. $('#show-contract-jl').text(contractJl);
  953. $('#contract-jl').val(contractJl);
  954. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  955. $('#show-qc-jl').text(qcJl);
  956. $('#qc-jl').val(qcJl);
  957. const qcMinusJl = data && data.qc_minus_jl ? data.qc_minus_jl : '';
  958. $('#show-qc-minus-jl').text(qcMinusJl);
  959. $('#qc-jl-minus-jl').val(qcMinusJl);
  960. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  961. $('#show-bgl-code').text(bglCode);
  962. $('#bgl-code').val(bglCode);
  963. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  964. $('#show-bgl-drawing-code').text(bglDrawingCode);
  965. $('#bgl-drawing-code').val(bglDrawingCode);
  966. const bwName = data && data.bw ? data.bw : '';
  967. $('#show-bw-name').text(bwName);
  968. $('#bw-name').val(bwName);
  969. const position = data && data.position ? data.position : '';
  970. $('#show-position').text(position);
  971. $('#position').val(position);
  972. const peg = data && data.peg ? data.peg : '';
  973. $('#show-peg').text(peg);
  974. $('#peg').val(peg);
  975. const xmName = data && data.xm ? data.xm: '';
  976. $('#show-xm-name').text(xmName);
  977. $('#xm-name').val(xmName);
  978. const jldy = data && data.jldy ? data.jldy: '';
  979. $('#show-jldy').text(jldy);
  980. $('#jldy').val(jldy);
  981. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  982. $('#show-drawing-code').text(drawingCode);
  983. $('#drawing-code').val(drawingCode);
  984. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  985. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  986. $('#calc-memo').val(calcMemo);
  987. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  988. $('#show-calc-img').attr('src', calcImgSrc);
  989. $('#calc-img').attr('src', calcImgSrc);
  990. $('#view-calc-img').attr('src', calcImgSrc);
  991. const calcImgRemark = data && data.calc_img_remark || '';
  992. $('#view-calc-remark').val(calcImgRemark);
  993. $("#view-calc-remark").attr('readonly', true);
  994. $('#text-edit').val(calcImgRemark)
  995. }
  996. reBuildImData() {
  997. const imData = stageIm.buildImData();
  998. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  999. this.reLoadDetailData();
  1000. this.loadLocateInfo();
  1001. }
  1002. }
  1003. // 展开收起附件
  1004. $('a', '.right-nav').bind('click', function () {
  1005. //const main = $('#main-view'), tool = $('#tools-view');
  1006. const tab = $(this), tabPanel = $(tab.attr('content'));
  1007. if (!tab.hasClass('active')) {
  1008. $('a', '.side-menu').removeClass('active');
  1009. $('.tab-content .tab-select-show').removeClass('active');
  1010. tab.addClass('active');
  1011. tabPanel.addClass('active');
  1012. showSideTools(tab.hasClass('active'));
  1013. if (tab.attr('content') === '#search' && !searchLedger) {
  1014. searchLedger = $.billsSearch({
  1015. selector: '#search',
  1016. searchSpread: slSpread,
  1017. searchOver: true,
  1018. searchEmpty: true,
  1019. resultSpreadSetting: {
  1020. cols: [
  1021. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  1022. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  1023. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  1024. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  1025. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  1026. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  1027. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  1028. ],
  1029. emptyRows: 0,
  1030. headRows: 1,
  1031. headRowHeight: [32],
  1032. headColWidth: [30],
  1033. defaultRowHeight: 21,
  1034. headerFont: '12px 微软雅黑',
  1035. font: '12px 微软雅黑',
  1036. selectedBackColor: '#fffacd',
  1037. },
  1038. afterLocated: function () {
  1039. stagePosSpreadObj.loadCurPosData();
  1040. },
  1041. customSearch: [
  1042. {
  1043. key: 'less', title: '漏计', valid: true,
  1044. check: function (node) {
  1045. if (node.quantity) {
  1046. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  1047. } else if (node.total_price) {
  1048. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  1049. }
  1050. }
  1051. }, {
  1052. key: 'over', title: '超计', valid: true,
  1053. check: function (node) {
  1054. return checkUtils.billsOver(node, checkTzMeasureType(), stagePos);
  1055. }
  1056. }, {
  1057. key: 'empty', title: '漏计', valid: false,
  1058. check: function (node) {
  1059. if (node.quantity) {
  1060. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  1061. } else if (node.total_price) {
  1062. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  1063. }
  1064. }
  1065. },
  1066. ],
  1067. });
  1068. searchLedger.spread.refresh();
  1069. }
  1070. if (tab.attr('content') === '#fujian') {
  1071. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1072. getNodeList(node.id);
  1073. }
  1074. if (tab.attr('content') === '#zhongjian') {
  1075. if (!detail) {
  1076. detail = new Detail($('#detail-spread'));
  1077. detail.spread.refresh();
  1078. $('#zhongjian .sjs-bottom').height('400px');
  1079. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1080. } else {
  1081. detail.spread.refresh();
  1082. }
  1083. }
  1084. } else {
  1085. tab.removeClass('active');
  1086. tabPanel.removeClass('active');
  1087. showSideTools(tab.hasClass('active'));
  1088. }
  1089. slSpread.refresh();
  1090. spSpread.refresh();
  1091. });
  1092. // 切换附件里节点和所有附件
  1093. $('#fujian .nav-link').on('click', function () {
  1094. const tabPanel = $(this).attr('fujian-content');
  1095. if (tabPanel !== 'syfujian') {
  1096. $('#showPage').hide();
  1097. $('#bach-download').prop('type', 'curr');
  1098. } else {
  1099. $('#showPage').show();
  1100. $('#bach-download').prop('type', 'all')
  1101. }
  1102. $('#showAttachment').hide();
  1103. });
  1104. // 获取附件信息
  1105. $('.list-table').on('click', '.att-file-name', function () {
  1106. const fid = $(this).attr('file-id');
  1107. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  1108. return;
  1109. }
  1110. const att = attData.find(function (item) {
  1111. return item.id === parseInt(fid);
  1112. });
  1113. $('#edit-att').hide();
  1114. $('#show-att').show();
  1115. if (att !== undefined) {
  1116. // 进来先把编辑功能隐藏
  1117. $('#btn-att a').eq(3).hide()
  1118. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  1119. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  1120. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  1121. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  1122. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  1123. $('#show-att tr').eq(3).children('td').text(att.remark);
  1124. // 附件uid等于当前用户id, 附件上传本人
  1125. if (parseInt(cur_uid) === att.uid) {
  1126. $('#btn-att').show();
  1127. $('#btn-att a').eq(2).hide();
  1128. $('#btn-att a').eq(4).hide();
  1129. $('#btn-att a').eq(5).hide();
  1130. } else {
  1131. $('#btn-att').hide();
  1132. $('#btn-att a').eq(3).hide();
  1133. $('#btn-att a').eq(2).hide();
  1134. $('#btn-att a').eq(4).hide();
  1135. $('#btn-att a').eq(5).hide();
  1136. }
  1137. $('#showAttachment').attr('file-id', fid);
  1138. $('#showAttachment').show();
  1139. } else {
  1140. $('#showAttachment').hide();
  1141. $('#showAttachment').attr('file-id', '');
  1142. toastr.error('附件信息获取失败');
  1143. }
  1144. });
  1145. // $('body').on('click', '.alllist-table a', handleFileList);
  1146. $('body').on('click', '#btn-att a', function () {
  1147. const content = $(this).attr('content');
  1148. const fid = $('#showAttachment').attr('file-id');
  1149. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1150. if (content === 'view') {
  1151. const data = {id: fid};
  1152. postData('/tender/' + relaTender.id + '/measure/stage/' + relaStage.order + '/check/file', data, function (result) {
  1153. const { filepath } = result
  1154. $('#load-file').attr('href', filepath);
  1155. $('#load-file')[0].click();
  1156. });
  1157. } else if (content === 'location') {
  1158. const att = attData.find(item => item.id === parseInt(fid));
  1159. if (Object.keys(att).length) {
  1160. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  1161. stagePosSpreadObj.loadCurPosData();
  1162. }
  1163. }
  1164. });
  1165. // 切换页数
  1166. $('.page-select').on('click', function () {
  1167. const totalPageNum = parseInt($('#totalPage').text());
  1168. const lastPageNum = parseInt($('#currentPage').text());
  1169. const status = $(this).attr('content');
  1170. if (status === 'pre' && lastPageNum > 1) {
  1171. getAllList(lastPageNum-1);
  1172. $('#showAttachment').hide();
  1173. $('#syfujian .check-all-file').prop('checked', false)
  1174. } else if (status === 'next' && lastPageNum < totalPageNum) {
  1175. getAllList(lastPageNum+1);
  1176. $('#showAttachment').hide();
  1177. $('#syfujian .check-all-file').prop('checked', false)
  1178. }
  1179. });
  1180. // 批量下载
  1181. $('#bach-download').click(function() {
  1182. const fileIds = [];
  1183. const type = $(this).attr('type');
  1184. let node = ''
  1185. if (type === 'curr') {
  1186. node = '#nodelist-table .check-file:checked'
  1187. } else {
  1188. node = '#alllist-table .check-file:checked'
  1189. }
  1190. $(node).each(function() {
  1191. const fileId = $(this).attr('file-id');
  1192. fileId && fileIds.push(fileId);
  1193. });
  1194. if (fileIds.length) {
  1195. if (fileIds.length > 20) {
  1196. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`)
  1197. }
  1198. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  1199. $(this).attr('disabled', "true")
  1200. const btn = $(this);
  1201. const fileArr = [];
  1202. for (const id of fileIds) {
  1203. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  1204. fileArr.push({
  1205. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  1206. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  1207. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  1208. });
  1209. }
  1210. const packageName = `${relaTender.name}-计量台账-第${relaStage.order}期-附件.zip`;
  1211. try {
  1212. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  1213. } catch (e) {
  1214. btn.removeAttr('disabled');
  1215. toastr.clear();
  1216. toastr.error('批量下载失败');
  1217. }
  1218. // postCompressFile(`/tender/${relaTender.id}/measure/stage/${relaStage.order}/download/compresse-file`, {fileIds}, function(result) {
  1219. // toastr.clear()
  1220. // toastr.success('压缩文件成功')
  1221. // btn.removeAttr('disabled')
  1222. // const href = window.URL.createObjectURL(result)
  1223. // $('#zipDown').attr('href', href);
  1224. // $('#zipDown').attr('download', `${relaTender.name}-计量台账-第${relaStage.order}期-附件.zip`);
  1225. // $("#zipDown")[0].click();
  1226. // }, () => {
  1227. // btn.removeAttr('disabled')
  1228. // toastr.clear()
  1229. // toastr.error('批量下载失败')
  1230. // });
  1231. }
  1232. });
  1233. // 监听附件check是否选中
  1234. $('.list-table').on('click', '.check-file', function() {
  1235. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  1236. const childs = $(this).parents('.list-table').children().length;
  1237. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  1238. if (checkedList.length === childs) {
  1239. checkBox.prop("checked", true);
  1240. } else {
  1241. checkBox.prop("checked", false);
  1242. }
  1243. });
  1244. $('.check-all-file').click(function() {
  1245. const isCheck = $(this).is(':checked');
  1246. $(this).parents('table').find('.list-table').each(function() {
  1247. $(this).find('input:checkbox').prop("checked", isCheck);
  1248. })
  1249. });
  1250. // 显示层次
  1251. (function (select, sheet) {
  1252. $(select).click(function () {
  1253. if (!sheet.zh_tree) return;
  1254. const tag = $(this).attr('tag');
  1255. const tree = sheet.zh_tree;
  1256. setTimeout(() => {
  1257. showWaitingView();
  1258. switch (tag) {
  1259. case "1":
  1260. case "2":
  1261. case "3":
  1262. case "4":
  1263. case "5":
  1264. tree.expandByLevel(parseInt(tag));
  1265. SpreadJsObj.refreshTreeRowVisible(sheet);
  1266. break;
  1267. case "last":
  1268. tree.expandByCustom(() => { return true; });
  1269. SpreadJsObj.refreshTreeRowVisible(sheet);
  1270. break;
  1271. case "leafXmj":
  1272. tree.expandToLeafXmj();
  1273. SpreadJsObj.refreshTreeRowVisible(sheet);
  1274. break;
  1275. case "curMeasure":
  1276. tree.expandByCustom(function (node) {
  1277. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  1278. if (node[field]) {
  1279. return true;
  1280. }
  1281. }
  1282. return false;
  1283. });
  1284. SpreadJsObj.refreshTreeRowVisible(sheet);
  1285. break;
  1286. }
  1287. closeWaitingView();
  1288. }, 100);
  1289. });
  1290. })('a[name=showLevel]', slSpread.getActiveSheet());
  1291. });