measure_material.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. 'use strict';
  2. /**
  3. * 期计量 - 期列表页面 js
  4. *
  5. * @author Mai
  6. * @date 2018/12/7
  7. * @version
  8. */
  9. $(function () {
  10. // 获取审批流程
  11. $('a[data-target="#sp-list" ]').on('click', function () {
  12. const data = {
  13. order: $(this).attr('m-order'),
  14. };
  15. postData('/tender/' + tenderId + '/measure/material/auditors', data, function (result) {
  16. const { auditHistory, auditors, user } = result
  17. let auditorsHTML = ''
  18. let historyHTML = ''
  19. auditors.forEach((auditor, idx) => {
  20. if (idx === 0) {
  21. auditorsHTML += `<li class="list-group-item">
  22. <i class="fa fa fa-play-circle fa-rotate-90"></i> ${auditor.name}
  23. <small class="text-muted">${auditor.role}</small>
  24. <span class="pull-right">原报</span>
  25. </li>`
  26. } else if(idx === auditors.length -1 && idx !== 0) {
  27. auditorsHTML += `<li class="list-group-item">
  28. <i class="fa fa fa-stop-circle"></i> ${auditor.name}
  29. <small class="text-muted">${auditor.role}</small>
  30. <span class="pull-right">终审</span>
  31. </li>`
  32. } else {
  33. auditorsHTML += `<li class="list-group-item">
  34. <i class="fa fa-chevron-circle-down"></i> ${auditor.name}
  35. <small class="text-muted">${auditor.role}</small>
  36. <span class="pull-right">${transFormToChinese(idx)}审</span>
  37. </li>`
  38. }
  39. })
  40. $('#auditor-list').empty()
  41. $('#auditor-list').append(auditorsHTML)
  42. const leftAuditors = auditors;
  43. auditHistory.forEach((auditors, idx) => {
  44. if(idx === auditHistory.length - 1 && auditHistory.length !== 1) {
  45. historyHTML += `<div class="text-right"><a href="javascript: void(0);" id="fold-btn" data-target="show"
  46. >展开历史审批流程</a></div>`
  47. }
  48. historyHTML += `<div class="${idx < auditHistory.length - 1 ? 'fold-card' : ''}">
  49. <div class="text-center text-muted">${idx + 1}#</div>
  50. <ul class="timeline-list list-unstyled mt-2">`
  51. auditors.forEach((auditor, index) => {
  52. if (index === 0) {
  53. historyHTML += `<li class="timeline-list-item pb-2">
  54. <div class="timeline-item-date">
  55. ${formatDate(auditor.begin_time)}
  56. </div>
  57. <div class="timeline-item-tail"></div>
  58. <div class="timeline-item-icon bg-success text-light">
  59. <i class="fa fa-caret-down"></i>
  60. </div>
  61. <div class="timeline-item-content">
  62. <div class="card">
  63. <div class="card-body p-3">
  64. <div class="card-text">
  65. <p class="mb-1"><span
  66. class="h5">${user.name}</span><span
  67. class="pull-right text-success">${idx !== 0 ? '重新' : ''}上报审批</span>
  68. </p>
  69. <p class="text-muted mb-0">${user.role}</p>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. </li>
  75. <li class="timeline-list-item pb-2">
  76. <div class="timeline-item-date">
  77. ${formatDate(auditor.end_time)}
  78. </div>`
  79. if(index < auditors.length - 1) {
  80. historyHTML += `<div class="timeline-item-tail"></div>`
  81. }
  82. if(auditor.status === auditConst.status.checked) {
  83. historyHTML += `<div class="timeline-item-icon bg-success text-light">
  84. <i class="fa fa-check"></i>
  85. </div>`
  86. } else if(auditor.status === auditConst.status.checkNo || auditor.status === auditConst.status.checkNoPre) {
  87. historyHTML += `<div class="timeline-item-icon bg-warning text-light">
  88. <i class="fa fa-level-up"></i>
  89. </div>`
  90. } else if(auditor.status === auditConst.status.checking) {
  91. historyHTML += `<div class="timeline-item-icon bg-warning text-light">
  92. <i class="fa fa-ellipsis-h"></i>
  93. </div>`
  94. } else {
  95. historyHTML += `<div class="timeline-item-icon bg-secondary text-light"></div>`
  96. }
  97. historyHTML += `<div class="timeline-item-content">
  98. <div class="card">
  99. <div class="card-body p-3">
  100. <div class="card-text">
  101. <p class="mb-1"><span class="h5">${auditor.name}</span><span
  102. class="pull-right ${auditConst.statusClass[auditor.status]}">${auditConst.statusString[auditor.status]}</span>
  103. </p>
  104. <p class="text-muted mb-0">${auditor.role}</p>
  105. </div>
  106. </div>`
  107. if (auditor.opinion) {
  108. historyHTML += `<div class="card-body p-3 border-top">
  109. <p style="margin: 0;">${auditor.opinion}</p>
  110. </div>`
  111. }
  112. historyHTML += `</div></div></li>`
  113. } else {
  114. historyHTML += `<li class="timeline-list-item pb-2">
  115. <div class="timeline-item-date">
  116. ${formatDate(auditor.end_time)}
  117. </div>`
  118. if(index < auditors.length - 1) {
  119. historyHTML += `<div class="timeline-item-tail"></div>`
  120. }
  121. if(auditor.status === auditConst.status.checked) {
  122. historyHTML += `<div class="timeline-item-icon bg-success text-light">
  123. <i class="fa fa-check"></i>
  124. </div>`
  125. } else if(auditor.status === auditConst.status.checkNo || auditor.status === auditConst.status.checkNoPre) {
  126. historyHTML += `<div class="timeline-item-icon bg-warning text-light">
  127. <i class="fa fa-level-up"></i>
  128. </div>`
  129. } else if(auditor.status === auditConst.status.checking) {
  130. historyHTML += `<div class="timeline-item-icon bg-warning text-light">
  131. <i class="fa fa-ellipsis-h"></i>
  132. </div>`
  133. } else {
  134. historyHTML += `<div class="timeline-item-icon bg-secondary text-light"></div>`
  135. }
  136. historyHTML += `<div class="timeline-item-content">
  137. <div class="card">
  138. <div class="card-body p-3">
  139. <div class="card-text">
  140. <p class="mb-1"><span class="h5">${auditor.name}</span>
  141. <span
  142. class="pull-right
  143. ${auditConst.statusClass[auditor.status]}">${auditor.status !== auditConst.status.uncheck ? auditConst.statusString[auditor.status] : ''}
  144. ${auditor.status === auditConst.status.checkNo ? user.name : ''}
  145. ${auditor.status === auditConst.status.checkNoPre ? (leftAuditors.find(item => item.order === auditor.sort-1) ? leftAuditors.find(item => item.order === auditor.sort-1).name : '') : ''}
  146. </span>
  147. </p>
  148. <p class="text-muted mb-0">${auditor.role}</p>
  149. </div>
  150. </div>`
  151. if (auditor.opinion) {
  152. historyHTML += `<div class="card-body p-3 border-top">
  153. <p style="margin: 0;">${auditor.opinion} </p>
  154. </div>`
  155. }
  156. historyHTML += `</div></div></li>`
  157. }
  158. })
  159. historyHTML += '</ul></div>'
  160. })
  161. $('#audit-list').empty()
  162. $('#audit-list').append(historyHTML)
  163. });
  164. });
  165. // 展开/收起历史审核记录
  166. $('#audit-list').on('click', 'a', function() {
  167. const type = $(this).data('target')
  168. const auditCard = $(this).parent().parent()
  169. console.log('auditCard', auditCard)
  170. if (type === 'show') {
  171. $(this).data('target', 'hide')
  172. auditCard.find('.fold-card').slideDown('swing', () => {
  173. auditCard.find('#end-target').text($(this).data('idx') + '#')
  174. auditCard.find('#fold-btn').text('收起历史审核记录')
  175. })
  176. } else {
  177. $(this).data('target', 'show')
  178. auditCard.find('.fold-card').slideUp('swing', () => {
  179. auditCard.find('#end-target').text('1#')
  180. auditCard.find('#fold-btn').text('展开历史审核记录')
  181. })
  182. }
  183. });
  184. function formatDate(date) {
  185. if (!date) return '';
  186. date = new Date(date)
  187. const year = date.getFullYear();
  188. let mon = date.getMonth() + 1;
  189. let day = date.getDate();
  190. let hour = date.getHours();
  191. let minute = date.getMinutes();
  192. let scond = date.getSeconds();
  193. if (mon < 10) {
  194. mon = '0' + mon.toString();
  195. }
  196. if (day < 10) {
  197. day = '0' + day.toString();
  198. }
  199. if (hour < 10) {
  200. hour = '0' + hour.toString();
  201. }
  202. if (minute < 10) {
  203. minute = '0' + minute.toString();
  204. }
  205. if (scond < 10) {
  206. scond = '0' + scond.toString();
  207. }
  208. return `${year}<span>${mon}-${day}</span><span>${hour}:${minute}:${scond}</span>`;
  209. };
  210. // 计量期选中
  211. $('.select-stage-order').on('click', function () {
  212. const stageList = $('.select-stage-order:checked');
  213. if (stageList.length === 0) {
  214. $('#show_order').hide();
  215. $('#s_order').val('');
  216. } else {
  217. const order_array = [];
  218. for (let s = 0; s < stageList.length; s++) {
  219. order_array.push(stageList.eq(s).data('order'));
  220. // console.log(stageList.eq(s));
  221. }
  222. $('#show_order').html('第<b class="mx-2">' + order_array.join(',') + '</b>期');
  223. $('#show_order').show();
  224. $('#s_order').val(order_array.join(','));
  225. if (stageList.length > 1) {
  226. if($('#material_unitPrice').is(':hidden')){
  227. $('#unitPrice_dl').prop('checked', true);
  228. }
  229. $('#material_unitPrice').show();
  230. } else {
  231. $('#material_unitPrice').hide();
  232. $('#unitPrice_gy').prop('checked', true);
  233. }
  234. }
  235. });
  236. let interval;
  237. let stop = false;
  238. // 提交表单判断
  239. $('#addMaterial').click(function () {
  240. $(this).attr('disabled', true);
  241. if ($('#s_order').val() == '') {
  242. toastr.error('请选择计量期');
  243. $(this).removeAttr('disabled');
  244. return false;
  245. }
  246. $(this).text('正在生成新一期数据中,请勿刷新本页!...');
  247. const _self = $(this);
  248. const stage_id = [];
  249. $('#add-qi input[name="stage_id[]"]:checked').each(function () {
  250. stage_id.push(parseInt($(this).val()));
  251. });
  252. const is_stage_self = parseInt($('input[name="is_stage_self"]:checked').val());
  253. const newMaterialData = {
  254. s_order: $('#s_order').val(),
  255. period: $('#add-qi input[name="period"]').val(),
  256. stage_id,
  257. is_stage_self,
  258. };
  259. if (lastMaterialListNum === 0) {
  260. console.log(newMaterialData);
  261. postData(preUrl + '/measure/material/add', newMaterialData, function (result) {
  262. window.location.href = preUrl + '/measure/material/' + result.order;
  263. }, function () {
  264. _self.attr('disabled', false).text('确认添加');
  265. });
  266. return;
  267. }
  268. $('#add-qi').modal('hide');
  269. $('#okedit').modal('show');
  270. interval = setInterval(progress, 50);
  271. postData(preUrl + '/measure/material/gcl/load', { stage_id, is_stage_self }, function (result) {
  272. // console.log(result);
  273. const ledger = result.ledger;
  274. const pos = result.pos;
  275. const gclList = result.gclList;
  276. const selfList = result.selfList;
  277. // 整理material,针对上期是独立单价并多个不同值的单独设置值进行部分值去除
  278. const materialListForSelf = _.uniqWith(_.orderBy(result.materialListForSelf, ['ms_id'], ['desc']), function(item1, item2) {
  279. return item1.xmj_id === item2.xmj_id && item1.gcl_id === item2.gcl_id && item1.mx_id === item2.mx_id && item1.mb_id === item2.mb_id;
  280. });
  281. console.log(materialListForSelf, result.materialListForSelf);
  282. const insertGclList = [];
  283. const insertList = [];
  284. const insertSelfList = [];// 需要单独添加的明细清单工料含量列表
  285. const removeGclList = [];
  286. const hadQtySelfList = [];
  287. if (is_stage_self) {
  288. for (const sid of stage_id) {
  289. const curLedger = _.find(result.curLedgerData, {sid: sid});
  290. const curPos = _.find(result.curPosData, {sid: sid});
  291. gclGatherModel.loadLedgerData(_.cloneDeep(ledger), curLedger.ledgerData);
  292. gclGatherModel.loadPosData(_.cloneDeep(pos), curPos.posData);
  293. const gclGatherData = gclGatherModel.gatherGclData();
  294. // console.log(gclGatherData);
  295. const insertGcl = [];
  296. for (const g of gclList) {
  297. const gcl = _.find(gclGatherData, function (item) {
  298. return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, {gcl_id: g.gcl_id}) !== -1;
  299. });
  300. if (gcl) {
  301. const ig = _.find(insertGcl, {gcl});
  302. if (ig) {
  303. if (_.findIndex(ig.bills, {mb_id: g.mb_id}) === -1) {
  304. ig.bills.push(g);
  305. }
  306. } else {
  307. insertGcl.push({
  308. bills: [g],
  309. gcl,
  310. leafXmjs: _.filter(gcl.leafXmjs, function (item) {
  311. return item.gather_qty !== undefined && item.gather_qty !== null
  312. }),
  313. })
  314. }
  315. } else {
  316. removeGclList.push(g);
  317. }
  318. }
  319. for (const one of insertGcl) {
  320. if (one.leafXmjs && one.leafXmjs.length > 0) {
  321. for (const xmj of one.leafXmjs) {
  322. const is_self = _.findIndex(selfList, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: xmj.mx_id ? xmj.mx_id : '' }) !== -1;// 区分单独计量的明细工料含量
  323. if (is_self) {
  324. const billsList = _.filter(materialListForSelf, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: xmj.mx_id ? xmj.mx_id : '' });
  325. for (const bill of billsList) {
  326. if (!_.find(hadQtySelfList, bill)) {
  327. hadQtySelfList.push(bill);
  328. }
  329. insertSelfList.push({
  330. gcl_id: xmj.gcl_id,
  331. mx_id: xmj.mx_id ? xmj.mx_id : '',
  332. xmj_id: xmj.id ? xmj.id : null,
  333. gather_qty: xmj.gather_qty,
  334. quantity: bill.quantity,
  335. expr: bill.expr,
  336. mb_id: bill.mb_id,
  337. order: bill.order,
  338. sid,
  339. });
  340. }
  341. } else {
  342. const newgcl = _.find(gclList, { gcl_id: xmj.gcl_id });
  343. for (const bill of one.bills) {
  344. insertList.push({
  345. gcl_id: xmj.gcl_id,
  346. mx_id: xmj.mx_id ? xmj.mx_id : '',
  347. xmj_id: xmj.id ? xmj.id : null,
  348. gather_qty: xmj.gather_qty,
  349. quantity: bill.quantity,
  350. expr: bill.expr,
  351. mb_id: bill.mb_id,
  352. order: bill.order,
  353. sid,
  354. });
  355. if (!newgcl) {
  356. if (_.findIndex(insertGclList, { gcl_id: xmj.gcl_id }) === -1) {
  357. insertGclList.push({
  358. gcl_id: xmj.gcl_id,
  359. quantity: bill.quantity,
  360. expr: bill.expr,
  361. old_quantity: bill.quantity,
  362. old_expr: bill.expr,
  363. mb_id: bill.mb_id,
  364. order: bill.order,
  365. });
  366. }
  367. }
  368. }
  369. }
  370. }
  371. }
  372. }
  373. }
  374. } else {
  375. const curLedgerData = result.curLedgerData;
  376. const curPosData = result.curPosData;
  377. gclGatherModel.loadLedgerData(_.cloneDeep(ledger), curLedgerData);
  378. gclGatherModel.loadPosData(_.cloneDeep(pos), curPosData);
  379. const gclGatherData = gclGatherModel.gatherGclData();
  380. const insertGcl = [];
  381. for (const g of gclList) {
  382. const gcl = _.find(gclGatherData, function (item) {
  383. return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, {gcl_id: g.gcl_id}) !== -1;
  384. });
  385. if (gcl) {
  386. const ig = _.find(insertGcl, {gcl});
  387. if (ig) {
  388. if (_.findIndex(ig.bills, {mb_id: g.mb_id}) === -1) {
  389. ig.bills.push(g);
  390. }
  391. } else {
  392. insertGcl.push({
  393. bills: [g],
  394. gcl,
  395. leafXmjs: _.filter(gcl.leafXmjs, function (item) {
  396. return item.gather_qty !== undefined && item.gather_qty !== null
  397. }),
  398. })
  399. }
  400. } else {
  401. removeGclList.push(g);
  402. }
  403. }
  404. for (const one of insertGcl) {
  405. if (one.leafXmjs && one.leafXmjs.length > 0) {
  406. for (const xmj of one.leafXmjs) {
  407. const is_self = _.findIndex(selfList, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: xmj.mx_id ? xmj.mx_id : null }) !== -1;// 区分单独计量的明细工料含量
  408. if (is_self) {
  409. const billsList = _.filter(materialListForSelf, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: xmj.mx_id ? xmj.mx_id : null });
  410. for (const bill of billsList) {
  411. hadQtySelfList.push(bill);
  412. insertSelfList.push({
  413. gcl_id: xmj.gcl_id,
  414. mx_id: xmj.mx_id ? xmj.mx_id : '',
  415. xmj_id: xmj.id ? xmj.id : null,
  416. gather_qty: xmj.gather_qty,
  417. quantity: bill.quantity,
  418. expr: bill.expr,
  419. mb_id: bill.mb_id,
  420. order: bill.order,
  421. });
  422. }
  423. } else {
  424. const newgcl = _.find(gclList, { gcl_id: xmj.gcl_id });
  425. for (const bill of one.bills) {
  426. insertList.push({
  427. gcl_id: xmj.gcl_id,
  428. mx_id: xmj.mx_id ? xmj.mx_id : '',
  429. xmj_id: xmj.id ? xmj.id : null,
  430. gather_qty: xmj.gather_qty,
  431. quantity: bill.quantity,
  432. expr: bill.expr,
  433. mb_id: bill.mb_id,
  434. order: bill.order,
  435. });
  436. if (!newgcl) {
  437. insertGclList.push({
  438. gcl_id: xmj.gcl_id,
  439. quantity: bill.quantity,
  440. expr: bill.expr,
  441. old_quantity: bill.quantity,
  442. old_expr: bill.expr,
  443. mb_id: bill.mb_id,
  444. order: bill.order,
  445. });
  446. }
  447. }
  448. }
  449. }
  450. }
  451. }
  452. }
  453. // 通过比较materialListForSelf和hadQtySelfList不重合部分,得出本期为null的gather_qty列表,插入到insertSelfList中
  454. const pushSelfList = _.xorWith(materialListForSelf, hadQtySelfList, _.isEqual);
  455. if (pushSelfList.length > 0) {
  456. for (const ps of pushSelfList) {
  457. insertSelfList.push({
  458. gcl_id: ps.gcl_id,
  459. mx_id: ps.mx_id,
  460. xmj_id: ps.xmj_id,
  461. gather_qty: null,
  462. quantity: ps.quantity,
  463. expr: ps.expr,
  464. mb_id: ps.mb_id,
  465. order: ps.order,
  466. });
  467. }
  468. }
  469. // 可能需要新增list_gcl表
  470. newMaterialData.material_list = insertList;
  471. newMaterialData.material_self_list = insertSelfList;
  472. newMaterialData.insertGclList = insertGclList;
  473. newMaterialData.removeGclList = removeGclList;
  474. console.log(newMaterialData);
  475. console.log(insertSelfList);
  476. postData(preUrl + '/measure/material/add', newMaterialData, function (result) {
  477. window.location.href = preUrl + '/measure/material/' + result.order;
  478. }, function () {
  479. stop = true;
  480. clearInterval(interval);
  481. console.log(_self.parents('div[id="add-qi"]'));
  482. $('#add-qi').modal('show');
  483. $('#okedit').modal('hide');
  484. _self.parents('div[id="add-qi"]').modal('show');
  485. _self.attr('disabled', false).text('确认添加');
  486. });
  487. return;
  488. });
  489. // $(this).parents('form').submit();
  490. });
  491. let value = 0;
  492. function progress(){
  493. if (stop) {
  494. setTimeout(function () {
  495. $('#add-qi').modal('show');
  496. $('#okedit').modal('hide');
  497. value = 0;
  498. clearInterval(interval);
  499. }, 500);
  500. }
  501. if (value < 100) {
  502. value = parseInt(value) + 1;
  503. $("#material-progress").css("width", value + "%").text(value + "%");
  504. } else if (value === 100) {
  505. value = parseInt(value) + 1;
  506. value = 30;
  507. }
  508. };
  509. let editPeriod = null;
  510. $('.edit-material').on('click', function () {
  511. const order = parseInt($(this).data('order'));
  512. const mid = parseInt($(this).data('mid'));
  513. $('#edit-period').val('');
  514. $('#edit-name').val('第 ' + order + ' 期');
  515. $('#edit-mid').val(mid);
  516. const m_period = $(this).data('period');
  517. const period = [];
  518. for (const p of m_period.split('~')) {
  519. if (p && p !== '') {
  520. period.push(new Date(p));
  521. }
  522. }
  523. $('#edit-period').val(m_period);
  524. editPeriod = !editPeriod ? $('#edit-period').datepicker().data('datepicker') : editPeriod;
  525. editPeriod.clear();
  526. if (period.length > 0) {
  527. editPeriod.selectDate(period);
  528. }
  529. });
  530. });
  531. function checkForm () {
  532. if ($('#edit-period').val() == '') {
  533. toastr.error('请选择调差周期');
  534. return false;
  535. }
  536. // const date = $('#edit-date').val();
  537. // const period = $('#edit-period').val();
  538. // const startDate = period.split('~')[0];
  539. // const endDate = period.split('~')[1];
  540. // if (startDate.indexOf(date) === -1 && endDate.indexOf(date) === -1) {
  541. // toastr.error('所选日期与当前月份不匹配,请重新选择');
  542. // $('#edit-period').parents('.form-group').find('.text-danger').remove();
  543. // $('#edit-period').parents('.form-group').append('<small class="text-danger">所选日期与当前月份不匹配,请重新选择</small>');
  544. // return false;
  545. // }
  546. };