stage.js 66 KB

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