| New file |
| | |
| | | <template> |
| | | <el-dialog v-model="visible" :title="dialogTitle" @closed="handleClosed" destroy-on-close> |
| | | <el-form ref="formRef" :model="formData" :rules="rules" :disabled="dialogReadonly" label-width="100px"> |
| | | <el-row> |
| | | <el-col :span="12"> |
| | | <el-form-item label="设备名称" prop="fwDeviceDTO.deviceName"> |
| | | <el-input v-model="formData.fwDeviceDTO.deviceName" maxlength="50" placeholder="请输入" clearable /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="设备类型" prop="fwDeviceDTO.deviceType"> |
| | | <el-select v-model="formData.fwDeviceDTO.deviceType" placeholder="请选择" clearable> |
| | | <el-option |
| | | v-for="item in dictObj.deviceType" |
| | | :key="item.dictKey" |
| | | :label="item.dictValue" |
| | | :value="item.dictKey" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="设备属性" prop="fwDeviceDTO.deviceAtt"> |
| | | <el-select v-model="formData.fwDeviceDTO.deviceAtt" placeholder="请选择" clearable> |
| | | <el-option |
| | | v-for="item in dictObj.deviceAtt" |
| | | :key="item.dictKey" |
| | | :label="item.dictValue" |
| | | :value="item.dictKey" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="型号" prop="fwDeviceDTO.deviceModel"> |
| | | <el-input v-model="formData.fwDeviceDTO.deviceModel" maxlength="50" placeholder="请输入" clearable /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="规格" prop="fwDeviceDTO.deviceSpecification"> |
| | | <el-input |
| | | v-model="formData.fwDeviceDTO.deviceSpecification" |
| | | maxlength="50" |
| | | placeholder="请输入" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="生产厂商" prop="fwDeviceDTO.manufacturer"> |
| | | <el-input v-model="formData.fwDeviceDTO.manufacturer" maxlength="50" placeholder="请输入" clearable /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="出库去向" prop="stockOutDestination"> |
| | | <el-input v-model="formData.stockOutDestination" maxlength="50" placeholder="请输入" clearable /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="来源" prop="fwDeviceDTO.source"> |
| | | <el-input v-model="formData.fwDeviceDTO.source" maxlength="50" placeholder="请输入" clearable /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="用途" prop="fwDeviceTrackDTO.purpose"> |
| | | <el-input v-model="formData.fwDeviceTrackDTO.purpose" maxlength="50" placeholder="请输入" clearable /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="所属部门" prop="fwDeviceDTO.ownerDept"> |
| | | <el-tree-select |
| | | v-model="formData.fwDeviceDTO.ownerDept" |
| | | node-key="id" |
| | | :data="deptTree" |
| | | :props="treeProps" |
| | | check-strictly |
| | | @change="getUserList" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="负责人" prop="fwDeviceTrackDTO.charger"> |
| | | <el-select |
| | | v-model="formData.fwDeviceTrackDTO.charger" |
| | | placeholder="请选择" |
| | | :disabled="!formData.fwDeviceDTO.ownerDept" |
| | | clearable |
| | | > |
| | | <el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="联系电话" prop="fwDeviceTrackDTO.contactPhone"> |
| | | <el-input v-model="formData.fwDeviceTrackDTO.contactPhone" maxlength="50" placeholder="请输入" clearable /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="联系电话" prop="fwDeviceTrackDTO.contactPhone"> |
| | | <el-input v-model="formData.fwDeviceTrackDTO.contactPhone" maxlength="50" placeholder="请输入" clearable /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | </el-form> |
| | | <template #footer> |
| | | <el-button @click="handleCancel">{{ dialogReadonly ? '关闭' : '取消' }}</el-button> |
| | | <el-button |
| | | v-if="!dialogReadonly" |
| | | type="primary" |
| | | :loading="submitting" |
| | | :disabled="submitting" |
| | | @click="handleSubmit" |
| | | > |
| | | 确定 |
| | | </el-button> |
| | | </template> |
| | | </el-dialog> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { computed, ref } from 'vue' |
| | | import { ElMessage } from 'element-plus' |
| | | import { fwDeviceDetailApi, fwDeviceSubmitApi } from '@/views/basicManage/deviceStock/fwDevice' |
| | | import { getUserListApi } from '@/api/system/user' |
| | | import { fieldRules } from '@ztzf/utils' |
| | | |
| | | const initForm = () => ({ |
| | | 'fwDeviceDTO': { |
| | | 'deviceAtt': '', |
| | | 'deviceModel': '', |
| | | 'deviceName': '', |
| | | 'deviceSpecification': '', |
| | | 'deviceType': '', |
| | | 'manufacturer': '', |
| | | 'remark': '', |
| | | 'source': '', |
| | | }, |
| | | 'fwDeviceTrackDTO': { |
| | | 'charger': '', |
| | | 'purpose': '', |
| | | 'contactPhone': '', |
| | | 'deptName': '', |
| | | 'outTarget': '', |
| | | 'outTime': '', |
| | | }, |
| | | }) |
| | | const treeProps = { |
| | | label: 'name', |
| | | children: 'children', |
| | | } |
| | | |
| | | const dictObj = inject('dictObj') |
| | | const deptTree = inject('deptTree') |
| | | const emit = defineEmits(['success']) |
| | | const formRef = ref(null) // 表单实例 |
| | | const formData = ref(initForm()) // 表单数据 |
| | | const visible = ref(false) // 弹框显隐 |
| | | const dialogMode = ref('add') // 弹框模式 |
| | | const submitting = ref(false) |
| | | const dialogReadonly = computed(() => dialogMode.value === 'view') |
| | | const dialogTitle = computed(() => { |
| | | if (dialogMode.value === 'edit') { |
| | | return '编辑' |
| | | } else if (dialogMode.value === 'view') { |
| | | return '查看' |
| | | } else { |
| | | return '新增' |
| | | } |
| | | }) |
| | | |
| | | const rules = { |
| | | deviceName: fieldRules(true, 50), |
| | | deviceType: fieldRules(true, 0), |
| | | deviceAtt: fieldRules(true, 0), |
| | | deviceModel: fieldRules(true, 50), |
| | | deviceSpecification: fieldRules(true, 50), |
| | | manufacturer: fieldRules(true, 50), |
| | | stockOutDestination: fieldRules(true, 50), |
| | | source: fieldRules(true, 50), |
| | | purpose: fieldRules(true, 50), |
| | | ownerDept: fieldRules(true, 50), |
| | | charger: fieldRules(true, 0), |
| | | } |
| | | |
| | | const userList = ref([]) |
| | | function getUserList(val) { |
| | | formData.value.charger = '' |
| | | if (val) { |
| | | getUserListApi(val).then(res => { |
| | | userList.value = res.data.data.records |
| | | }) |
| | | } |
| | | } |
| | | |
| | | // 关闭弹框 |
| | | function handleCancel() { |
| | | visible.value = false |
| | | } |
| | | |
| | | // 提交新增/编辑 |
| | | async function handleSubmit() { |
| | | const isValid = await formRef.value?.validate().catch(() => false) |
| | | if (!isValid) return |
| | | submitting.value = true |
| | | try { |
| | | await fwDeviceSubmitApi(formData.value) |
| | | ElMessage.success(dialogMode.value === 'add' ? '新增成功' : '更新成功') |
| | | visible.value = false |
| | | emit('success') |
| | | } finally { |
| | | submitting.value = false |
| | | } |
| | | } |
| | | |
| | | // 加载详情 |
| | | async function loadDetail() { |
| | | if (!formData.value.id) return |
| | | const res = await fwDeviceDetailApi({ id: formData.value.id }) |
| | | formData.value = res?.data?.data ?? {} |
| | | } |
| | | |
| | | // 关闭后重置 |
| | | function handleClosed() { |
| | | formData.value = initForm() |
| | | } |
| | | |
| | | // 打开弹框 |
| | | async function open({ mode, row } = {}) { |
| | | dialogMode.value = mode || 'add' |
| | | formData.value = row |
| | | visible.value = true |
| | | if (dialogMode.value === 'add') { |
| | | formData.value = initForm() |
| | | } else { |
| | | await loadDetail() |
| | | } |
| | | } |
| | | |
| | | defineExpose({ open }) |
| | | </script> |