stage.js 93 KB

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