pc_vue_admin/src/views/basicData/unit/detail/index.vue

143 lines
3.8 KiB
Vue
Raw Normal View History

2024-07-24 02:48:33 +00:00
<template>
2024-07-26 13:11:03 +00:00
<a-page-header style="padding: 10px; font-size: 20px" @back="handleBack">
<template #extra>
<a-button key="1" type="primary" @click="onSubmit"></a-button>
</template>
</a-page-header>
<a-card :bordered="false" title="基本信息">
<a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
<a-row :gutter="16">
<a-col :span="6">
2024-07-27 05:28:17 +00:00
<a-form-item label="单位组:" name="unitGroupId">
<a-select
v-model:value="formData.unitGroupId"
placeholder="请选择单位组"
:options="unitGroupList"
:fieldNames="{
label: 'name',
value: 'id'
}"
/>
2024-07-26 13:11:03 +00:00
</a-form-item>
</a-col>
<a-col :span="6">
<a-form-item label="编码:" name="number">
<a-input v-model:value="formData.number" placeholder="请输入编码" allow-clear />
</a-form-item>
</a-col>
<a-col :span="6">
<a-form-item label="名称:" name="name">
<a-input v-model:value="formData.name" placeholder="请输入名称" allow-clear />
</a-form-item>
</a-col>
<a-col :span="6">
2024-07-27 05:28:17 +00:00
<a-form-item label="可用状态:">
2024-07-26 13:11:03 +00:00
<a-select
2024-07-27 05:28:17 +00:00
v-model:value="formData.enabledState"
2024-07-26 13:11:03 +00:00
placeholder="请选择可用状态"
:options="tool.dictList('COMMON_STATUS')"
/>
</a-form-item>
</a-col>
<a-col :span="6">
<a-form-item label="换算率:" name="rate">
<a-input v-model:value="formData.rate" placeholder="请输入换算率" allow-clear />
</a-form-item>
</a-col>
<a-col :span="6">
<a-form-item label="是否基本单位:" name="isBase">
<a-select
2024-07-27 05:28:17 +00:00
v-model:value="formData.isBase"
2024-07-26 13:11:03 +00:00
placeholder="请选择是否基本单位"
2024-07-27 05:28:17 +00:00
:options="tool.dictList('YES_NO')"
2024-07-26 13:11:03 +00:00
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="备注:" name="remarks">
<a-textarea v-model:value="formData.remarks" placeholder="请输入备注" allow-clear />
</a-form-item>
</a-col>
</a-row>
</a-form>
</a-card>
2024-07-24 02:48:33 +00:00
</template>
2024-07-30 09:47:29 +00:00
<script setup name="basicDataUnitDetail">
2024-07-26 13:11:03 +00:00
import tool from '@/utils/tool'
import { cloneDeep } from 'lodash-es'
import { required } from '@/utils/formRules'
import useTabs from '@/utils/useTabs'
import router from '@/router'
2024-07-27 05:28:17 +00:00
import unitGroupsApi from '@/api/base/unit/unitGroupsApi'
import unitApi from '@/api/base/unit/unitApi'
import { useRoute } from 'vue-router'
const useRouter = useRoute()
2024-07-26 13:11:03 +00:00
// 抽屉状态
const visible = ref(false)
const emit = defineEmits({ successful: null })
const formRef = ref()
// 表单数据
2024-07-27 05:28:17 +00:00
const formData = ref({
enabledState: 'ENABLE',
isBase: 'NO'
})
2024-07-26 13:11:03 +00:00
const submitLoading = ref(false)
2024-07-24 02:48:33 +00:00
2024-07-26 13:11:03 +00:00
// 默认要校验的
const formRules = {
2024-07-27 05:28:17 +00:00
unitGroupId: [required('请选择单位')],
2024-07-26 13:11:03 +00:00
name: [required('请输入名称')],
2024-07-27 05:28:17 +00:00
isBase: [required('请选择是否基本单位')]
2024-07-26 13:11:03 +00:00
}
// 验证并提交数据
const onSubmit = () => {
formRef.value.validate().then(() => {
submitLoading.value = true
const formDataParam = cloneDeep(formData.value)
2024-07-27 05:28:17 +00:00
unitApi
2024-07-26 13:11:03 +00:00
.sysUnitSubmitForm(formDataParam, formDataParam.id)
.then(() => {
2024-07-27 05:28:17 +00:00
// emit('successful')
handleBack()
2024-07-26 13:11:03 +00:00
})
.finally(() => {
submitLoading.value = false
})
})
}
// 返回之后关闭标签
const handleBack = () => {
2024-07-27 05:28:17 +00:00
router.replace('/basicData/unit')
2024-07-26 13:11:03 +00:00
useTabs.close()
}
2024-07-27 05:28:17 +00:00
let state = reactive({
PAGE_TYPE: ''
})
let unitGroupList = ref([])
onMounted(() => {
// 单位组
unitGroupsApi
.sysUnitGroupList({
enabledState: 'ENABLE'
})
.then((res) => {
unitGroupList.value = res
})
state.PAGE_TYPE = useRouter.query.type
if (state.PAGE_TYPE && state.PAGE_TYPE !== 'ADD') {
state.detailId = useRouter.query.id
unitApi
.sysUnitDetail({
id: useRouter.query.id
})
.then((res) => {
formData.value = res
})
}
})
2024-07-24 02:48:33 +00:00
</script>