/** * crm 新建/编辑通用逻辑 * @author yxk */ import { QueryField, CheckOnlyField } from 'API/base' import { PreviewFiledName } from 'API/examine' import { QueryBusinessSetting } from 'API/crm/flow' import formMixins from '@/mixins/formMixins.js' import { deepCopy } from '@/utils/lib.js' import { isArray, isObject } from '@/utils/types.js' // import invoiceField from '../invoiceField.js' import { crmEnum } from '../enum.js' export default { mixins: [formMixins], data() { return { id: null, batchId: null, guid: null, routerQuery: {}, fieldArr: [], showAudit: false, auditUser: null, authInfo: {}, auditConditionFields: [], loading: false, timer: null } }, computed: { typeObj() { return crmEnum[this.moduleType] || {} }, navTitle() { const action = this.routerQuery.id ? '编辑' : '新建' return action + this.typeObj.label || '' } }, onLoad(options) { this.routerQuery = options || {} this.id = options.id this.batchId = options.batchId this.guid = this.$guid() }, onUnload() { getApp().globalData.formBridge = {} }, methods: { /** * 根据权限判断字段是否可编辑 * @param {Object} field */ getDisabledStatusByAuth(field) { const crmType = this.moduleType if (crmType === 'business' && ['business_type', 'business_status'].includes(field.formType)) return false if (crmType === 'contract' && ['business', 'contacts', 'customer'].includes(field.formType)) return false if (crmType === 'receivables' && ['contract', 'customer'].includes(field.formType)) return false if (crmType === 'visit' && ['business', 'contacts', 'customer'].includes(field.formType)) return false if (crmType === 'invoice' && ['contractId', 'contractMoney'].includes(field.fieldName)) return true // 1 不能查看不能编辑 2 可查看 3 可查看可编辑 return field.authLevel !== 3 // false 可编辑 }, setForm() { const bridge = getApp().globalData.formBridge // console.log('setForm bridge: ', bridge) if (!bridge.default) return this.$nextTick(() => { this.$refs.form.setForm(bridge.default || {}) Object.keys(bridge.default).forEach(key => { this.$refs.form.setDisabled(key, true) this.$refs.form.setConfig(key, { disabledMsg: '' }) }) }) // #ifdef APP-PLUS // App 偶发会出现字段渲染不上的问题,在此强制刷新页面 this.$nextTick(() => { if (!this.$isEmpty(bridge.default)) { this.$refs.form.updateView() } }) // #endif }, /** * 获取审批流程条件 */ getAuditList() { const label = { contract: 1, receivables: 2, invoice: 3 }[this.routerQuery.type] || '' PreviewFiledName({ label }) .then(res => { this.showAudit = res !== null if (!this.showAudit) return const mapIns = new Map() this.auditConditionFields = res.filter(o => !mapIns.has(o.fieldId) && mapIns.set(o.fieldId, 1)) console.log('PreviewFiledName: ', this.auditConditionFields) this.$nextTick(() => { const dataMap = {} const bridge = getApp().globalData.formBridge || {} this.auditConditionFields.forEach(o => { const findRes = this.fieldArr.find(f => f.fieldName === o.fieldName) if (findRes) { let value = null if (bridge.default && bridge.default.hasOwnProperty(o.fieldName)) { value = bridge.default[o.fieldName] } else { value = findRes.value } switch (findRes.formType) { case 'select': if (this.$isEmpty(value)) value = '' if (isArray(value)) { value = value[0].value } break case 'checkbox': if (this.$isEmpty(value)) value = '' if (isArray(value)) { value = value.map(o => o.value).join(',') } break default: value = this.$isEmpty(value) ? '' : value } o._val = value dataMap[o.fieldName] = value } }) this.$refs.wkAuditAdd.getAuditInfo({ label, dataMap }) }) }) .catch(() => {}) }, /** * 根据审批条件变更审批流 */ changeAuditFlow(field, value) { if (!this.showAudit) return if (![ 'contract', 'receivables', 'invoice' ].includes(this.moduleType)) return const findRes = this.auditConditionFields.find(o => o.fieldName === field.fieldName) if (!findRes) return if (this.timer) { clearTimeout(this.timer) this.timer = null } this.timer = setTimeout(() => { // number floatnumber select checkbox switch (field.formType) { case 'select': if (this.$isEmpty(value)) value = '' if (isArray(value)) { value = value[0].value } break case 'checkbox': if (this.$isEmpty(value)) value = '' if (isArray(value)) { value = value.map(o => o.value).join(',') } break default: value = this.$isEmpty(value) ? '' : value } findRes._val = value const dataMap = {} this.auditConditionFields.forEach(o => { if (o.hasOwnProperty('_val')) { dataMap[o.fieldName] = this.$isEmpty(o._val) ? '' : o._val } else { dataMap[o.fieldName] = '' } }) this.$nextTick(() => { const label = { contract: 1, receivables: 2, invoice: 3 }[this.routerQuery.type] || '' this.$refs.wkAuditAdd.getAuditInfo({ label, dataMap }) clearTimeout(this.timer) this.timer = null }) }, 500) }, /** * 获取保存的审批数据 * @param {Object} form */ baseGetAuditSaveData(form) { // 审批信息 if (this.showAudit) { const data = this.$refs.wkAuditAdd.getSaveData() if (data === null) { this.loading = false return } const dataMap = {} this.auditConditionFields.forEach(o => { if (o.hasOwnProperty('_val')) { dataMap[o.fieldName] = this.$isEmpty(o._val) ? '' : o._val } }) const label = { contract: 1, receivables: 2, invoice: 3 }[this.routerQuery.type] || '' form.examineFlowData = { ...data, label, dataMap } } }, /** * 保存前处理数据 * @param {Object} form */ baseFormatSaveData(form) { if (this.id && this.batchId) { form.entity[this.typeObj.primaryKey] = this.id form.entity.batchId = this.batchId } if (!form.hasOwnProperty('field')) { form.field = [] } const bridge = getApp().globalData.formBridge || {} if (bridge.assignForm) { form = Object.assign(form, bridge.assignForm) } const arr = form.field .filter(o => o.formType !== 'desc_text') .map(o => { return { fieldName: o.fieldName, name: o.name, type: o.type, fieldId: o.fieldId, value: o.value, fieldType: o.fieldType } }) form.field = arr } } }