stage.js 82 KB

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