measure_material.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. 'use strict';
  2. /**
  3. * 期计量 - 期列表页面 js
  4. *
  5. * @author Mai
  6. * @date 2018/12/7
  7. * @version
  8. */
  9. $(function () {
  10. const getGroupAuditHtml = function (group) {
  11. return group.map(u => { return `<small class="d-inline-block text-dark mx-1" title="${u.role}" data-auditorId="${u.aid}">${u.name}</small>`; }).join('');
  12. };
  13. const getAuditTypeHtml = function (type) {
  14. if (type === auditType.key.common) return '';
  15. return `<div class="li-subscript"><span class="badge badge-pill badge-${auditType.info[type].class} p-1 badge-bg-small"><small>${auditType.info[type].short}</small></span></div>`;
  16. };
  17. const getAuditTypeText = function (type) {
  18. if (type === auditType.key.common) return '';
  19. return `<span class="text-${auditType.info[type].class}">${auditType.info[type].long}</span>`;
  20. };
  21. // 获取审批流程
  22. $('a[data-target="#sp-list" ]').on('click', function () {
  23. const data = {
  24. order: $(this).attr('m-order'),
  25. };
  26. postData('/tender/' + tenderId + '/measure/material/auditors', data, function (result) {
  27. const { auditHistory, auditors2, user } = result
  28. let auditorsHTML = [];
  29. auditors2.forEach((group, idx) => {
  30. if (idx === 0) {
  31. auditorsHTML.push(`<li class="list-group-item d-flex justify-content-between align-items-center">
  32. <span class="mr-1"><i class="fa fa fa-play-circle fa-rotate-90"></i></span>
  33. <span class="text-muted">${getGroupAuditHtml(group)}</span>
  34. <span class="badge badge-light badge-pill ml-auto"><small>原报</small></span>
  35. </li>`);
  36. } else if(idx === auditors2.length -1 && idx !== 0) {
  37. auditorsHTML.push(`<li class="list-group-item d-flex justify-content-between align-items-center">
  38. <span class="mr-1"><i class="fa fa fa-stop-circle fa-rotate-90"></i></span>
  39. <span class="text-muted">${getGroupAuditHtml(group)}</span>
  40. <div class="d-flex ml-auto">
  41. ${getAuditTypeHtml(group[0].audit_type)}
  42. <span class="badge badge-light badge-pill ml-auto"><small>终审</small></span>
  43. </div>
  44. </li>`);
  45. } else {
  46. auditorsHTML.push(`<li class="list-group-item d-flex justify-content-between align-items-center">
  47. <span class="mr-1"><i class="fa fa fa-chevron-circle-down"></i></span>
  48. <span class="text-muted">${getGroupAuditHtml(group)}</span>
  49. <div class="d-flex ml-auto">
  50. ${getAuditTypeHtml(group[0].audit_type)}
  51. <span class="badge badge-light badge-pill"><small>${transFormToChinese(idx)}审</small></span>
  52. </div>
  53. </li>`);
  54. }
  55. });
  56. $('#auditor-list').empty()
  57. $('#auditor-list').append(auditorsHTML.join(''));
  58. let historyHTML = [];
  59. auditHistory.forEach((his, idx) => {
  60. if (idx === auditHistory.length - 1 && auditHistory.length !== 1) {
  61. historyHTML.push(`<div class="text-right"><a href="javascript: void(0);" id="fold-btn" data-target="show">展开历史审批流程</a></div>`);
  62. }
  63. historyHTML.push(`<div class="${idx < auditHistory.length - 1 ? 'fold-card' : ''}">`);
  64. historyHTML.push(`<div class="text-center text-muted">${idx+1}#</div>`);
  65. historyHTML.push(`<ul class="timeline-list list-unstyled mt-2 ${ idx === auditHistory.length - 1 && auditHistory.length !== 1 ? 'last-auditor-list' : '' }">`);
  66. his.forEach((group, index) => {
  67. if (index === 0) {
  68. historyHTML.push(`<li class="timeline-list-item pb-2">
  69. <div class="timeline-item-date">
  70. ${group.beginYear}
  71. <span>${group.beginDate}</span>
  72. <span>${group.beginTime}</span>
  73. </div>
  74. <div class="timeline-item-tail"></div>
  75. <div class="timeline-item-icon bg-success text-light"><i class="fa fa-caret-down"></i></div>
  76. <div class="timeline-item-content">
  77. <div class="py-1">
  78. <span class="text-black-50">原报</span>
  79. <span class="pull-right text-success">${idx !== 0 ? '重新' : '' }上报审批</span>
  80. </div>
  81. <div class="card">
  82. <div class="card-body px-3 py-0">
  83. <div class="card-text p-2 py-3 row">
  84. <div class="col">
  85. <span class="h6">${user.name}</span>
  86. <span class="text-muted ml-1">${user.role}</span>
  87. </div>
  88. <div class="col">
  89. <span class="pull-right text-success"><i class="fa fa-check-circle"></i></span>
  90. </div>
  91. </div>
  92. </div>
  93. </div>
  94. </div>
  95. </li>`);
  96. }
  97. historyHTML.push(`<li class="timeline-list-item pb-2 ${ group.status === auditConst.status.uncheck && idx === auditHistory.length - 1 && auditHistory.length !== 1 ? 'is_uncheck' : ''}">`);
  98. if (group.endYear) {
  99. historyHTML.push(`<div class="timeline-item-date">${group.endYear}<span>${group.endDate}</span><span>${group.endTime}</span></div>`);
  100. }
  101. if (index < his.length - 1) {
  102. historyHTML.push('<div class="timeline-item-tail"></div>');
  103. }
  104. if (group.status === auditConst.status.checked) {
  105. historyHTML.push('<div class="timeline-item-icon bg-success text-light"><i class="fa fa-check"></i></div>');
  106. } else if (group.status === auditConst.status.checkNo || group.status === auditConst.status.checkNoPre || group.status === auditConst.status.checkCancel) {
  107. historyHTML.push('<div class="timeline-item-icon bg-warning text-light"><i class="fa fa-level-up"></i></div>');
  108. } else if (group.status === auditConst.status.checking) {
  109. historyHTML.push('<div class="timeline-item-icon bg-warning text-light"><i class="fa fa-ellipsis-h"></i></div>');
  110. } else {
  111. historyHTML.push('<div class="timeline-item-icon bg-secondary text-light"></div>');
  112. }
  113. historyHTML.push('<div class="timeline-item-content">');
  114. const statuStr = group.status !== auditConst.status.uncheck ?
  115. `<span class="pull-right ${auditConst.statusClass[group.status]}">${auditConst.statusString[group.status]}</span>` : '';
  116. historyHTML.push(`<div class="py-1">
  117. <span class="text-black-50">
  118. ${ !group.is_final ? group.audit_order + '' : '终' }审 ${getAuditTypeText(group.audit_type)}
  119. </span>
  120. ${statuStr}
  121. </div>`);
  122. historyHTML.push('<div class="card"><div class="card-body px-3 py-0">');
  123. for (const [i, auditor] of group.auditors.entries()) {
  124. historyHTML.push(`<div class="card-text p-2 py-3 row ${ ( i > 0 ? 'border-top' : '') }">`);
  125. historyHTML.push(`<div class="col"><span class="h6">${auditor.name}</span><span class="text-muted ml-1">${auditor.role}</span></div>`);
  126. historyHTML.push('<div class="col">');
  127. if (auditor.status === auditConst.status.checked) {
  128. historyHTML.push('<span class="pull-right text-success"><i class="fa fa-check-circle"></i></span>');
  129. } if (auditor.status === auditConst.status.checkNo || auditor.status === auditConst.status.checkNoPre || auditor.status === auditConst.status.checkCancel) {
  130. historyHTML.push('<span class="pull-right text-warning"><i class="fa fa-share-square fa-rotate-270"></i></span>');
  131. }
  132. historyHTML.push('</div>');
  133. if (auditor.opinion) {
  134. historyHTML.push(`<div class="col-12 py-1 bg-light"><i class="fa fa-commenting-o mr-1"></i>${auditor.opinion}</div>`);
  135. }
  136. historyHTML.push('</div>');
  137. }
  138. historyHTML.push('</div></div>');
  139. historyHTML.push('</div>');
  140. historyHTML.push('</li>');
  141. });
  142. historyHTML.push('</div>');
  143. historyHTML.push('</ul>');
  144. });
  145. $('#audit-list').empty();
  146. $('#audit-list').append(historyHTML.join(''));
  147. });
  148. });
  149. // 展开/收起历史审核记录
  150. $('#audit-list').on('click', 'a', function() {
  151. const type = $(this).data('target')
  152. const auditCard = $(this).parent().parent()
  153. console.log('auditCard', auditCard)
  154. if (type === 'show') {
  155. $(this).data('target', 'hide')
  156. auditCard.find('.fold-card').slideDown('swing', () => {
  157. auditCard.find('#end-target').text($(this).data('idx') + '#')
  158. auditCard.find('#fold-btn').text('收起历史审核记录')
  159. })
  160. } else {
  161. $(this).data('target', 'show')
  162. auditCard.find('.fold-card').slideUp('swing', () => {
  163. auditCard.find('#end-target').text('1#')
  164. auditCard.find('#fold-btn').text('展开历史审核记录')
  165. })
  166. }
  167. });
  168. function formatDate(date) {
  169. if (!date) return '';
  170. date = new Date(date)
  171. const year = date.getFullYear();
  172. let mon = date.getMonth() + 1;
  173. let day = date.getDate();
  174. let hour = date.getHours();
  175. let minute = date.getMinutes();
  176. let scond = date.getSeconds();
  177. if (mon < 10) {
  178. mon = '0' + mon.toString();
  179. }
  180. if (day < 10) {
  181. day = '0' + day.toString();
  182. }
  183. if (hour < 10) {
  184. hour = '0' + hour.toString();
  185. }
  186. if (minute < 10) {
  187. minute = '0' + minute.toString();
  188. }
  189. if (scond < 10) {
  190. scond = '0' + scond.toString();
  191. }
  192. return `${year}<span>${mon}-${day}</span><span>${hour}:${minute}:${scond}</span>`;
  193. };
  194. $('input[name="hz-radio"]').on('change', function () {
  195. if ($(this).val() === '1') {
  196. $('#hz-input').attr('readonly', 'readonly');
  197. $('#hz-btn').attr('disabled', 'disabled');
  198. } else {
  199. $('#hz-input').removeAttr('readonly');
  200. $('#hz-btn').removeAttr('disabled');
  201. }
  202. $('#hz-btn').trigger('click');
  203. });
  204. $('#hz-input').on('keypress', function () {
  205. // 还要判断是否是readonly
  206. if(window.event.keyCode === 13 && !$(this).prop('readonly') && !$(this).prop('disabled')) {
  207. $('#hz-btn').trigger('click');
  208. }
  209. });
  210. // $('#hz-input').blur(function () {
  211. // $('#hz-btn').trigger('click');
  212. // });
  213. $('#hz-btn').on('click', function () {
  214. const radio = parseInt($('input[name="hz-radio"]:checked').val());
  215. const materialTotalPrice = {
  216. m_tp: 0,
  217. tax_tp: 0,
  218. ex_tp: 0,
  219. ex_tax_tp: 0,
  220. m_tax_tp: 0,
  221. total_tp: 0,
  222. total_tax_tp: 0
  223. };
  224. let hzMaterials = [];
  225. if (radio === 1) {
  226. hzMaterials = materials;
  227. } else if (radio === 2) {
  228. const materialsStr = $('#hz-input').val();
  229. if (!materialsStr) {
  230. hzMaterials = [];
  231. } else {
  232. const hzOrders = materialsStr.split(',');
  233. for (const order of hzOrders) {
  234. if (order && order.trim() === '') continue; // 跳过空字符串
  235. if (!isNaN(parseFloat(order)) && isFinite(order)) {
  236. const material = materials.find(m => m.order === parseInt(order.trim()));
  237. if (material) {
  238. hzMaterials.push(material);
  239. }
  240. } else if (_.indexOf(order, '-') !== -1) {
  241. const range = order.split('-').map(o => parseInt(o.trim()));
  242. if (range.length === 2 && !isNaN(range[0]) && !isNaN(range[1])) {
  243. hzMaterials = hzMaterials.concat(materials.filter(m => m.order >= range[0] && m.order <= range[1]));
  244. }
  245. }
  246. }
  247. }
  248. }
  249. console.log(hzMaterials);
  250. for (const s of hzMaterials) {
  251. materialTotalPrice.m_tp = ZhCalc.add(materialTotalPrice.m_tp, ZhCalc.round(s.m_tp, s.decimal.tp));
  252. materialTotalPrice.tax_tp = !s.material_tax ? ZhCalc.add(materialTotalPrice.tax_tp, ZhCalc.round(ZhCalc.mul(s.m_tp, 1 + s.rate / 100), s.decimal.tp)) : materialTotalPrice.tax_tp;
  253. materialTotalPrice.ex_tp = ZhCalc.add(materialTotalPrice.ex_tp, ZhCalc.round(s.ex_tp, s.decimal.tp));
  254. materialTotalPrice.ex_tax_tp = ZhCalc.add(materialTotalPrice.ex_tax_tp, ZhCalc.round(ZhCalc.mul(s.ex_tp, 1 + s.exponent_rate / 100), s.decimal.tp));
  255. materialTotalPrice.m_tax_tp = s.material_tax ? ZhCalc.add(materialTotalPrice.m_tax_tp, ZhCalc.round(s.m_tax_tp, s.decimal.tp)) : materialTotalPrice.m_tax_tp;
  256. }
  257. materialTotalPrice.total_tp = ZhCalc.add(materialTotalPrice.m_tp, materialTotalPrice.ex_tp);
  258. materialTotalPrice.total_tax_tp = ZhCalc.add(materialTotalPrice.tax_tp, materialTotalPrice.ex_tax_tp);
  259. $('#hz-table tr').eq(0).children('td').eq(0).text(materialTotalPrice.m_tp || '');
  260. $('#hz-table tr').eq(0).children('td').eq(1).text(materialTotalPrice.ex_tp || '');
  261. $('#hz-table tr').eq(0).children('td').eq(2).text(materialTotalPrice.total_tp || '');
  262. $('#hz-table tr').eq(1).children('td').eq(0).text(materialTotalPrice.tax_tp || '');
  263. $('#hz-table tr').eq(1).children('td').eq(1).text(materialTotalPrice.ex_tax_tp || '');
  264. $('#hz-table tr').eq(1).children('td').eq(2).text(materialTotalPrice.total_tax_tp || '');
  265. if (openMaterialTax) {
  266. $('#hz-table tr').eq(2).children('td').eq(0).text(materialTotalPrice.m_tax_tp || '');
  267. $('#hz-table tr').eq(2).children('td').eq(2).text(materialTotalPrice.m_tax_tp || '');
  268. }
  269. });
  270. // 计量期选中
  271. $('.select-stage-order').on('click', function () {
  272. const stageList = $('.select-stage-order:checked');
  273. if (stageList.length === 0) {
  274. $('#show_order').hide();
  275. $('#s_order').val('');
  276. } else {
  277. const order_array = [];
  278. for (let s = 0; s < stageList.length; s++) {
  279. order_array.push(stageList.eq(s).data('order'));
  280. // console.log(stageList.eq(s));
  281. }
  282. $('#show_order').html('第<b class="mx-2">' + order_array.join(',') + '</b>期');
  283. $('#show_order').show();
  284. $('#s_order').val(order_array.join(','));
  285. if (stageList.length > 1) {
  286. if($('#material_unitPrice').is(':hidden')){
  287. $('#unitPrice_dl').prop('checked', true);
  288. }
  289. $('#material_unitPrice').show();
  290. } else {
  291. $('#material_unitPrice').hide();
  292. $('#unitPrice_gy').prop('checked', true);
  293. }
  294. }
  295. });
  296. let interval;
  297. let stop = false;
  298. // 提交表单判断
  299. $('#addMaterial').click(function () {
  300. $(this).attr('disabled', true);
  301. if ($('#s_order').val() == '') {
  302. toastr.error('请选择计量期');
  303. $(this).removeAttr('disabled');
  304. return false;
  305. }
  306. $(this).text('正在生成新一期数据中,请勿刷新本页!...');
  307. const _self = $(this);
  308. const stage_id = [];
  309. $('#add-qi input[name="stage_id[]"]:checked').each(function () {
  310. stage_id.push(parseInt($(this).val()));
  311. });
  312. const is_stage_self = parseInt($('input[name="is_stage_self"]:checked').val());
  313. if (is_stage_self && stage_id.length > 12) {
  314. toastr.error('独立调差下最多选择12个计量期');
  315. $(this).removeAttr('disabled').text('确认添加');
  316. return false;
  317. }
  318. const newMaterialData = {
  319. s_order: $('#s_order').val(),
  320. period: $('#add-qi input[name="period"]').val(),
  321. stage_id,
  322. is_stage_self,
  323. qty_source: parseInt($('#add-qi input[name="qty_source"]:checked').val()),
  324. };
  325. if (lastMaterialListNum === 0) {
  326. console.log(newMaterialData);
  327. postData(preUrl + '/measure/material/add', newMaterialData, function (result) {
  328. window.location.href = preUrl + '/measure/material/' + result.order;
  329. }, function () {
  330. _self.attr('disabled', false).text('确认添加');
  331. });
  332. return;
  333. }
  334. $('#add-qi').modal('hide');
  335. $('#okedit').modal('show');
  336. interval = setInterval(progress, 50);
  337. postData(preUrl + '/measure/material/add', newMaterialData, function (result) {
  338. window.location.href = preUrl + '/measure/material/' + result.order;
  339. }, function () {
  340. stop = true;
  341. clearInterval(interval);
  342. console.log(_self.parents('div[id="add-qi"]'));
  343. $('#add-qi').modal('show');
  344. $('#okedit').modal('hide');
  345. _self.parents('div[id="add-qi"]').modal('show');
  346. _self.attr('disabled', false).text('确认添加');
  347. });
  348. // postData(preUrl + '/measure/material/gcl/load', { stage_id, is_stage_self }, function (result) {
  349. // // console.log(result);
  350. // const ledger = result.ledger;
  351. // const pos = result.pos;
  352. // const gclList = result.gclList;
  353. // const selfList = result.selfList;
  354. // // 整理material,针对上期是独立单价并多个不同值的单独设置值进行部分值去除
  355. // const materialListForSelf = _.uniqWith(_.orderBy(result.materialListForSelf, ['ms_id'], ['desc']), function(item1, item2) {
  356. // 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;
  357. // });
  358. // console.log(materialListForSelf, result.materialListForSelf);
  359. // const insertGclList = [];
  360. // const insertList = [];
  361. // const insertSelfList = [];// 需要单独添加的明细清单工料含量列表
  362. // const removeGclList = [];
  363. // const hadQtySelfList = [];
  364. // if (is_stage_self) {
  365. // for (const sid of stage_id) {
  366. // const curLedger = _.find(result.curLedgerData, {sid: sid});
  367. // const curPos = _.find(result.curPosData, {sid: sid});
  368. // gclGatherModel.loadLedgerData(_.cloneDeep(ledger), curLedger.ledgerData);
  369. // gclGatherModel.loadPosData(_.cloneDeep(pos), curPos.posData);
  370. // const gclGatherData = gclGatherModel.gatherGclData();
  371. // // console.log(gclGatherData);
  372. // const insertGcl = [];
  373. // for (const g of gclList) {
  374. // const gcl = _.find(gclGatherData, function (item) {
  375. // return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, {gcl_id: g.gcl_id}) !== -1;
  376. // });
  377. // if (gcl) {
  378. // const ig = _.find(insertGcl, {gcl});
  379. // if (ig) {
  380. // if (_.findIndex(ig.bills, {mb_id: g.mb_id}) === -1) {
  381. // ig.bills.push(g);
  382. // }
  383. // } else {
  384. // insertGcl.push({
  385. // bills: [g],
  386. // gcl,
  387. // leafXmjs: _.filter(gcl.leafXmjs, function (item) {
  388. // return item.gather_qty !== undefined && item.gather_qty !== null
  389. // }),
  390. // })
  391. // }
  392. // } else {
  393. // removeGclList.push(g);
  394. // }
  395. // }
  396. // for (const one of insertGcl) {
  397. // if (one.leafXmjs && one.leafXmjs.length > 0) {
  398. // for (const xmj of one.leafXmjs) {
  399. // const is_self = _.findIndex(selfList, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: xmj.mx_id ? xmj.mx_id : '' }) !== -1;// 区分单独计量的明细工料含量
  400. // if (is_self) {
  401. // const billsList = _.filter(materialListForSelf, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: xmj.mx_id ? xmj.mx_id : '' });
  402. // for (const bill of billsList) {
  403. // if (!_.find(hadQtySelfList, bill)) {
  404. // hadQtySelfList.push(bill);
  405. // }
  406. // insertSelfList.push({
  407. // gcl_id: xmj.gcl_id,
  408. // mx_id: xmj.mx_id ? xmj.mx_id : '',
  409. // xmj_id: xmj.id ? xmj.id : null,
  410. // contract_qty: xmj.contract_qty,
  411. // qc_qty: xmj.qc_qty,
  412. // qc_minus_qty: xmj.qc_minus_qty,
  413. // gather_qty: xmj.gather_qty,
  414. // quantity: bill.quantity,
  415. // expr: bill.expr,
  416. // mb_id: bill.mb_id,
  417. // order: bill.order,
  418. // sid,
  419. // });
  420. // }
  421. // } else {
  422. // const newgcl = _.find(gclList, { gcl_id: xmj.gcl_id });
  423. // for (const bill of one.bills) {
  424. // insertList.push({
  425. // gcl_id: xmj.gcl_id,
  426. // mx_id: xmj.mx_id ? xmj.mx_id : '',
  427. // xmj_id: xmj.id ? xmj.id : null,
  428. // contract_qty: xmj.contract_qty,
  429. // qc_qty: xmj.qc_qty,
  430. // qc_minus_qty: xmj.qc_minus_qty,
  431. // gather_qty: xmj.gather_qty,
  432. // quantity: bill.quantity,
  433. // expr: bill.expr,
  434. // mb_id: bill.mb_id,
  435. // order: bill.order,
  436. // sid,
  437. // });
  438. // if (!newgcl) {
  439. // if (_.findIndex(insertGclList, { gcl_id: xmj.gcl_id }) === -1) {
  440. // insertGclList.push({
  441. // gcl_id: xmj.gcl_id,
  442. // quantity: bill.quantity,
  443. // expr: bill.expr,
  444. // old_quantity: bill.quantity,
  445. // old_expr: bill.expr,
  446. // mb_id: bill.mb_id,
  447. // order: bill.order,
  448. // });
  449. // }
  450. // }
  451. // }
  452. // }
  453. // }
  454. // }
  455. // }
  456. // }
  457. // } else {
  458. // const curLedgerData = result.curLedgerData;
  459. // const curPosData = result.curPosData;
  460. // gclGatherModel.loadLedgerData(_.cloneDeep(ledger), curLedgerData);
  461. // gclGatherModel.loadPosData(_.cloneDeep(pos), curPosData);
  462. // const gclGatherData = gclGatherModel.gatherGclData();
  463. // const insertGcl = [];
  464. // for (const g of gclList) {
  465. // const gcl = _.find(gclGatherData, function (item) {
  466. // return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, {gcl_id: g.gcl_id}) !== -1;
  467. // });
  468. // if (gcl) {
  469. // const ig = _.find(insertGcl, {gcl});
  470. // if (ig) {
  471. // if (_.findIndex(ig.bills, {mb_id: g.mb_id}) === -1) {
  472. // ig.bills.push(g);
  473. // }
  474. // } else {
  475. // insertGcl.push({
  476. // bills: [g],
  477. // gcl,
  478. // leafXmjs: _.filter(gcl.leafXmjs, function (item) {
  479. // return item.gather_qty !== undefined && item.gather_qty !== null || (item.qc_minus_qty !== undefined && item.qc_minus_qty !== null)
  480. // }),
  481. // })
  482. // }
  483. // } else {
  484. // removeGclList.push(g);
  485. // }
  486. // }
  487. // for (const one of insertGcl) {
  488. // if (one.leafXmjs && one.leafXmjs.length > 0) {
  489. // for (const xmj of one.leafXmjs) {
  490. // const is_self = _.findIndex(selfList, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: xmj.mx_id ? xmj.mx_id : null }) !== -1;// 区分单独计量的明细工料含量
  491. // if (is_self) {
  492. // const billsList = _.filter(materialListForSelf, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: xmj.mx_id ? xmj.mx_id : null });
  493. // for (const bill of billsList) {
  494. // hadQtySelfList.push(bill);
  495. // insertSelfList.push({
  496. // gcl_id: xmj.gcl_id,
  497. // mx_id: xmj.mx_id ? xmj.mx_id : '',
  498. // xmj_id: xmj.id ? xmj.id : null,
  499. // contract_qty: xmj.contract_qty,
  500. // qc_qty: xmj.qc_qty,
  501. // qc_minus_qty: xmj.qc_minus_qty,
  502. // gather_qty: xmj.gather_qty,
  503. // quantity: bill.quantity,
  504. // expr: bill.expr,
  505. // mb_id: bill.mb_id,
  506. // order: bill.order,
  507. // });
  508. // }
  509. // } else {
  510. // const newgcl = _.find(gclList, { gcl_id: xmj.gcl_id });
  511. // for (const bill of one.bills) {
  512. // insertList.push({
  513. // gcl_id: xmj.gcl_id,
  514. // mx_id: xmj.mx_id ? xmj.mx_id : '',
  515. // xmj_id: xmj.id ? xmj.id : null,
  516. // contract_qty: xmj.contract_qty,
  517. // qc_qty: xmj.qc_qty,
  518. // qc_minus_qty: xmj.qc_minus_qty,
  519. // gather_qty: xmj.gather_qty,
  520. // quantity: bill.quantity,
  521. // expr: bill.expr,
  522. // mb_id: bill.mb_id,
  523. // order: bill.order,
  524. // });
  525. // if (!newgcl) {
  526. // insertGclList.push({
  527. // gcl_id: xmj.gcl_id,
  528. // quantity: bill.quantity,
  529. // expr: bill.expr,
  530. // old_quantity: bill.quantity,
  531. // old_expr: bill.expr,
  532. // mb_id: bill.mb_id,
  533. // order: bill.order,
  534. // });
  535. // }
  536. // }
  537. // }
  538. // }
  539. // }
  540. // }
  541. // }
  542. // // 通过比较materialListForSelf和hadQtySelfList不重合部分,得出本期为null的gather_qty列表,插入到insertSelfList中
  543. // const pushSelfList = _.xorWith(materialListForSelf, hadQtySelfList, _.isEqual);
  544. // if (pushSelfList.length > 0) {
  545. // for (const ps of pushSelfList) {
  546. // insertSelfList.push({
  547. // gcl_id: ps.gcl_id,
  548. // mx_id: ps.mx_id,
  549. // xmj_id: ps.xmj_id,
  550. // contract_qty: null,
  551. // qc_qty: null,
  552. // qc_minus_qty: null,
  553. // gather_qty: null,
  554. // quantity: ps.quantity,
  555. // expr: ps.expr,
  556. // mb_id: ps.mb_id,
  557. // order: ps.order,
  558. // });
  559. // }
  560. // }
  561. // // 可能需要新增list_gcl表
  562. // newMaterialData.material_list = insertList;
  563. // newMaterialData.material_self_list = insertSelfList;
  564. // newMaterialData.insertGclList = insertGclList;
  565. // newMaterialData.removeGclList = removeGclList;
  566. // console.log(newMaterialData);
  567. // console.log(insertSelfList);
  568. // postData(preUrl + '/measure/material/add', newMaterialData, function (result) {
  569. // window.location.href = preUrl + '/measure/material/' + result.order;
  570. // }, function () {
  571. // stop = true;
  572. // clearInterval(interval);
  573. // console.log(_self.parents('div[id="add-qi"]'));
  574. // $('#add-qi').modal('show');
  575. // $('#okedit').modal('hide');
  576. // _self.parents('div[id="add-qi"]').modal('show');
  577. // _self.attr('disabled', false).text('确认添加');
  578. // });
  579. // return;
  580. // });
  581. // $(this).parents('form').submit();
  582. });
  583. let value = 0;
  584. function progress(){
  585. if (stop) {
  586. setTimeout(function () {
  587. $('#add-qi').modal('show');
  588. $('#okedit').modal('hide');
  589. value = 0;
  590. clearInterval(interval);
  591. }, 500);
  592. }
  593. if (value < 100) {
  594. value = parseInt(value) + 1;
  595. $("#material-progress").css("width", value + "%").text(value + "%");
  596. } else if (value === 100) {
  597. value = parseInt(value) + 1;
  598. value = 30;
  599. }
  600. };
  601. let editPeriod = null;
  602. $('.edit-material').on('click', function () {
  603. const order = parseInt($(this).data('order'));
  604. const mid = parseInt($(this).data('mid'));
  605. $('#edit-period').val('');
  606. $('#edit-name').val('第 ' + order + ' 期');
  607. $('#edit-mid').val(mid);
  608. const m_period = $(this).data('period');
  609. const period = [];
  610. for (const p of m_period.split('~')) {
  611. if (p && p !== '') {
  612. period.push(new Date(p));
  613. }
  614. }
  615. $('#edit-period').val(m_period);
  616. editPeriod = !editPeriod ? $('#edit-period').datepicker().data('datepicker') : editPeriod;
  617. editPeriod.clear();
  618. if (period.length > 0) {
  619. editPeriod.selectDate(period);
  620. }
  621. });
  622. $('#row-view').on('show.bs.modal', function () {
  623. let html = '';
  624. for (const col of materialColShow) {
  625. html += `<tr><td>${col.name}</td><td><input type="checkbox" value="${col.value}" ${col.checked ? 'checked=""' : ''}></td></tr>`;
  626. }
  627. $('#material_col_table').html(html);
  628. });
  629. $('#set_material_list_show_btn').on('click', function () {
  630. // 至少展示一个
  631. const material_col_data = [];
  632. $('#material_col_table input').each(function () {
  633. material_col_data.push({
  634. name: $(this).parents('tr').children('td').eq(0).text(),
  635. value: $(this).val(),
  636. checked: $(this).is(':checked'),
  637. });
  638. });
  639. postData('/tender/' + tenderId + '/measure/material/save/data', { type: 'material_col_set', material_col_data }, function (result) {
  640. window.location.reload();
  641. });
  642. });
  643. });
  644. function checkForm () {
  645. if ($('#edit-period').val() == '') {
  646. toastr.error('请选择调差周期');
  647. return false;
  648. }
  649. // const date = $('#edit-date').val();
  650. // const period = $('#edit-period').val();
  651. // const startDate = period.split('~')[0];
  652. // const endDate = period.split('~')[1];
  653. // if (startDate.indexOf(date) === -1 && endDate.indexOf(date) === -1) {
  654. // toastr.error('所选日期与当前月份不匹配,请重新选择');
  655. // $('#edit-period').parents('.form-group').find('.text-danger').remove();
  656. // $('#edit-period').parents('.form-group').append('<small class="text-danger">所选日期与当前月份不匹配,请重新选择</small>');
  657. // return false;
  658. // }
  659. };