setting_approval.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. 'use strict';
  2. const tenderApprovalEditor = {
  3. data: null,
  4. active: null,
  5. saving: false,
  6. loading: false,
  7. saved: false,
  8. init() {
  9. const self = this;
  10. $('body').on('click', '.approval-edit', function () { self.open($(this).attr('data-code')); });
  11. $('body').on('click', '.approval-copy', function () {
  12. const code = $(this).attr('data-code'), kind = $(this).attr('data-kind');
  13. $('#approval-card-store .' + code + '_div .' + kind).trigger('click');
  14. });
  15. $('#approval-save').on('click', function () { self.save(); });
  16. $('#approval-editor').on('hide.bs.modal', function (event) {
  17. if (self.saving || (self.active && self.active.operations.length && !self.saved && !window.confirm('有未保存的修改,确定放弃并关闭吗?'))) event.preventDefault();
  18. }).on('hidden.bs.modal', function () {
  19. const saved = self.saved, tid = self.active ? self.active.tid : cur_tenderid;
  20. self.active = null; self.saved = false;
  21. $('#approval-edit-body').empty();
  22. if (self.data) self.setData(self.data);
  23. if (saved) loadTenderApproval(tid);
  24. });
  25. const children = $('#batch, #batch2, #cooperation, #union, #multi, #spzsave, #spzdelete');
  26. children.on('show.bs.modal', function () {
  27. if ($('#approval-editor').hasClass('show')) $(this).addClass('approval-child-modal');
  28. }).on('shown.bs.modal', function () {
  29. if ($(this).hasClass('approval-child-modal')) $('.modal-backdrop').last().addClass('approval-child-backdrop');
  30. }).on('hidden.bs.modal', function () {
  31. $(this).removeClass('approval-child-modal');
  32. if ($('#approval-editor').hasClass('show')) $('body').addClass('modal-open');
  33. });
  34. },
  35. setData(data) {
  36. this.data = data;
  37. sp_lc = _.cloneDeep(data.shenpi.sp_lc);
  38. this.render();
  39. renderTenderApproval(Object.assign({}, data.shenpi, { sp_lc }), data.tender, data.revising, '#approval-card-store');
  40. },
  41. summary(flow) {
  42. if (flow.status === 1) return '';
  43. if (flow.status === 3) return flow.audit ? flow.audit.name : '未设置';
  44. const groups = flow.auditGroupList || [];
  45. const selected = (flow.groupList || []).find(x => x.is_select === 1);
  46. const text = groups.map(group => {
  47. const type = group.length && auditType.info[group[0].audit_type];
  48. return group.map(x => x.name).join('/') + (type && type.value !== 1 ? '(' + type.name + ')' : '');
  49. }).join('、') || '未设置';
  50. return (selected ? selected.name + ':' : '') + text;
  51. },
  52. render() {
  53. const html = ['<table class="table table-bordered table-sm approval-summary-table"><thead><tr><th class="approval-column-name">栏目</th><th>审批流程</th><th class="approval-column-actions">操作</th></tr></thead><tbody>'];
  54. for (const flow of this.data.shenpi.sp_lc) {
  55. html.push('<tr><td>', _.escape(flow.name), '</td><td><span class="badge badge-light approval-mode">', _.escape(sp_status_list[flow.status].name), '</span> ', _.escape(this.summary(flow)), '</td>');
  56. html.push('<td class="approval-actions"><a href="javascript:void(0);" class="approval-edit" data-code="', flow.code, '">编辑</a> ');
  57. html.push('<div class="dropdown d-inline-block ml-2"><a href="javascript:void(0);" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">更多</a><div class="dropdown-menu dropdown-menu-right">');
  58. for (const item of [{ kind: 'set-otherShenpi', name: '设置其他流程' }, { kind: 'set-otherTender', name: '设置其他标段' }]) {
  59. html.push('<a class="dropdown-item approval-copy" href="javascript:void(0);" data-code="', flow.code, '" data-kind="', item.kind, '">', item.name, '</a>');
  60. }
  61. html.push('</div></div></td></tr>');
  62. }
  63. html.push('</tbody></table>');
  64. $('#splc').html(html.join(''));
  65. },
  66. open(code) {
  67. if (this.loading || this.active || !this.data) return;
  68. const self = this, tid = cur_tenderid;
  69. self.loading = true;
  70. postData(`/sp/${spid}/setting/manage/tender/save`, { type: 'approval-draft', tid, code }, function (result) {
  71. self.loading = false;
  72. if (tid !== cur_tenderid) return;
  73. self.active = { tid, code, version: result.version, model: new TenderApprovalDraft(result.snapshot, result.options), operations: [] };
  74. self.saved = false;
  75. sp_lc = _.cloneDeep(self.data.shenpi.sp_lc);
  76. const flow = self.active.model.view();
  77. sp_lc[sp_lc.findIndex(x => x.code === code)] = flow;
  78. $('#approval-card-store .' + code + '_div').closest('.card').remove();
  79. renderTenderApproval(Object.assign({}, self.data.shenpi, { sp_lc: [flow] }), self.data.tender, self.data.revising, '#approval-edit-body');
  80. $('#approval-editor').modal('show');
  81. $('body').trigger('tender-approval-edit-open');
  82. }, function () { self.loading = false; });
  83. },
  84. save() {
  85. if (!this.active || this.saving) return;
  86. if (!this.active.operations.length) { $('#approval-editor').modal('hide'); return; }
  87. try { this.active.model.validate(); } catch (error) { toastr.warning(error.message); return; }
  88. const self = this, draft = self.active;
  89. self.saving = true;
  90. $('#approval-save').prop('disabled', true);
  91. $('#approval-edit-body').addClass('approval-saving');
  92. postData(`/sp/${spid}/setting/manage/tender/save`, {
  93. type: 'approval-save', tid: draft.tid, code: draft.code, version: draft.version, operations: draft.operations,
  94. }, function () {
  95. self.saving = false; self.saved = true;
  96. $('#approval-save').prop('disabled', false);
  97. $('#approval-edit-body').removeClass('approval-saving');
  98. toastr.success('审批流程已保存');
  99. $('#approval-editor').modal('hide');
  100. }, function () {
  101. self.saving = false;
  102. $('#approval-save').prop('disabled', false);
  103. $('#approval-edit-body').removeClass('approval-saving');
  104. });
  105. },
  106. request(url, data, success, failure, waiting, message) {
  107. const self = this, draft = self.active;
  108. if (self.saving) { if (failure) failure('正在保存'); return; }
  109. if (url.endsWith('/ass/load') || url.endsWith('/union/load')) {
  110. postData(url, data, function (result) {
  111. if (self.active !== draft) return;
  112. if (url.endsWith('/ass/load')) result.auditAssList = _.cloneDeep(draft.model.state.assistants);
  113. else result.unionAuditors = _.cloneDeep(draft.model.activeAudits(2).filter(x => x.audit_order === Number(data.audit_order)));
  114. if (success) success(result);
  115. }, failure, waiting, message);
  116. return;
  117. }
  118. if (['copy2ot', 'copy2os'].includes(data.type)) {
  119. if (draft.operations.length) { toastr.warning('请先保存当前修改,再设置其他流程或标段'); return; }
  120. return postData(url, data, success, failure, waiting, message);
  121. }
  122. const kind = url.endsWith('/shenpi/save') ? 'status' : url.endsWith('/audit/save') ? 'audit' : url.endsWith('/multi/save') ? 'multi' : url.endsWith('/union/save') ? 'union' : '';
  123. try {
  124. const operation = { kind, data: _.cloneDeep(data) };
  125. const result = draft.model.apply(operation);
  126. draft.operations.push(operation);
  127. if (success) success(result);
  128. // Existing callbacks update the controls; keep every group's cached view in sync with the draft.
  129. const index = sp_lc.findIndex(x => x.code === draft.code);
  130. sp_lc[index] = draft.model.view();
  131. } catch (error) {
  132. toastr.warning(error.message || String(error));
  133. if (failure) failure(error.message);
  134. }
  135. },
  136. };