stage.js 93 KB

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