Răsfoiți Sursa

fix:文件类型组件回填值显示逻辑

liujiayin 2 ani în urmă
părinte
comite
c1d2de84b6

+ 18 - 3
src/business/platform/form/formrender/dynamic-form/dynamic-form-item.vue

@@ -209,7 +209,8 @@ export default {
     watch: {
         dataModel: {
             handler (val) {
-                if (FormOptions.t.NON_MODEL_FIELD_TYPES.includes(this.fieldType)) {
+                const noreturnField = ['piLiangGuiDang', 'guiDangLuJingId']
+                if (FormOptions.t.NON_MODEL_FIELD_TYPES.includes(this.fieldType) && (!noreturnField.includes(this.fieldName))) {
                     return
                 }
                 this.handleModels(this.fieldName, val)
@@ -243,11 +244,25 @@ export default {
         }
     },
     methods: {
-        handleModels (name, val) {
+        handleModels (name, val, index, page, pageSize) {
             if (this.$utils.isEmpty(name)) {
                 return
             }
-            this.models[name] = val
+            if (index !== undefined) {
+                // 判断是来自子表的更新
+                for (const key in this.models) {
+                    if (Object.hasOwnProperty.call(this.models, key)) {
+                        const element = this.models[key]
+                        if (Array.isArray(element)) {
+                            this.models[key][(page - 1) * pageSize + index][name] = val
+                            break
+                        }
+                    }
+                }
+            } else {
+                this.models[name] = val
+            }
+            // this.models[name] = val
             this.$emit('update:models', {
                 ...this.models,
                 [name]: val

+ 522 - 517
src/business/platform/form/formrender/dynamic-form/dynamic-form.vue

@@ -1,6 +1,6 @@
 <template>
     <div :class="{ 'jbd-form': !isDialog }">
-        <div class="jbd-replce"></div>
+        <div class="jbd-replce" />
         <div class="dynamic-form" :class="{ 'jbd-form-cont': !isDialog }">
             <!--表头-->
             <div v-if="hasHeader" class="form-header">
@@ -19,7 +19,7 @@
                         :form="form"
                     />
                 </div>
-                <div v-if="hasDesc" class="desc" v-html="$utils.formatText(formDef.desc)"></div>
+                <div v-if="hasDesc" class="desc" v-html="$utils.formatText(formDef.desc)" />
             </div>
             <!--表单-->
             <el-form
@@ -69,585 +69,590 @@
 </template>
 
 <script>
-    import Vue from 'vue'
+import Vue from 'vue'
 
-    import { nestedFieldTypes } from '@/business/platform/form/constants/fieldTypes'
-    import FormOptions from '../../constants/formOptions'
-    import FormUtils from '../../utils/formUtil'
-    import relevanceTable from './mixins/relevanceTable'
-    import StatisOrRecordTable from './mixins/StatisOrRecordTable'
+import { nestedFieldTypes } from '@/business/platform/form/constants/fieldTypes'
+import FormOptions from '../../constants/formOptions'
+import FormUtils from '../../utils/formUtil'
+import relevanceTable from './mixins/relevanceTable'
+import StatisOrRecordTable from './mixins/StatisOrRecordTable'
 
-    import DynamicFormItem from './dynamic-form-item'
-    import DynamicFormField from './dynamic-form-field'
-    import DynamicFormOther from './dynamic-form-other'
-    import DynamicFormOpinion from './components/approval-opinion'
-    import DynamicFormGrid from './dynamic-form-grid'
-    import DynamicFormTabs from './dynamic-form-tabs'
-    import DynamicFormSteps from './dynamic-form-steps'
-    import DynamicFormCollapse from './dynamic-form-collapse'
-    import DynamicFormTable from './dynamic-form-table'
-    import DynamicFormTableItem from './dynamic-form-table-item'
-    import DynamicFormTableBlock from './dynamic-form-table-block'
-    // import templateList from '@/views/platform/data/dataTemplate/template-list.vue'
+import DynamicFormItem from './dynamic-form-item'
+import DynamicFormField from './dynamic-form-field'
+import DynamicFormOther from './dynamic-form-other'
+import DynamicFormOpinion from './components/approval-opinion'
+import DynamicFormGrid from './dynamic-form-grid'
+import DynamicFormTabs from './dynamic-form-tabs'
+import DynamicFormSteps from './dynamic-form-steps'
+import DynamicFormCollapse from './dynamic-form-collapse'
+import DynamicFormTable from './dynamic-form-table'
+import DynamicFormTableItem from './dynamic-form-table-item'
+import DynamicFormTableBlock from './dynamic-form-table-block'
+// import templateList from '@/views/platform/data/dataTemplate/template-list.vue'
 
-    Vue.component('ibps-dynamic-form-item', DynamicFormItem)
-    Vue.component('ibps-dynamic-form-field', DynamicFormField)
-    Vue.component('ibps-dynamic-form-other', DynamicFormOther)
-    Vue.component('ibps-dynamic-form-opinion', DynamicFormOpinion)
-    Vue.component('ibps-dynamic-form-grid', DynamicFormGrid)
-    Vue.component('ibps-dynamic-form-tabs', DynamicFormTabs)
-    Vue.component('ibps-dynamic-form-steps', DynamicFormSteps)
-    Vue.component('ibps-dynamic-form-collapse', DynamicFormCollapse)
-    Vue.component('ibps-dynamic-form-table', DynamicFormTable)
-    Vue.component('ibps-dynamic-form-table-item', DynamicFormTableItem)
-    Vue.component('ibps-dynamic-form-table-block', DynamicFormTableBlock)
-    // Vue.component('template-list', templateList)
+Vue.component('ibps-dynamic-form-item', DynamicFormItem)
+Vue.component('ibps-dynamic-form-field', DynamicFormField)
+Vue.component('ibps-dynamic-form-other', DynamicFormOther)
+Vue.component('ibps-dynamic-form-opinion', DynamicFormOpinion)
+Vue.component('ibps-dynamic-form-grid', DynamicFormGrid)
+Vue.component('ibps-dynamic-form-tabs', DynamicFormTabs)
+Vue.component('ibps-dynamic-form-steps', DynamicFormSteps)
+Vue.component('ibps-dynamic-form-collapse', DynamicFormCollapse)
+Vue.component('ibps-dynamic-form-table', DynamicFormTable)
+Vue.component('ibps-dynamic-form-table-item', DynamicFormTableItem)
+Vue.component('ibps-dynamic-form-table-block', DynamicFormTableBlock)
+// Vue.component('template-list', templateList)
 
-    // Vue.component('ibps-dynamic-form-layout-table', DynamicFormLayoutTable)
+// Vue.component('ibps-dynamic-form-layout-table', DynamicFormLayoutTable)
 
-    export default {
-        components: {
-            relevanceTable,
-            StatisOrRecordTable
-        },
-        provide() {
-            return {
-                dynamicForm: this
-            }
+export default {
+    components: {
+        relevanceTable,
+        StatisOrRecordTable
+    },
+    provide () {
+        return {
+            dynamicForm: this
+        }
+    },
+    props: {
+        isDialog: {
+            type: Boolean,
+            default: false
         },
-        props: {
-            isDialog: {
-                type: Boolean,
-                default: false
-            },
-            form: {
-                type: Object
-            },
-            dynamicParams: {
-                type: Object
-            },
-            formDef: {
-                type: Object,
-                required: true
-            },
-            value: {
-                type: Object
-            },
-            readonly: {
-                type: Boolean,
-                default: false
-            },
-            permissions: {
-                type: Object
-            },
-            BpmnForm: {
-                type: Boolean,
-                default: false
-            },
-            validateImmediately: {
-                // 是否初始验证
-                type: Boolean,
-                default: true
-            },
-            initialization: {
-                type: Boolean,
-                default: false
-            },
-            // 扩展参数
-            params: Object,
-            // 当前激活步骤
-            curActiveStep: Number
-        },
-        data() {
-            return {
-                models: {}, // 表单model对象数据
-                rights: {}, // 表单权限
-                responseFormula: {}, // 公式
-                responseLinkages: {}, // 联动数据
-                responseVerifys: [], // 表单提交校验
-                responseOpinionFields: {}, // 表单的意见字段
-                responseFormOpinionData: {}, // 已填写的表单意见
-                responseLabelFields: {}, // 表单的文本字段
-                unComplateOpinion: '', // 未提交的审批意见
-                invalidFields: {},
-                activeStep: 0,
-                titleList: [],
-                record: []
+        form: {
+            type: Object
+        },
+        dynamicParams: {
+            type: Object
+        },
+        formDef: {
+            type: Object,
+            required: true
+        },
+        value: {
+            type: Object
+        },
+        readonly: {
+            type: Boolean,
+            default: false
+        },
+        permissions: {
+            type: Object
+        },
+        BpmnForm: {
+            type: Boolean,
+            default: false
+        },
+        validateImmediately: {
+            // 是否初始验证
+            type: Boolean,
+            default: true
+        },
+        initialization: {
+            type: Boolean,
+            default: false
+        },
+        // 扩展参数
+        params: Object,
+        // 当前激活步骤
+        curActiveStep: Number
+    },
+    data () {
+        return {
+            models: {}, // 表单model对象数据
+            rights: {}, // 表单权限
+            responseFormula: {}, // 公式
+            responseLinkages: {}, // 联动数据
+            responseVerifys: [], // 表单提交校验
+            responseOpinionFields: {}, // 表单的意见字段
+            responseFormOpinionData: {}, // 已填写的表单意见
+            responseLabelFields: {}, // 表单的文本字段
+            unComplateOpinion: '', // 未提交的审批意见
+            invalidFields: {},
+            activeStep: 0,
+            titleList: [],
+            record: []
+        }
+    },
+    computed: {
+        formAttrs () {
+            return this.formDef ? this.formDef.attrs || {} : {}
+        },
+        hasHeader () {
+            return this.formAttrs && !this.formAttrs.hide_name
+        },
+        hasDesc () {
+            return this.formAttrs && !this.formAttrs.hide_desc && this.formDef.desc
+        },
+        titlePosition () {
+            if (this.formAttrs.title_position === 'center') {
+                return 'ibps-tc'
+            } else if (this.formAttrs.title_position === 'right') {
+                return 'ibps-tr'
+            } else {
+                return ''
             }
         },
-        computed: {
-            formAttrs() {
-                return this.formDef ? this.formDef.attrs || {} : {}
-            },
-            hasHeader() {
-                return this.formAttrs && !this.formAttrs.hide_name
-            },
-            hasDesc() {
-                return this.formAttrs && !this.formAttrs.hide_desc && this.formDef.desc
-            },
-            titlePosition() {
-                if (this.formAttrs.title_position === 'center') {
-                    return 'ibps-tc'
-                } else if (this.formAttrs.title_position === 'right') {
-                    return 'ibps-tr'
-                } else {
-                    return ''
-                }
-            },
-            size() {
-                return this.formAttrs.size || (this.$ELEMENT || {}).size
-            },
-            inline() {
-                return this.formAttrs.inline || false
-            },
-            labelSuffix() {
-                return this.formAttrs ? (this.formAttrs.colon ? this.formAttrs.labelSuffix || ':' : '') : ''
-            },
-            labelWidth() {
-                if (this.$utils.isNotEmpty(this.formAttrs.labelWidth) && this.$utils.isNotEmpty(this.formAttrs.labelWidthUnit)) {
-                    return this.formAttrs.labelWidth + this.formAttrs.labelWidthUnit
-                } else {
-                    return '100px'
-                }
-            },
-            labelPosition() {
-                return this.$utils.isNotEmpty(this.formAttrs.labelPosition) ? this.formAttrs.labelPosition : 'right'
-            },
-            descPosition() {
-                return this.$utils.isNotEmpty(this.formAttrs.descPosition) ? this.formAttrs.descPosition || 'inline' : 'inline'
-            },
-            customClass() {
-                return this.$utils.isNotEmpty(this.formAttrs.customClass) ? this.formAttrs.customClass : null
-            },
-            statusIcon() {
-                return this.$utils.isNotEmpty(this.formAttrs.statusIcon) ? this.formAttrs.statusIcon : false
-            },
-            hideRequiredAsterisk() {
-                return this.$utils.toBoolean(this.formAttrs.hideRequiredAsterisk, false)
-            },
-            code() {
-                return this.formDef.code
-            },
-            readonlyRights() {
-                return this.readonly
-            },
-            readonlyStyle() {
-                return this.formAttrs && this.formAttrs.read_style ? this.formAttrs.read_style : 'text'
-            },
-            hasScript() {
-                return this.formAttrs ? this.$utils.isNotEmpty(this.formAttrs.script) : false
-            },
-            formParams() {
-                const params = {
-                    responseFormula: this.responseFormula,
-                    responseLinkages: this.responseLinkages,
-                    responseFormOpinionData: this.responseFormOpinionData,
-                    unComplateOpinion: this.unComplateOpinion,
-                    readonly: this.readonly,
-                    readonlyStyle: this.readonlyStyle,
-                    labelWidth: this.labelWidth,
-                    labelSuffix: this.labelSuffix,
-                    descPosition: this.descPosition,
-                    formAttrs: this.formAttrs,
-                    invalidFields: this.invalidFields
-                }
-                return Object.assign(params, this.params)
+        size () {
+            return this.formAttrs.size || (this.$ELEMENT || {}).size
+        },
+        inline () {
+            return this.formAttrs.inline || false
+        },
+        labelSuffix () {
+            return this.formAttrs ? (this.formAttrs.colon ? this.formAttrs.labelSuffix || ':' : '') : ''
+        },
+        labelWidth () {
+            if (this.$utils.isNotEmpty(this.formAttrs.labelWidth) && this.$utils.isNotEmpty(this.formAttrs.labelWidthUnit)) {
+                return this.formAttrs.labelWidth + this.formAttrs.labelWidthUnit
+            } else {
+                return '100px'
             }
         },
-        watch: {
-            formDef: {
-                handler(val) {
-                    this.initResponseFields()
-                },
-                deep: true,
-                immediate: true
-            },
-            // models: {
-            //     handler (val) {
-            //         // 延迟验证
-            //         this.$nextTick(() => {
-            //             this.validate(() => { })
-            //         })
-            //     },
-            //     deep: true
-            // },
-            // initialization (val) {
-            //     if (val && this.hasScript) {
-            //         this.$emit('load-script')
-            //     }
-            // },
-            // curActiveStep (val) {
-            //     this.activeStep = val
-            // },
-            // activeStep (val, oldVal) {
-            //     if (val !== oldVal) {
-            //         this.$emit('update:cur-active-step', val)
-            //     }
-            // }
-        },
-        mounted() {
-            // 初始化脚本
-            // this.$nextTick(() => {
-            //     if (this.validateImmediately) {
-            //         this.validate(() => {})
-            //     }
-            // }) 
-            this.titleList = []
-            this.record = []
-        },
-        methods: {
-            /**
+        labelPosition () {
+            return this.$utils.isNotEmpty(this.formAttrs.labelPosition) ? this.formAttrs.labelPosition : 'right'
+        },
+        descPosition () {
+            return this.$utils.isNotEmpty(this.formAttrs.descPosition) ? this.formAttrs.descPosition || 'inline' : 'inline'
+        },
+        customClass () {
+            return this.$utils.isNotEmpty(this.formAttrs.customClass) ? this.formAttrs.customClass : null
+        },
+        statusIcon () {
+            return this.$utils.isNotEmpty(this.formAttrs.statusIcon) ? this.formAttrs.statusIcon : false
+        },
+        hideRequiredAsterisk () {
+            return this.$utils.toBoolean(this.formAttrs.hideRequiredAsterisk, false)
+        },
+        code () {
+            return this.formDef.code
+        },
+        readonlyRights () {
+            return this.readonly
+        },
+        readonlyStyle () {
+            return this.formAttrs && this.formAttrs.read_style ? this.formAttrs.read_style : 'text'
+        },
+        hasScript () {
+            return this.formAttrs ? this.$utils.isNotEmpty(this.formAttrs.script) : false
+        },
+        formParams () {
+            const params = {
+                responseFormula: this.responseFormula,
+                responseLinkages: this.responseLinkages,
+                responseFormOpinionData: this.responseFormOpinionData,
+                unComplateOpinion: this.unComplateOpinion,
+                readonly: this.readonly,
+                readonlyStyle: this.readonlyStyle,
+                labelWidth: this.labelWidth,
+                labelSuffix: this.labelSuffix,
+                descPosition: this.descPosition,
+                formAttrs: this.formAttrs,
+                invalidFields: this.invalidFields
+            }
+            return Object.assign(params, this.params)
+        }
+    },
+    watch: {
+        formDef: {
+            handler (val) {
+                this.initResponseFields()
+            },
+            deep: true,
+            immediate: true
+        }
+        // models: {
+        //     handler (val) {
+        //         // 延迟验证
+        //         this.$nextTick(() => {
+        //             this.validate(() => { })
+        //         })
+        //     },
+        //     deep: true
+        // },
+        // initialization (val) {
+        //     if (val && this.hasScript) {
+        //         this.$emit('load-script')
+        //     }
+        // },
+        // curActiveStep (val) {
+        //     this.activeStep = val
+        // },
+        // activeStep (val, oldVal) {
+        //     if (val !== oldVal) {
+        //         this.$emit('update:cur-active-step', val)
+        //     }
+        // }
+    },
+    mounted () {
+        // 初始化脚本
+        // this.$nextTick(() => {
+        //     if (this.validateImmediately) {
+        //         this.validate(() => {})
+        //     }
+        // })
+        this.titleList = []
+        this.record = []
+    },
+    methods: {
+        /**
              * 初始化字段
              */
-            async initResponseFields() {
-                let fields
-                if (this.formDef && this.formDef.fields) fields = this.formDef.fields
-                if (!fields) {
-                    return
-                }
-                await this.generateModles(fields)
-                // 初始化运行公式计算
-                await this.initRunCalFormula()
-                // 初始化表单意见
-                await this.initResponseOpinionData()
-            },
-            /**
+        async initResponseFields () {
+            let fields
+            if (this.formDef && this.formDef.fields) fields = this.formDef.fields
+            if (!fields) {
+                return
+            }
+            await this.generateModles(fields)
+            // 初始化运行公式计算
+            await this.initRunCalFormula()
+            // 初始化表单意见
+            await this.initResponseOpinionData()
+        },
+        /**
              * 生成modles
              */
-            async generateModles(fields) {
-                for (let i = 0; i < fields.length; i++) {
-                    const field = fields[i]
-                    const fieldName = field.name
-                    const fieldType = field.field_type
-                    const fieldOptions = field.field_options
+        async generateModles (fields) {
+            for (let i = 0; i < fields.length; i++) {
+                const field = fields[i]
+                const fieldName = field.name
+                const fieldType = field.field_type
+                const fieldOptions = field.field_options
 
-                    if (nestedFieldTypes.includes(fieldType)) {
-                        // 嵌套布局
-                        if (this.$utils.isNotEmpty(fieldOptions) && this.$utils.isNotEmpty(fieldOptions.columns)) {
-                            // 循环遍历所有字段
-                            fieldOptions.columns.forEach(item => {
-                                this.generateModles(item.fields)
-                            })
-                        }
-                    } else if (fieldType === 'table') {
-                        // 子表单
-                        const data = this.value ? this.value[fieldName] : []
-                        if (fieldOptions.mode === 'block') {
-                            if (this.$utils.isEmpty(data)) {
-                                this.$set(this.models, fieldName, [])
-                                const defaultValue = await FormUtils.getTableDefaultData(field)
-                                this.models[fieldName].push(JSON.parse(JSON.stringify(defaultValue)))
-                            } else {
-                                this.models[fieldName] = data || []
-                            }
+                if (nestedFieldTypes.includes(fieldType)) {
+                    // 嵌套布局
+                    if (this.$utils.isNotEmpty(fieldOptions) && this.$utils.isNotEmpty(fieldOptions.columns)) {
+                        // 循环遍历所有字段
+                        fieldOptions.columns.forEach(item => {
+                            this.generateModles(item.fields)
+                        })
+                    }
+                } else if (fieldType === 'table') {
+                    // 子表单
+                    const data = this.value ? this.value[fieldName] : []
+                    if (fieldOptions.mode === 'block') {
+                        if (this.$utils.isEmpty(data)) {
+                            this.$set(this.models, fieldName, [])
+                            const defaultValue = await FormUtils.getTableDefaultData(field)
+                            this.models[fieldName].push(JSON.parse(JSON.stringify(defaultValue)))
                         } else {
                             this.models[fieldName] = data || []
                         }
-                        // 初始化表单扩展参数
-                        this.initFormFieldParameter(field)
-                    } else if (fieldType === 'approval_opinion') {
-                        // 审批意见
-                        this.models[fieldName] = ''
-                        this.responseOpinionFields[fieldName] = field
-                        // ====== 初始化表单权限
-                        this.initFormApprovalOpinionRights(field)
                     } else {
-                        if (fieldType === 'label') {
-                            // 文本字段
-                            this.responseLabelFields[fieldName] = field
-                        }
-                        // 不是只读字段
-                        if (!FormOptions.t.NON_MODEL_FIELD_TYPES.includes(fieldType)) {
-                            // 空值默认
-                            const defaultValueEmpty = fieldOptions.uncheck ? '' : this.$utils.toBoolean(fieldOptions.default_value_empty, true)
-                            if (this.value && Object.keys(this.value).indexOf(fieldName) >= 0) {
-                                // 有值
-                                const data = this.value[fieldName]
-                                if (this.$utils.isEmpty(data)) {
-                                    if (defaultValueEmpty) {
-                                        const defaultValue = await FormUtils.getFieldDefaultValue(field)
-                                        this.models[fieldName] = defaultValue
-                                    }
-                                } else {
-                                    this.models[fieldName] = await this.getInitData(field, data)
+                        this.models[fieldName] = data || []
+                    }
+                    // 初始化表单扩展参数
+                    this.initFormFieldParameter(field)
+                } else if (fieldType === 'approval_opinion') {
+                    // 审批意见
+                    this.models[fieldName] = ''
+                    this.responseOpinionFields[fieldName] = field
+                    // ====== 初始化表单权限
+                    this.initFormApprovalOpinionRights(field)
+                } else {
+                    if (fieldType === 'label') {
+                        // 文本字段
+                        this.responseLabelFields[fieldName] = field
+                    }
+                    // 不是只读字段
+                    if (!FormOptions.t.NON_MODEL_FIELD_TYPES.includes(fieldType)) {
+                        // 空值默认
+                        const defaultValueEmpty = fieldOptions.uncheck ? '' : this.$utils.toBoolean(fieldOptions.default_value_empty, true)
+                        if (this.value && Object.keys(this.value).indexOf(fieldName) >= 0) {
+                            // 有值
+                            const data = this.value[fieldName]
+                            if (this.$utils.isEmpty(data)) {
+                                if (defaultValueEmpty) {
+                                    const defaultValue = await FormUtils.getFieldDefaultValue(field)
+                                    this.models[fieldName] = defaultValue
                                 }
                             } else {
-                                // 默认值
-                                this.models[fieldName] = await FormUtils.getFieldDefaultValue(field)
-                                if (this.dynamicParams && this.dynamicParams[field.field_name]) {
-                                    this.models[fieldName] = this.dynamicParams[field.field_name]
-                                }
+                                this.models[fieldName] = await this.getInitData(field, data)
+                            }
+                        } else {
+                            // 默认值
+                            this.models[fieldName] = await FormUtils.getFieldDefaultValue(field)
+                            if (this.dynamicParams && this.dynamicParams[field.field_name]) {
+                                this.models[fieldName] = this.dynamicParams[field.field_name]
                             }
                         }
-                        // 初始化表单扩展参数
-                        this.initFormFieldParameter(field)
+                    } else {
+                        // 自定义组件单独处理
+                        if (fieldType === 'component') {
+                            this.models[fieldName] = this.value[fieldName]
+                        }
                     }
+                    // 初始化表单扩展参数
+                    this.initFormFieldParameter(field)
                 }
-            },
-            async getInitData(field, data) {
-                const fieldType = field.field_type
-                const copyFlow = this.$utils.toBoolean(this.formParams ? this.formParams.copyFlow : false, false)
-                if (fieldType === 'autoNumber' && copyFlow) {
-                    // 复制流程初始化数据
-                    return await FormUtils.getFieldDefaultValue(field)
-                }
-                return data
-            },
-            /**
+            }
+        },
+        async getInitData (field, data) {
+            const fieldType = field.field_type
+            const copyFlow = this.$utils.toBoolean(this.formParams ? this.formParams.copyFlow : false, false)
+            if (fieldType === 'autoNumber' && copyFlow) {
+                // 复制流程初始化数据
+                return await FormUtils.getFieldDefaultValue(field)
+            }
+            return data
+        },
+        /**
              *  初始化表单扩展参数
              */
-            initFormFieldParameter(field) {
-                // ====== 初始化表单权限
-                this.initFormRights(field)
-                // ====== 初始化需要进行公式计算的字段
-                this.initResponseFormula(field)
-                // ======  初始化需要进行联动数据的字段
-                this.initResponseLinkages(field)
-            },
-            initFormApprovalOpinionRights(field) {
-                this.rights[field.name] = FormUtils.getDefaultApprovalOpinionRigths(field, this.params) || this.getPermissions(this.permissions, field) || FormUtils.getDefaultRigths(field)
-            },
-            /**
+        initFormFieldParameter (field) {
+            // ====== 初始化表单权限
+            this.initFormRights(field)
+            // ====== 初始化需要进行公式计算的字段
+            this.initResponseFormula(field)
+            // ======  初始化需要进行联动数据的字段
+            this.initResponseLinkages(field)
+        },
+        initFormApprovalOpinionRights (field) {
+            this.rights[field.name] = FormUtils.getDefaultApprovalOpinionRigths(field, this.params) || this.getPermissions(this.permissions, field) || FormUtils.getDefaultRigths(field)
+        },
+        /**
              *  初始化表单权限
              */
-            initFormRights(field) {
-                this.rights[field.name] = this.getPermissions(this.permissions, field) || FormUtils.getDefaultRigths(field)
-            },
-            // 获取权限
-            getPermissions(permissions, field) {
-                if (this.$utils.isEmpty(permissions)) {
-                    return
-                }
-                const fieldType = field.field_type
-                const name = field.name
-                let rightsValue = null
-                const isNonInputField = FormOptions.t.NON_INPUT_FIELD_TYPES.includes(fieldType)
-                let isSpecial = false
-                if (isNonInputField && permissions.fields) {
-                    // 非输入字段
-                    rightsValue = permissions.fields[name] ? permissions.fields[name] : null
-                } else if (fieldType === 'approval_opinion' && permissions.opinions) {
-                    // 意见 特殊处理
-                    rightsValue = permissions.opinions[name] ? permissions.opinions[name] : null
-                } else if (fieldType === 'table' && permissions.tables) {
-                    // 子表
-                    isSpecial = true
-                    rightsValue = permissions.tables[name] ? permissions.tables[name] : null
-                } else {
-                    // 字段
-                    rightsValue = permissions.fields[name] ? permissions.fields[name] : null
-                }
-                if (this.readonly && !isNonInputField && !isSpecial) {
-                    // 只读权限
-                    // 修复空权限默认值的bug
-                    if (this.$utils.isEmpty(rightsValue)) {
-                        rightsValue = FormUtils.getDefaultRigths(field)
-                    }
-                    rightsValue = rightsValue !== FormOptions.t.PERMISSIONS.HIDE ? FormOptions.t.PERMISSIONS.READ : rightsValue
-                }
-                return rightsValue
-            },
-            // 初始化需要进行公式计算的字段
-            initResponseFormula(item) {
-                FormUtils.setResponseFormula(this.responseFormula, item, this.code)
-            },
-            // 初始化运行公式计算
-            initRunCalFormula() {
-                // 不需要字段的进行公式计算 比如获取但其当前时间
-                FormUtils.runCalFormula(this, this.responseFormula[FormUtils.NOT_NEED_FIELD], this.formDef.code)
-            },
-            // 初始化联动数据
-            initResponseLinkages(item) {
-                FormUtils.setResponseLinkages(this.responseLinkages, item, this.code)
-            },
-            // 初始化表单意见
-            initResponseOpinionData() {
-                this.responseFormOpinionData = {}
-                this.unComplateOpinion = null
-                const opinionData = this.params ? this.params.formOpinionData || {} : {}
-                if (this.$utils.isEmpty(opinionData) || !this.hasFormOpinion()) {
-                    return
+        initFormRights (field) {
+            this.rights[field.name] = this.getPermissions(this.permissions, field) || FormUtils.getDefaultRigths(field)
+        },
+        // 获取权限
+        getPermissions (permissions, field) {
+            if (this.$utils.isEmpty(permissions)) {
+                return
+            }
+            const fieldType = field.field_type
+            const name = field.name
+            let rightsValue = null
+            const isNonInputField = FormOptions.t.NON_INPUT_FIELD_TYPES.includes(fieldType)
+            let isSpecial = false
+            if (isNonInputField && permissions.fields) {
+                // 非输入字段
+                rightsValue = permissions.fields[name] ? permissions.fields[name] : null
+            } else if (fieldType === 'approval_opinion' && permissions.opinions) {
+                // 意见 特殊处理
+                rightsValue = permissions.opinions[name] ? permissions.opinions[name] : null
+            } else if (fieldType === 'table' && permissions.tables) {
+                // 子表
+                isSpecial = true
+                rightsValue = permissions.tables[name] ? permissions.tables[name] : null
+            } else {
+                // 字段
+                rightsValue = permissions.fields[name] ? permissions.fields[name] : null
+            }
+            if (this.readonly && !isNonInputField && !isSpecial) {
+                // 只读权限
+                // 修复空权限默认值的bug
+                if (this.$utils.isEmpty(rightsValue)) {
+                    rightsValue = FormUtils.getDefaultRigths(field)
                 }
-                // 处理审批人信息
-                const { userList = [] } = this.$store.getters || {}
-                opinionData.opinionList.forEach(item => {
-                    const userInfo = userList.find(i => i.userId === item.auditor)
-                    item.auditorName = userInfo ? userInfo.userName : ''
-                })
-                this.unComplateOpinion = opinionData.unComplateOpinion
-                const hasBindNode = opinionData.hasBindNode
-                const formOpinionConfig = opinionData.formOpinionConfig
-                if (hasBindNode) {
-                    // 1、有流程节点绑定的流程意见
-                    const nodeData = opinionData.formOpinionNodeData
-                    for (const key in this.responseOpinionFields) {
-                        if (this.responseOpinionFields.hasOwnProperty(key)) {
-                            if (formOpinionConfig[key]) {
-                                this.responseFormOpinionData[key] = nodeData[key]
-                            } /* else {
+                rightsValue = rightsValue !== FormOptions.t.PERMISSIONS.HIDE ? FormOptions.t.PERMISSIONS.READ : rightsValue
+            }
+            return rightsValue
+        },
+        // 初始化需要进行公式计算的字段
+        initResponseFormula (item) {
+            FormUtils.setResponseFormula(this.responseFormula, item, this.code)
+        },
+        // 初始化运行公式计算
+        initRunCalFormula () {
+            // 不需要字段的进行公式计算 比如获取但其当前时间
+            FormUtils.runCalFormula(this, this.responseFormula[FormUtils.NOT_NEED_FIELD], this.formDef.code)
+        },
+        // 初始化联动数据
+        initResponseLinkages (item) {
+            FormUtils.setResponseLinkages(this.responseLinkages, item, this.code)
+        },
+        // 初始化表单意见
+        initResponseOpinionData () {
+            this.responseFormOpinionData = {}
+            this.unComplateOpinion = null
+            const opinionData = this.params ? this.params.formOpinionData || {} : {}
+            if (this.$utils.isEmpty(opinionData) || !this.hasFormOpinion()) {
+                return
+            }
+            // 处理审批人信息
+            const { userList = [] } = this.$store.getters || {}
+            opinionData.opinionList.forEach(item => {
+                const userInfo = userList.find(i => i.userId === item.auditor)
+                item.auditorName = userInfo ? userInfo.userName : ''
+            })
+            this.unComplateOpinion = opinionData.unComplateOpinion
+            const hasBindNode = opinionData.hasBindNode
+            const formOpinionConfig = opinionData.formOpinionConfig
+            if (hasBindNode) {
+                // 1、有流程节点绑定的流程意见
+                const nodeData = opinionData.formOpinionNodeData
+                for (const key in this.responseOpinionFields) {
+                    if (this.responseOpinionFields.hasOwnProperty(key)) {
+                        if (formOpinionConfig[key]) {
+                            this.responseFormOpinionData[key] = nodeData[key]
+                        } /* else {
                                 this.responseFormOpinionData[key] = opinionData.opinionList
                             } */
-                        }
                     }
-                } else {
-                    for (const key in this.responseOpinionFields) {
-                        if (this.responseOpinionFields.hasOwnProperty(key)) {
-                            this.responseFormOpinionData[key] = opinionData.opinionList
-                        }
+                }
+            } else {
+                for (const key in this.responseOpinionFields) {
+                    if (this.responseOpinionFields.hasOwnProperty(key)) {
+                        this.responseFormOpinionData[key] = opinionData.opinionList
                     }
                 }
-            },
-            /**
+            }
+        },
+        /**
              * 表单提交校验
              */
-            formSubmitVerify(callback) {
-                let flag = true
-                const verifys = this.formAttrs ? this.formAttrs.verifys : []
-                if (this.$utils.isEmpty(verifys)) {
-                    callback(flag)
+        formSubmitVerify (callback) {
+            let flag = true
+            const verifys = this.formAttrs ? this.formAttrs.verifys : []
+            if (this.$utils.isEmpty(verifys)) {
+                callback(flag)
+                return
+            }
+            const formData = this.getFormData()
+            for (let i = 0; i < verifys.length; i++) {
+                const verify = verifys[i]
+                if (!FormUtils.runFormSubmitVerify(verify.formula, formData, this.formDef.code)) {
+                    flag = false
+                    callback(flag, verify.msg)
                     return
                 }
-                const formData = this.getFormData()
-                for (let i = 0; i < verifys.length; i++) {
-                    const verify = verifys[i]
-                    if (!FormUtils.runFormSubmitVerify(verify.formula, formData, this.formDef.code)) {
-                        flag = false
-                        callback(flag, verify.msg)
-                        return
-                    }
-                }
-                flag = true
-                callback(flag)
-            },
-            /**
+            }
+            flag = true
+            callback(flag)
+        },
+        /**
              * 获取表单数据
              */
-            getFormData() {
-                const data = {}
-                // 去除文本字段,表单意见字段
-                for (var key in this.models) {
-                    if (!this.responseOpinionFields[key] && !this.responseLabelFields[key]) {
-                        data[key] = this.models[key]
-                    }
+        getFormData () {
+            const data = {}
+            // 去除文本字段,表单意见字段
+            for (var key in this.models) {
+                if (!this.responseOpinionFields[key] && !this.responseLabelFields[key]) {
+                    data[key] = this.models[key]
                 }
-                return data
-            },
-            /**
+            }
+            return data
+        },
+        /**
              * 设置表单字段数据
              */
-            setFieldData(name, value) {
-                this.models[name] = value
-            },
-            /**
+        setFieldData (name, value) {
+            this.models[name] = value
+        },
+        /**
              * 设置表单权限
              */
-            getFormRights(name) {
-                return this.rights[name]
-            },
-            /**
+        getFormRights (name) {
+            return this.rights[name]
+        },
+        /**
              * 设置表单权限
              */
-            setFormRights(name, value) {
-                this.rights[name] = value
-            },
-            /**
+        setFormRights (name, value) {
+            this.rights[name] = value
+        },
+        /**
              *  是否有审批意见字段
              */
-            hasFormOpinion() {
-                return this.$utils.isNotEmpty(this.responseOpinionFields)
-            },
-            /**
+        hasFormOpinion () {
+            return this.$utils.isNotEmpty(this.responseOpinionFields)
+        },
+        /**
              * 获取审批意见数据
              */
-            getFormOpinionData() {
-                const data = {}
-                for (var key in this.models) {
-                    if (this.responseOpinionFields[key] && (this.$utils.isEmpty(this.rights[key]) || this.rights[key] === FormOptions.t.PERMISSIONS.EDIT || this.rights[key] === FormOptions.t.PERMISSIONS.REQUIRED)) {
-                        data[key] = this.models[key]
-                    }
+        getFormOpinionData () {
+            const data = {}
+            for (var key in this.models) {
+                if (this.responseOpinionFields[key] && (this.$utils.isEmpty(this.rights[key]) || this.rights[key] === FormOptions.t.PERMISSIONS.EDIT || this.rights[key] === FormOptions.t.PERMISSIONS.REQUIRED)) {
+                    data[key] = this.models[key]
                 }
-                return data
-            },
-            /**
+            }
+            return data
+        },
+        /**
              * 获取审批意见验证
              */
-            formOpinionValidate(callback, flag = false) {
-                if (this.$utils.isEmpty(this.responseOpinionFields)) {
-                    callback(true)
-                    return
-                }
-                let i = 0
-                if (flag) {
-                    for (const key in this.responseOpinionFields) {
-                        if (this.$utils.isEmpty(this.models[key]) && (this.$utils.isEmpty(this.rights[key]) || this.rights[key] === FormOptions.t.PERMISSIONS.EDIT || this.rights[key] === FormOptions.t.PERMISSIONS.REQUIRED)) {
-                            this.models[key] = '退回修改 / 驳回'
-                        }
+        formOpinionValidate (callback, flag = false) {
+            if (this.$utils.isEmpty(this.responseOpinionFields)) {
+                callback(true)
+                return
+            }
+            let i = 0
+            if (flag) {
+                for (const key in this.responseOpinionFields) {
+                    if (this.$utils.isEmpty(this.models[key]) && (this.$utils.isEmpty(this.rights[key]) || this.rights[key] === FormOptions.t.PERMISSIONS.EDIT || this.rights[key] === FormOptions.t.PERMISSIONS.REQUIRED)) {
+                        this.models[key] = '退回修改 / 驳回'
                     }
-                } else {
-                    for (const key in this.responseOpinionFields) {
-                        if (this.$utils.isEmpty(this.models[key]) && this.rights[key] === FormOptions.t.PERMISSIONS.REQUIRED) {
-                            i++
-                        }
+                }
+            } else {
+                for (const key in this.responseOpinionFields) {
+                    if (this.$utils.isEmpty(this.models[key]) && this.rights[key] === FormOptions.t.PERMISSIONS.REQUIRED) {
+                        i++
                     }
                 }
+            }
 
-                if (i > 0) {
-                    callback(false)
-                } else {
-                    callback(true)
-                }
-            },
-            /**
+            if (i > 0) {
+                callback(false)
+            } else {
+                callback(true)
+            }
+        },
+        /**
              * 表单验证
              */
-            validate(callback) {
-                // 先移除校验再进行校验
-                this.$refs.form.clearValidate()
-                this.$refs.form.validate((valid, invalidFields) => {
-                    this.invalidFields = invalidFields
-                    if (callback) callback(valid, invalidFields)
-                })
-            },
-            //表单关联
-            getTableList(list) {
-                this.titleList = list
-            },
-            // 将对象参数传入, 进行渲染
-            getStatisOrRecord(type) {
-                this.record = type
-            }
-            /**
+        validate (callback) {
+            // 先移除校验再进行校验
+            this.$refs.form.clearValidate()
+            this.$refs.form.validate((valid, invalidFields) => {
+                this.invalidFields = invalidFields
+                if (callback) callback(valid, invalidFields)
+            })
+        },
+        // 表单关联
+        getTableList (list) {
+            this.titleList = list
+        },
+        // 将对象参数传入, 进行渲染
+        getStatisOrRecord (type) {
+            this.record = type
+        }
+        /**
              * 获取表单字段的具体控件组件实例
              */
-            // getRefsField (fieldName) {
-            //     const refs = this.getRefs(fieldName)
-            //     if (this.$utils.isEmpty(refs) || this.$utils.isEmpty(refs[0]) || this.$utils.isEmpty(refs[0].$refs) || this.$utils.isEmpty(refs[0].$refs['formField'])) {
-            //         return null
-            //     }
-            //     return refs[0].$refs.formField
-            // },
-            // getRefs (fieldName) {
-            //     const key = 'formItem' + fieldName
-            //     return this.getDynamicRefs(this.$refs, key)
-            // },
-            // getDynamicRefs (formRefs, key) {
-            //     if (this.$utils.isEmpty(formRefs)) {
-            //         return
-            //     }
-            //     for (const refKey in formRefs) {
-            //         const formRef = formRefs[refKey]
-            //         if (refKey === key) { return formRef }
-            //         for (let j = 0; j < formRef.length; j++) {
-            //             const refs = formRef[j]
-            //             const v = this.getDynamicRefs(refs.$refs, key)
-            //             if (v) {
-            //                 return v
-            //             }
-            //         }
-            //     }
-            // }
-        }
+        // getRefsField (fieldName) {
+        //     const refs = this.getRefs(fieldName)
+        //     if (this.$utils.isEmpty(refs) || this.$utils.isEmpty(refs[0]) || this.$utils.isEmpty(refs[0].$refs) || this.$utils.isEmpty(refs[0].$refs['formField'])) {
+        //         return null
+        //     }
+        //     return refs[0].$refs.formField
+        // },
+        // getRefs (fieldName) {
+        //     const key = 'formItem' + fieldName
+        //     return this.getDynamicRefs(this.$refs, key)
+        // },
+        // getDynamicRefs (formRefs, key) {
+        //     if (this.$utils.isEmpty(formRefs)) {
+        //         return
+        //     }
+        //     for (const refKey in formRefs) {
+        //         const formRef = formRefs[refKey]
+        //         if (refKey === key) { return formRef }
+        //         for (let j = 0; j < formRef.length; j++) {
+        //             const refs = formRef[j]
+        //             const v = this.getDynamicRefs(refs.$refs, key)
+        //             if (v) {
+        //                 return v
+        //             }
+        //         }
+        //     }
+        // }
     }
+}
 </script>
 
 <style lang="scss">

+ 90 - 27
src/views/component/selectType.vue

@@ -1,51 +1,95 @@
+<!--
+ * @Descripttion: 文件修订选择文件归档路径
+ * @version: 1.0
+ * @Author: Liu_jiaYin
+ * @Date: 2024-04-01 15:45:19
+ * @LastEditors: Do not edit
+ * @LastEditTime: 2024-04-13 09:48:53
+-->
 <template>
-    <el-cascader ref="cascader" :props="props" @change="handleChange" />
+    <el-cascader ref="cascader" v-model="cascaderData" :disabled="readonly" :options="options" :props="props" @change="handleChange">
+        <template slot-scope="{ node, data }">
+            <span>{{ data.name_ }}</span>
+            <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
+        </template>
+    </el-cascader>
 </template>
-
 <script>
 import curdPost from '@/business/platform/form/utils/custom/joinCURD.js'
+import Json from '@/business/platform/serv/components/json.vue'
+import TreeUtils from '@/utils/tree'
+
 export default {
+    props: {
+        value: { // value
+            type: [String, Number, Object, Array],
+            default () {
+                return this.multiple ? [] : {}
+            }
+        },
+        // 所有字段数据,(包含主主子表)
+        formData: [Object, Array],
+        field: {
+            type: Object,
+            required: true
+        },
+        readonly: {
+            type: Boolean,
+            default: false
+        },
+        readonlyStyle: {
+            type: String,
+            default: 'text'
+        }
+    },
     data () {
         const { first, second } = this.$store.getters.level
         const levelInfos = second || first
         return {
             props: {
-                lazy: true,
-                lazyLoad (node, resolve) {
-                    const { level, value } = node
-                    let sqlString1 = ''
-                    if (level === 0) {
-                        // 286814138233389367 是文件分类标识的id,在ibps_cat_category
-                        sqlString1 = `select *FROM ibps_cat_type WHERE parent_id_='286814138233389367' and authority_name like '%${levelInfos}%' ORDER BY sn_ ASC`
+                value: 'ID_', label: 'name_', children: 'children'
+            },
+            levelInfos,
+            cascaderData: [],
+            options: []
+        }
+    },
+    watch: {
+        value: {
+            handler (val, oldVal) {
+                if (val) {
+                    if (typeof val === 'string') {
+                        this.cascaderData = val.split(',')
                     } else {
-                        sqlString1 = `select *FROM ibps_cat_type WHERE parent_id_ in (select id_ from ibps_cat_type where ID_= '${value}'  AND category_key_ ='FILE_TYPE') ORDER BY sn_ ASC`
+                        this.cascaderData = val
                     }
-                    curdPost('sql', sqlString1).then((res1) => {
-                        const datas1 = res1.variables.data
-                        setTimeout(() => {
-                            const nodes = datas1.map((item) => ({
-                                value: item.ID_,
-                                label: item.name_,
-                                authority: item.AUTHORITY_NAME
-                            }))
-                            // 通过调用resolve将子节点数据返回,通知组件数据加载完成
-                            resolve(nodes)
-                        }, 100)
-                    })
+                } else {
+                    this.cascaderData = []
                 }
             },
-            levelInfos
+            immediate: true
         }
+        // readonly: {
+        //     handler: function (val, oldVal) {
+        //         // console.log('65 formData', this.formData)
+        //         // console.log('65 readonly', val)
+        //         console.log('65 readonlyStyle', this.readonlyStyle)
+        //     },
+        //     immediate: true
+        // }
+    },
+    async created () {
+        await this.getCascaderOptions()
     },
-    watch: {},
-    mounted () {},
     methods: {
         handleChange (v) {
             const nodesInfo = this.$refs['cascader'].getCheckedNodes()[0]
             const xilei = []
             const authorityBuMen = []
-            const authority = JSON.parse(nodesInfo.data.authority)
+            const authority = JSON.parse(nodesInfo.data.AUTHORITY_NAME)
             const wenJianXiLeiArrs = nodesInfo.pathNodes.map((item) => item.label)
+            // 组件本身字段的回填值
+            this.$emit('update:value', nodesInfo.path.join(','))
             this.$emit(
                 'change-data',
                 'guiDangLuJingXinX',
@@ -53,7 +97,6 @@ export default {
                     wenJianXiLei: wenJianXiLeiArrs.join(' / '),
                     xiLeiId: nodesInfo.value,
                     quanXianLeiXing: authority.chaYue })
-
             )
             this.$emit('change-data', 'wenJianXiLei', wenJianXiLeiArrs.join(' / '))
             this.$emit('change-data', 'xiLeiId', nodesInfo.value)
@@ -71,6 +114,26 @@ export default {
             )
             this.$emit('change-data', 'zhuanYeBuMen', authorityBuMen.join(','))
             this.$emit('change-data', 'guiShu', authorityBuMen.join(','))
+        },
+        // 获取文件分类信息
+        async getCascaderOptions () {
+            const sql = `select *FROM ibps_cat_type WHERE  authority_name like '%${this.levelInfos}%' ORDER BY sn_ ASC`
+            curdPost('sql', sql).then((res) => {
+                if (res.state === 200) {
+                    const datas = res.variables.data
+                    this.sqlDatas = datas
+                    if (datas.length > 0) {
+                        this.options = this.toTree(datas)
+                    }
+                }
+            })
+        },
+        toTree (data) {
+            return TreeUtils.transformToTreeFormat(data, {
+                idKey: 'ID_',
+                pIdKey: 'PARENT_ID_',
+                childrenKey: 'children'
+            })
         }
     }
 }