| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- 'use strict';
- const tenderApprovalEditor = {
- data: null,
- active: null,
- saving: false,
- loading: false,
- saved: false,
- init() {
- const self = this;
- $('body').on('click', '.approval-edit', function () { self.open($(this).attr('data-code')); });
- $('body').on('click', '.approval-copy', function () {
- const code = $(this).attr('data-code'), kind = $(this).attr('data-kind');
- $('#approval-card-store .' + code + '_div .' + kind).trigger('click');
- });
- $('#approval-save').on('click', function () { self.save(); });
- $('#approval-editor').on('hide.bs.modal', function (event) {
- if (self.saving || (self.active && self.active.operations.length && !self.saved && !window.confirm('有未保存的修改,确定放弃并关闭吗?'))) event.preventDefault();
- }).on('hidden.bs.modal', function () {
- const saved = self.saved, tid = self.active ? self.active.tid : cur_tenderid;
- self.active = null; self.saved = false;
- $('#approval-edit-body').empty();
- if (self.data) self.setData(self.data);
- if (saved) loadTenderApproval(tid);
- });
- const children = $('#batch, #batch2, #cooperation, #union, #multi, #spzsave, #spzdelete');
- children.on('show.bs.modal', function () {
- if ($('#approval-editor').hasClass('show')) $(this).addClass('approval-child-modal');
- }).on('shown.bs.modal', function () {
- if ($(this).hasClass('approval-child-modal')) $('.modal-backdrop').last().addClass('approval-child-backdrop');
- }).on('hidden.bs.modal', function () {
- $(this).removeClass('approval-child-modal');
- if ($('#approval-editor').hasClass('show')) $('body').addClass('modal-open');
- });
- },
- setData(data) {
- this.data = data;
- sp_lc = _.cloneDeep(data.shenpi.sp_lc);
- this.render();
- renderTenderApproval(Object.assign({}, data.shenpi, { sp_lc }), data.tender, data.revising, '#approval-card-store');
- },
- summary(flow) {
- if (flow.status === 1) return '';
- if (flow.status === 3) return flow.audit ? flow.audit.name : '未设置';
- const groups = flow.auditGroupList || [];
- const selected = (flow.groupList || []).find(x => x.is_select === 1);
- const text = groups.map(group => {
- const type = group.length && auditType.info[group[0].audit_type];
- return group.map(x => x.name).join('/') + (type && type.value !== 1 ? '(' + type.name + ')' : '');
- }).join('、') || '未设置';
- return (selected ? selected.name + ':' : '') + text;
- },
- render() {
- 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>'];
- for (const flow of this.data.shenpi.sp_lc) {
- 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>');
- html.push('<td class="approval-actions"><a href="javascript:void(0);" class="approval-edit" data-code="', flow.code, '">编辑</a> ');
- 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">');
- for (const item of [{ kind: 'set-otherShenpi', name: '设置其他流程' }, { kind: 'set-otherTender', name: '设置其他标段' }]) {
- html.push('<a class="dropdown-item approval-copy" href="javascript:void(0);" data-code="', flow.code, '" data-kind="', item.kind, '">', item.name, '</a>');
- }
- html.push('</div></div></td></tr>');
- }
- html.push('</tbody></table>');
- $('#splc').html(html.join(''));
- },
- open(code) {
- if (this.loading || this.active || !this.data) return;
- const self = this, tid = cur_tenderid;
- self.loading = true;
- postData(`/sp/${spid}/setting/manage/tender/save`, { type: 'approval-draft', tid, code }, function (result) {
- self.loading = false;
- if (tid !== cur_tenderid) return;
- self.active = { tid, code, version: result.version, model: new TenderApprovalDraft(result.snapshot, result.options), operations: [] };
- self.saved = false;
- sp_lc = _.cloneDeep(self.data.shenpi.sp_lc);
- const flow = self.active.model.view();
- sp_lc[sp_lc.findIndex(x => x.code === code)] = flow;
- $('#approval-card-store .' + code + '_div').closest('.card').remove();
- renderTenderApproval(Object.assign({}, self.data.shenpi, { sp_lc: [flow] }), self.data.tender, self.data.revising, '#approval-edit-body');
- $('#approval-editor').modal('show');
- $('body').trigger('tender-approval-edit-open');
- }, function () { self.loading = false; });
- },
- save() {
- if (!this.active || this.saving) return;
- if (!this.active.operations.length) { $('#approval-editor').modal('hide'); return; }
- try { this.active.model.validate(); } catch (error) { toastr.warning(error.message); return; }
- const self = this, draft = self.active;
- self.saving = true;
- $('#approval-save').prop('disabled', true);
- $('#approval-edit-body').addClass('approval-saving');
- postData(`/sp/${spid}/setting/manage/tender/save`, {
- type: 'approval-save', tid: draft.tid, code: draft.code, version: draft.version, operations: draft.operations,
- }, function () {
- self.saving = false; self.saved = true;
- $('#approval-save').prop('disabled', false);
- $('#approval-edit-body').removeClass('approval-saving');
- toastr.success('审批流程已保存');
- $('#approval-editor').modal('hide');
- }, function () {
- self.saving = false;
- $('#approval-save').prop('disabled', false);
- $('#approval-edit-body').removeClass('approval-saving');
- });
- },
- request(url, data, success, failure, waiting, message) {
- const self = this, draft = self.active;
- if (self.saving) { if (failure) failure('正在保存'); return; }
- if (url.endsWith('/ass/load') || url.endsWith('/union/load')) {
- postData(url, data, function (result) {
- if (self.active !== draft) return;
- if (url.endsWith('/ass/load')) result.auditAssList = _.cloneDeep(draft.model.state.assistants);
- else result.unionAuditors = _.cloneDeep(draft.model.activeAudits(2).filter(x => x.audit_order === Number(data.audit_order)));
- if (success) success(result);
- }, failure, waiting, message);
- return;
- }
- if (['copy2ot', 'copy2os'].includes(data.type)) {
- if (draft.operations.length) { toastr.warning('请先保存当前修改,再设置其他流程或标段'); return; }
- return postData(url, data, success, failure, waiting, message);
- }
- const kind = url.endsWith('/shenpi/save') ? 'status' : url.endsWith('/audit/save') ? 'audit' : url.endsWith('/multi/save') ? 'multi' : url.endsWith('/union/save') ? 'union' : '';
- try {
- const operation = { kind, data: _.cloneDeep(data) };
- const result = draft.model.apply(operation);
- draft.operations.push(operation);
- if (success) success(result);
- // Existing callbacks update the controls; keep every group's cached view in sync with the draft.
- const index = sp_lc.findIndex(x => x.code === draft.code);
- sp_lc[index] = draft.model.view();
- } catch (error) {
- toastr.warning(error.message || String(error));
- if (failure) failure(error.message);
- }
- },
- };
|