stage.js 83 KB

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