measure_material.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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. // 计量期选中
  195. $('.select-stage-order').on('click', function () {
  196. const stageList = $('.select-stage-order:checked');
  197. if (stageList.length === 0) {
  198. $('#show_order').hide();
  199. $('#s_order').val('');
  200. } else {
  201. const order_array = [];
  202. for (let s = 0; s < stageList.length; s++) {
  203. order_array.push(stageList.eq(s).data('order'));
  204. // console.log(stageList.eq(s));
  205. }
  206. $('#show_order').html('第<b class="mx-2">' + order_array.join(',') + '</b>期');
  207. $('#show_order').show();
  208. $('#s_order').val(order_array.join(','));
  209. if (stageList.length > 1) {
  210. if($('#material_unitPrice').is(':hidden')){
  211. $('#unitPrice_dl').prop('checked', true);
  212. }
  213. $('#material_unitPrice').show();
  214. } else {
  215. $('#material_unitPrice').hide();
  216. $('#unitPrice_gy').prop('checked', true);
  217. }
  218. }
  219. });
  220. let interval;
  221. let stop = false;
  222. // 提交表单判断
  223. $('#addMaterial').click(function () {
  224. $(this).attr('disabled', true);
  225. if ($('#s_order').val() == '') {
  226. toastr.error('请选择计量期');
  227. $(this).removeAttr('disabled');
  228. return false;
  229. }
  230. $(this).text('正在生成新一期数据中,请勿刷新本页!...');
  231. const _self = $(this);
  232. const stage_id = [];
  233. $('#add-qi input[name="stage_id[]"]:checked').each(function () {
  234. stage_id.push(parseInt($(this).val()));
  235. });
  236. const is_stage_self = parseInt($('input[name="is_stage_self"]:checked').val());
  237. const newMaterialData = {
  238. s_order: $('#s_order').val(),
  239. period: $('#add-qi input[name="period"]').val(),
  240. stage_id,
  241. is_stage_self,
  242. qty_source: parseInt($('#add-qi input[name="qty_source"]:checked').val()),
  243. };
  244. if (lastMaterialListNum === 0) {
  245. console.log(newMaterialData);
  246. postData(preUrl + '/measure/material/add', newMaterialData, function (result) {
  247. window.location.href = preUrl + '/measure/material/' + result.order;
  248. }, function () {
  249. _self.attr('disabled', false).text('确认添加');
  250. });
  251. return;
  252. }
  253. $('#add-qi').modal('hide');
  254. $('#okedit').modal('show');
  255. interval = setInterval(progress, 50);
  256. postData(preUrl + '/measure/material/gcl/load', { stage_id, is_stage_self }, function (result) {
  257. // console.log(result);
  258. const ledger = result.ledger;
  259. const pos = result.pos;
  260. const gclList = result.gclList;
  261. const selfList = result.selfList;
  262. // 整理material,针对上期是独立单价并多个不同值的单独设置值进行部分值去除
  263. const materialListForSelf = _.uniqWith(_.orderBy(result.materialListForSelf, ['ms_id'], ['desc']), function(item1, item2) {
  264. 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;
  265. });
  266. console.log(materialListForSelf, result.materialListForSelf);
  267. const insertGclList = [];
  268. const insertList = [];
  269. const insertSelfList = [];// 需要单独添加的明细清单工料含量列表
  270. const removeGclList = [];
  271. const hadQtySelfList = [];
  272. if (is_stage_self) {
  273. for (const sid of stage_id) {
  274. const curLedger = _.find(result.curLedgerData, {sid: sid});
  275. const curPos = _.find(result.curPosData, {sid: sid});
  276. gclGatherModel.loadLedgerData(_.cloneDeep(ledger), curLedger.ledgerData);
  277. gclGatherModel.loadPosData(_.cloneDeep(pos), curPos.posData);
  278. const gclGatherData = gclGatherModel.gatherGclData();
  279. // console.log(gclGatherData);
  280. const insertGcl = [];
  281. for (const g of gclList) {
  282. const gcl = _.find(gclGatherData, function (item) {
  283. return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, {gcl_id: g.gcl_id}) !== -1;
  284. });
  285. if (gcl) {
  286. const ig = _.find(insertGcl, {gcl});
  287. if (ig) {
  288. if (_.findIndex(ig.bills, {mb_id: g.mb_id}) === -1) {
  289. ig.bills.push(g);
  290. }
  291. } else {
  292. insertGcl.push({
  293. bills: [g],
  294. gcl,
  295. leafXmjs: _.filter(gcl.leafXmjs, function (item) {
  296. return item.gather_qty !== undefined && item.gather_qty !== null
  297. }),
  298. })
  299. }
  300. } else {
  301. removeGclList.push(g);
  302. }
  303. }
  304. for (const one of insertGcl) {
  305. if (one.leafXmjs && one.leafXmjs.length > 0) {
  306. for (const xmj of one.leafXmjs) {
  307. const is_self = _.findIndex(selfList, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: xmj.mx_id ? xmj.mx_id : '' }) !== -1;// 区分单独计量的明细工料含量
  308. if (is_self) {
  309. const billsList = _.filter(materialListForSelf, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: xmj.mx_id ? xmj.mx_id : '' });
  310. for (const bill of billsList) {
  311. if (!_.find(hadQtySelfList, bill)) {
  312. hadQtySelfList.push(bill);
  313. }
  314. insertSelfList.push({
  315. gcl_id: xmj.gcl_id,
  316. mx_id: xmj.mx_id ? xmj.mx_id : '',
  317. xmj_id: xmj.id ? xmj.id : null,
  318. contract_qty: xmj.contract_qty,
  319. qc_qty: xmj.qc_qty,
  320. qc_minus_qty: xmj.qc_minus_qty,
  321. gather_qty: xmj.gather_qty,
  322. quantity: bill.quantity,
  323. expr: bill.expr,
  324. mb_id: bill.mb_id,
  325. order: bill.order,
  326. sid,
  327. });
  328. }
  329. } else {
  330. const newgcl = _.find(gclList, { gcl_id: xmj.gcl_id });
  331. for (const bill of one.bills) {
  332. insertList.push({
  333. gcl_id: xmj.gcl_id,
  334. mx_id: xmj.mx_id ? xmj.mx_id : '',
  335. xmj_id: xmj.id ? xmj.id : null,
  336. contract_qty: xmj.contract_qty,
  337. qc_qty: xmj.qc_qty,
  338. qc_minus_qty: xmj.qc_minus_qty,
  339. gather_qty: xmj.gather_qty,
  340. quantity: bill.quantity,
  341. expr: bill.expr,
  342. mb_id: bill.mb_id,
  343. order: bill.order,
  344. sid,
  345. });
  346. if (!newgcl) {
  347. if (_.findIndex(insertGclList, { gcl_id: xmj.gcl_id }) === -1) {
  348. insertGclList.push({
  349. gcl_id: xmj.gcl_id,
  350. quantity: bill.quantity,
  351. expr: bill.expr,
  352. old_quantity: bill.quantity,
  353. old_expr: bill.expr,
  354. mb_id: bill.mb_id,
  355. order: bill.order,
  356. });
  357. }
  358. }
  359. }
  360. }
  361. }
  362. }
  363. }
  364. }
  365. } else {
  366. const curLedgerData = result.curLedgerData;
  367. const curPosData = result.curPosData;
  368. gclGatherModel.loadLedgerData(_.cloneDeep(ledger), curLedgerData);
  369. gclGatherModel.loadPosData(_.cloneDeep(pos), curPosData);
  370. const gclGatherData = gclGatherModel.gatherGclData();
  371. const insertGcl = [];
  372. for (const g of gclList) {
  373. const gcl = _.find(gclGatherData, function (item) {
  374. return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, {gcl_id: g.gcl_id}) !== -1;
  375. });
  376. if (gcl) {
  377. const ig = _.find(insertGcl, {gcl});
  378. if (ig) {
  379. if (_.findIndex(ig.bills, {mb_id: g.mb_id}) === -1) {
  380. ig.bills.push(g);
  381. }
  382. } else {
  383. insertGcl.push({
  384. bills: [g],
  385. gcl,
  386. leafXmjs: _.filter(gcl.leafXmjs, function (item) {
  387. return item.gather_qty !== undefined && item.gather_qty !== null || (item.qc_minus_qty !== undefined && item.qc_minus_qty !== null)
  388. }),
  389. })
  390. }
  391. } else {
  392. removeGclList.push(g);
  393. }
  394. }
  395. for (const one of insertGcl) {
  396. if (one.leafXmjs && one.leafXmjs.length > 0) {
  397. for (const xmj of one.leafXmjs) {
  398. const is_self = _.findIndex(selfList, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: xmj.mx_id ? xmj.mx_id : null }) !== -1;// 区分单独计量的明细工料含量
  399. if (is_self) {
  400. const billsList = _.filter(materialListForSelf, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: xmj.mx_id ? xmj.mx_id : null });
  401. for (const bill of billsList) {
  402. hadQtySelfList.push(bill);
  403. insertSelfList.push({
  404. gcl_id: xmj.gcl_id,
  405. mx_id: xmj.mx_id ? xmj.mx_id : '',
  406. xmj_id: xmj.id ? xmj.id : null,
  407. contract_qty: xmj.contract_qty,
  408. qc_qty: xmj.qc_qty,
  409. qc_minus_qty: xmj.qc_minus_qty,
  410. gather_qty: xmj.gather_qty,
  411. quantity: bill.quantity,
  412. expr: bill.expr,
  413. mb_id: bill.mb_id,
  414. order: bill.order,
  415. });
  416. }
  417. } else {
  418. const newgcl = _.find(gclList, { gcl_id: xmj.gcl_id });
  419. for (const bill of one.bills) {
  420. insertList.push({
  421. gcl_id: xmj.gcl_id,
  422. mx_id: xmj.mx_id ? xmj.mx_id : '',
  423. xmj_id: xmj.id ? xmj.id : null,
  424. contract_qty: xmj.contract_qty,
  425. qc_qty: xmj.qc_qty,
  426. qc_minus_qty: xmj.qc_minus_qty,
  427. gather_qty: xmj.gather_qty,
  428. quantity: bill.quantity,
  429. expr: bill.expr,
  430. mb_id: bill.mb_id,
  431. order: bill.order,
  432. });
  433. if (!newgcl) {
  434. insertGclList.push({
  435. gcl_id: xmj.gcl_id,
  436. quantity: bill.quantity,
  437. expr: bill.expr,
  438. old_quantity: bill.quantity,
  439. old_expr: bill.expr,
  440. mb_id: bill.mb_id,
  441. order: bill.order,
  442. });
  443. }
  444. }
  445. }
  446. }
  447. }
  448. }
  449. }
  450. // 通过比较materialListForSelf和hadQtySelfList不重合部分,得出本期为null的gather_qty列表,插入到insertSelfList中
  451. const pushSelfList = _.xorWith(materialListForSelf, hadQtySelfList, _.isEqual);
  452. if (pushSelfList.length > 0) {
  453. for (const ps of pushSelfList) {
  454. insertSelfList.push({
  455. gcl_id: ps.gcl_id,
  456. mx_id: ps.mx_id,
  457. xmj_id: ps.xmj_id,
  458. contract_qty: null,
  459. qc_qty: null,
  460. qc_minus_qty: null,
  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. $('#row-view').on('show.bs.modal', function () {
  531. let html = '';
  532. for (const col of materialColShow) {
  533. html += `<tr><td>${col.name}</td><td><input type="checkbox" value="${col.value}" ${col.checked ? 'checked=""' : ''}></td></tr>`;
  534. }
  535. $('#material_col_table').html(html);
  536. });
  537. $('#set_material_list_show_btn').on('click', function () {
  538. // 至少展示一个
  539. const material_col_data = [];
  540. $('#material_col_table input').each(function () {
  541. material_col_data.push({
  542. name: $(this).parents('tr').children('td').eq(0).text(),
  543. value: $(this).val(),
  544. checked: $(this).is(':checked'),
  545. });
  546. });
  547. postData('/tender/' + tenderId + '/measure/material/save/data', { type: 'material_col_set', material_col_data }, function (result) {
  548. window.location.reload();
  549. });
  550. });
  551. });
  552. function checkForm () {
  553. if ($('#edit-period').val() == '') {
  554. toastr.error('请选择调差周期');
  555. return false;
  556. }
  557. // const date = $('#edit-date').val();
  558. // const period = $('#edit-period').val();
  559. // const startDate = period.split('~')[0];
  560. // const endDate = period.split('~')[1];
  561. // if (startDate.indexOf(date) === -1 && endDate.indexOf(date) === -1) {
  562. // toastr.error('所选日期与当前月份不匹配,请重新选择');
  563. // $('#edit-period').parents('.form-group').find('.text-danger').remove();
  564. // $('#edit-period').parents('.form-group').append('<small class="text-danger">所选日期与当前月份不匹配,请重新选择</small>');
  565. // return false;
  566. // }
  567. };