rpt_change_rela.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. const rptChangeRela = (function (){
  2. const info = {
  3. change: { title: '请选择变更令', colHeader: ['选择', '变更令号', '工程名称'] },
  4. change_project: { title: '请选择变更立项', colHeader: ['选择', '变更立项编号', '工程名称'] },
  5. change_apply: { title: '请选择变更申请', colHeader: ['选择', '变更申请编号', '工程名称'] },
  6. };
  7. const data = {};
  8. let curType = '';
  9. const initList = function () {
  10. const header = info[curType].colHeader;
  11. $('#scr-header').html(`<tr class="text-center"><th>${header[0]}</th><th>${header[1]}</th><th>${header[2]}</th></tr>`);
  12. const html = [], arr = data[curType];
  13. for (const a of arr) {
  14. const checked = a.selected ? 'checked' : '';
  15. html.push('<tr>', `<td class="text-center"><input type="checkbox" name="scr-check" ${checked} value="${a.cid || a.id}"></td>`, `<td>${a.code}</td>`, `<td>${a.name}</td>`, '</tr>');
  16. }
  17. $('#scr-list').html(html.join(''));
  18. };
  19. const showChangeRela = async function (type) {
  20. curType = type;
  21. document.getElementById('scr-title').innerText = info[type].title;
  22. if (!data[type]) {
  23. const result = await postDataAsync(`/tender/${window.location.pathname.split('/')[2]}/load`, { filter: curType });
  24. data[curType] = result[curType];
  25. }
  26. initList();
  27. $('#select-change-rela').modal('show');
  28. $('#scr-all').change(function () {
  29. const check = this.checked;
  30. $('[name=scr-check]').each((i, c) => { c.checked = check });
  31. })
  32. };
  33. const updateChangeRela = async function () {
  34. const updateData = {};
  35. updateData[curType] = [];
  36. if (curType === 'change') {
  37. $('[name=scr-check]').each((i, c) => {
  38. const ci = data[curType].find(x => { return x.cid === c.value });
  39. const checked = c.checked ? 1 : 0;
  40. if (ci && ci.selected !== checked) {
  41. updateData[curType].push({ cid: c.value, selected: c.checked });
  42. }
  43. });
  44. } else {
  45. $('[name=scr-check]').each((i, c) => {
  46. const ci = data[curType].find(x => { return x.id == c.value });
  47. const checked = c.checked ? 1 : 0;
  48. if (ci && ci.selected !== checked) {
  49. updateData[curType].push({id: c.value, selected: c.checked})
  50. }
  51. });
  52. }
  53. if (updateData[curType].length > 0) {
  54. await postData(`/tender/${window.location.pathname.split('/')[2]}/saveRela`, updateData);
  55. if (curType === 'change') {
  56. $('[name=scr-check]').each((i, c) => {
  57. const ci = data[curType].find(x => {
  58. return x.cid === c.value
  59. });
  60. if (ci) ci.selected = c.checked ? 1 : 0;
  61. });
  62. } else {
  63. $('[name=scr-check]').each((i, c) => {
  64. const ci = data[curType].find(x => {
  65. return x.id == c.value
  66. });
  67. if (ci) ci.selected = c.checked ? 1 : 0;
  68. });
  69. }
  70. }
  71. $('#select-change-rela').modal('hide');
  72. };
  73. return { showChangeRela, updateChangeRela }
  74. })();