stage.js 93 KB

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