stage.js 84 KB

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