style:设备台账-生产日期、入厂日期时间格式调整

main
黄伟杰 4 weeks ago
parent 6c589adb1d
commit fbf4da5e81

@ -17,8 +17,8 @@ export interface DeviceLedgerVO {
deviceLocation: string // 设备位置
useDept?: string // 使用部门
deviceManager: string // 设备负责人
productionDate: Date // 设备生产日期
factoryEntryDate: Date // 设备入厂日期
productionDate: string | number | Date // 设备生产日期
factoryEntryDate: string | number | Date // 设备入厂日期
deviceRemark: string // 设备备注
remark: string // 备注
creator?: string // 创建人

@ -87,13 +87,13 @@
<el-col :span="24">
<el-form-item label="生产日期" prop="productionDate" required>
<el-date-picker v-model="formData.productionDate" type="date" value-format="x" placeholder="请选择生产日期" class="!w-full" />
<el-date-picker v-model="formData.productionDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择生产日期" class="!w-full" />
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="入厂日期" prop="factoryEntryDate" required>
<el-date-picker v-model="formData.factoryEntryDate" type="date" value-format="x" placeholder="请选择入厂日期" class="!w-full" />
<el-date-picker v-model="formData.factoryEntryDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择入厂日期" class="!w-full" />
</el-form-item>
</el-col>
@ -156,6 +156,7 @@
import { DeviceLedgerApi, DeviceLedgerVO } from '@/api/mes/deviceledger'
import { DeviceTypeApi, DeviceTypeTreeVO } from '@/api/mes/devicetype'
import { getSimpleUserList, UserVO } from '@/api/system/user'
import { formatDate } from '@/utils/formatTime'
import type { FormRules } from 'element-plus'
/** 设备类型 表单 */
@ -178,6 +179,21 @@ const parseIdsValue = (value: any): number[] => {
.filter((v) => !Number.isNaN(v))
}
const normalizeYmd = (value: any): string | undefined => {
if (value === null || value === undefined || value === '') return undefined
if (typeof value === 'string') {
const trimmed = value.trim()
const matched = trimmed.match(/^(\d{4}-\d{2}-\d{2})/)
if (matched?.[1]) return matched[1]
const parsed = Date.parse(trimmed)
if (!Number.isNaN(parsed)) return formatDate(new Date(parsed), 'YYYY-MM-DD')
return trimmed
}
if (typeof value === 'number') return formatDate(new Date(value), 'YYYY-MM-DD')
if (value instanceof Date) return formatDate(value, 'YYYY-MM-DD')
return formatDate(new Date(value), 'YYYY-MM-DD')
}
const initFormData = () => ({
id: undefined,
deviceCode: undefined,
@ -242,7 +258,9 @@ const open = async (type: string, id?: number, defaultDeviceTypeId?: number) =>
formData.value = {
...initFormData(),
...(detail as any),
deviceManagerIds: parseIdsValue((detail as any)?.deviceManager)
deviceManagerIds: parseIdsValue((detail as any)?.deviceManager),
productionDate: normalizeYmd((detail as any)?.productionDate),
factoryEntryDate: normalizeYmd((detail as any)?.factoryEntryDate)
}
} finally {
formLoading.value = false
@ -261,6 +279,8 @@ const submitForm = async () => {
try {
const data = {
...(formData.value as any),
productionDate: normalizeYmd(formData.value.productionDate),
factoryEntryDate: normalizeYmd(formData.value.factoryEntryDate),
deviceManager: formData.value.deviceManagerIds?.length ? formData.value.deviceManagerIds.join(',') : undefined
} as unknown as DeviceLedgerVO
delete (data as any).deviceManagerIds

@ -113,8 +113,8 @@
<el-table-column label="规格" align="center" prop="deviceSpec" />
<el-table-column label="型号" align="center" prop="deviceModel" />
<el-table-column label="品牌" align="center" prop="deviceBrand" />
<el-table-column label="生产日期" align="center" prop="productionDate" :formatter="dateFormatter" width="180px" />
<el-table-column label="入厂日期" align="center" prop="factoryEntryDate" :formatter="dateFormatter" width="180px" />
<el-table-column label="生产日期" align="center" prop="productionDate" :formatter="dateFormatter2" width="140px" />
<el-table-column label="入厂日期" align="center" prop="factoryEntryDate" :formatter="dateFormatter2" width="140px" />
<el-table-column label="供应商" align="center" prop="supplier" width="110px"/>
<el-table-column label="所属车间" align="center" prop="workshop" width="110px"/>
<el-table-column label="位置" align="center" prop="deviceLocation" />
@ -198,7 +198,7 @@
</template>
<script setup lang="ts">
import { dateFormatter, formatDate } from '@/utils/formatTime'
import { dateFormatter, dateFormatter2, formatDate } from '@/utils/formatTime'
import download from '@/utils/download'
import { DeviceLedgerApi, DeviceLedgerVO } from '@/api/mes/deviceledger'
import { DeviceTypeApi, DeviceTypeTreeVO } from '@/api/mes/devicetype'

Loading…
Cancel
Save