<!-- 设备台账新增或编辑页面 --> <script lang="ts" setup name="measureDevice"> import type { FormInstance, FormRules } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus' import type { menuType } from '../standingBook-interface' import baseInfo from './baseInfo.vue' // 基本信息 import table from './templateTable.vue' const props = defineProps({ title: { type: String, require: true, }, name: { type: String, require: true, }, row: { type: Object, defaule: () => ({}), }, }) const emits = defineEmits(['resetData']) const title = ref(props.title) const name = ref(props.name) const row = ref(props.row) const menu = shallowRef<menuType[]>([ { name: '基本信息', comp: baseInfo }, { name: '周检记录', comp: table }, { name: '状态变更记录', comp: table }, { name: '使用记录', comp: table }, { name: '检定证书', comp: table }, ]) const currentCompRef = ref() const current = ref('基本信息') const currentComp = shallowRef(baseInfo) watch(current, (newValue) => { currentComp.value = menu.value.filter(item => item.name === newValue)[0].comp }) // 取消 const resetForm = () => { emits('resetData') } // 提交 const submitForm = async () => { ElMessageBox.confirm( '确认提交吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then(async (res) => { current.value = '基本信息' setTimeout(() => { currentCompRef.value.submitForm().validate().then(() => { // 整理数据发送请求 console.log(JSON.parse(sessionStorage.getItem('deviceBaseInfo'))) // form表单信息数据 console.log(JSON.parse(sessionStorage.getItem('tableData'))) // table表格信息数据 // // emits('resetData') }) }) }) } watch(() => props, (newVal) => { title.value = newVal.title name.value = newVal.name row.value = newVal.row }, { deep: true, immediate: true, }) </script> <template> <app-container style="overflow: hidden;"> <detail-page :title="`${name}-${title}`"> <template #btns> <el-button v-if="title !== '详情'" type="primary" @click="submitForm"> 保存 </el-button> <el-button type="info" @click="resetForm"> 关闭 </el-button> </template> </detail-page> <!-- 展示区域 --> <keep-alive> <component :is="currentComp" ref="currentCompRef" :name="current" :title="title" :row="row"> <template #menuswitch> <!-- 三级菜单 --> <el-radio-group v-model="current"> <el-radio-button v-for="item in menu" :key="item.name" :label="item.name"> {{ item.name }} </el-radio-button> </el-radio-group> </template> </component> </keep-alive> </app-container> </template> <style lang="scss" scoped> .body-container { .form { border-radius: 8px; background-color: #fff; margin-top: 10px; padding-top: 10px; } .header { background-color: #fff; height: 40px; border-radius: 8px; align-items: center; flex-direction: column; justify-content: center; display: flex; .title { font-weight: 700; } .btns { position: absolute; right: 40px; top: 14px; } } .body { background-color: #fff; margin-top: 10px; } } .marg { margin-top: 5px; } .isDetail { ::v-deep { .el-form-item.is-required:not(.is-no-asterisk) .el-form-item__label-wrap > .el-form-item__label::before, .el-form-item.is-required:not(.is-no-asterisk) > .el-form-item__label::before { display: none; } } } </style>