|
|
|
|
@ -28,7 +28,7 @@
|
|
|
|
|
</el-col>
|
|
|
|
|
<el-col :xs="24" :sm="6" :md="4" :lg="3" :xl="2">
|
|
|
|
|
<div>
|
|
|
|
|
<el-switch v-model="formData.isCode" :disabled="formType === 'update'" />
|
|
|
|
|
<el-switch v-model="formData.isCode" :disabled="formType === 'update'" @change="handleCodeAutoChange" />
|
|
|
|
|
</div>
|
|
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
|
|
|
|
@ -51,6 +51,21 @@
|
|
|
|
|
<el-form-item :label="t('ErpStock.WarehouseArea.status')" prop="status">
|
|
|
|
|
<el-switch v-model="formData.status" :active-value="CommonStatusEnum.ENABLE" :inactive-value="CommonStatusEnum.DISABLE" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item v-if="formType === 'update'" :label="t('ErpStock.WarehouseArea.qrcode')" prop="qrcodeUrl">
|
|
|
|
|
<QrcodeActionCard
|
|
|
|
|
:image-url="currentQrcodeUrl"
|
|
|
|
|
:print-id="formData.id"
|
|
|
|
|
:print-title="t('ErpStock.WarehouseArea.qrcodePrintTitle', { name: formData.areaName || t('ErpStock.WarehouseArea.areaName') })"
|
|
|
|
|
:empty-text="t('ErpStock.WarehouseArea.qrcodeEmpty')"
|
|
|
|
|
:error-text="t('ErpStock.WarehouseArea.qrcodeLoadError')"
|
|
|
|
|
:refresh-url="getQrcodeRefreshUrl()"
|
|
|
|
|
:refresh-disabled="!formData.id || !formData.areaCode"
|
|
|
|
|
:refresh-confirm-text="t('ErpStock.WarehouseArea.qrcodeRefreshConfirm')"
|
|
|
|
|
:template-json="formData.templateJson"
|
|
|
|
|
:print-data="buildPrintData()"
|
|
|
|
|
@refresh-success="handleQrcodeRefreshSuccess"
|
|
|
|
|
/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
<template #footer>
|
|
|
|
|
<el-button @click="submitForm" type="primary" :disabled="formLoading">{{ t('common.ok') }}</el-button>
|
|
|
|
|
@ -60,10 +75,10 @@
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
|
|
|
|
|
import { WarehouseAreaApi, WarehouseAreaVO } from '@/api/erp/stock/warehousearea'
|
|
|
|
|
import { WarehouseApi } from '@/api/erp/stock/warehouse'
|
|
|
|
|
import { CommonStatusEnum } from '@/utils/constants'
|
|
|
|
|
import QrcodeActionCard from '@/components/QrcodeActionCard/index.vue'
|
|
|
|
|
|
|
|
|
|
defineOptions({ name: 'WarehouseAreaForm' })
|
|
|
|
|
|
|
|
|
|
@ -74,23 +89,40 @@ const dialogVisible = ref(false)
|
|
|
|
|
const dialogTitle = ref('')
|
|
|
|
|
const formLoading = ref(false)
|
|
|
|
|
const formType = ref('')
|
|
|
|
|
const formData = ref({
|
|
|
|
|
const formData = ref<any>({
|
|
|
|
|
id: undefined,
|
|
|
|
|
warehouseId: undefined,
|
|
|
|
|
areaCode: undefined,
|
|
|
|
|
qrcode: undefined,
|
|
|
|
|
qrcodeUrl: undefined,
|
|
|
|
|
templateJson: undefined,
|
|
|
|
|
areaName: undefined,
|
|
|
|
|
areaSize: undefined,
|
|
|
|
|
description: undefined,
|
|
|
|
|
status: undefined,
|
|
|
|
|
isCode: true
|
|
|
|
|
})
|
|
|
|
|
const validateAreaCode = (_rule: any, value: any, callback: any) => {
|
|
|
|
|
if (Boolean(formData.value.isCode)) {
|
|
|
|
|
callback()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (value === undefined || value === null || String(value).trim() === '') {
|
|
|
|
|
callback(new Error(t('ErpStock.WarehouseArea.validatorAreaCodeRequired')))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
callback()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const formRules = reactive({
|
|
|
|
|
warehouseId: [{ required: true, message: t('ErpStock.WarehouseArea.validatorWarehouseIdRequired'), trigger: 'blur' }],
|
|
|
|
|
areaCode: [{ validator: validateAreaCode, trigger: ['blur', 'change'] }],
|
|
|
|
|
areaName: [{ required: true, message: t('ErpStock.WarehouseArea.validatorAreaNameRequired'), trigger: 'blur' }],
|
|
|
|
|
status: [{ required: true, message: t('ErpStock.WarehouseArea.validatorStatusRequired'), trigger: 'blur' }]
|
|
|
|
|
})
|
|
|
|
|
const formRef = ref()
|
|
|
|
|
const warehouseList = ref<any[]>([])
|
|
|
|
|
const currentQrcodeUrl = computed(() => formData.value.qrcodeUrl || formData.value.qrcode || '')
|
|
|
|
|
|
|
|
|
|
const open = async (type: string, id?: number) => {
|
|
|
|
|
dialogVisible.value = true
|
|
|
|
|
@ -101,7 +133,14 @@ const open = async (type: string, id?: number) => {
|
|
|
|
|
if (id) {
|
|
|
|
|
formLoading.value = true
|
|
|
|
|
try {
|
|
|
|
|
formData.value = await WarehouseAreaApi.getWarehouseArea(id)
|
|
|
|
|
const areaData = await WarehouseAreaApi.getWarehouseArea(id)
|
|
|
|
|
const templateJson = areaData?.templateJson
|
|
|
|
|
formData.value = {
|
|
|
|
|
...formData.value,
|
|
|
|
|
...areaData,
|
|
|
|
|
templateJson: typeof templateJson === 'string' ? JSON.parse(templateJson) : templateJson,
|
|
|
|
|
isCode: false
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
formLoading.value = false
|
|
|
|
|
}
|
|
|
|
|
@ -115,6 +154,9 @@ const submitForm = async () => {
|
|
|
|
|
formLoading.value = true
|
|
|
|
|
try {
|
|
|
|
|
const data = { ...formData.value } as unknown as WarehouseAreaVO
|
|
|
|
|
delete (data as any).qrcode
|
|
|
|
|
delete (data as any).qrcodeUrl
|
|
|
|
|
delete (data as any).templateJson
|
|
|
|
|
if (data.isCode) {
|
|
|
|
|
data.areaCode = undefined
|
|
|
|
|
}
|
|
|
|
|
@ -132,11 +174,49 @@ const submitForm = async () => {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleCodeAutoChange = (value: boolean) => {
|
|
|
|
|
if (value) {
|
|
|
|
|
formData.value.areaCode = undefined
|
|
|
|
|
}
|
|
|
|
|
formRef.value?.clearValidate('areaCode')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getQrcodeRefreshUrl = () => {
|
|
|
|
|
if (!formData.value.id || !formData.value.areaCode) return ''
|
|
|
|
|
return `/erp/warehouse-area/regenerate-code?id=${formData.value.id}&code=${encodeURIComponent(String(formData.value.areaCode))}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const buildPrintData = () => {
|
|
|
|
|
return {
|
|
|
|
|
id: formData.value.id,
|
|
|
|
|
areaCode: formData.value.areaCode,
|
|
|
|
|
areaName: formData.value.areaName,
|
|
|
|
|
warehouseId: formData.value.warehouseId,
|
|
|
|
|
description: formData.value.description,
|
|
|
|
|
qrcodeUrl: currentQrcodeUrl.value
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleQrcodeRefreshSuccess = async (data: any) => {
|
|
|
|
|
const qrcode = data?.qrcodeUrl ?? data?.qrcode
|
|
|
|
|
if (qrcode) {
|
|
|
|
|
formData.value.qrcodeUrl = qrcode
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (!formData.value.id) return
|
|
|
|
|
const areaData = await WarehouseAreaApi.getWarehouseArea(formData.value.id)
|
|
|
|
|
formData.value.qrcodeUrl = areaData?.qrcodeUrl ?? areaData?.qrcode
|
|
|
|
|
formData.value.areaCode = areaData?.areaCode ?? formData.value.areaCode
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const resetForm = () => {
|
|
|
|
|
formData.value = {
|
|
|
|
|
id: undefined,
|
|
|
|
|
warehouseId: undefined,
|
|
|
|
|
areaCode: undefined,
|
|
|
|
|
qrcode: undefined,
|
|
|
|
|
qrcodeUrl: undefined,
|
|
|
|
|
templateJson: undefined,
|
|
|
|
|
areaName: undefined,
|
|
|
|
|
areaSize: undefined,
|
|
|
|
|
description: undefined,
|
|
|
|
|
|