stage.js 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526
  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.final_dgn_price = ZhCalc.round(ZhCalc.div(node.end_gather_tp, ZhCalc.add(node.deal_dgn_qty1, node.c_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. ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
  452. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  453. stageTree.loadDatas(ledgerData);
  454. // stageTree.loadCurStageData(curStageData);
  455. // stageTree.loadPreStageData(preStageData);
  456. // 根据设置 计算 台账树结构
  457. treeCalc.calculateAll(stageTree);
  458. // 绘制界面
  459. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  460. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  461. //初始化所有附件列表
  462. getAllList();
  463. // 初始化 部位明细 Spread
  464. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  465. const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
  466. spCol.readOnly = true;
  467. spCol.cellType = 'imageBtn';
  468. spCol.hoverImg = '#ellipsis-icon';
  469. spCol.indent = 5;
  470. spCol.showImage = function (data) {
  471. return data;
  472. };
  473. posSpreadSetting.imageClick = function (data) {
  474. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  475. changesObj.loadChanges({bills: node, pos: data});
  476. };
  477. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  478. const stageTreeSpreadObj = {
  479. refreshTreeNodes: function (sheet, nodes) {
  480. const tree = sheet.zh_tree;
  481. if (!tree) { return }
  482. const rows = [];
  483. for (const node of nodes) {
  484. rows.push(tree.nodes.indexOf(node));
  485. }
  486. SpreadJsObj.reLoadRowsData(sheet, rows);
  487. },
  488. editEnded: function (e, info) {
  489. if (info.sheet.zh_setting) {
  490. const col = info.sheet.zh_setting.cols[info.col];
  491. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  492. const node = sortData[info.row], updateData = {};
  493. const orgValue = node[col.field];
  494. const newValue = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  495. if (orgValue == newValue || ((!orgValue || orgValue === '') && (newValue === ''))) {
  496. return;
  497. }
  498. if (col.field.indexOf('_dgn_') > 0) {
  499. if (node.b_code && node.b_code !== '') {
  500. toast('仅项目节可输入设计数量');
  501. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  502. return;
  503. }
  504. } else if (col.field !== 'postil') {
  505. if (node.children && node.children.length > 0) {
  506. toast('清单父项不可计量', 'error');
  507. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  508. return;
  509. } else {
  510. const nodePos = stagePos.getLedgerPos(node.id);
  511. if (nodePos && nodePos.length > 0) {
  512. toast('该清单有部位明细,请在部位明细处计量', 'error');
  513. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  514. return;
  515. }
  516. }
  517. }
  518. if (col.field.indexOf('_dgn_') > 0) {
  519. updateData.dgn = {
  520. id: node.id
  521. };
  522. updateData.dgn[col.field] = newValue;
  523. } else {
  524. updateData.stage = {
  525. lid: node.id
  526. };
  527. updateData.stage[col.field] = newValue;
  528. }
  529. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  530. const nodes = stageTree.loadPostStageData(data);
  531. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  532. needCheckDetail();
  533. });
  534. }
  535. },
  536. selectionChanged: function (e, info) {
  537. stagePosSpreadObj.loadCurPosData();
  538. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  539. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  540. },
  541. deletePress(sheet) {
  542. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  543. const tree = sheet.zh_tree;
  544. if (!tree) { return; }
  545. const sel = sheet.getSelections()[0];
  546. const validCols = [];
  547. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  548. if (!sheet.zh_setting.cols[iCol].readOnly) {
  549. validCols.push(iCol);
  550. }
  551. }
  552. if (validCols.length === 0) { return; }
  553. const sortData = sheet.zh_tree.nodes;
  554. const datas = [], dgnDatas = [];
  555. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  556. const node = sortData[iRow];
  557. if (node) {
  558. const data = { lid: node.id }, dgnData = { id: node.id };
  559. let filter = true, filterDgn = true;
  560. for (const iCol of validCols) {
  561. const colSetting = sheet.zh_setting.cols[iCol];
  562. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  563. if (node.b_code && node.b_code !== '') continue;
  564. } else if (colSetting.field !== 'postil') {
  565. if (node.children && node.children.length > 0) { continue; }
  566. const nodePos = stagePos.getLedgerPos(node.id);
  567. if (nodePos && nodePos.length > 0) { continue; }
  568. }
  569. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  570. if (node[colSetting.field] && node[colSetting.field] !== 0) {
  571. dgnData[colSetting.field] = 0;
  572. filterDgn = false;
  573. }
  574. } else {
  575. data[colSetting.field] = null;
  576. filter = false;
  577. }
  578. }
  579. if (!filter) datas.push(data);
  580. if (!filterDgn) dgnDatas.push(dgnData);
  581. }
  582. }
  583. if (datas.length > 0 || dgnDatas.length > 0) {
  584. const bills = {};
  585. if (datas.length > 0) bills.stage = datas;
  586. if (dgnDatas.length > 0) bills.dgn = dgnDatas;
  587. postData(window.location.href + '/update', {bills: bills}, function (result) {
  588. const nodes = stageTree.loadPostStageData(result);
  589. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  590. needCheckDetail();
  591. });
  592. }
  593. }
  594. },
  595. clipboardPasting(e, info) {
  596. if (info.sheet.zh_setting) {
  597. const setting = info.sheet.zh_setting;
  598. const range = info.cellRange;
  599. const stageField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'];
  600. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  601. const col = info.sheet.zh_setting.cols[iCol];
  602. if ((stageField.indexOf(col.field) === -1) && setting.dgnUpFields.indexOf(col.field) === -1) {
  603. toast('不可修改此数据', 'error');
  604. info.cancel = true;
  605. return;
  606. }
  607. }
  608. }
  609. },
  610. clipboardPasted(e, info) {
  611. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  612. const sheet = info.sheet, setting = info.sheet.zh_setting;
  613. const filterNodes = [], datas = [], dgnDatas = [];
  614. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  615. const curRow = iRow + info.cellRange.row;
  616. const node = sheet.zh_tree.getItemsByIndex(curRow);
  617. const data = {lid: node.id}, dgnData = {id: node.id};
  618. let filter = true, filterDgn = true;
  619. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  620. const curCol = info.cellRange.col + iCol;
  621. const col = info.sheet.zh_setting.cols[curCol];
  622. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  623. if (node.b_code && node.b_code !== '') continue;
  624. } else if (col.field !== 'postil') {
  625. if (node.children && node.children.length > 0) continue;
  626. const nodePos = stagePos.getLedgerPos(node.id);
  627. if (nodePos && nodePos.length > 0) continue;
  628. }
  629. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  630. dgnData[col.field] = _.toNumber(sheet.getText(curRow, curCol));
  631. filterDgn = false;
  632. } else {
  633. data[col.field] = col.type === 'Number' ? _.toNumber(sheet.getText(curRow, curCol)) : sheet.getText(curRow, curCol);
  634. filter = false;
  635. }
  636. }
  637. if (filter && filterDgn) {
  638. filterNodes.push(node);
  639. } else {
  640. if (!filter) datas.push(data);
  641. if (!filterDgn) dgnDatas.push(dgnData);
  642. }
  643. }
  644. if (datas.length > 0 || dgnDatas.length > 0) {
  645. const updateData = {};
  646. if (datas.length > 0) updateData.stage = datas;
  647. if (dgnDatas.length > 0) updateData.dgn = dgnDatas;
  648. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  649. const nodes = stageTree.loadPostStageData(data);
  650. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  651. needCheckDetail();
  652. });
  653. } else {
  654. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  655. }
  656. }
  657. },
  658. measureAllPosInNode(node, ratio = 1) {
  659. const posterity = stageTree.getPosterity(node);
  660. const data = {updateType: 'update', updateData: []};
  661. for (const p of posterity) {
  662. if (p.children && p.children.length > 0) continue;
  663. const posRange = stagePos.getLedgerPos(p.id);
  664. if (posRange && posRange.length > 0) {
  665. for (const pr of posRange) {
  666. if (pr.contract_qty && !checkZero(pr.contract_qty)) continue;
  667. const validValue = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
  668. if (validValue <= 0) continue;
  669. const value = ratio !== 1 ? ZhCalc.mul(pr.quantity, ratio) : pr.quantity;
  670. const pData = {
  671. pid: pr.id,
  672. lid: pr.lid,
  673. contract_qty: validValue > 0 ? (value > validValue ? validValue : value) : (value < validValue ? validValue : value),
  674. };
  675. data.updateData.push(pData);
  676. }
  677. }
  678. if (data.updateData.length > 1000 || _.map(data.updateData, 'lid').length > 200) {
  679. toastr.warning('选中的数据过多,仅计量' + data.updateData.length + '条,请稍后');
  680. break;
  681. }
  682. }
  683. console.log(data);
  684. if (data.updateData.length === 0) {
  685. toastr.info('其下全部部位明细均已计量');
  686. return;
  687. }
  688. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  689. if (result.pos) {
  690. stagePos.updateDatas(result.pos.pos);
  691. stagePos.loadCurStageData(result.pos.curStageData);
  692. }
  693. const nodes = stageTree.loadPostStageData(result.ledger);
  694. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  695. stagePosSpreadObj.loadCurPosData();
  696. needCheckDetail();
  697. toastr.success('已计量' + data.updateData.length + '条');
  698. }, function () {
  699. stagePosSpreadObj.loadCurPosData();
  700. });
  701. },
  702. topRowChanged(e, info) {
  703. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  704. },
  705. };
  706. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  707. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  708. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  709. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  710. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  711. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  712. $.contextMenu({
  713. selector: '#stage-ledger',
  714. build: function ($trigger, e) {
  715. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  716. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  717. },
  718. items: {
  719. 'measureAll': {
  720. name: '计量其下所有部位明细',
  721. icon: 'fa-rocket',
  722. callback: function (key, opt) {
  723. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  724. stageTreeSpreadObj.measureAllPosInNode(node);
  725. },
  726. visible: function (key, opt) {
  727. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  728. return select;
  729. }
  730. },
  731. 'measureAllFiveTenth': {
  732. name: '计量其下所有部位明细(计量50%)',
  733. icon: 'fa-plane',
  734. callback: function (key, opt) {
  735. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  736. stageTreeSpreadObj.measureAllPosInNode(node, 0.5);
  737. },
  738. visible: function (key, opt) {
  739. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  740. return select;
  741. }
  742. },
  743. 'measureAllOneTenth': {
  744. name: '计量其下所有部位明细(计量10%)',
  745. icon: 'fa-car',
  746. callback: function (key, opt) {
  747. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  748. stageTreeSpreadObj.measureAllPosInNode(node, 0.1);
  749. },
  750. visible: function (key, opt) {
  751. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  752. return select;
  753. }
  754. },
  755. 'hint1': {
  756. name: '最多计量200条清单下1000条部位明细',
  757. className: 'text-danger',
  758. visible: function (key, opt) {
  759. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  760. return select;
  761. },
  762. disabled: function (key, opt) {
  763. return true;
  764. }
  765. },
  766. 'hint1_1': {
  767. name: '(计数以清单为准,会计完清单下全部部位)',
  768. className: 'text-danger',
  769. visible: function (key, opt) {
  770. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  771. return select;
  772. },
  773. disabled: function (key, opt) {
  774. return true;
  775. }
  776. },
  777. 'hint2': {
  778. name: '可再次使用该功能计量剩下的节点',
  779. className: 'text-danger',
  780. visible: function (key, opt) {
  781. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  782. return select;
  783. },
  784. disabled: function (key, opt) {
  785. return true;
  786. }
  787. },
  788. 'hint2_2': {
  789. name: '(凡是计量的部位,不论计量多少,均不再计量)',
  790. className: 'text-danger',
  791. visible: function (key, opt) {
  792. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  793. return select;
  794. },
  795. disabled: function (key, opt) {
  796. return true;
  797. }
  798. },
  799. 'hint3': {
  800. name: '如提示数据过多后,未成功,请缩小范围再试',
  801. className: 'text-danger',
  802. visible: function (key, opt) {
  803. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  804. return select;
  805. },
  806. disabled: function (key, opt) {
  807. return true;
  808. }
  809. },
  810. 'hint4': {
  811. name: '该功能仅供测试用,请勿滥用,可能导致服务挂掉',
  812. className: 'text-danger',
  813. visible: function (key, opt) {
  814. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  815. return select;
  816. },
  817. disabled: function (key, opt) {
  818. return true;
  819. }
  820. },
  821. }
  822. });
  823. const stagePosSpreadObj = {
  824. /**
  825. * 加载部位明细 根据当前台账选择节点
  826. */
  827. loadCurPosData: function () {
  828. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  829. if (node) {
  830. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  831. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  832. getNodeList(node.id);
  833. // 如果是附件是当前节点,隐藏
  834. if ($('#dqjiedian').hasClass('active')) {
  835. $('#showAttachment').hide();
  836. }
  837. } else {
  838. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  839. }
  840. },
  841. editEnded: function (e, info) {
  842. if (info.sheet.zh_setting) {
  843. // 未改变过,则直接跳过
  844. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  845. const col = info.sheet.zh_setting.cols[info.col];
  846. const orgText = posData ? posData[col.field] : null;
  847. if (orgText === info.editingText || ((!orgText || orgText === '') && (info.editingText === ''))) {
  848. return;
  849. }
  850. // 台账模式下,不可新增
  851. if (checkTzMeasureType() && !posData) {
  852. toast('台账模式不可新增部位明细数据', 'error');
  853. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  854. info.cancel = true;
  855. return ;
  856. }
  857. // 不同节点下,部位明细检查输入
  858. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  859. const node = stagePosSpreadObj.stageTreeNode;
  860. if (!node) {
  861. toast('数据错误, 请刷新页面后再试', 'warning');
  862. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  863. return;
  864. } else if (info.editingText !== '' && node.children && node.children > 0) {
  865. toast('父节点不可插入部位明细', 'error');
  866. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  867. return;
  868. } else if (info.editingText !== '' && !node.b_code || node.b_code === '') {
  869. toast('项目节不可插入部位明细', 'error');
  870. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  871. return;
  872. }
  873. // 生成提交数据
  874. const data = {};
  875. if (col.field === 'name') {
  876. if (info.editingText === '' && pos) {
  877. toast('部位名称不可为空', 'error', 'exclamation-circle');
  878. info.cancel = true;
  879. return;
  880. } else if (!posData) {
  881. if (info.editingText !== '') {
  882. data.updateType = 'add';
  883. data.updateData = {name: info.editingText, lid: node.id, tid: tender.id};
  884. } else {
  885. return;
  886. }
  887. } else {
  888. data.updateType = 'update';
  889. data.updateData = {pid: posData.id, lid: posData.lid, name: info.editingText};
  890. }
  891. } else if (!posData) {
  892. toast('新增部位请先输入名称', 'warning');
  893. } else {
  894. data.updateType = 'update';
  895. data.updateData = {pid: posData.id, lid: posData.lid};
  896. data.updateData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  897. }
  898. // 提交数据到服务器
  899. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  900. if (result.pos) {
  901. stagePos.updateDatas(result.pos.pos);
  902. stagePos.loadCurStageData(result.pos.curStageData);
  903. }
  904. const refreshData = stageTree.loadPostStageData(result.ledger);
  905. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  906. stagePosSpreadObj.loadCurPosData();
  907. needCheckDetail();
  908. }, function () {
  909. stagePosSpreadObj.loadCurPosData();
  910. });
  911. }
  912. },
  913. editStarting: function (e, info) {
  914. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  915. },
  916. clipboardPasting: function (e, info) {
  917. if (info.sheet.zh_setting) {
  918. const sortData = info.sheet.zh_data;
  919. const range = info.cellRange;
  920. const validField = ['contract_qty', 'qc_qty', 'postil'];
  921. if (!checkTzMeasureType()) {
  922. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty');
  923. }
  924. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  925. const col = info.sheet.zh_setting.cols[iCol];
  926. if (validField.indexOf(col.field) === -1) {
  927. if (checkTzMeasureType()) {
  928. toast('不可修改此数据', 'error');
  929. info.cancel = true;
  930. return;
  931. } else {
  932. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  933. const pos = sortData(iRow);
  934. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  935. toast('不可修改此数据', 'error');
  936. info.cancel = true;
  937. return;
  938. }
  939. }
  940. }
  941. }
  942. }
  943. }
  944. },
  945. clipboardPasted: function (e, info) {
  946. const self = this;
  947. if (info.sheet.zh_setting) {
  948. const data = { updateType: '', updateData: [], };
  949. const sortData = info.sheet.zh_data;
  950. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  951. if (sortData && (info.cellRange.row >= sortData.length)) {
  952. data.updateType = 'add';
  953. if (info.cellRange.col !== 0) {
  954. toast('新增部位请先输入名称', 'warning');
  955. self.loadCurPosData();
  956. return;
  957. }
  958. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  959. const curRow = info.cellRange.row + iRow;
  960. const newData = {lid: node.id};
  961. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  962. const curCol = info.cellRange.col + iCol;
  963. const colSetting = info.sheet.zh_setting.cols[curCol];
  964. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  965. if (colSetting.type === 'Number') {
  966. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  967. }
  968. }
  969. data.updateData.push(newData);
  970. }
  971. } else {
  972. data.updateType = 'update';
  973. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  974. const curRow = info.cellRange.row + iRow;
  975. const curPos = sortData[curRow];
  976. if (curPos) {
  977. const newData = {pid: curPos.id, lid: curPos.lid};
  978. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  979. const curCol = info.cellRange.col + iCol;
  980. const colSetting = info.sheet.zh_setting.cols[curCol];
  981. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  982. if (colSetting.type === 'Number') {
  983. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  984. }
  985. }
  986. data.updateData.push(newData);
  987. }
  988. }
  989. }
  990. console.log(data);
  991. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  992. if (result.pos) {
  993. stagePos.updateDatas(result.pos.pos);
  994. stagePos.loadCurStageData(result.pos.curStageData);
  995. }
  996. const nodes = stageTree.loadPostStageData(result.ledger);
  997. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  998. stagePosSpreadObj.loadCurPosData();
  999. needCheckDetail();
  1000. }, function () {
  1001. stagePosSpreadObj.loadCurPosData();
  1002. });
  1003. }
  1004. },
  1005. deletePress: function (sheet) {
  1006. if (sheet.zh_setting && sheet.zh_data) {
  1007. const sortData = sheet.zh_data;
  1008. if (!sortData || sortData.length === 0) { return; }
  1009. const sel = sheet.getSelections()[0];
  1010. const validCols = [];
  1011. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1012. if (!sheet.zh_setting.cols[iCol].readOnly) {
  1013. validCols.push(iCol);
  1014. }
  1015. }
  1016. if (validCols.length === 0) { return; }
  1017. const datas = [], posSelects = [];
  1018. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1019. const node = sortData[iRow];
  1020. if (node) {
  1021. const data = {pid: node.id, lid: node.lid};
  1022. for (const iCol of validCols) {
  1023. const colSetting = sheet.zh_setting.cols[iCol];
  1024. if (colSetting.field === 'name') {
  1025. toast('部位名称不能为空', 'error');
  1026. return;
  1027. }
  1028. data[colSetting.field] = null;
  1029. }
  1030. datas.push(data);
  1031. posSelects.push(node);
  1032. }
  1033. }
  1034. if (datas.length > 0) {
  1035. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  1036. if (result.pos) {
  1037. stagePos.updateDatas(result.pos.pos);
  1038. stagePos.loadCurStageData(result.pos.curStageData);
  1039. }
  1040. const nodes = stageTree.loadPostStageData(result.ledger);
  1041. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1042. needCheckDetail();
  1043. // todo 只加载改变项
  1044. stagePosSpreadObj.loadCurPosData();
  1045. });
  1046. }
  1047. }
  1048. },
  1049. leaveCell: function (e, info) {
  1050. console.log(1);
  1051. },
  1052. };
  1053. // 加载上下窗口resizer
  1054. $.divResizer({
  1055. select: '#main-resize',
  1056. callback: function () {
  1057. slSpread.refresh();
  1058. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1059. $(".sp-wrap").height(bcontent-40);
  1060. spSpread.refresh();
  1061. }
  1062. });
  1063. // 加载部位明细数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1064. console.time('loadPosFromServer');
  1065. postData(window.location.pathname + '/pos', null, function (result) {
  1066. console.timeEnd('loadPosFromServer');
  1067. console.log('pos: ' + result.length);
  1068. stagePos.loadDatas(result);
  1069. stagePos.calculateAll();
  1070. stagePosSpreadObj.loadCurPosData();
  1071. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  1072. });
  1073. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  1074. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  1075. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  1076. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  1077. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  1078. if (!checkTzMeasureType()) {
  1079. }
  1080. $('#row-view').on('show.bs.modal', function () {
  1081. const html = [], customDisplay = customColDisplay();
  1082. for (const cd of customDisplay) {
  1083. html.push('<tr>');
  1084. html.push('<td>', cd.title, '</td>');
  1085. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  1086. html.push('</tr>');
  1087. }
  1088. $('#row-view-list').html(html.join(''));
  1089. });
  1090. $('#row-view-ok').click(function () {
  1091. const customDisplay = customColDisplay();
  1092. const cvl = $('#row-view-list').children();
  1093. for (const cv of cvl) {
  1094. const title = $(cv).children()[0].innerHTML;
  1095. const check = $('input', cv)[0].checked;
  1096. const cd = customDisplay.find(function (c) {
  1097. return c.title === title;
  1098. });
  1099. cd.visible = check;
  1100. }
  1101. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  1102. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  1103. Cookies.set('stage-col-visible', JSON.stringify(customDisplay), 7*24*60*60*1000);
  1104. $('#row-view').modal('hide');
  1105. });
  1106. class SearchLedger {
  1107. constructor(obj, mainSpread) {
  1108. const self = this;
  1109. this.obj = obj;
  1110. this.mainSpread = mainSpread;
  1111. this.spreadSetting = {
  1112. cols: [
  1113. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@'},
  1114. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  1115. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@'},
  1116. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  1117. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  1118. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  1119. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  1120. ],
  1121. emptyRows: 3,
  1122. headRows: 1,
  1123. headRowHeight: [40],
  1124. defaultRowHeight: 21,
  1125. readOnly: true
  1126. };
  1127. this.spread = SpreadJsObj.createNewSpread($('#search-result', this.obj)[0]);
  1128. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1129. $('#searchLedger', this.obj).bind('click', function () {
  1130. const keyword = $('#keyword', self.obj).val();
  1131. if (keyword !== '') {
  1132. $('#over', obj)[0].checked = false;
  1133. $('#empty', obj)[0].checked = false;
  1134. this.searchResult = [];
  1135. const sortData = SpreadJsObj.getSortData(self.mainSpread.getActiveSheet());
  1136. for (const node of sortData) {
  1137. if ((node.code && node.code.indexOf(keyword) > -1) ||
  1138. node.b_code && node.b_code.indexOf(keyword) > -1 ||
  1139. node.name && node.name.indexOf(keyword) > -1) {
  1140. this.searchResult.push(node);
  1141. }
  1142. }
  1143. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', this.searchResult);
  1144. }
  1145. });
  1146. $('#over', this.obj).bind('change', function () {
  1147. this.searchResult = [];
  1148. const sortData = SpreadJsObj.getSortData(self.mainSpread.getActiveSheet());
  1149. for (const node of sortData) {
  1150. if (node.children && node.children.length > 0) continue;
  1151. if (node.end_gather_qty) {
  1152. if (!node.quantity || Math.abs(node.end_gather_qty) > Math.abs(node.quantity)) {
  1153. this.searchResult.push(node);
  1154. }
  1155. } else if (node.end_gather_tp) {
  1156. if (!node.total_price || Math.abs(node.end_gather_tp) > Math.abs(node.total_price)) {
  1157. this.searchResult.push(node);
  1158. }
  1159. }
  1160. }
  1161. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', this.searchResult);
  1162. });
  1163. $('#empty', this.obj).bind('change', function () {
  1164. this.searchResult = [];
  1165. const sortData = SpreadJsObj.getSortData(self.mainSpread.getActiveSheet());
  1166. for (const node of sortData) {
  1167. if (node.children && node.children.length > 0) continue;
  1168. if (node.quantity) {
  1169. if (!node.end_gather_qty || checkZero(node.end_gather_qty)) {
  1170. this.searchResult.push(node);
  1171. }
  1172. } else if (node.total_price) {
  1173. if (!node.end_gather_tp || checkZero(node.end_gather_tp)) {
  1174. this.searchResult.push(node);
  1175. }
  1176. }
  1177. }
  1178. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', this.searchResult);
  1179. });
  1180. this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1181. const sheet = info.sheet;
  1182. const data = sheet.zh_data;
  1183. if (!data) { return }
  1184. const curBills = data[info.row];
  1185. if (!curBills) { return }
  1186. SpreadJsObj.locateTreeNode(self.mainSpread.getActiveSheet(), curBills.ledger_id);
  1187. });
  1188. }
  1189. }
  1190. let searchLedger;
  1191. $.divResizer({
  1192. select: '#right-spr',
  1193. callback: function () {
  1194. slSpread.refresh();
  1195. spSpread.refresh();
  1196. if (searchLedger) {
  1197. searchLedger.spread.refresh();
  1198. }
  1199. }
  1200. });
  1201. // 展开收起附件
  1202. $('a', '.right-nav').bind('click', function () {
  1203. //const main = $('#main-view'), tool = $('#tools-view');
  1204. const tab = $(this), tabPanel = $(tab.attr('content'));
  1205. const showTools = function (show) {
  1206. const left = $('#main-view'), right = $('#tools-view'), parent = left.parent();
  1207. if (show) {
  1208. right.show();
  1209. autoFlashHeight();
  1210. /**
  1211. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1212. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1213. * 故需要通过最终的parent.width再计算一次left.width
  1214. *
  1215. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1216. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1217. *
  1218. */
  1219. //left.css('width', parent.width() - right.outerWidth());
  1220. //left.css('width', parent.width() - right.outerWidth());
  1221. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1222. left.css('width', percent + '%');
  1223. } else {
  1224. right.hide();
  1225. left.css('width', '100%');
  1226. }
  1227. };
  1228. if (!tab.hasClass('active')) {
  1229. $('a', '.side-menu').removeClass('active');
  1230. $('.tab-content .tab-select-show').removeClass('active');
  1231. tab.addClass('active');
  1232. tabPanel.addClass('active');
  1233. showTools(tab.hasClass('active'));
  1234. if (tab.attr('content') === '#search' && !searchLedger) {
  1235. searchLedger = new SearchLedger($('#search'), slSpread);
  1236. searchLedger.spread.refresh();
  1237. }
  1238. if (tab.attr('content') === '#fujian') {
  1239. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1240. getNodeList(node.id);
  1241. }
  1242. } else {
  1243. tab.removeClass('active');
  1244. tabPanel.removeClass('active');
  1245. showTools(tab.hasClass('active'));
  1246. }
  1247. slSpread.refresh();
  1248. spSpread.refresh();
  1249. });
  1250. // 切换附件里节点和所有附件
  1251. $('#fujian .nav-link').on('click', function () {
  1252. const tabPanel = $(this).attr('fujian-content');
  1253. if (tabPanel !== 'syfujian') {
  1254. $('#showPage').hide();
  1255. } else {
  1256. $('#showPage').show();
  1257. }
  1258. $('#showAttachment').hide();
  1259. });
  1260. // 上传附件
  1261. $('#upload-file-btn').click(function () {
  1262. const files = $('#upload-file')[0].files;
  1263. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1264. const formData = new FormData();
  1265. formData.append('lid', node.id);
  1266. for (const file of files) {
  1267. if (file === undefined) {
  1268. toast('未选择上传文件!', 'error');
  1269. return false;
  1270. }
  1271. const filesize = file.size;
  1272. if (filesize > 10 * 1024 * 1024) {
  1273. toast('存在上传文件大小过大!', 'error');
  1274. return false;
  1275. }
  1276. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  1277. if (whiteList.indexOf(fileext) === -1) {
  1278. toast('只能上传指定格式的附件!', 'error');
  1279. return false;
  1280. }
  1281. formData.append('size', filesize);
  1282. formData.append('file[]', file);
  1283. }
  1284. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  1285. $('#upload').modal('hide');
  1286. // 插入到attData中
  1287. attData = data.concat(attData);
  1288. // 重新生成List
  1289. getAllList();
  1290. getNodeList(node.id);
  1291. }, function () {
  1292. toast('附件上传失败', 'error');
  1293. });
  1294. $('#upload-file').val('');
  1295. });
  1296. // 获取附件信息
  1297. $('body').on('click', '.list-table a', function () {
  1298. const fid = $(this).attr('file-id');
  1299. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  1300. return;
  1301. }
  1302. const att = attData.find(function (item) {
  1303. return item.id === parseInt(fid);
  1304. });
  1305. $('#edit-att').hide();
  1306. $('#show-att').show();
  1307. if (att !== undefined) {
  1308. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  1309. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  1310. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  1311. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  1312. $('#show-att tr').eq(3).children('td').eq(0).text(att.username);
  1313. $('#show-att tr').eq(3).children('td').eq(1).text(att.in_time);
  1314. $('#show-att tr').eq(4).children('td').text(att.remark);
  1315. if (parseInt(userID) === att.uid) {
  1316. $('#btn-att').show();
  1317. $('#btn-att a').eq(1).show();
  1318. $('#btn-att a').eq(0).hide();
  1319. $('#btn-att a').eq(2).hide();
  1320. $('#btn-att a').eq(3).hide();
  1321. } else {
  1322. $('#btn-att').hide();
  1323. $('#btn-att a').eq(1).hide();
  1324. $('#btn-att a').eq(0).hide();
  1325. $('#btn-att a').eq(2).hide();
  1326. $('#btn-att a').eq(3).hide();
  1327. }
  1328. $('#showAttachment').attr('file-id', fid);
  1329. $('#showAttachment').show();
  1330. } else {
  1331. $('#showAttachment').hide();
  1332. $('#showAttachment').attr('file-id', '');
  1333. toast('附件信息获取失败', 'error');
  1334. }
  1335. });
  1336. $('body').on('click', '#btn-att a', function () {
  1337. const content = $(this).attr('content');
  1338. const fid = $('#showAttachment').attr('file-id');
  1339. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1340. if (content === 'edit') {
  1341. $('#btn-att a').eq(1).hide();
  1342. $('#btn-att a').eq(0).show();
  1343. $('#btn-att a').eq(2).show();
  1344. $('#btn-att a').eq(3).show();
  1345. $('#show-att').hide();
  1346. $('#edit-att').show();
  1347. const att = attData.find(function (item) {
  1348. return item.id === parseInt(fid);
  1349. });
  1350. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  1351. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  1352. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  1353. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  1354. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  1355. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  1356. } else if (content === 'cancel') {
  1357. $('#show-att').show();
  1358. $('#edit-att').hide();
  1359. $('#btn-att a').eq(1).show();
  1360. $('#btn-att a').eq(0).hide();
  1361. $('#btn-att a').eq(2).hide();
  1362. $('#btn-att a').eq(3).hide();
  1363. } else if (content === 'save') {
  1364. const formData = new FormData();
  1365. formData.append('id', fid);
  1366. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  1367. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  1368. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  1369. const file = $('#change-att-btn')[0];
  1370. if (file.files[0] !== undefined) {
  1371. const filesize = file.files[0].size;
  1372. formData.append('size', filesize);
  1373. formData.append('file', file.files[0]);
  1374. }
  1375. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  1376. // 替换到attData中
  1377. const att_index = attData.findIndex(function (item) {
  1378. return item.id === parseInt(fid);
  1379. });
  1380. attData.splice(att_index, 1, data);
  1381. // 重新生成List
  1382. getAllList(parseInt($('#currentPage').text()));
  1383. getNodeList(node.id);
  1384. $('#show-att').show();
  1385. $('#edit-att').hide();
  1386. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  1387. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  1388. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  1389. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  1390. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  1391. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  1392. $('#show-att tr').eq(4).children('td').text(data.remark);
  1393. $('#btn-att a').eq(1).show();
  1394. $('#btn-att a').eq(0).hide();
  1395. $('#btn-att a').eq(2).hide();
  1396. $('#btn-att a').eq(3).hide();
  1397. }, function () {
  1398. toast('附件上传失败', 'error');
  1399. });
  1400. $('#change-att-btn').val('');
  1401. } else if (content === 'del') {
  1402. const data = {id: fid};
  1403. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  1404. // 删除到attData中
  1405. const att_index = attData.findIndex(function (item) {
  1406. return item.id === parseInt(fid);
  1407. });
  1408. attData.splice(att_index, 1);
  1409. // 重新生成List
  1410. getAllList();
  1411. getNodeList(node.id);
  1412. $('#showAttachment').hide();
  1413. $('#showAttachment').attr('file-id', '');
  1414. });
  1415. }
  1416. });
  1417. // 替换附件
  1418. $('#change-att-btn').on('change', function () {
  1419. const file = $('#change-att-btn')[0].files[0];
  1420. const name = file.name;
  1421. const filename = name.substring(0, name.lastIndexOf("."));
  1422. const fileext = name.substr(name.indexOf("."));
  1423. const filesize = file.size;
  1424. if (filesize > 10 * 1024 * 1024) {
  1425. toast('文件大小过大!', 'error');
  1426. $('#change-att-btn').val('');
  1427. return false;
  1428. }
  1429. if (whiteList.indexOf(fileext) === -1) {
  1430. toast('只能上传指定格式的附件!', 'error');
  1431. $('#change-att-btn').val('');
  1432. return false;
  1433. }
  1434. $('#edit-att .form-group').eq(0).find('input').val(filename);
  1435. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  1436. });
  1437. // 切换页数
  1438. $('.page-select').on('click', function () {
  1439. const totalPageNum = $('#totalPage').text();
  1440. const lastPageNum = $('#currentPage').text();
  1441. const status = $(this).attr('content');
  1442. if (status === 'pre' && lastPageNum > 1) {
  1443. getAllList(parseInt(lastPageNum)-1);
  1444. $('#showAttachment').hide();
  1445. } else if (status === 'next' && lastPageNum < totalPageNum) {
  1446. getAllList(parseInt(lastPageNum)+1);
  1447. $('#showAttachment').hide();
  1448. }
  1449. });
  1450. // 显示层次
  1451. (function (select, sheet) {
  1452. if (!sheet.zh_tree) return;
  1453. $(select).click(function () {
  1454. const tag = $(this).attr('tag');
  1455. const tree = sheet.zh_tree;
  1456. switch (tag) {
  1457. case "1":
  1458. case "2":
  1459. case "3":
  1460. case "4":
  1461. case "5":
  1462. tree.expandByLevel(parseInt(tag));
  1463. SpreadJsObj.refreshTreeRowVisible(sheet);
  1464. break;
  1465. case "last":
  1466. tree.expandByCustom(() => { return true; });
  1467. SpreadJsObj.refreshTreeRowVisible(sheet);
  1468. break;
  1469. case "leafXmj":
  1470. tree.expandToLeafXmj();
  1471. SpreadJsObj.refreshTreeRowVisible(sheet);
  1472. break;
  1473. case "curMeasure":
  1474. tree.expandByCustom(function (node) {
  1475. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  1476. if (node[field]) {
  1477. return true;
  1478. }
  1479. }
  1480. return false;
  1481. });
  1482. SpreadJsObj.refreshTreeRowVisible(sheet);
  1483. break;
  1484. }
  1485. });
  1486. })('a[name=showLevel]', slSpread.getActiveSheet());
  1487. });