schedule_controller.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Ellisran
  6. * @date 2020/7/2
  7. * @version
  8. */
  9. const moment = require('moment');
  10. const reviseStatus = require('../const/audit').revise.status;
  11. const measureType = require('../const/tender').measureType;
  12. const scheduleConst = require('../const/schedule');
  13. const billsPosConvert = require('../lib/bills_pos_convert');
  14. const _ = require('lodash');
  15. module.exports = app => {
  16. class ScheduleController extends app.BaseController {
  17. async _getSelectedLedgerList(ctx) {
  18. const scheduleLedgerList = await ctx.service.scheduleLedger.getAllDataByCondition({ where: { tid: ctx.tender.id } });
  19. return _.map(scheduleLedgerList, 'ledger_id');
  20. }
  21. async _getLastPlanMonth(ctx) {
  22. const lastMonth = await ctx.service.scheduleMonth.getLastPlanMonth();
  23. return lastMonth && lastMonth[0] && lastMonth[0].yearmonth ? lastMonth[0].yearmonth : null;
  24. }
  25. async _getLastReviseStatus(ctx) {
  26. const lastRevise = await ctx.service.ledgerRevise.getLastestRevise(ctx.tender.id);
  27. return (lastRevise && lastRevise.status !== reviseStatus.checked) || false;
  28. }
  29. async _checkScheduleCanModify(ctx) {
  30. if (await this._getLastReviseStatus(ctx)) {
  31. throw '台账修订中,请勿修改提交进度数据';
  32. }
  33. }
  34. async index(ctx) {
  35. try {
  36. const schedule = await ctx.service.schedule.getDataByCondition({ tid: ctx.tender.id });
  37. const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: ctx.tender.id }, orders: [['yearmonth', 'asc']] });
  38. const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: ctx.tender.id }, orders: [['yearmonth', 'asc']] });
  39. // 汇总并统计前几个计划月总计划额
  40. for (const i in scheduleStage) {
  41. let nowIndex = 0;
  42. let lastIndex = 0;
  43. if (i > 0) {
  44. nowIndex = _.findIndex(scheduleMonth, { yearmonth: scheduleStage[i].yearmonth }) + 1;
  45. lastIndex = _.findIndex(scheduleMonth, { yearmonth: scheduleStage[i - 1].yearmonth }) + 1;
  46. } else {
  47. nowIndex = _.findIndex(scheduleMonth, { yearmonth: scheduleStage[i].yearmonth }) + 1;
  48. }
  49. // 获取新计划月数组
  50. const newSm = scheduleMonth.slice(lastIndex, nowIndex);
  51. scheduleStage[i].plan_tp = _.sumBy(newSm, 'plan_tp');
  52. }
  53. const renderData = {
  54. schedule,
  55. scheduleMonth,
  56. scheduleStage,
  57. tender: ctx.tender.data,
  58. tenderMenu: this.menu.tenderMenu,
  59. planMonth: await this._getLastPlanMonth(ctx),
  60. scheduleLedgerList: await this._getSelectedLedgerList(ctx),
  61. preUrl: '/tender/' + ctx.tender.id,
  62. revising: await this._getLastReviseStatus(ctx),
  63. };
  64. await this.layout('schedule/index.ejs', renderData, 'schedule/modal.ejs');
  65. } catch (err) {
  66. this.log(err);
  67. ctx.redirect(this.menu.menu.dashboard.url);
  68. }
  69. }
  70. async ledger(ctx) {
  71. const tender = ctx.tender;
  72. const schedule = await ctx.service.schedule.getDataByCondition({ tid: ctx.tender.id });
  73. const scheduleLedgerList = await this._getSelectedLedgerList(ctx);
  74. const allSlmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: ctx.tender.id } });
  75. const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: tender.id }, orders: [['order', 'desc']] });
  76. const hadDataLidList = [];
  77. for (const sl of scheduleLedgerList) {
  78. const info = _.find(allSlmList, function(item) {
  79. return item.lid === sl && ((item.plan_tp !== null && item.plan_tp !== 0) ||
  80. (item.plan_gcl !== null && item.plan_gcl !== 0) ||
  81. (item.sj_tp !== null && item.sj_tp !== 0) ||
  82. (item.sj_gcl !== null && item.sj_gcl !== 0));
  83. });
  84. if (info) {
  85. hadDataLidList.push(info.lid);
  86. }
  87. }
  88. const renderData = {
  89. schedule,
  90. tender: tender.data,
  91. tenderInfo: tender.info,
  92. measureType,
  93. scheduleLedgerList,
  94. hadDataLidList,
  95. scheduleStage,
  96. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.schedule.ledger),
  97. revising: await this._getLastReviseStatus(ctx),
  98. };
  99. await this.layout('schedule/ledger.ejs', renderData, 'schedule/modal.ejs');
  100. }
  101. async plan(ctx) {
  102. const tender = ctx.tender;
  103. const schedule = await ctx.service.schedule.getDataByCondition({ tid: tender.id });
  104. const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'asc']] });
  105. const renderData = {
  106. tender: tender.data,
  107. tenderInfo: tender.info,
  108. schedule,
  109. scheduleMonth,
  110. planMonth: await this._getLastPlanMonth(ctx),
  111. measureType,
  112. mode: scheduleConst.plan_mode,
  113. scheduleLedgerList: await this._getSelectedLedgerList(ctx),
  114. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.schedule.plan),
  115. revising: await this._getLastReviseStatus(ctx),
  116. };
  117. await this.layout('schedule/plan.ejs', renderData, 'schedule/plan_modal.ejs');
  118. }
  119. async stageTp(ctx) {
  120. const tender = ctx.tender;
  121. const schedule = await ctx.service.schedule.getDataByCondition({ tid: tender.id });
  122. const { slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData,
  123. scheduleMonth, stageOrderList, scheduleStage, curScheduleStage } = await this._getStageAndPlanData(ctx);
  124. const renderData = {
  125. tender: tender.data,
  126. tenderInfo: tender.info,
  127. schedule,
  128. scheduleMonth,
  129. measureType,
  130. stageOrderList,
  131. scheduleStage,
  132. curScheduleStage,
  133. slmList,
  134. nextSlmList,
  135. endSlmList,
  136. yearSlmList,
  137. curYearStageData,
  138. scheduleLedgerList: await this._getSelectedLedgerList(ctx),
  139. revising: await this._getLastReviseStatus(ctx),
  140. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.schedule.stageTp),
  141. };
  142. await this.layout('schedule/stage_tp.ejs', renderData, 'schedule/stage_tp_modal.ejs');
  143. }
  144. async stageGcl(ctx) {
  145. const tender = ctx.tender;
  146. const schedule = await ctx.service.schedule.getDataByCondition({ tid: tender.id });
  147. const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'asc']] });
  148. // const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: tender.id }, orders: [['order', 'desc']] });
  149. const gclScheduleMonth = _.filter(scheduleMonth, { stage_gcl_used: 1 });
  150. const curScheduleMonth = scheduleMonth.length > 0 ? _.maxBy(gclScheduleMonth, 'yearmonth') : null;
  151. const renderData = {
  152. tender: tender.data,
  153. tenderInfo: tender.info,
  154. schedule,
  155. scheduleMonth,
  156. measureType,
  157. // scheduleStage,
  158. curScheduleMonth,
  159. gclScheduleMonth,
  160. scheduleLedgerList: await this._getSelectedLedgerList(ctx),
  161. revising: await this._getLastReviseStatus(ctx),
  162. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.schedule.stageGcl),
  163. };
  164. await this.layout('schedule/stage_gcl.ejs', renderData, 'schedule/stage_gcl_modal.ejs');
  165. }
  166. /**
  167. * 获取金额模式下台账数据(Ajax)
  168. *
  169. * @param ctx
  170. * @return {Promise<void>}
  171. */
  172. async loadTpLedgerData(ctx) {
  173. try {
  174. const ledgerData = await this._getStageLedgerData(ctx, ctx.params.order);
  175. const postData = { ledgerData };
  176. const data = JSON.parse(ctx.request.body.data);
  177. if (data.filter && data.filter === 'gcl') {
  178. const { slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData } = await this._getStageAndPlanData(ctx);
  179. _.assignIn(postData, { slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData });
  180. }
  181. ctx.body = { err: 0, msg: '', data: postData };
  182. } catch (err) {
  183. this.log(err);
  184. ctx.body = { err: 1, msg: err.toString(), data: [] };
  185. }
  186. }
  187. /**
  188. * 获取工程量模式下台账数据(Ajax)
  189. *
  190. * @param ctx
  191. * @return {Promise<void>}
  192. */
  193. async loadGclLedgerData(ctx) {
  194. try {
  195. const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
  196. const postData = { ledgerData };
  197. const { slmList, nextSlmList, endSlmList, yearSlmList } = await this._getGclAndPlanData(ctx);
  198. _.assignIn(postData, { slmList, nextSlmList, endSlmList, yearSlmList });
  199. ctx.body = { err: 0, msg: '', data: postData };
  200. } catch (err) {
  201. this.log(err);
  202. ctx.body = { err: 1, msg: err.toString(), data: [] };
  203. }
  204. }
  205. /**
  206. * 获取所有期下台账数据(Ajax)
  207. *
  208. * @param ctx
  209. * @return {Promise<void>}
  210. */
  211. async _getAllStageLedgerData(ctx) {
  212. const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
  213. const stageList = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: ctx.tender.id }, orders: [['order', 'desc']] });
  214. if (stageList.length > 0) {
  215. const dgnData = await ctx.service.stageBillsDgn.getDgnData(ctx.tender.id);
  216. for (const d of dgnData) {
  217. const l = ctx.app._.find(ledgerData, { id: d.id });
  218. ctx.app._.assignIn(l, d);
  219. }
  220. for (const s of stageList) {
  221. const stageInfo = await ctx.service.stage.getDataByCondition({
  222. tid: ctx.tender.id,
  223. order: s.order,
  224. });
  225. // let preStageData;
  226. // 当前操作人查看最新数据,其他人查看历史数据
  227. const curStageData = await ctx.service.stageBills.getLastestStageData(ctx.tender.id, stageInfo.id);
  228. // // 查询截止上期数据
  229. // if (stageInfo.order > 1) {
  230. // preStageData = await ctx.service.stageBillsFinal.getFinalData(ctx.tender.data, stageInfo.order - 1);
  231. // } else {
  232. // preStageData = [];
  233. // }
  234. this.ctx.helper.assignRelaData(ledgerData, [
  235. { data: curStageData, fields: ['contract_tp', 'qc_tp'], prefix: s.order + '_', relaId: 'lid' },
  236. // { data: preStageData, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'used'], prefix: s.order + '_pre_', relaId: 'lid' },
  237. ]);
  238. }
  239. }
  240. return ledgerData;
  241. }
  242. async _getStageLedgerData(ctx, stageOrder) {
  243. const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
  244. const dgnData = await ctx.service.stageBillsDgn.getDgnData(ctx.tender.id);
  245. for (const d of dgnData) {
  246. const l = ctx.app._.find(ledgerData, { id: d.id });
  247. ctx.app._.assignIn(l, d);
  248. }
  249. const stageInfo = await ctx.service.stage.getDataByCondition({
  250. tid: ctx.tender.id,
  251. order: stageOrder,
  252. });
  253. let preStageData;
  254. // 当前操作人查看最新数据,其他人查看历史数据
  255. const curStageData = await ctx.service.stageBills.getLastestStageData(ctx.tender.id, stageInfo.id);
  256. // 查询截止上期数据
  257. if (stageInfo.order > 1) {
  258. preStageData = await ctx.service.stageBillsFinal.getFinalData(ctx.tender.data, stageInfo.order - 1);
  259. } else {
  260. preStageData = [];
  261. }
  262. this.ctx.helper.assignRelaData(ledgerData, [
  263. { data: curStageData, fields: ['contract_qty', 'contract_expr', 'contract_tp', 'qc_qty', 'qc_tp', 'postil'], prefix: '', relaId: 'lid' },
  264. { data: preStageData, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'used'], prefix: 'pre_', relaId: 'lid' },
  265. ]);
  266. return ledgerData;
  267. }
  268. /**
  269. * 获取本期下台账计量和计划数据(Ajax)
  270. *
  271. * @param ctx
  272. * @return {Promise<void>}
  273. */
  274. async _getStageAndPlanData(ctx) {
  275. const tender = ctx.tender;
  276. const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'asc']] });
  277. const stageOrderList = await ctx.service.stage.getAllDataByCondition({ columns: ['id', 's_time', 'order'], where: { tid: tender.id } });
  278. const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'desc']] });
  279. let curScheduleStage = scheduleStage.length > 0 ? _.maxBy(scheduleStage, 'yearmonth') : null;
  280. if (ctx.params.order && scheduleStage.length > 0) {
  281. curScheduleStage = _.find(scheduleStage, { order: parseInt(ctx.params.order) });
  282. }
  283. let slmList = [];
  284. let nextSlmList = [];
  285. let endSlmList = [];
  286. let yearSlmList = [];
  287. let curYearStageData = [];
  288. if (curScheduleStage) {
  289. const newSM = _.sortBy(scheduleMonth, 'yearmonth');
  290. const nowScheduleStage = _.findIndex(newSM, { yearmonth: curScheduleStage.yearmonth });
  291. slmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: curScheduleStage.yearmonth } });
  292. const nextScheduleStage = nowScheduleStage >= 0 && nowScheduleStage + 1 <= newSM.length - 1 ? newSM[nowScheduleStage + 1] : null;
  293. if (nextScheduleStage) nextSlmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: nextScheduleStage.yearmonth } });
  294. if (nowScheduleStage === 0) {
  295. endSlmList = slmList;
  296. } else if (nowScheduleStage > 0) {
  297. const endYearmonthCollection = _.map(_.take(newSM, nowScheduleStage + 1), 'yearmonth');
  298. endSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, endYearmonthCollection);
  299. }
  300. const yearConllection = _.map(_.filter(newSM, function(item) {
  301. return item.yearmonth.indexOf(curScheduleStage.yearmonth.split('-')[0]) !== -1;
  302. }), 'yearmonth');
  303. yearSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, yearConllection);
  304. // 获取本年完成计量数据
  305. const curStage = _.find(stageOrderList, { order: curScheduleStage.order });
  306. const stageList = _.filter(stageOrderList, function(item) {
  307. return item.s_time.indexOf(curStage.s_time.split('-')[0]) !== -1;
  308. });
  309. // const newSS = _.sortBy(scheduleStage, 'yearmonth');
  310. // const stageIdList = _.map(_.filter(stageList, function(item) {
  311. // return _.find(newSS, { order: item.order });
  312. // }), 'id');
  313. const stageIdList = _.map(stageList, 'id');
  314. curYearStageData = await ctx.service.stageBills.getStagesData(tender.id, stageIdList.join(','));
  315. }
  316. return { slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData, scheduleMonth, stageOrderList, scheduleStage, curScheduleStage };
  317. }
  318. /**
  319. * 获取工程量模式汇总下台账的计划数据(Ajax)
  320. *
  321. * @param ctx
  322. * @return {Promise<void>}
  323. */
  324. async _getGclAndPlanData(ctx) {
  325. const tender = ctx.tender;
  326. const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'asc']] });
  327. let curScheduleMonth = scheduleMonth.length > 0 ? _.maxBy(scheduleMonth, 'order') : null;
  328. const gclScheduleMonth = _.filter(scheduleMonth, { stage_gcl_used: 1 });
  329. if (ctx.params.order && gclScheduleMonth.length > 0) {
  330. curScheduleMonth = _.find(gclScheduleMonth, { id: parseInt(ctx.params.order) });
  331. }
  332. let slmList = [];
  333. let nextSlmList = [];
  334. let endSlmList = [];
  335. let yearSlmList = [];
  336. if (curScheduleMonth) {
  337. const newSM = _.sortBy(scheduleMonth, 'yearmonth');
  338. const nowScheduleMonth = _.findIndex(newSM, { yearmonth: curScheduleMonth.yearmonth });
  339. slmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: curScheduleMonth.yearmonth } });
  340. const nextScheduleMonth = nowScheduleMonth >= 0 && nowScheduleMonth + 1 <= newSM.length - 1 ? newSM[nowScheduleMonth + 1] : null;
  341. if (nextScheduleMonth) nextSlmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: nextScheduleMonth.yearmonth } });
  342. if (nowScheduleMonth === 0) {
  343. endSlmList = slmList;
  344. } else if (nowScheduleMonth > 0) {
  345. const endYearmonthCollection = _.map(_.take(newSM, nowScheduleMonth + 1), 'yearmonth');
  346. endSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, endYearmonthCollection);
  347. }
  348. const yearConllection = _.map(_.filter(newSM, function(item) {
  349. return item.yearmonth.indexOf(curScheduleMonth.yearmonth.split('-')[0]) !== -1;
  350. }), 'yearmonth');
  351. yearSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, yearConllection);
  352. }
  353. return { slmList, nextSlmList, endSlmList, yearSlmList, scheduleMonth, curScheduleMonth };
  354. }
  355. /**
  356. * 获取台账数据(Ajax)
  357. *
  358. * @param ctx
  359. * @return {Promise<void>}
  360. */
  361. async loadLedgerData(ctx) {
  362. try {
  363. // const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
  364. const ledgerData = await this._getAllStageLedgerData(ctx);
  365. // const posData = ctx.tender.data.measure_type === measureType.tz.value
  366. // ? await ctx.service.pos.getPosData({ tid: ctx.tender.id }) : [];
  367. // const convert = new billsPosConvert(ctx);
  368. // convert.loadData(ledgerData, posData, []);
  369. // const result = await convert.convert();
  370. const scheduleLedgerMonthData = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: ctx.tender.id } });
  371. const scheduleLedgerHistoryData = await ctx.service.scheduleLedgerHistory.getAllDataByCondition({ where: { tid: ctx.tender.id } });
  372. ctx.body = { err: 0, msg: '', data: { bills: ledgerData, slm: scheduleLedgerMonthData, slh: scheduleLedgerHistoryData } };
  373. } catch (err) {
  374. this.log(err);
  375. ctx.body = { err: 1, msg: err.toString(), data: [] };
  376. }
  377. }
  378. /**
  379. * 台账选中提交(Ajax)
  380. *
  381. * @param ctx
  382. * @return {Promise<void>}
  383. */
  384. async saveLedger(ctx) {
  385. try {
  386. await this._checkScheduleCanModify(ctx);
  387. const data = JSON.parse(ctx.request.body.data);
  388. const result = await ctx.service.scheduleLedger.saveLedger(data);
  389. ctx.body = { err: 0, msg: '', data: result };
  390. } catch (err) {
  391. this.log(err);
  392. ctx.body = { err: 1, msg: err.toString(), data: [] };
  393. }
  394. }
  395. /**
  396. * 计划进度计算方式提交(Ajax)
  397. *
  398. * @param ctx
  399. * @return {Promise<void>}
  400. */
  401. async savePlan(ctx) {
  402. try {
  403. await this._checkScheduleCanModify(ctx);
  404. const data = JSON.parse(ctx.request.body.data);
  405. const responseData = {
  406. err: 0,
  407. msg: '',
  408. data: {},
  409. };
  410. switch (data.type) {
  411. case 'mode':
  412. responseData.data = await ctx.service.schedule.saveMode(data.postData);
  413. break;
  414. case 'addmonth':
  415. responseData.data = await ctx.service.scheduleMonth.add(data.postData);
  416. break;
  417. case 'delmonth':
  418. responseData.data = await ctx.service.scheduleMonth.del(data.postData);
  419. break;
  420. case 'ledger_edit':
  421. responseData.data = await ctx.service.scheduleLedgerMonth.save(data.postData);
  422. break;
  423. case 'ledger_paste':
  424. responseData.data = await ctx.service.scheduleLedgerMonth.saveDatas(data.postData);
  425. break;
  426. default: throw '参数有误';
  427. }
  428. ctx.body = responseData;
  429. } catch (err) {
  430. this.log(err);
  431. ctx.body = { err: 1, msg: err.toString(), data: null };
  432. }
  433. }
  434. /**
  435. * 计量进度金额模式计算方式提交(Ajax)
  436. *
  437. * @param ctx
  438. * @return {Promise<void>}
  439. */
  440. async saveStageTp(ctx) {
  441. try {
  442. await this._checkScheduleCanModify(ctx);
  443. const data = JSON.parse(ctx.request.body.data);
  444. const responseData = {
  445. err: 0,
  446. msg: '',
  447. data: {},
  448. };
  449. switch (data.type) {
  450. case 'add_stage':
  451. responseData.data = await ctx.service.scheduleStage.add(data.postData);
  452. break;
  453. case 'del_stage':
  454. responseData.data = await ctx.service.scheduleStage.del(data.postData);
  455. break;
  456. case 'reload_stage':
  457. responseData.data = await ctx.service.scheduleStage.changeOrder(data.postData);
  458. break;
  459. case 'update_tp':
  460. responseData.data = await ctx.service.scheduleStage.updateOneTp(data.postData);
  461. break;
  462. default: throw '参数有误';
  463. }
  464. ctx.body = responseData;
  465. } catch (err) {
  466. this.log(err);
  467. ctx.body = { err: 1, msg: err.toString(), data: null };
  468. }
  469. }
  470. /**
  471. * 计量进度工程量模式计算方式提交(Ajax)
  472. *
  473. * @param ctx
  474. * @return {Promise<void>}
  475. */
  476. async saveStageGcl(ctx) {
  477. try {
  478. await this._checkScheduleCanModify(ctx);
  479. const data = JSON.parse(ctx.request.body.data);
  480. const responseData = {
  481. err: 0,
  482. msg: '',
  483. data: {},
  484. };
  485. switch (data.type) {
  486. case 'add_stage':
  487. responseData.data = await ctx.service.scheduleMonth.addStageUsed(data.postData);
  488. break;
  489. case 'del_stage':
  490. responseData.data = await ctx.service.scheduleMonth.delStageUsed(data.postData);
  491. break;
  492. case 'ledger_edit':
  493. responseData.data = await ctx.service.scheduleLedgerMonth.saveSj(data.postData);
  494. break;
  495. case 'ledger_paste':
  496. responseData.data = await ctx.service.scheduleLedgerMonth.saveSjDatas(data.postData);
  497. break;
  498. default: throw '参数有误';
  499. }
  500. ctx.body = responseData;
  501. } catch (err) {
  502. this.log(err);
  503. ctx.body = { err: 1, msg: err.toString(), data: null };
  504. }
  505. }
  506. }
  507. return ScheduleController;
  508. };