stage.js 75 KB

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