From ef0d559612ff1320762be0fcfa57d984c37ce0fd Mon Sep 17 00:00:00 2001 From: yufei0306 <13417315+yufei0306@user.noreply.gitee.com> Date: Tue, 2 Apr 2024 10:30:03 +0800 Subject: [PATCH] =?UTF-8?q?MES--=E5=B7=A5=E4=BD=8D=E7=AE=A1=E7=90=86--?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E5=AD=90=E9=A1=B5=E9=9D=A2=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?SearchTable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mes/workstation/components/Detail.vue | 106 +++++++++++++++++- src/views/mes/workstation/index.vue | 34 ++++-- 2 files changed, 126 insertions(+), 14 deletions(-) diff --git a/src/views/mes/workstation/components/Detail.vue b/src/views/mes/workstation/components/Detail.vue index 81dc468ec..e73351b0a 100644 --- a/src/views/mes/workstation/components/Detail.vue +++ b/src/views/mes/workstation/components/Detail.vue @@ -138,6 +138,8 @@ @onBlur="onBlur" @formFormDateChange="formFormDateChange" /> + + @@ -299,7 +301,18 @@ const props = defineProps({ type: Boolean, required: false, default: true - } + }, + //是否直接展示搜索表单 + isOpenSearchTable:{ + type: Boolean, + required: false, + default: false + }, + searchTableSchema: { + type: Array, + required: false, + default: null + }, }) const isShowDrawer = ref(false) const detailLoading = ref(false) @@ -381,6 +394,79 @@ const HeadButttondata = ref() // 列表-操作按钮 const buttondata = ref() + +/** isOpenSearchTable 对应 表格弹窗 */ +const initModel = (schema: FormSchema[], formModel: Recordable) => { + const model: Recordable = { ...formModel } + schema.map((v) => { + // 如果是hidden,就删除对应的值 + if (v.hidden) { + delete model[v.field] + } else if (v.component && v.component !== 'Divider') { + const hasField = Reflect.has(model, v.field) + // 如果先前已经有值存在,则不进行重新赋值,而是采用现有的值 + model[v.field] = hasField ? model[v.field] : v.value !== void 0 ? v.value : '' + } + }) + return model +} +const searchTableRef = ref() +const searchTableFormModel = ref({}) +if(props.isOpenSearchTable){ + searchTableFormModel.value = initModel(props.searchTableSchema.formSchema, unref(searchTableFormModel)) +} +const searchTableFormType = ref('') // 表单的类型:create - 新增;update - 修改 + + +// 直接打开表格数据 --> 对应:isOpenSearchTable === true +const opensearchTable = ( + formField, + searchField, + searchTitle, + searchAllSchemas, + searchPage, + searchCondition, + multiple, + type, + row +) => { + const _searchCondition = {} + // 判断查询条件中,是否存在指向主表的数据 + if (searchCondition && searchCondition.length > 0) { + // 转换筛选条件所需 + for (var i=0; i< searchCondition.length; i++ ) { + // 查询条件为主表某字段,需要赋值主表数据,数据来源是详情的,赋值需要从row中获取 + if (searchCondition[i].isMainValue) { + _searchCondition[searchCondition[i].key] = detailData + ? detailData.value[searchCondition[i].value] + : '' + }else{ + _searchCondition[searchCondition[i].key] = searchCondition[i].value + } + } + } + console.log(searchCondition) + console.log(_searchCondition) + searchTableRef.value.open( + searchTitle, + searchAllSchemas, + searchPage, + formField, + searchField, + multiple, + type, + row, + _searchCondition + ) +} +const searchTableSuccess1 = (formField, searchField, val, formRef) => { + console.log('searchTableSuccess1',val) + searchTableFormModel.value[formField] = val.map(item=>item[searchField]).join(',') + console.log('searchTableSuccess1',searchTableFormModel) + submitForm(searchTableFormType.value,searchTableFormModel.value) + emit('searchTableSuccessDetail', formField, searchField, val, formRef) +} + /** 打开弹窗 */ const formRef = ref() const titleNameRef = ref() @@ -512,7 +598,22 @@ const { getList } = tableMethodsRef.value const buttonBaseClick = (val, item) => { if (val == 'add') { // 新增 - openForm('create') + if(props.isOpenSearchTable){ + searchTableFormType.value = 'create' + // 如果需要直接打开表格数据 + const item = props.searchTableSchema.formSchema[0] + opensearchTable( + item.field, item?.componentProps?.searchField, + item?.componentProps?.searchTitle, + item?.componentProps?.searchAllSchemas, + item?.componentProps?.searchPage, + item?.componentProps?.searchCondition, + item?.componentProps?.multiple, + undefined,undefined + ) + }else{ + openForm('create') + } } else if (val == 'import') { // 导入 handleImport() @@ -554,6 +655,7 @@ const openForm = async (type: string, row?: number) => { } // form 提交 const submitForm = async (formType, data) => { + console.log('submitForm',data) try { // 子表新增编辑校验 如果业务需要子表提交校验 需在主页详情组件添加 detailValidate 参数及方法 const rs = (await props.detailValidate) ? await props.detailValidate(data) : true diff --git a/src/views/mes/workstation/index.vue b/src/views/mes/workstation/index.vue index 8c3be7b0c..61ed6f2b0 100644 --- a/src/views/mes/workstation/index.vue +++ b/src/views/mes/workstation/index.vue @@ -52,18 +52,21 @@ { apiPage.value = WorkstationApi.getTeamPage detailAllSchemas.value = Team.allSchemas tabsDeleteApi = WorkstationApi.deleteTeamRelation + tabsCreateApi = WorkstationApi.createTeamRelation }else if(data.prop == 'Equipment'){ apiPage.value = WorkstationApi.getEquipmentPage detailAllSchemas.value = Equipment.allSchemas tabsDeleteApi = WorkstationApi.deleteEquipmentRelation + tabsCreateApi = WorkstationApi.createEquipmentRelation + }else if(data.prop == 'Process'){ apiPage.value = WorkstationApi.getProcessPage detailAllSchemas.value = Process.allSchemas tabsDeleteApi = WorkstationApi.deleteProcessRelation + tabsCreateApi = WorkstationApi.createProcessRelation + }else if(data.prop == 'Opersteps'){ apiPage.value = WorkstationApi.getOperstepsPage detailAllSchemas.value = Opersteps.allSchemas tabsDeleteApi = WorkstationApi.deleteOperstepsRelation + tabsCreateApi = WorkstationApi.createOperstepsRelation } } const teamListRef = ref()