|
|
|
|
@ -21,10 +21,24 @@
|
|
|
|
|
/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item :label="t('EnergyManagement.EnergyType.dialogUnitLabel')" prop="unit">
|
|
|
|
|
<el-input
|
|
|
|
|
v-model="formData.unit"
|
|
|
|
|
:placeholder="t('EnergyManagement.EnergyType.dialogUnitPlaceholder')"
|
|
|
|
|
/>
|
|
|
|
|
<el-select v-model="formData.unit" clearable
|
|
|
|
|
:placeholder="t('EnergyManagement.EnergyType.dialogUnitPlaceholder')" class="!w-full">
|
|
|
|
|
<el-option v-for="item in unitList" :key="item.id" :label="item.name" :value="item.name" />
|
|
|
|
|
<template #footer>
|
|
|
|
|
<div v-if="!isAddingUnit" class="px-10px py-6px">
|
|
|
|
|
<el-button text bg size="small" @click.stop="onAddUnit">
|
|
|
|
|
+ 新增单位
|
|
|
|
|
</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
<div v-else class="px-10px py-6px">
|
|
|
|
|
<el-input v-model="unitInputName" size="small" placeholder="请输入单位名称" class="mb-6px" />
|
|
|
|
|
<div class="flex gap-6px">
|
|
|
|
|
<el-button type="primary" size="small" @click.stop="onConfirmAddUnit">确定</el-button>
|
|
|
|
|
<el-button size="small" @click.stop="clearAddUnit">取消</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item :label="t('EnergyManagement.EnergyType.dialogIsEnableLabel')" prop="isEnable">
|
|
|
|
|
<el-radio-group v-model="formData.isEnable">
|
|
|
|
|
@ -57,6 +71,8 @@
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import {DICT_TYPE, getBoolDictOptions} from '@/utils/dict'
|
|
|
|
|
import { EnergyTypeApi, EnergyTypeVO } from '@/api/mes/energytype'
|
|
|
|
|
import { ProductUnitApi, ProductUnitVO } from '@/api/erp/product/unit'
|
|
|
|
|
import { CommonStatusEnum } from '@/utils/constants'
|
|
|
|
|
|
|
|
|
|
/** 能耗类型 表单 */
|
|
|
|
|
defineOptions({ name: 'EnergyTypeForm' })
|
|
|
|
|
@ -84,12 +100,58 @@ const formRules = reactive({
|
|
|
|
|
})
|
|
|
|
|
const formRef = ref() // 表单 Ref
|
|
|
|
|
|
|
|
|
|
// 单位管理相关
|
|
|
|
|
const unitList = ref<ProductUnitVO[]>([])
|
|
|
|
|
const isAddingUnit = ref(false)
|
|
|
|
|
const unitInputName = ref('')
|
|
|
|
|
|
|
|
|
|
const onAddUnit = () => {
|
|
|
|
|
isAddingUnit.value = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onConfirmAddUnit = async () => {
|
|
|
|
|
if (!unitInputName.value.trim()) {
|
|
|
|
|
message.warning('请输入单位名称')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
formLoading.value = true
|
|
|
|
|
try {
|
|
|
|
|
await ProductUnitApi.createProductUnit({
|
|
|
|
|
name: unitInputName.value.trim(),
|
|
|
|
|
status: CommonStatusEnum.ENABLE,
|
|
|
|
|
primaryFlag: 'Y'
|
|
|
|
|
} as ProductUnitVO)
|
|
|
|
|
// 刷新单位列表并自动选中新单位
|
|
|
|
|
const newList = await ProductUnitApi.getProductUnitSimpleList()
|
|
|
|
|
unitList.value = newList
|
|
|
|
|
const newUnit = newList.find((u: any) => u.name === unitInputName.value.trim())
|
|
|
|
|
if (newUnit) {
|
|
|
|
|
formData.value.unit = newUnit.name
|
|
|
|
|
}
|
|
|
|
|
clearAddUnit()
|
|
|
|
|
message.success('新增单位成功')
|
|
|
|
|
} finally {
|
|
|
|
|
formLoading.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const clearAddUnit = () => {
|
|
|
|
|
unitInputName.value = ''
|
|
|
|
|
isAddingUnit.value = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 打开弹窗 */
|
|
|
|
|
const open = async (type: string, id?: number) => {
|
|
|
|
|
dialogVisible.value = true
|
|
|
|
|
dialogTitle.value = t('action.' + type)
|
|
|
|
|
formType.value = type
|
|
|
|
|
resetForm()
|
|
|
|
|
// 加载单位列表
|
|
|
|
|
try {
|
|
|
|
|
unitList.value = await ProductUnitApi.getProductUnitSimpleList()
|
|
|
|
|
} catch {
|
|
|
|
|
unitList.value = []
|
|
|
|
|
}
|
|
|
|
|
// 修改时,设置数据
|
|
|
|
|
if (id) {
|
|
|
|
|
formLoading.value = true
|
|
|
|
|
|