stage.js 91 KB

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