stage.js 83 KB

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