budget_list.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. let curBudget = {};
  10. const budgetNameChange = function (obj) {
  11. if (obj.value.length > 100) {
  12. obj.classList.add('is-invalid');
  13. } else {
  14. obj.classList.remove('is-invalid');
  15. }
  16. };
  17. const addBudget = function () {
  18. const name = $('#add-budget-name').val();
  19. if (!name || name.length > 100) return;
  20. const std_id = parseInt($('[name=std_id]:checked').val());
  21. postData('/budget/add', { name, std_id }, function () {
  22. window.location.reload();
  23. });
  24. };
  25. const showModal = function (obj) {
  26. const tr = obj.parentNode.parentNode;
  27. curBudget.id = tr.getAttribute('bid');
  28. curBudget.name = tr.getAttribute('bname');
  29. curBudget.rela_tender = tr.getAttribute('rela-tender');
  30. $(obj.getAttribute('data-target')).modal('show');
  31. };
  32. const saveBudget = function () {
  33. const name = $('#modify-budget-name').val();
  34. if (!name || name.length > 100) return;
  35. postData('/budget/save', { id: curBudget.id, name}, function () {
  36. window.location.reload();
  37. })
  38. };
  39. const delBudget = function () {
  40. postData('/budget/del', { id: curBudget.id }, function () {
  41. window.location.reload();
  42. });
  43. };
  44. const relaTender = function () {
  45. // todo 选择标段
  46. const rela = [];
  47. const select = $('[name=select-rela-check]:checked');
  48. for (const s of select) {
  49. rela.push(s.getAttribute('tid'));
  50. }
  51. postData('/budget/save', { id: curBudget.id, rela_tender: rela.join(',') }, function () {
  52. $(`[bid=${curBudget.id}]`)[0].setAttribute('brela', rela.join(','));
  53. $('#select-rela').modal('hide');
  54. });
  55. };
  56. $(document).ready(() => {
  57. autoFlashHeight();
  58. $('#del-budget').on('show.bs.modal', () => {
  59. $('#del-budget-name').text(curBudget.name);
  60. });
  61. $('#select-rela').on('show.bs.modal', () => {
  62. $('[name=select-rela-check]').removeAttr('checked');
  63. const rela = curBudget.rela_tender ? curBudget.rela_tender.split(',') : [];
  64. console.log(rela);
  65. for (const r of rela) {
  66. $(`[tid=${r}]`).attr("checked", "checked");
  67. }
  68. });
  69. });