stage.js 82 KB

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