stage.js 93 KB

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