stage.js 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799
  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 ? 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. if (data.updateData.length === 0) {
  696. toastr.info('其下全部部位明细均已计量');
  697. return;
  698. }
  699. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  700. if (result.pos) {
  701. stagePos.updateDatas(result.pos.pos);
  702. stagePos.loadCurStageData(result.pos.curStageData);
  703. }
  704. const nodes = stageTree.loadPostStageData(result.ledger);
  705. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  706. stagePosSpreadObj.loadCurPosData();
  707. needCheckDetail();
  708. toastr.success('已计量' + data.updateData.length + '条');
  709. }, function () {
  710. stagePosSpreadObj.loadCurPosData();
  711. });
  712. },
  713. topRowChanged(e, info) {
  714. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  715. },
  716. };
  717. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  718. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  719. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  720. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  721. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  722. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  723. $.contextMenu({
  724. selector: '#stage-ledger',
  725. build: function ($trigger, e) {
  726. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  727. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  728. },
  729. items: {
  730. 'measureAll': {
  731. name: '计量其下所有部位明细',
  732. icon: 'fa-rocket',
  733. callback: function (key, opt) {
  734. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  735. stageTreeSpreadObj.measureAllPosInNode(node);
  736. },
  737. visible: function (key, opt) {
  738. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  739. return select;
  740. }
  741. },
  742. 'measureAllFiveTenth': {
  743. name: '计量其下所有部位明细(计量50%)',
  744. icon: 'fa-plane',
  745. callback: function (key, opt) {
  746. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  747. stageTreeSpreadObj.measureAllPosInNode(node, 0.5);
  748. },
  749. visible: function (key, opt) {
  750. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  751. return select;
  752. }
  753. },
  754. 'measureAllOneTenth': {
  755. name: '计量其下所有部位明细(计量10%)',
  756. icon: 'fa-car',
  757. callback: function (key, opt) {
  758. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  759. stageTreeSpreadObj.measureAllPosInNode(node, 0.1);
  760. },
  761. visible: function (key, opt) {
  762. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  763. return select;
  764. }
  765. },
  766. 'hint1': {
  767. name: '最多计量200条清单下1000条部位明细',
  768. className: 'text-danger',
  769. visible: function (key, opt) {
  770. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  771. return select;
  772. },
  773. disabled: function (key, opt) {
  774. return true;
  775. }
  776. },
  777. 'hint1_1': {
  778. name: '(计数以清单为准,会计完清单下全部部位)',
  779. className: 'text-danger',
  780. visible: function (key, opt) {
  781. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  782. return select;
  783. },
  784. disabled: function (key, opt) {
  785. return true;
  786. }
  787. },
  788. 'hint2': {
  789. name: '可再次使用该功能计量剩下的节点',
  790. className: 'text-danger',
  791. visible: function (key, opt) {
  792. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  793. return select;
  794. },
  795. disabled: function (key, opt) {
  796. return true;
  797. }
  798. },
  799. 'hint2_2': {
  800. name: '(凡是计量的部位,不论计量多少,均不再计量)',
  801. className: 'text-danger',
  802. visible: function (key, opt) {
  803. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  804. return select;
  805. },
  806. disabled: function (key, opt) {
  807. return true;
  808. }
  809. },
  810. 'hint3': {
  811. name: '如提示数据过多后,未成功,请缩小范围再试',
  812. className: 'text-danger',
  813. visible: function (key, opt) {
  814. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  815. return select;
  816. },
  817. disabled: function (key, opt) {
  818. return true;
  819. }
  820. },
  821. 'hint4': {
  822. name: '该功能仅供测试用,请勿滥用,可能导致服务挂掉',
  823. className: 'text-danger',
  824. visible: function (key, opt) {
  825. const select = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  826. return select;
  827. },
  828. disabled: function (key, opt) {
  829. return true;
  830. }
  831. },
  832. }
  833. });
  834. const stagePosSpreadObj = {
  835. /**
  836. * 加载部位明细 根据当前台账选择节点
  837. */
  838. loadCurPosData: function () {
  839. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  840. if (node) {
  841. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  842. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  843. getNodeList(node.id);
  844. // 如果是附件是当前节点,隐藏
  845. if ($('#dqjiedian').hasClass('active')) {
  846. $('#showAttachment').hide();
  847. }
  848. } else {
  849. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  850. }
  851. },
  852. editEnded: function (e, info) {
  853. if (info.sheet.zh_setting) {
  854. // 未改变过,则直接跳过
  855. const sortData = info.sheet.zh_data;
  856. const posData = sortData ? sortData[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. return ;
  867. }
  868. // 不同节点下,部位明细检查输入
  869. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  870. const node = stagePosSpreadObj.stageTreeNode;
  871. if (!node) {
  872. toast('数据错误, 请刷新页面后再试', 'warning');
  873. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  874. return;
  875. } else if (info.editingText !== '' && node.children && node.children > 0) {
  876. toast('父节点不可插入部位明细', 'error');
  877. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  878. return;
  879. } else if (info.editingText !== '' && !node.b_code || node.b_code === '') {
  880. toast('项目节不可插入部位明细', 'error');
  881. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  882. return;
  883. }
  884. // 生成提交数据
  885. const data = {};
  886. if (col.field === 'name') {
  887. if ((!info.editingText || info.editingText === '') && posData) {
  888. toast('部位名称不可为空', 'error', 'exclamation-circle');
  889. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  890. return;
  891. } else if (!posData) {
  892. if (info.editingText !== '') {
  893. data.updateType = 'add';
  894. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  895. data.updateData = {name: info.editingText, lid: node.id, tid: tender.id, porder: order};
  896. } else {
  897. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  898. return;
  899. }
  900. } else {
  901. data.updateType = 'update';
  902. data.updateData = {pid: posData.id, lid: posData.lid, name: info.editingText};
  903. }
  904. } else if (!posData) {
  905. toast('新增部位请先输入名称', 'warning');
  906. } else {
  907. data.updateType = 'update';
  908. data.updateData = {pid: posData.id, lid: posData.lid};
  909. data.updateData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  910. }
  911. // 提交数据到服务器
  912. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  913. if (result.pos) {
  914. stagePos.updateDatas(result.pos.pos);
  915. stagePos.loadCurStageData(result.pos.curStageData);
  916. }
  917. const refreshData = stageTree.loadPostStageData(result.ledger);
  918. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  919. stagePosSpreadObj.loadCurPosData();
  920. needCheckDetail();
  921. }, function () {
  922. stagePosSpreadObj.loadCurPosData();
  923. });
  924. }
  925. },
  926. editStarting: function (e, info) {
  927. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  928. },
  929. clipboardPasting: function (e, info) {
  930. if (info.sheet.zh_setting) {
  931. const sortData = info.sheet.zh_data;
  932. const range = info.cellRange;
  933. const validField = ['contract_qty', 'qc_qty', 'postil'];
  934. if (!checkTzMeasureType()) {
  935. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty');
  936. }
  937. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  938. const col = info.sheet.zh_setting.cols[iCol];
  939. if (validField.indexOf(col.field) === -1) {
  940. if (checkTzMeasureType()) {
  941. toast('不可修改此数据', 'error');
  942. info.cancel = true;
  943. return;
  944. } else {
  945. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  946. const pos = sortData(iRow);
  947. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  948. toast('不可修改此数据', 'error');
  949. info.cancel = true;
  950. return;
  951. }
  952. }
  953. }
  954. }
  955. }
  956. }
  957. },
  958. clipboardPasted: function (e, info) {
  959. const self = this;
  960. if (info.sheet.zh_setting) {
  961. const data = { updateType: '', updateData: [], };
  962. const sortData = info.sheet.zh_data;
  963. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  964. if (sortData && (info.cellRange.row >= sortData.length)) {
  965. data.updateType = 'add';
  966. if (info.cellRange.col !== 0) {
  967. toast('新增部位请先输入名称', 'warning');
  968. self.loadCurPosData();
  969. return;
  970. }
  971. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  972. const curRow = info.cellRange.row + iRow;
  973. const newData = {lid: node.id};
  974. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  975. const curCol = info.cellRange.col + iCol;
  976. const colSetting = info.sheet.zh_setting.cols[curCol];
  977. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  978. if (colSetting.type === 'Number') {
  979. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  980. }
  981. }
  982. data.updateData.push(newData);
  983. }
  984. } else {
  985. data.updateType = 'update';
  986. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  987. const curRow = info.cellRange.row + iRow;
  988. const curPos = sortData[curRow];
  989. if (curPos) {
  990. const newData = {pid: curPos.id, lid: curPos.lid};
  991. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  992. const curCol = info.cellRange.col + iCol;
  993. const colSetting = info.sheet.zh_setting.cols[curCol];
  994. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  995. if (colSetting.type === 'Number') {
  996. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  997. }
  998. }
  999. data.updateData.push(newData);
  1000. }
  1001. }
  1002. }
  1003. console.log(data);
  1004. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1005. if (result.pos) {
  1006. stagePos.updateDatas(result.pos.pos);
  1007. stagePos.loadCurStageData(result.pos.curStageData);
  1008. }
  1009. const nodes = stageTree.loadPostStageData(result.ledger);
  1010. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1011. stagePosSpreadObj.loadCurPosData();
  1012. needCheckDetail();
  1013. }, function () {
  1014. stagePosSpreadObj.loadCurPosData();
  1015. });
  1016. }
  1017. },
  1018. deletePress: function (sheet) {
  1019. if (sheet.zh_setting && sheet.zh_data) {
  1020. const sortData = sheet.zh_data;
  1021. if (!sortData || sortData.length === 0) { return; }
  1022. const sel = sheet.getSelections()[0];
  1023. const validCols = [];
  1024. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1025. if (!sheet.zh_setting.cols[iCol].readOnly) {
  1026. validCols.push(iCol);
  1027. }
  1028. }
  1029. if (validCols.length === 0) { return; }
  1030. const datas = [], posSelects = [];
  1031. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1032. const node = sortData[iRow];
  1033. if (node) {
  1034. const data = {pid: node.id, lid: node.lid};
  1035. for (const iCol of validCols) {
  1036. const colSetting = sheet.zh_setting.cols[iCol];
  1037. if (colSetting.field === 'name') {
  1038. toast('部位名称不能为空', 'error');
  1039. return;
  1040. }
  1041. data[colSetting.field] = null;
  1042. }
  1043. datas.push(data);
  1044. posSelects.push(node);
  1045. }
  1046. }
  1047. if (datas.length > 0) {
  1048. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  1049. if (result.pos) {
  1050. stagePos.updateDatas(result.pos.pos);
  1051. stagePos.loadCurStageData(result.pos.curStageData);
  1052. }
  1053. const nodes = stageTree.loadPostStageData(result.ledger);
  1054. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1055. needCheckDetail();
  1056. // todo 只加载改变项
  1057. stagePosSpreadObj.loadCurPosData();
  1058. });
  1059. }
  1060. }
  1061. },
  1062. deletePos: function (sheet) {
  1063. const sels = sheet.getSelections();
  1064. const sel = sels ? sels[0] : null;
  1065. if (sheet.zh_data && sel) {
  1066. const data = {updateType: 'delete', updateData: []};
  1067. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  1068. const posData = sheet.zh_data[sel.row + iRow];
  1069. if (posData) {
  1070. data.updateData.push(posData.id);
  1071. }
  1072. }
  1073. if (data.updateData.length > 0) {
  1074. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1075. stagePos.removeDatas(result.pos.pos);
  1076. const refreshData = stageTree.loadPostStageData(result.ledger);
  1077. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1078. stagePosSpreadObj.loadCurPosData();
  1079. needCheckDetail();
  1080. });
  1081. }
  1082. }
  1083. },
  1084. };
  1085. // 加载上下窗口resizer
  1086. $.divResizer({
  1087. select: '#main-resize',
  1088. callback: function () {
  1089. slSpread.refresh();
  1090. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1091. $(".sp-wrap").height(bcontent-40);
  1092. spSpread.refresh();
  1093. }
  1094. });
  1095. // 加载部位明细数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1096. console.time('loadPosFromServer');
  1097. postData(window.location.pathname + '/pos', null, function (result) {
  1098. console.timeEnd('loadPosFromServer');
  1099. console.log('pos: ' + result.length);
  1100. stagePos.loadDatas(result);
  1101. stagePos.calculateAll();
  1102. stagePosSpreadObj.loadCurPosData();
  1103. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  1104. }, null, true);
  1105. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  1106. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  1107. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  1108. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  1109. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  1110. if (!checkTzMeasureType()) {
  1111. $.contextMenu({
  1112. selector: '#stage-pos',
  1113. build: function ($trigger, e) {
  1114. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  1115. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1116. },
  1117. items: {
  1118. 'del': {
  1119. name: '删除',
  1120. icon: 'fa-remove',
  1121. disabled: function (key, opt) {
  1122. const sheet = spSpread.getActiveSheet();
  1123. if (sheet.zh_data && !readOnly) {
  1124. const selection = sheet.getSelections();
  1125. if (selection && selection[0]) {
  1126. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1127. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  1128. const posData = sheet.zh_data[selection[0].row + iRow];
  1129. if (posData) {
  1130. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  1131. valid = true;
  1132. break;
  1133. }
  1134. } else {
  1135. valid = true;
  1136. break;
  1137. }
  1138. }
  1139. return valid;
  1140. } else {
  1141. return true;
  1142. }
  1143. } else {
  1144. return true;
  1145. }
  1146. },
  1147. callback: function (key, opt) {
  1148. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  1149. }
  1150. }
  1151. }
  1152. })
  1153. }
  1154. $.subMenu({
  1155. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1156. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1157. //key: 'stage.memu.1.0.0',
  1158. callback: function (info) {
  1159. if (info.mini) {
  1160. $('.panel-title').addClass('fluid');
  1161. $('#sub-menu').removeClass('panel-sidebar');
  1162. } else {
  1163. $('.panel-title').removeClass('fluid');
  1164. $('#sub-menu').addClass('panel-sidebar');
  1165. }
  1166. autoFlashHeight();
  1167. slSpread.refresh();
  1168. spSpread.refresh();
  1169. }
  1170. });
  1171. $('#row-view').on('show.bs.modal', function () {
  1172. const html = [], customDisplay = customColDisplay();
  1173. for (const cd of customDisplay) {
  1174. html.push('<tr>');
  1175. html.push('<td>', cd.title, '</td>');
  1176. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  1177. html.push('</tr>');
  1178. }
  1179. $('#row-view-list').html(html.join(''));
  1180. });
  1181. $('#row-view-ok').click(function () {
  1182. const customDisplay = customColDisplay();
  1183. const cvl = $('#row-view-list').children();
  1184. for (const cv of cvl) {
  1185. const title = $(cv).children()[0].innerHTML;
  1186. const check = $('input', cv)[0].checked;
  1187. const cd = customDisplay.find(function (c) {
  1188. return c.title === title;
  1189. });
  1190. cd.visible = check;
  1191. }
  1192. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  1193. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  1194. Cookies.set('stage-col-visible-1.0.1-' + tender.id, JSON.stringify(customDisplay), 30*24*60*60*1000);
  1195. $('#row-view').modal('hide');
  1196. });
  1197. class SearchLedger {
  1198. constructor(obj, mainSpread) {
  1199. const self = this;
  1200. this.obj = obj;
  1201. this.mainSpread = mainSpread;
  1202. this.spreadSetting = {
  1203. cols: [
  1204. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@'},
  1205. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  1206. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@'},
  1207. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  1208. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  1209. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  1210. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  1211. ],
  1212. emptyRows: 0,
  1213. headRows: 1,
  1214. headRowHeight: [40],
  1215. defaultRowHeight: 21,
  1216. readOnly: true
  1217. };
  1218. this.spread = SpreadJsObj.createNewSpread($('#search-result', this.obj)[0]);
  1219. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1220. $('#keyword', this.obj).bind('keydown', function(e) {
  1221. if (e.keyCode == 13) self.searchText();
  1222. });
  1223. $('#searchLedger', this.obj).bind('click', () => {self.searchText()});
  1224. $('#over', this.obj).bind('change', () => {self.searchOver()});
  1225. $('#empty', this.obj).bind('change', () => {self.searchLess()});
  1226. this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1227. const sheet = info.sheet;
  1228. const data = sheet.zh_data;
  1229. if (!data) { return }
  1230. const curBills = data[info.row];
  1231. if (!curBills) { return }
  1232. SpreadJsObj.locateTreeNode(self.mainSpread.getActiveSheet(), curBills.ledger_id, true);
  1233. stagePosSpreadObj.loadCurPosData();
  1234. });
  1235. }
  1236. calculateCompletePercent() {
  1237. if (!this.searchResult) return;
  1238. for (const sr of this.searchResult) {
  1239. const base = ZhCalc.add(sr.total_price, sr.end_qc_tp);
  1240. sr.complete_percent = base !== 0 ? ZhCalc.mul(ZhCalc.div(sr.end_gather_tp, base), 100, 2) : 0;
  1241. }
  1242. }
  1243. searchText() {
  1244. const keyword = $('#keyword', this.obj).val();
  1245. if (keyword !== '') {
  1246. $('#over', this.obj)[0].checked = false;
  1247. $('#empty', this.obj)[0].checked = false;
  1248. this.searchResult = [];
  1249. const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
  1250. for (const node of sortData) {
  1251. if ((node.code && node.code.indexOf(keyword) > -1) ||
  1252. node.b_code && node.b_code.indexOf(keyword) > -1 ||
  1253. node.name && node.name.indexOf(keyword) > -1) {
  1254. const data = JSON.parse(JSON.stringify(node));
  1255. data.visible = true;
  1256. this.searchResult.push(data);
  1257. }
  1258. }
  1259. this.calculateCompletePercent();
  1260. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
  1261. }
  1262. }
  1263. searchOver() {
  1264. this.searchResult = [];
  1265. const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
  1266. for (const node of sortData) {
  1267. if (node.children && node.children.length > 0) continue;
  1268. if (node.end_gather_qty) {
  1269. if (!node.quantity || Math.abs(node.end_gather_qty) > Math.abs(node.quantity)) {
  1270. const data = JSON.parse(JSON.stringify(node));
  1271. data.visible = true;
  1272. this.searchResult.push(data);
  1273. }
  1274. } else if (node.end_gather_tp) {
  1275. if (!node.total_price || Math.abs(node.end_gather_tp) > Math.abs(node.total_price)) {
  1276. const data = JSON.parse(JSON.stringify(node));
  1277. data.visible = true;
  1278. this.searchResult.push(data);
  1279. }
  1280. }
  1281. }
  1282. this.calculateCompletePercent();
  1283. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
  1284. }
  1285. searchEmpty() {
  1286. this.searchResult = [];
  1287. const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
  1288. for (const node of sortData) {
  1289. if (node.children && node.children.length > 0) continue;
  1290. if (node.quantity) {
  1291. if (!node.end_gather_qty || checkZero(node.end_gather_qty)) {
  1292. const data = JSON.parse(JSON.stringify(node));
  1293. data.visible = true;
  1294. this.searchResult.push(data);
  1295. }
  1296. } else if (node.total_price) {
  1297. if (!node.end_gather_tp || checkZero(node.end_gather_tp)) {
  1298. const data = JSON.parse(JSON.stringify(node));
  1299. data.visible = true;
  1300. this.searchResult.push(data);
  1301. }
  1302. }
  1303. }
  1304. this.calculateCompletePercent();
  1305. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
  1306. }
  1307. searchLess() {
  1308. this.searchResult = [];
  1309. const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
  1310. for (const node of sortData) {
  1311. if (node.children && node.children.length > 0) continue;
  1312. if (node.quantity) {
  1313. if (ZhCalc.sub(node.quantity, node.end_gather_qty) > 0) {
  1314. const data = JSON.parse(JSON.stringify(node));
  1315. data.visible = true;
  1316. this.searchResult.push(data);
  1317. }
  1318. } else if (node.total_price) {
  1319. if (ZhCalc.sub(node.total_price, node.end_gather_tp) > 0) {
  1320. const data = JSON.parse(JSON.stringify(node));
  1321. data.visible = true;
  1322. this.searchResult.push(data);
  1323. }
  1324. }
  1325. }
  1326. this.calculateCompletePercent();
  1327. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
  1328. }
  1329. }
  1330. let searchLedger;
  1331. const posSearch = (function () {
  1332. let resultArr = [];
  1333. const search = function () {
  1334. resultArr = [];
  1335. const keyword = $('#pos-search-keyword').val();
  1336. const checkOver = $('#pos-over-search')[0].checked;
  1337. const checkEmpty = $('#pos-empty-search')[0].checked;
  1338. const sortData = spSpread.getActiveSheet().zh_data;
  1339. if (checkOver || checkEmpty) {
  1340. if (sortData) {
  1341. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1342. const sd = sortData[i];
  1343. let match = false;
  1344. if (checkOver) {
  1345. if (sd.end_gather_qty) {
  1346. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(sd.quantity)) match = true;
  1347. }
  1348. }
  1349. if (checkEmpty) {
  1350. if (sd.quantity) {
  1351. if (!sd.end_gather_qty || checkZero(sd.end_gather_qty)) match = true;
  1352. }
  1353. }
  1354. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  1355. if (match) {
  1356. resultArr.push({index: i, data: sd});
  1357. }
  1358. }
  1359. }
  1360. } else if (keyword && keyword !== '') {
  1361. if (sortData) {
  1362. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1363. const sd = sortData[i];
  1364. if (sd.name && sd.name.indexOf(keyword) > -1) {
  1365. resultArr.push({index: i, data: sd});
  1366. }
  1367. }
  1368. }
  1369. }
  1370. $('#pos-search-result').html('结果:' + resultArr.length);
  1371. };
  1372. const searchAndLocate = function () {
  1373. search();
  1374. if (resultArr.length > 0) {
  1375. const sheet = spSpread.getActiveSheet();
  1376. const sel = sheet.getSelections()[0];
  1377. const curRow = sel ? sel.row : 0;
  1378. const pos = resultArr[0];
  1379. if (pos.index !== curRow) {
  1380. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  1381. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  1382. }
  1383. }
  1384. };
  1385. const locateNext = function () {
  1386. if (resultArr.length > 0) {
  1387. const sheet = spSpread.getActiveSheet();
  1388. const sel = sheet.getSelections()[0];
  1389. const curRow = sel ? sel.row : 0;
  1390. let next = _.find(resultArr, function (d) {
  1391. return d.index > curRow;
  1392. });
  1393. if (!next) next = resultArr[0];
  1394. if (next.index !== curRow) {
  1395. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1396. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1397. }
  1398. }
  1399. };
  1400. const locatePre = function () {
  1401. if (resultArr.length > 0) {
  1402. const sheet = spSpread.getActiveSheet();
  1403. const sel = sheet.getSelections()[0];
  1404. const curRow = sel ? sel.row : 0;
  1405. let next = _.findLast(resultArr, function (d) {
  1406. return d.index < curRow;
  1407. });
  1408. if (!next) next = resultArr[resultArr.length - 1];
  1409. if (next.index !== curRow) {
  1410. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1411. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1412. }
  1413. }
  1414. };
  1415. return {search, searchAndLocate, locateNext, locatePre};
  1416. })();
  1417. $('#pos-search-keyword').bind('keydown', function(e){
  1418. if (e.keyCode == 13) posSearch.searchAndLocate();
  1419. });
  1420. $('#pos-empty-search').click(function () {
  1421. if (this.checked) {
  1422. $('[for=' + this.id +']').addClass('text-warning');
  1423. } else {
  1424. $('[for=' + this.id +']').removeClass('text-warning');
  1425. }
  1426. if (this.checked) {
  1427. if ($('#pos-over-search')[0].checked) {
  1428. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1429. } else {
  1430. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  1431. }
  1432. } else {
  1433. if ($('#pos-over-search')[0].checked) {
  1434. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  1435. } else {
  1436. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1437. }
  1438. }
  1439. posSearch.searchAndLocate();
  1440. });
  1441. $('#pos-over-search').click(function () {
  1442. if (this.checked) {
  1443. $('[for=' + this.id +']').addClass('text-danger');
  1444. } else {
  1445. $('[for=' + this.id +']').removeClass('text-danger');
  1446. }
  1447. if (this.checked) {
  1448. if ($('#pos-empty-search')[0].checked) {
  1449. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1450. } else {
  1451. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  1452. }
  1453. } else {
  1454. if ($('#pos-empty-search')[0].checked) {
  1455. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  1456. } else {
  1457. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1458. }
  1459. }
  1460. posSearch.searchAndLocate();
  1461. });
  1462. $('#pos-search-next').click(() => {posSearch.locateNext()});
  1463. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  1464. $.divResizer({
  1465. select: '#right-spr',
  1466. callback: function () {
  1467. slSpread.refresh();
  1468. spSpread.refresh();
  1469. if (searchLedger) {
  1470. searchLedger.spread.refresh();
  1471. }
  1472. }
  1473. });
  1474. // 展开收起附件
  1475. $('a', '.right-nav').bind('click', function () {
  1476. //const main = $('#main-view'), tool = $('#tools-view');
  1477. const tab = $(this), tabPanel = $(tab.attr('content'));
  1478. const showTools = function (show) {
  1479. const left = $('#main-view'), right = $('#tools-view'), parent = left.parent();
  1480. if (show) {
  1481. right.show();
  1482. autoFlashHeight();
  1483. /**
  1484. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1485. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1486. * 故需要通过最终的parent.width再计算一次left.width
  1487. *
  1488. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1489. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1490. *
  1491. */
  1492. //left.css('width', parent.width() - right.outerWidth());
  1493. //left.css('width', parent.width() - right.outerWidth());
  1494. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1495. left.css('width', percent + '%');
  1496. } else {
  1497. right.hide();
  1498. left.css('width', '100%');
  1499. }
  1500. };
  1501. if (!tab.hasClass('active')) {
  1502. $('a', '.side-menu').removeClass('active');
  1503. $('.tab-content .tab-select-show').removeClass('active');
  1504. tab.addClass('active');
  1505. tabPanel.addClass('active');
  1506. showTools(tab.hasClass('active'));
  1507. if (tab.attr('content') === '#search' && !searchLedger) {
  1508. searchLedger = new SearchLedger($('#search'), slSpread);
  1509. searchLedger.spread.refresh();
  1510. }
  1511. if (tab.attr('content') === '#fujian') {
  1512. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1513. getNodeList(node.id);
  1514. }
  1515. } else {
  1516. tab.removeClass('active');
  1517. tabPanel.removeClass('active');
  1518. showTools(tab.hasClass('active'));
  1519. }
  1520. slSpread.refresh();
  1521. spSpread.refresh();
  1522. });
  1523. // 切换附件里节点和所有附件
  1524. $('#fujian .nav-link').on('click', function () {
  1525. const tabPanel = $(this).attr('fujian-content');
  1526. if (tabPanel !== 'syfujian') {
  1527. $('#showPage').hide();
  1528. } else {
  1529. $('#showPage').show();
  1530. }
  1531. $('#showAttachment').hide();
  1532. });
  1533. // 上传附件
  1534. $('#upload-file-btn').click(function () {
  1535. const files = $('#upload-file')[0].files;
  1536. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1537. const formData = new FormData();
  1538. formData.append('lid', node.id);
  1539. for (const file of files) {
  1540. if (file === undefined) {
  1541. toast('未选择上传文件!', 'error');
  1542. return false;
  1543. }
  1544. const filesize = file.size;
  1545. if (filesize > 10 * 1024 * 1024) {
  1546. toast('存在上传文件大小过大!', 'error');
  1547. return false;
  1548. }
  1549. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  1550. if (whiteList.indexOf(fileext) === -1) {
  1551. toast('只能上传指定格式的附件!', 'error');
  1552. return false;
  1553. }
  1554. formData.append('size', filesize);
  1555. formData.append('file[]', file);
  1556. }
  1557. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  1558. $('#upload').modal('hide');
  1559. // 插入到attData中
  1560. attData = data.concat(attData);
  1561. // 重新生成List
  1562. getAllList();
  1563. getNodeList(node.id);
  1564. }, function () {
  1565. toast('附件上传失败', 'error');
  1566. });
  1567. $('#upload-file').val('');
  1568. });
  1569. // 获取附件信息
  1570. $('body').on('click', '.list-table a', function () {
  1571. const fid = $(this).attr('file-id');
  1572. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  1573. return;
  1574. }
  1575. const att = attData.find(function (item) {
  1576. return item.id === parseInt(fid);
  1577. });
  1578. $('#edit-att').hide();
  1579. $('#show-att').show();
  1580. if (att !== undefined) {
  1581. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  1582. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  1583. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  1584. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  1585. $('#show-att tr').eq(3).children('td').eq(0).text(att.username);
  1586. $('#show-att tr').eq(3).children('td').eq(1).text(att.in_time);
  1587. $('#show-att tr').eq(4).children('td').text(att.remark);
  1588. if (parseInt(userID) === att.uid) {
  1589. $('#btn-att').show();
  1590. $('#btn-att a').eq(1).show();
  1591. $('#btn-att a').eq(0).hide();
  1592. $('#btn-att a').eq(2).hide();
  1593. $('#btn-att a').eq(3).hide();
  1594. } else {
  1595. $('#btn-att').hide();
  1596. $('#btn-att a').eq(1).hide();
  1597. $('#btn-att a').eq(0).hide();
  1598. $('#btn-att a').eq(2).hide();
  1599. $('#btn-att a').eq(3).hide();
  1600. }
  1601. $('#showAttachment').attr('file-id', fid);
  1602. $('#showAttachment').show();
  1603. } else {
  1604. $('#showAttachment').hide();
  1605. $('#showAttachment').attr('file-id', '');
  1606. toast('附件信息获取失败', 'error');
  1607. }
  1608. });
  1609. $('body').on('click', '#btn-att a', function () {
  1610. const content = $(this).attr('content');
  1611. const fid = $('#showAttachment').attr('file-id');
  1612. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1613. if (content === 'edit') {
  1614. $('#btn-att a').eq(1).hide();
  1615. $('#btn-att a').eq(0).show();
  1616. $('#btn-att a').eq(2).show();
  1617. $('#btn-att a').eq(3).show();
  1618. $('#show-att').hide();
  1619. $('#edit-att').show();
  1620. const att = attData.find(function (item) {
  1621. return item.id === parseInt(fid);
  1622. });
  1623. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  1624. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  1625. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  1626. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  1627. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  1628. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  1629. } else if (content === 'cancel') {
  1630. $('#show-att').show();
  1631. $('#edit-att').hide();
  1632. $('#btn-att a').eq(1).show();
  1633. $('#btn-att a').eq(0).hide();
  1634. $('#btn-att a').eq(2).hide();
  1635. $('#btn-att a').eq(3).hide();
  1636. } else if (content === 'save') {
  1637. const formData = new FormData();
  1638. formData.append('id', fid);
  1639. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  1640. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  1641. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  1642. const file = $('#change-att-btn')[0];
  1643. if (file.files[0] !== undefined) {
  1644. const filesize = file.files[0].size;
  1645. formData.append('size', filesize);
  1646. formData.append('file', file.files[0]);
  1647. }
  1648. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  1649. // 替换到attData中
  1650. const att_index = attData.findIndex(function (item) {
  1651. return item.id === parseInt(fid);
  1652. });
  1653. attData.splice(att_index, 1, data);
  1654. // 重新生成List
  1655. getAllList(parseInt($('#currentPage').text()));
  1656. getNodeList(node.id);
  1657. $('#show-att').show();
  1658. $('#edit-att').hide();
  1659. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  1660. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  1661. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  1662. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  1663. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  1664. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  1665. $('#show-att tr').eq(4).children('td').text(data.remark);
  1666. $('#btn-att a').eq(1).show();
  1667. $('#btn-att a').eq(0).hide();
  1668. $('#btn-att a').eq(2).hide();
  1669. $('#btn-att a').eq(3).hide();
  1670. }, function () {
  1671. toast('附件上传失败', 'error');
  1672. });
  1673. $('#change-att-btn').val('');
  1674. } else if (content === 'del') {
  1675. const data = {id: fid};
  1676. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  1677. // 删除到attData中
  1678. const att_index = attData.findIndex(function (item) {
  1679. return item.id === parseInt(fid);
  1680. });
  1681. attData.splice(att_index, 1);
  1682. // 重新生成List
  1683. getAllList();
  1684. getNodeList(node.id);
  1685. $('#showAttachment').hide();
  1686. $('#showAttachment').attr('file-id', '');
  1687. });
  1688. }
  1689. });
  1690. // 替换附件
  1691. $('#change-att-btn').on('change', function () {
  1692. const file = $('#change-att-btn')[0].files[0];
  1693. const name = file.name;
  1694. const filename = name.substring(0, name.lastIndexOf("."));
  1695. const fileext = name.substr(name.indexOf("."));
  1696. const filesize = file.size;
  1697. if (filesize > 10 * 1024 * 1024) {
  1698. toast('文件大小过大!', 'error');
  1699. $('#change-att-btn').val('');
  1700. return false;
  1701. }
  1702. if (whiteList.indexOf(fileext) === -1) {
  1703. toast('只能上传指定格式的附件!', 'error');
  1704. $('#change-att-btn').val('');
  1705. return false;
  1706. }
  1707. $('#edit-att .form-group').eq(0).find('input').val(filename);
  1708. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  1709. });
  1710. // 切换页数
  1711. $('.page-select').on('click', function () {
  1712. const totalPageNum = $('#totalPage').text();
  1713. const lastPageNum = $('#currentPage').text();
  1714. const status = $(this).attr('content');
  1715. if (status === 'pre' && lastPageNum > 1) {
  1716. getAllList(parseInt(lastPageNum)-1);
  1717. $('#showAttachment').hide();
  1718. } else if (status === 'next' && lastPageNum < totalPageNum) {
  1719. getAllList(parseInt(lastPageNum)+1);
  1720. $('#showAttachment').hide();
  1721. }
  1722. });
  1723. // 显示层次
  1724. (function (select, sheet) {
  1725. if (!sheet.zh_tree) return;
  1726. $(select).click(function () {
  1727. const tag = $(this).attr('tag');
  1728. const tree = sheet.zh_tree;
  1729. switch (tag) {
  1730. case "1":
  1731. case "2":
  1732. case "3":
  1733. case "4":
  1734. case "5":
  1735. tree.expandByLevel(parseInt(tag));
  1736. SpreadJsObj.refreshTreeRowVisible(sheet);
  1737. break;
  1738. case "last":
  1739. tree.expandByCustom(() => { return true; });
  1740. SpreadJsObj.refreshTreeRowVisible(sheet);
  1741. break;
  1742. case "leafXmj":
  1743. tree.expandToLeafXmj();
  1744. SpreadJsObj.refreshTreeRowVisible(sheet);
  1745. break;
  1746. case "curMeasure":
  1747. tree.expandByCustom(function (node) {
  1748. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  1749. if (node[field]) {
  1750. return true;
  1751. }
  1752. }
  1753. return false;
  1754. });
  1755. SpreadJsObj.refreshTreeRowVisible(sheet);
  1756. break;
  1757. }
  1758. });
  1759. })('a[name=showLevel]', slSpread.getActiveSheet());
  1760. });