stage.js 84 KB

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