stage.js 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488
  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. /**
  14. * 从cookie中读取缓存的列显示设置,没有则取默认
  15. * @returns {*[]}
  16. */
  17. function customColDisplay () {
  18. const defaultSetting = [
  19. { title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true },
  20. { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
  21. { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl'], visible: true },
  22. { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
  23. { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
  24. { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl'], visible: true },
  25. { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp'], visible: true },
  26. { title: '图册号', fields: ['drawing_code'], visible: true },
  27. { title: '累计完成率(%)', fields: ['percent'], visible: true },
  28. { title: '备注', fields: ['memo'], visible: true },
  29. ];
  30. const settingStr = Cookies.get('stage-col-visible-1.0.0');
  31. return settingStr ? JSON.parse(settingStr) : defaultSetting;
  32. }
  33. /**
  34. * 根据列显示设置,调整setting中的列是否显示
  35. * @param setting
  36. * @param customDisplay
  37. */
  38. function customizeStageTreeSetting(setting, customDisplay) {
  39. for (const cd of customDisplay) {
  40. for (const c of setting.cols) {
  41. if (cd.fields.indexOf(c.field) !== -1) {
  42. c.visible = cd.visible;
  43. }
  44. }
  45. }
  46. }
  47. /**
  48. * 初始化 树结构 列事件
  49. * @param setting
  50. */
  51. function initTreeColSettingEvents(setting) {
  52. const Events = {
  53. readOnly: {
  54. measureData: function (node) {
  55. return node.children && node.children.length > 0;
  56. },
  57. },
  58. };
  59. const getEvent = function (eventName) {
  60. const names = eventName.split('.');
  61. let event = Events;
  62. for (let name of names) {
  63. if (event[name]) {
  64. event = event[name];
  65. } else {
  66. return null;
  67. }
  68. }
  69. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  70. return null;
  71. } else {
  72. return event;
  73. }
  74. };
  75. for (const col of setting.cols) {
  76. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  77. col.readOnly = getEvent(col.readOnly);
  78. }
  79. }
  80. }
  81. function needCheckDetail() {
  82. stage.check_detail = true;
  83. $('#check_point').show();
  84. }
  85. // 生成所有附件列表
  86. function getAllList(currPageNum = 1) {
  87. // 每页最多几个附件
  88. const pageCount = 11;
  89. // 附件总数
  90. const total = attData.length;
  91. // 总页数
  92. const pageNum = Math.ceil(total/pageCount);
  93. $('#totalPage').text(pageNum);
  94. $('#currentPage').text(currPageNum);
  95. // 当前页附件内容
  96. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  97. let html = '';
  98. for(const att of currPageAttData) {
  99. html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  100. }
  101. $('#alllist-table').html(html);
  102. }
  103. // 生成当前节点列表
  104. function getNodeList(node) {
  105. let html = '';
  106. for(const att of attData) {
  107. if (node === att.lid) {
  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. }
  111. $('#nodelist-table').html(html);
  112. }
  113. $(document).ready(() => {
  114. // 提示窗
  115. toastr.options = {
  116. "closeButton": false,
  117. "debug": false,
  118. "newestOnTop": false,
  119. "progressBar": false,
  120. "positionClass": "toast-top-center",
  121. "preventDuplicates": false,
  122. "onclick": null,
  123. "showDuration": "300",
  124. "hideDuration": "1000",
  125. "timeOut": "5000",
  126. "extendedTimeOut": "1000",
  127. "showEasing": "swing",
  128. "hideEasing": "linear",
  129. "showMethod": "fadeIn",
  130. "hideMethod": "fadeOut"
  131. };
  132. // 界面布局
  133. autoFlashHeight();
  134. // 初始化 台账树结构 数据结构
  135. const stageTreeSetting = {
  136. id: 'ledger_id',
  137. pid: 'ledger_pid',
  138. order: 'order',
  139. level: 'level',
  140. rootId: -1,
  141. keys: ['id', 'tender_id', 'ledger_id'],
  142. stageId: 'id',
  143. };
  144. // 台账树结构计算相关设置
  145. stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil'];
  146. stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
  147. 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp'];
  148. stageTreeSetting.calcFun = function (node) {
  149. if (node.children && node.children.length === 0) {
  150. node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
  151. node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
  152. node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty);
  153. node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
  154. node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
  155. }
  156. node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
  157. node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
  158. node.end_contract_tp = ZhCalc.add(node.pre_contract_tp, node.contract_tp);
  159. node.end_qc_tp = ZhCalc.add(node.pre_qc_tp, node.qc_tp);
  160. node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
  161. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), tenderInfo.decimal.up);
  162. };
  163. const stageTree = createNewPathTree('stage', stageTreeSetting);
  164. // 初始化 部位明细 数据结构
  165. const stagePosSetting = {
  166. id: 'id', ledgerId: 'lid',
  167. updateFields: ['contract_qty', 'qc_qty', 'postil'],
  168. };
  169. stagePosSetting.calcFun = function (pos) {
  170. pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
  171. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  172. pos.end_contract_qty = ZhCalc.add(pos.pre_contract_qty, pos.contract_qty);
  173. pos.end_qc_qty = ZhCalc.add(pos.pre_qc_qty, pos.qc_qty);
  174. pos.end_gather_qty = ZhCalc.add(pos.pre_gather_qty, pos.gather_qty);
  175. };
  176. const stagePos = new StagePosData(stagePosSetting);
  177. class Changes {
  178. constructor(obj) {
  179. const self = this;
  180. this.obj = obj;
  181. // 初始化 清单编号窗口 参数
  182. this.spreadSetting = {
  183. cols: [
  184. {title: '已用', field: '', width: 45, formatter: '@', cellType: 'image', readOnly: true, hAlign: 1, indent: 14, img: function (data) {
  185. if (data.uamount && !checkZero(data.uamount)) {
  186. return $('#icon-ok')[0];
  187. } else {
  188. return null;
  189. }
  190. }},
  191. {title: '变更令号', field: 'code', width: 100, formatter: '@', readOnly: true, hAlign: 0, },
  192. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true, hAlign: 0,},
  193. {title: '总数量', field: 'b_amount', width: 60, formatter: '@', readOnly: true, hAlign: 2, },
  194. {title: '可变更数量', field: 'vamount', width: 60, readOnly: true, hAlign: 2, },
  195. {title: '本期计量', field: 'uamount', width: 60, formatter: '@', hAlign: 2, type: 'Number', },
  196. ],
  197. emptyRows: 0,
  198. headRows: 1,
  199. headRowHeight: [40],
  200. getColor: function (data, col, defaultColor) {
  201. if (col.field === 'uamount') {
  202. if (!data.vamount) {
  203. return data.uamount ? '#ff6f5c' : defaultColor;
  204. } else if (data.uamount) {
  205. return data.uamount > data.vamount ? '#ff6f5c' : defaultColor;
  206. } else {
  207. return defaultColor;
  208. }
  209. } else {
  210. return defaultColor;
  211. }
  212. }
  213. };
  214. this.curChangeId = '';
  215. this.spread = SpreadJsObj.createNewSpread($('#change-spread')[0]);
  216. this.firstView = true;
  217. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  218. // 初次显示,需刷新spread界面,保证界面绘制正确
  219. this.obj.bind('shown.bs.modal', function () {
  220. if (self.firstView) {
  221. self.firstView = false;
  222. self.spread.refresh();
  223. }
  224. });
  225. // 切换变更令,加载右侧明细数据
  226. this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  227. const change = SpreadJsObj.getSelectObject(info.sheet);
  228. self._loadChangeDetail(change);
  229. });
  230. // 填写本期计量
  231. this.spread.bind(spreadNS.Events.EditEnded, function (e, info) {
  232. if (info.sheet.zh_setting) {
  233. const col = info.sheet.zh_setting.cols[info.col];
  234. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  235. const node = sortData[info.row];
  236. node[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  237. // 刷新界面
  238. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  239. }
  240. });
  241. this.spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  242. if (info.sheet.zh_setting) {
  243. const sortData = SpreadJsObj.getSortData(info.sheet);
  244. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  245. const curRow = iRow + info.cellRange.row;
  246. const curCol = info.cellRange.col;
  247. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  248. sortData[curRow][col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
  249. }
  250. SpreadJsObj.reLoadRowData(sheet, info.cellRange.row, sel.cellRange.rowCount);
  251. }
  252. });
  253. SpreadJsObj.addDeleteBind(this.spread, function (sheet) {
  254. if (sheet.zh_setting) {
  255. const sel = sheet.getSelections()[0];
  256. const sortData = SpreadJsObj.getSortData(sheet);
  257. // 仅本期计量可删除
  258. if (sel.col === 5 || sel.colCount === 1) {
  259. const col = sheet.zh_setting.cols[sel.col];
  260. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  261. const data = sortData[iRow];
  262. data[col.field] = null;
  263. }
  264. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  265. }
  266. }
  267. });
  268. // 过滤可变更数量为0
  269. $('#filterEmpty').click(function () {
  270. self._filterChange(!this.checked, $('#matchPos')[0].checked);
  271. });
  272. // 匹配编号
  273. $('#matchPos').click(function () {
  274. self._filterChange(!$('#filterEmpty')[0].checked, this.checked);
  275. });
  276. // 展开收起 变更令详细信息
  277. $('#show-bgl-detail').bind('click', function () {
  278. const detail = $('#bgl-detail'), bgl=$('#bgl'), obj=$(this);
  279. if (detail.hasClass('col-4')) {
  280. detail.attr('class', 'col').hide();
  281. bgl.attr('class', 'col-12');
  282. $('a', obj).attr('title', '展开侧栏');
  283. $('i', obj).attr('class', 'fa fa-chevron-left');
  284. self.spread.refresh();
  285. } else {
  286. detail.attr('class', 'col-4').show();
  287. bgl.attr('class', 'col-8');
  288. $('a', obj).attr('title', '收起侧栏');
  289. $('i', obj).attr('class', 'fa fa-chevron-right');
  290. self.spread.refresh();
  291. }
  292. });
  293. // 添加调用变更令
  294. $('#usg-bg-ok').click(function () {
  295. const data = { target: self.callData, change: [] };
  296. for (const c of self.displayChanges) {
  297. if (c.uamount) {
  298. if (!c.vamount || checkZero(c.vamount)) {
  299. toast('变更令:' + c.code + ' 当前不可使用', 'error');
  300. return;
  301. } else {
  302. if (c.uamount > c.vamount) {
  303. toast('变更令:' + c.code + ' 超计,请修改本期计量后,再提交', 'error');
  304. return;
  305. }
  306. }
  307. data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount });
  308. }
  309. }
  310. // 提交数据到后端
  311. postData(window.location.pathname + '/use-change', data, function(result) {
  312. if (result.pos) {
  313. stagePos.loadCurStageData(result.pos.curStageData);
  314. }
  315. const nodes = stageTree.loadPostStageData(result.bills);
  316. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  317. stagePosSpreadObj.loadCurPosData();
  318. needCheckDetail();
  319. self.obj.modal('hide');
  320. });
  321. })
  322. }
  323. _calculateAmount() {
  324. for (const c of this.changes) {
  325. c.bamount = _.toNumber(c.b_amount);
  326. c.vamount = ZhCalc.sub(c.bamount, c.used_amount);
  327. const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid});
  328. if (uc) {
  329. c.org_uamount = uc.qty;
  330. c.uamount = uc.qty;
  331. c.vamount = ZhCalc.add(c.vamount, c.uamount);
  332. }
  333. }
  334. }
  335. _loadChangeDetail(change) {
  336. if (change) {
  337. if (change.cid === this.curChangeId) { return; }
  338. this.curChangeId = change.cid;
  339. const inputs = $('input[type!=checkbox]', this.obj);
  340. for (const i of inputs) {
  341. const field = $(i).attr('name');
  342. const text = (field && change[field]) ? change[field] : '';
  343. $(i).val(text);
  344. }
  345. const textareas = $('textarea', this.obj);
  346. for (const ta of textareas) {
  347. const field = $(ta).attr('name');
  348. const text = (field && change[field]) ? change[field] : '';
  349. ta.innerText = text;
  350. }
  351. const html = [];
  352. for (const a of change.attachments) {
  353. html.push('<tr>');
  354. html.push('<td>', '<a href="/change/download/file/' + a.id + '">', a.filename + a.fileext, '</a>', '</td>');
  355. html.push('<td>', a.u_name, '</td>');
  356. html.push('</tr>');
  357. }
  358. // 变更类型
  359. if (change.type) {
  360. const cType = change.type.split(',');
  361. $('input[name="type"]').prop("checked", false);
  362. for (const c of cType) {
  363. $('input[name="type"][value='+ c +']').prop("checked", true);
  364. }
  365. }
  366. // 变更类别
  367. $('select[name=class]').val(change.class);
  368. // 变更性质
  369. $('select[name=quality]').val(change.quality);
  370. // 变更单位
  371. $('select[name=company]').html('<option>' + change.company + '</option>');
  372. // 费用承担方
  373. $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
  374. // 附件
  375. $('#attachment').html(html.join(''));
  376. } else {
  377. const inputs = $('input', this.obj);
  378. for (const i of inputs) {
  379. $(i).val('');
  380. }
  381. const textareas = $('textarea', this.obj);
  382. for (const ta of textareas) {
  383. ta.innerText = '';
  384. }
  385. $('#attachment').html('');
  386. }
  387. }
  388. _viewChanges() {
  389. const sheet = this.spread.getActiveSheet();
  390. if (this.changes) {
  391. sheet.setSelection(0, 0, 1, 1);
  392. //SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, this.changes);
  393. this._filterChange(!$('#filterEmpty')[0].checked, $('#matchPos')[0].checked);
  394. this._loadChangeDetail(this.changes[0]);
  395. } else {
  396. toast('查询变更令有误,请刷新页面后重试', 'warning');
  397. }
  398. }
  399. _filterChange(filterEmpty, matchPosName) {
  400. this.displayChanges = [];
  401. for (const c of this.changes) {
  402. const filterVisible = filterEmpty ? (c.vamount ? !checkZero(c.vamount) : false) : true;
  403. const matchVisible = matchPosName && this.callData.pos ? c.b_bwmx === this.callData.pos.name : true;
  404. if ((filterVisible && matchVisible) || (c.org_uamount)) {
  405. this.displayChanges.push(c);
  406. }
  407. //c.visible = filterVisible && matchVisible;
  408. }
  409. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), SpreadJsObj.DataType.Data, this.displayChanges);
  410. //SpreadJsObj.refreshTreeRowVisible(this.spread.getActiveSheet());
  411. }
  412. loadChanges(data) {
  413. this.callData = data;
  414. if (this.callData.pos) {
  415. $('#matchPos').parent().show();
  416. } else {
  417. $('#matchPos').parent().hide();
  418. }
  419. const self = this;
  420. $('#b-code-hint').text('当前变更清单:' + data.bills.b_code);
  421. postData(window.location.pathname + '/valid-change', data, function (result) {
  422. self.changes = result.changes;
  423. self.useChanges = result.useChanges;
  424. self._calculateAmount();
  425. self._viewChanges();
  426. self.obj.modal('show');
  427. });
  428. }
  429. }
  430. const changesObj = new Changes($('#use-bg'));
  431. // 初始化 台账 spread
  432. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  433. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  434. // 数量变更列,添加按钮
  435. const col = _.find(ledgerSpreadSetting.cols, {field: 'qc_qty'});
  436. col.readOnly = true;
  437. col.cellType = 'imageBtn';
  438. col.hoverImg = '#ellipsis-icon';
  439. col.indent = 5;
  440. col.showImage = function (data) {
  441. if (!data || (data.children && data.children.length > 0) || !(data.b_code && data.b_code !== '')) {
  442. return false;
  443. } else {
  444. const nodePos = stagePos.getLedgerPos(data.id);
  445. return !(nodePos && nodePos.length > 0);
  446. }
  447. };
  448. ledgerSpreadSetting.imageClick = function (data) {
  449. changesObj.loadChanges({bills: data});
  450. };
  451. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  452. stageTree.loadDatas(ledgerData);
  453. // stageTree.loadCurStageData(curStageData);
  454. // stageTree.loadPreStageData(preStageData);
  455. // 根据设置 计算 台账树结构
  456. treeCalc.calculateAll(stageTree);
  457. // 绘制界面
  458. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  459. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  460. //初始化所有附件列表
  461. getAllList();
  462. // 初始化 部位明细 Spread
  463. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  464. const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
  465. spCol.readOnly = true;
  466. spCol.cellType = 'imageBtn';
  467. spCol.hoverImg = '#ellipsis-icon';
  468. spCol.indent = 5;
  469. spCol.showImage = function (data) {
  470. return data;
  471. };
  472. posSpreadSetting.imageClick = function (data) {
  473. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  474. changesObj.loadChanges({bills: node, pos: data});
  475. };
  476. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  477. const stageTreeSpreadObj = {
  478. refreshTreeNodes: function (sheet, nodes) {
  479. const tree = sheet.zh_tree;
  480. if (!tree) { return }
  481. const rows = [];
  482. for (const node of nodes) {
  483. rows.push(tree.nodes.indexOf(node));
  484. }
  485. SpreadJsObj.reLoadRowsData(sheet, rows);
  486. },
  487. editEnded: function (e, info) {
  488. if (info.sheet.zh_setting) {
  489. const col = info.sheet.zh_setting.cols[info.col];
  490. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  491. const node = sortData[info.row];
  492. if (col.field !== 'postil') {
  493. if (node.children && node.children.length > 0) {
  494. toast('清单父项不可计量', 'error');
  495. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  496. return;
  497. } else {
  498. const nodePos = stagePos.getLedgerPos(node.id);
  499. if (nodePos && nodePos.length > 0) {
  500. toast('该清单有部位明细,请在部位明细处计量', 'error');
  501. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  502. return;
  503. }
  504. }
  505. }
  506. const billsData = {
  507. lid: node.id
  508. };
  509. billsData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  510. postData(window.location.href + '/update', { bills: billsData }, function (data) {
  511. const nodes = stageTree.loadPostStageData(data);
  512. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  513. needCheckDetail();
  514. });
  515. }
  516. },
  517. selectionChanged: function (e, info) {
  518. stagePosSpreadObj.loadCurPosData();
  519. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  520. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  521. },
  522. deletePress(sheet) {
  523. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  524. const tree = sheet.zh_tree;
  525. if (!tree) { return; }
  526. const sel = sheet.getSelections()[0];
  527. const validCols = [];
  528. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  529. if (!sheet.zh_setting.cols[iCol].readOnly) {
  530. validCols.push(iCol);
  531. }
  532. }
  533. if (validCols.length === 0) { return; }
  534. const sortData = sheet.zh_tree.nodes;
  535. const datas = [];
  536. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  537. const node = sortData[iRow];
  538. if (node) {
  539. const data = { lid: node.id };
  540. let filter = true;
  541. for (const iCol of validCols) {
  542. const colSetting = sheet.zh_setting.cols[iCol];
  543. if (colSetting.field !== 'postil') {
  544. if (node.children && node.children.length > 0) { continue; }
  545. const nodePos = stagePos.getLedgerPos(node.id);
  546. if (nodePos && nodePos.length > 0) { continue; }
  547. }
  548. data[colSetting.field] = null;
  549. filter = false;
  550. }
  551. if (!filter) {
  552. datas.push(data);
  553. }
  554. }
  555. }
  556. if (datas.length > 0) {
  557. postData(window.location.href + '/update', {bills: datas}, function (result) {
  558. const nodes = stageTree.loadPostStageData(result);
  559. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  560. needCheckDetail();
  561. });
  562. }
  563. }
  564. },
  565. clipboardPasting(e, info) {
  566. if (info.sheet.zh_setting) {
  567. const sortData = info.sheet.zh_data;
  568. const range = info.cellRange;
  569. const validField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'];
  570. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  571. const col = info.sheet.zh_setting.cols[iCol];
  572. if (validField.indexOf(col.field) === -1) {
  573. toast('不可修改此数据', 'error');
  574. info.cancel = true;
  575. return;
  576. }
  577. }
  578. }
  579. },
  580. clipboardPasted(e, info) {
  581. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  582. const sheet = info.sheet;
  583. const filterNodes = [], datas = [];
  584. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  585. const curRow = iRow + info.cellRange.row;
  586. const node = sheet.zh_tree.getItemsByIndex(curRow);
  587. const data = {lid: node.id};
  588. let filter = true;
  589. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  590. const curCol = info.cellRange.col + iCol;
  591. const col = info.sheet.zh_setting.cols[curCol];
  592. if (col.field !== 'postil') {
  593. if (node.children && node.children.length > 0) {
  594. continue;
  595. }
  596. const nodePos = stagePos.getLedgerPos(node.id);
  597. if (nodePos && nodePos.length > 0) {
  598. continue;
  599. }
  600. }
  601. data[col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
  602. filter = false;
  603. }
  604. if (filter) {
  605. filterNodes.push(node);
  606. } else {
  607. datas.push(data);
  608. }
  609. }
  610. if (datas.length > 0) {
  611. postData(window.location.href + '/update', { bills: datas }, function (data) {
  612. const nodes = stageTree.loadPostStageData(data);
  613. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  614. needCheckDetail();
  615. });
  616. } else {
  617. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  618. }
  619. }
  620. },
  621. measureAllPosInNode(node, ratio = 1) {
  622. const posterity = stageTree.getPosterity(node);
  623. const data = {updateType: 'update', updateData: []};
  624. for (const p of posterity) {
  625. if (p.children && p.children.length > 0) continue;
  626. const posRange = stagePos.getLedgerPos(p.id);
  627. if (posRange && posRange.length > 0) {
  628. for (const pr of posRange) {
  629. if (pr.contract_qty && !checkZero(pr.contract_qty)) continue;
  630. const validValue = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
  631. if (validValue <= 0) continue;
  632. const value = ratio !== 1 ? ZhCalc.mul(pr.quantity, ratio) : pr.quantity;
  633. const pData = {
  634. pid: pr.id,
  635. lid: pr.lid,
  636. contract_qty: validValue > 0 ? (value > validValue ? validValue : value) : (value < validValue ? validValue : value),
  637. };
  638. data.updateData.push(pData);
  639. }
  640. }
  641. if (data.updateData.length > 1000 || _.map(data.updateData, 'lid').length > 200) {
  642. toastr.warning('选中的数据过多,仅计量' + data.updateData.length + '条,请稍后');
  643. break;
  644. }
  645. }
  646. console.log(data);
  647. if (data.updateData.length === 0) {
  648. toastr.info('其下全部部位明细均已计量');
  649. return;
  650. }
  651. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  652. if (result.pos) {
  653. stagePos.updateDatas(result.pos.pos);
  654. stagePos.loadCurStageData(result.pos.curStageData);
  655. }
  656. const nodes = stageTree.loadPostStageData(result.ledger);
  657. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  658. stagePosSpreadObj.loadCurPosData();
  659. needCheckDetail();
  660. toastr.success('已计量' + data.updateData.length + '条');
  661. }, function () {
  662. stagePosSpreadObj.loadCurPosData();
  663. });
  664. },
  665. topRowChanged(e, info) {
  666. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  667. },
  668. };
  669. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  670. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  671. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  672. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  673. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  674. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  675. $.contextMenu({
  676. selector: '#stage-ledger',
  677. build: function ($trigger, e) {
  678. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  679. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  680. },
  681. items: {
  682. 'measureAll': {
  683. name: '计量其下所有部位明细',
  684. icon: 'fa-rocket',
  685. callback: function (key, opt) {
  686. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  687. stageTreeSpreadObj.measureAllPosInNode(node);
  688. },
  689. visible: function (key, opt) {
  690. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  691. return select;
  692. }
  693. },
  694. 'measureAllFiveTenth': {
  695. name: '计量其下所有部位明细(计量50%)',
  696. icon: 'fa-plane',
  697. callback: function (key, opt) {
  698. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  699. stageTreeSpreadObj.measureAllPosInNode(node, 0.5);
  700. },
  701. visible: function (key, opt) {
  702. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  703. return select;
  704. }
  705. },
  706. 'measureAllOneTenth': {
  707. name: '计量其下所有部位明细(计量10%)',
  708. icon: 'fa-car',
  709. callback: function (key, opt) {
  710. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  711. stageTreeSpreadObj.measureAllPosInNode(node, 0.1);
  712. },
  713. visible: function (key, opt) {
  714. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  715. return select;
  716. }
  717. },
  718. 'hint1': {
  719. name: '最多计量200条清单下1000条部位明细',
  720. className: 'text-danger',
  721. visible: function (key, opt) {
  722. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  723. return select;
  724. },
  725. disabled: function (key, opt) {
  726. return true;
  727. }
  728. },
  729. 'hint1_1': {
  730. name: '(计数以清单为准,会计完清单下全部部位)',
  731. className: 'text-danger',
  732. visible: function (key, opt) {
  733. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  734. return select;
  735. },
  736. disabled: function (key, opt) {
  737. return true;
  738. }
  739. },
  740. 'hint2': {
  741. name: '可再次使用该功能计量剩下的节点',
  742. className: 'text-danger',
  743. visible: function (key, opt) {
  744. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  745. return select;
  746. },
  747. disabled: function (key, opt) {
  748. return true;
  749. }
  750. },
  751. 'hint2_2': {
  752. name: '(凡是计量的部位,不论计量多少,均不再计量)',
  753. className: 'text-danger',
  754. visible: function (key, opt) {
  755. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  756. return select;
  757. },
  758. disabled: function (key, opt) {
  759. return true;
  760. }
  761. },
  762. 'hint3': {
  763. name: '如提示数据过多后,未成功,请缩小范围再试',
  764. className: 'text-danger',
  765. visible: function (key, opt) {
  766. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  767. return select;
  768. },
  769. disabled: function (key, opt) {
  770. return true;
  771. }
  772. },
  773. 'hint4': {
  774. name: '该功能仅供测试用,请勿滥用,可能导致服务挂掉',
  775. className: 'text-danger',
  776. visible: function (key, opt) {
  777. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  778. return select;
  779. },
  780. disabled: function (key, opt) {
  781. return true;
  782. }
  783. },
  784. }
  785. });
  786. const stagePosSpreadObj = {
  787. /**
  788. * 加载部位明细 根据当前台账选择节点
  789. */
  790. loadCurPosData: function () {
  791. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  792. if (node) {
  793. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  794. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  795. getNodeList(node.id);
  796. // 如果是附件是当前节点,隐藏
  797. if ($('#dqjiedian').hasClass('active')) {
  798. $('#showAttachment').hide();
  799. }
  800. } else {
  801. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  802. }
  803. },
  804. editEnded: function (e, info) {
  805. if (info.sheet.zh_setting) {
  806. // 未改变过,则直接跳过
  807. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  808. const col = info.sheet.zh_setting.cols[info.col];
  809. const orgText = posData ? posData[col.field] : null;
  810. if (orgText === info.editingText || ((!orgText || orgText === '') && (info.editingText === ''))) {
  811. return;
  812. }
  813. // 台账模式下,不可新增
  814. if (checkTzMeasureType() && !posData) {
  815. toast('台账模式不可新增部位明细数据', 'error');
  816. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  817. info.cancel = true;
  818. return ;
  819. }
  820. // 不同节点下,部位明细检查输入
  821. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  822. const node = stagePosSpreadObj.stageTreeNode;
  823. if (!node) {
  824. toast('数据错误, 请刷新页面后再试', 'warning');
  825. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  826. return;
  827. } else if (info.editingText !== '' && node.children && node.children > 0) {
  828. toast('父节点不可插入部位明细', 'error');
  829. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  830. return;
  831. } else if (info.editingText !== '' && !node.b_code || node.b_code === '') {
  832. toast('项目节不可插入部位明细', 'error');
  833. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  834. return;
  835. }
  836. // 生成提交数据
  837. const data = {};
  838. if (col.field === 'name') {
  839. if (info.editingText === '' && pos) {
  840. toast('部位名称不可为空', 'error', 'exclamation-circle');
  841. info.cancel = true;
  842. return;
  843. } else if (!posData) {
  844. if (info.editingText !== '') {
  845. data.updateType = 'add';
  846. data.updateData = {name: info.editingText, lid: node.id, tid: tender.id};
  847. } else {
  848. return;
  849. }
  850. } else {
  851. data.updateType = 'update';
  852. data.updateData = {pid: posData.id, lid: posData.lid, name: info.editingText};
  853. }
  854. } else if (!posData) {
  855. toast('新增部位请先输入名称', 'warning');
  856. } else {
  857. data.updateType = 'update';
  858. data.updateData = {pid: posData.id, lid: posData.lid};
  859. data.updateData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  860. }
  861. // 提交数据到服务器
  862. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  863. if (result.pos) {
  864. stagePos.updateDatas(result.pos.pos);
  865. stagePos.loadCurStageData(result.pos.curStageData);
  866. }
  867. const refreshData = stageTree.loadPostStageData(result.ledger);
  868. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  869. stagePosSpreadObj.loadCurPosData();
  870. needCheckDetail();
  871. }, function () {
  872. stagePosSpreadObj.loadCurPosData();
  873. });
  874. }
  875. },
  876. editStarting: function (e, info) {
  877. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  878. },
  879. clipboardPasting: function (e, info) {
  880. if (info.sheet.zh_setting) {
  881. const sortData = info.sheet.zh_data;
  882. const range = info.cellRange;
  883. const validField = ['contract_qty', 'qc_qty', 'postil'];
  884. if (!checkTzMeasureType()) {
  885. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty');
  886. }
  887. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  888. const col = info.sheet.zh_setting.cols[iCol];
  889. if (validField.indexOf(col.field) === -1) {
  890. if (checkTzMeasureType()) {
  891. toast('不可修改此数据', 'error');
  892. info.cancel = true;
  893. return;
  894. } else {
  895. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  896. const pos = sortData(iRow);
  897. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  898. toast('不可修改此数据', 'error');
  899. info.cancel = true;
  900. return;
  901. }
  902. }
  903. }
  904. }
  905. }
  906. }
  907. },
  908. clipboardPasted: function (e, info) {
  909. const self = this;
  910. if (info.sheet.zh_setting) {
  911. const data = { updateType: '', updateData: [], };
  912. const sortData = info.sheet.zh_data;
  913. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  914. if (sortData && (info.cellRange.row >= sortData.length)) {
  915. data.updateType = 'add';
  916. if (info.cellRange.col !== 0) {
  917. toast('新增部位请先输入名称', 'warning');
  918. self.loadCurPosData();
  919. return;
  920. }
  921. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  922. const curRow = info.cellRange.row + iRow;
  923. const newData = {lid: node.id};
  924. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  925. const curCol = info.cellRange.col + iCol;
  926. const colSetting = info.sheet.zh_setting.cols[curCol];
  927. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  928. if (colSetting.type === 'Number') {
  929. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  930. }
  931. }
  932. data.updateData.push(newData);
  933. }
  934. } else {
  935. data.updateType = 'update';
  936. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  937. const curRow = info.cellRange.row + iRow;
  938. const curPos = sortData[curRow];
  939. if (curPos) {
  940. const newData = {pid: curPos.id, lid: curPos.lid};
  941. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  942. const curCol = info.cellRange.col + iCol;
  943. const colSetting = info.sheet.zh_setting.cols[curCol];
  944. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  945. if (colSetting.type === 'Number') {
  946. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  947. }
  948. }
  949. data.updateData.push(newData);
  950. }
  951. }
  952. }
  953. console.log(data);
  954. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  955. if (result.pos) {
  956. stagePos.updateDatas(result.pos.pos);
  957. stagePos.loadCurStageData(result.pos.curStageData);
  958. }
  959. const nodes = stageTree.loadPostStageData(result.ledger);
  960. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  961. stagePosSpreadObj.loadCurPosData();
  962. needCheckDetail();
  963. }, function () {
  964. stagePosSpreadObj.loadCurPosData();
  965. });
  966. }
  967. },
  968. deletePress: function (sheet) {
  969. if (sheet.zh_setting && sheet.zh_data) {
  970. const sortData = sheet.zh_data;
  971. if (!sortData || sortData.length === 0) { return; }
  972. const sel = sheet.getSelections()[0];
  973. const validCols = [];
  974. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  975. if (!sheet.zh_setting.cols[iCol].readOnly) {
  976. validCols.push(iCol);
  977. }
  978. }
  979. if (validCols.length === 0) { return; }
  980. const datas = [], posSelects = [];
  981. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  982. const node = sortData[iRow];
  983. if (node) {
  984. const data = {pid: node.id, lid: node.lid};
  985. for (const iCol of validCols) {
  986. const colSetting = sheet.zh_setting.cols[iCol];
  987. if (colSetting.field === 'name') {
  988. toast('部位名称不能为空', 'error');
  989. return;
  990. }
  991. data[colSetting.field] = null;
  992. }
  993. datas.push(data);
  994. posSelects.push(node);
  995. }
  996. }
  997. if (datas.length > 0) {
  998. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  999. if (result.pos) {
  1000. stagePos.updateDatas(result.pos.pos);
  1001. stagePos.loadCurStageData(result.pos.curStageData);
  1002. }
  1003. const nodes = stageTree.loadPostStageData(result.ledger);
  1004. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1005. needCheckDetail();
  1006. // todo 只加载改变项
  1007. stagePosSpreadObj.loadCurPosData();
  1008. });
  1009. }
  1010. }
  1011. },
  1012. leaveCell: function (e, info) {
  1013. console.log(1);
  1014. },
  1015. };
  1016. // 加载上下窗口resizer
  1017. $.divResizer({
  1018. select: '#main-resize',
  1019. callback: function () {
  1020. slSpread.refresh();
  1021. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1022. $(".sp-wrap").height(bcontent-40);
  1023. spSpread.refresh();
  1024. }
  1025. });
  1026. // 加载部位明细数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1027. console.time('loadPosFromServer');
  1028. postData(window.location.pathname + '/pos', null, function (result) {
  1029. console.timeEnd('loadPosFromServer');
  1030. console.log('pos: ' + result.length);
  1031. stagePos.loadDatas(result);
  1032. stagePos.calculateAll();
  1033. stagePosSpreadObj.loadCurPosData();
  1034. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  1035. });
  1036. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  1037. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  1038. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  1039. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  1040. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  1041. if (!checkTzMeasureType()) {
  1042. }
  1043. $('#row-view').on('show.bs.modal', function () {
  1044. const html = [], customDisplay = customColDisplay();
  1045. for (const cd of customDisplay) {
  1046. html.push('<tr>');
  1047. html.push('<td>', cd.title, '</td>');
  1048. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  1049. html.push('</tr>');
  1050. }
  1051. $('#row-view-list').html(html.join(''));
  1052. });
  1053. $('#row-view-ok').click(function () {
  1054. const customDisplay = customColDisplay();
  1055. const cvl = $('#row-view-list').children();
  1056. for (const cv of cvl) {
  1057. const title = $(cv).children()[0].innerHTML;
  1058. const check = $('input', cv)[0].checked;
  1059. const cd = customDisplay.find(function (c) {
  1060. return c.title === title;
  1061. });
  1062. cd.visible = check;
  1063. }
  1064. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  1065. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  1066. Cookies.set('stage-col-visible', JSON.stringify(customDisplay), 7*24*60*60*1000);
  1067. $('#row-view').modal('hide');
  1068. });
  1069. class SearchLedger {
  1070. constructor(obj, mainSpread) {
  1071. const self = this;
  1072. this.obj = obj;
  1073. this.mainSpread = mainSpread;
  1074. this.spreadSetting = {
  1075. cols: [
  1076. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@'},
  1077. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  1078. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@'},
  1079. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  1080. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  1081. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  1082. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  1083. ],
  1084. emptyRows: 3,
  1085. headRows: 1,
  1086. headRowHeight: [40],
  1087. defaultRowHeight: 21,
  1088. readOnly: true
  1089. };
  1090. this.spread = SpreadJsObj.createNewSpread($('#search-result', this.obj)[0]);
  1091. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1092. $('#searchLedger', this.obj).bind('click', function () {
  1093. const keyword = $('#keyword', self.obj).val();
  1094. if (keyword !== '') {
  1095. $('#over', obj)[0].checked = false;
  1096. $('#empty', obj)[0].checked = false;
  1097. this.searchResult = [];
  1098. const sortData = SpreadJsObj.getSortData(self.mainSpread.getActiveSheet());
  1099. for (const node of sortData) {
  1100. if ((node.code && node.code.indexOf(keyword) > -1) ||
  1101. node.b_code && node.b_code.indexOf(keyword) > -1 ||
  1102. node.name && node.name.indexOf(keyword) > -1) {
  1103. this.searchResult.push(node);
  1104. }
  1105. }
  1106. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', this.searchResult);
  1107. }
  1108. });
  1109. $('#over', this.obj).bind('change', function () {
  1110. this.searchResult = [];
  1111. const sortData = SpreadJsObj.getSortData(self.mainSpread.getActiveSheet());
  1112. for (const node of sortData) {
  1113. if (node.children && node.children.length > 0) continue;
  1114. if (node.end_gather_qty) {
  1115. if (!node.quantity || Math.abs(node.end_gather_qty) > Math.abs(node.quantity)) {
  1116. this.searchResult.push(node);
  1117. }
  1118. } else if (node.end_gather_tp) {
  1119. if (!node.total_price || Math.abs(node.end_gather_tp) > Math.abs(node.total_price)) {
  1120. this.searchResult.push(node);
  1121. }
  1122. }
  1123. }
  1124. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', this.searchResult);
  1125. });
  1126. $('#empty', this.obj).bind('change', function () {
  1127. this.searchResult = [];
  1128. const sortData = SpreadJsObj.getSortData(self.mainSpread.getActiveSheet());
  1129. for (const node of sortData) {
  1130. if (node.children && node.children.length > 0) continue;
  1131. if (node.quantity) {
  1132. if (!node.end_gather_qty || checkZero(node.end_gather_qty)) {
  1133. this.searchResult.push(node);
  1134. }
  1135. } else if (node.total_price) {
  1136. if (!node.end_gather_tp || checkZero(node.end_gather_tp)) {
  1137. this.searchResult.push(node);
  1138. }
  1139. }
  1140. }
  1141. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', this.searchResult);
  1142. });
  1143. this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1144. const sheet = info.sheet;
  1145. const data = sheet.zh_data;
  1146. if (!data) { return }
  1147. const curBills = data[info.row];
  1148. if (!curBills) { return }
  1149. SpreadJsObj.locateTreeNode(self.mainSpread.getActiveSheet(), curBills.ledger_id);
  1150. });
  1151. }
  1152. }
  1153. let searchLedger;
  1154. $.divResizer({
  1155. select: '#right-spr',
  1156. callback: function () {
  1157. slSpread.refresh();
  1158. spSpread.refresh();
  1159. if (searchLedger) {
  1160. searchLedger.spread.refresh();
  1161. }
  1162. }
  1163. });
  1164. // 展开收起附件
  1165. $('a', '.right-nav').bind('click', function () {
  1166. //const main = $('#main-view'), tool = $('#tools-view');
  1167. const tab = $(this), tabPanel = $(tab.attr('content'));
  1168. const showTools = function (show) {
  1169. const left = $('#main-view'), right = $('#tools-view'), parent = left.parent();
  1170. if (show) {
  1171. right.show();
  1172. autoFlashHeight();
  1173. /**
  1174. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1175. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1176. * 故需要通过最终的parent.width再计算一次left.width
  1177. *
  1178. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1179. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1180. *
  1181. */
  1182. //left.css('width', parent.width() - right.outerWidth());
  1183. //left.css('width', parent.width() - right.outerWidth());
  1184. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1185. left.css('width', percent + '%');
  1186. } else {
  1187. right.hide();
  1188. left.css('width', '100%');
  1189. }
  1190. };
  1191. if (!tab.hasClass('active')) {
  1192. $('a', '.side-menu').removeClass('active');
  1193. $('.tab-content .tab-select-show').removeClass('active');
  1194. tab.addClass('active');
  1195. tabPanel.addClass('active');
  1196. showTools(tab.hasClass('active'));
  1197. if (tab.attr('content') === '#search' && !searchLedger) {
  1198. searchLedger = new SearchLedger($('#search'), slSpread);
  1199. searchLedger.spread.refresh();
  1200. }
  1201. if (tab.attr('content') === '#fujian') {
  1202. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1203. getNodeList(node.id);
  1204. }
  1205. } else {
  1206. tab.removeClass('active');
  1207. tabPanel.removeClass('active');
  1208. showTools(tab.hasClass('active'));
  1209. }
  1210. slSpread.refresh();
  1211. spSpread.refresh();
  1212. });
  1213. // 切换附件里节点和所有附件
  1214. $('#fujian .nav-link').on('click', function () {
  1215. const tabPanel = $(this).attr('fujian-content');
  1216. if (tabPanel !== 'syfujian') {
  1217. $('#showPage').hide();
  1218. } else {
  1219. $('#showPage').show();
  1220. }
  1221. $('#showAttachment').hide();
  1222. });
  1223. // 上传附件
  1224. $('#upload-file-btn').click(function () {
  1225. const files = $('#upload-file')[0].files;
  1226. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1227. const formData = new FormData();
  1228. formData.append('lid', node.id);
  1229. for (const file of files) {
  1230. if (file === undefined) {
  1231. toast('未选择上传文件!', 'error');
  1232. return false;
  1233. }
  1234. const filesize = file.size;
  1235. if (filesize > 10 * 1024 * 1024) {
  1236. toast('存在上传文件大小过大!', 'error');
  1237. return false;
  1238. }
  1239. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  1240. if (whiteList.indexOf(fileext) === -1) {
  1241. toast('只能上传指定格式的附件!', 'error');
  1242. return false;
  1243. }
  1244. formData.append('size', filesize);
  1245. formData.append('file[]', file);
  1246. }
  1247. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  1248. $('#upload').modal('hide');
  1249. // 插入到attData中
  1250. attData = data.concat(attData);
  1251. // 重新生成List
  1252. getAllList();
  1253. getNodeList(node.id);
  1254. }, function () {
  1255. toast('附件上传失败', 'error');
  1256. });
  1257. $('#upload-file').val('');
  1258. });
  1259. // 获取附件信息
  1260. $('body').on('click', '.list-table a', function () {
  1261. const fid = $(this).attr('file-id');
  1262. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  1263. return;
  1264. }
  1265. const att = attData.find(function (item) {
  1266. return item.id === parseInt(fid);
  1267. });
  1268. $('#edit-att').hide();
  1269. $('#show-att').show();
  1270. if (att !== undefined) {
  1271. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  1272. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  1273. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  1274. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  1275. $('#show-att tr').eq(3).children('td').eq(0).text(att.username);
  1276. $('#show-att tr').eq(3).children('td').eq(1).text(att.in_time);
  1277. $('#show-att tr').eq(4).children('td').text(att.remark);
  1278. if (parseInt(userID) === att.uid) {
  1279. $('#btn-att').show();
  1280. $('#btn-att a').eq(1).show();
  1281. $('#btn-att a').eq(0).hide();
  1282. $('#btn-att a').eq(2).hide();
  1283. $('#btn-att a').eq(3).hide();
  1284. } else {
  1285. $('#btn-att').hide();
  1286. $('#btn-att a').eq(1).hide();
  1287. $('#btn-att a').eq(0).hide();
  1288. $('#btn-att a').eq(2).hide();
  1289. $('#btn-att a').eq(3).hide();
  1290. }
  1291. $('#showAttachment').attr('file-id', fid);
  1292. $('#showAttachment').show();
  1293. } else {
  1294. $('#showAttachment').hide();
  1295. $('#showAttachment').attr('file-id', '');
  1296. toast('附件信息获取失败', 'error');
  1297. }
  1298. });
  1299. $('body').on('click', '#btn-att a', function () {
  1300. const content = $(this).attr('content');
  1301. const fid = $('#showAttachment').attr('file-id');
  1302. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1303. if (content === 'edit') {
  1304. $('#btn-att a').eq(1).hide();
  1305. $('#btn-att a').eq(0).show();
  1306. $('#btn-att a').eq(2).show();
  1307. $('#btn-att a').eq(3).show();
  1308. $('#show-att').hide();
  1309. $('#edit-att').show();
  1310. const att = attData.find(function (item) {
  1311. return item.id === parseInt(fid);
  1312. });
  1313. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  1314. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  1315. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  1316. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  1317. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  1318. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  1319. } else if (content === 'cancel') {
  1320. $('#show-att').show();
  1321. $('#edit-att').hide();
  1322. $('#btn-att a').eq(1).show();
  1323. $('#btn-att a').eq(0).hide();
  1324. $('#btn-att a').eq(2).hide();
  1325. $('#btn-att a').eq(3).hide();
  1326. } else if (content === 'save') {
  1327. const formData = new FormData();
  1328. formData.append('id', fid);
  1329. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  1330. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  1331. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  1332. const file = $('#change-att-btn')[0];
  1333. if (file.files[0] !== undefined) {
  1334. const filesize = file.files[0].size;
  1335. formData.append('size', filesize);
  1336. formData.append('file', file.files[0]);
  1337. }
  1338. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  1339. // 替换到attData中
  1340. const att_index = attData.findIndex(function (item) {
  1341. return item.id === parseInt(fid);
  1342. });
  1343. attData.splice(att_index, 1, data);
  1344. // 重新生成List
  1345. getAllList(parseInt($('#currentPage').text()));
  1346. getNodeList(node.id);
  1347. $('#show-att').show();
  1348. $('#edit-att').hide();
  1349. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  1350. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  1351. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  1352. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  1353. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  1354. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  1355. $('#show-att tr').eq(4).children('td').text(data.remark);
  1356. $('#btn-att a').eq(1).show();
  1357. $('#btn-att a').eq(0).hide();
  1358. $('#btn-att a').eq(2).hide();
  1359. $('#btn-att a').eq(3).hide();
  1360. }, function () {
  1361. toast('附件上传失败', 'error');
  1362. });
  1363. $('#change-att-btn').val('');
  1364. } else if (content === 'del') {
  1365. const data = {id: fid};
  1366. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  1367. // 删除到attData中
  1368. const att_index = attData.findIndex(function (item) {
  1369. return item.id === parseInt(fid);
  1370. });
  1371. attData.splice(att_index, 1);
  1372. // 重新生成List
  1373. getAllList();
  1374. getNodeList(node.id);
  1375. $('#showAttachment').hide();
  1376. $('#showAttachment').attr('file-id', '');
  1377. });
  1378. }
  1379. });
  1380. // 替换附件
  1381. $('#change-att-btn').on('change', function () {
  1382. const file = $('#change-att-btn')[0].files[0];
  1383. const name = file.name;
  1384. const filename = name.substring(0, name.lastIndexOf("."));
  1385. const fileext = name.substr(name.indexOf("."));
  1386. const filesize = file.size;
  1387. if (filesize > 10 * 1024 * 1024) {
  1388. toast('文件大小过大!', 'error');
  1389. $('#change-att-btn').val('');
  1390. return false;
  1391. }
  1392. if (whiteList.indexOf(fileext) === -1) {
  1393. toast('只能上传指定格式的附件!', 'error');
  1394. $('#change-att-btn').val('');
  1395. return false;
  1396. }
  1397. $('#edit-att .form-group').eq(0).find('input').val(filename);
  1398. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  1399. });
  1400. // 切换页数
  1401. $('.page-select').on('click', function () {
  1402. const totalPageNum = $('#totalPage').text();
  1403. const lastPageNum = $('#currentPage').text();
  1404. const status = $(this).attr('content');
  1405. if (status === 'pre' && lastPageNum > 1) {
  1406. getAllList(parseInt(lastPageNum)-1);
  1407. $('#showAttachment').hide();
  1408. } else if (status === 'next' && lastPageNum < totalPageNum) {
  1409. getAllList(parseInt(lastPageNum)+1);
  1410. $('#showAttachment').hide();
  1411. }
  1412. });
  1413. // 显示层次
  1414. (function (select, sheet) {
  1415. if (!sheet.zh_tree) return;
  1416. $(select).click(function () {
  1417. const tag = $(this).attr('tag');
  1418. const tree = sheet.zh_tree;
  1419. switch (tag) {
  1420. case "1":
  1421. case "2":
  1422. case "3":
  1423. case "4":
  1424. case "5":
  1425. tree.expandByLevel(parseInt(tag));
  1426. SpreadJsObj.refreshTreeRowVisible(sheet);
  1427. break;
  1428. case "last":
  1429. tree.expandByCustom(() => { return true; });
  1430. SpreadJsObj.refreshTreeRowVisible(sheet);
  1431. break;
  1432. case "leafXmj":
  1433. tree.expandToLeafXmj();
  1434. SpreadJsObj.refreshTreeRowVisible(sheet);
  1435. break;
  1436. case "curMeasure":
  1437. tree.expandByCustom(function (node) {
  1438. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  1439. if (node[field]) {
  1440. return true;
  1441. }
  1442. }
  1443. return false;
  1444. });
  1445. SpreadJsObj.refreshTreeRowVisible(sheet);
  1446. break;
  1447. }
  1448. });
  1449. })('a[name=showLevel]', slSpread.getActiveSheet());
  1450. });