stage.js 91 KB

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