stage.js 74 KB

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