设备修改前端代码
This commit is contained in:
parent
f32d8667f7
commit
b5e9540454
@ -1,441 +0,0 @@
|
||||
<template>
|
||||
<div class="page-container">
|
||||
<n-card>
|
||||
<!-- 搜索表单 -->
|
||||
<div class="search-form">
|
||||
<n-form inline :model="searchForm" label-placement="left">
|
||||
<n-form-item label="维保记录编号(后端代码自动生成,唯一主键)">
|
||||
<n-input v-model:value="searchForm.recordId" placeholder="请输入维保记录编号(后端代码自动生成,唯一主键)" clearable />
|
||||
</n-form-item>
|
||||
<n-form-item>
|
||||
<n-space>
|
||||
<n-button type="primary" @click="handleSearch">
|
||||
<template #icon><n-icon><SearchOutline /></n-icon></template>
|
||||
搜索
|
||||
</n-button>
|
||||
<n-button @click="handleReset">
|
||||
<template #icon><n-icon><RefreshOutline /></n-icon></template>
|
||||
重置
|
||||
</n-button>
|
||||
</n-space>
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
</div>
|
||||
|
||||
<!-- 工具栏 -->
|
||||
<div class="table-toolbar">
|
||||
<n-space>
|
||||
<n-button type="primary" @click="handleAdd">
|
||||
<template #icon><n-icon><AddOutline /></n-icon></template>
|
||||
新增
|
||||
</n-button>
|
||||
<n-button @click="importModalVisible = true">
|
||||
<template #icon><n-icon><CloudUploadOutline /></n-icon></template>
|
||||
导入
|
||||
</n-button>
|
||||
<n-button @click="handleExport">
|
||||
<template #icon><n-icon><DownloadOutline /></n-icon></template>
|
||||
导出{{ selectedIds.length > 0 ? `(${selectedIds.length})` : '' }}
|
||||
</n-button>
|
||||
<n-button type="error" :disabled="selectedIds.length === 0" @click="handleBatchDelete">
|
||||
<template #icon><n-icon><TrashOutline /></n-icon></template>
|
||||
删除
|
||||
</n-button>
|
||||
</n-space>
|
||||
</div>
|
||||
|
||||
<!-- 表格 -->
|
||||
<n-data-table
|
||||
:columns="columns"
|
||||
:data="tableData"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
:row-key="(row) => row.recordId"
|
||||
:scroll-x="1200"
|
||||
@update:page="handlePageChange"
|
||||
@update:page-size="handlePageSizeChange"
|
||||
@update:checked-row-keys="handleCheck"
|
||||
/>
|
||||
</n-card>
|
||||
|
||||
<!-- 新增/编辑弹窗 -->
|
||||
<n-modal v-model:show="modalVisible" preset="card" :title="modalTitle" style="width: 600px">
|
||||
<n-form ref="formRef" :model="formData" :rules="formRules" label-placement="left" label-width="100px">
|
||||
<n-form-item label="设备ID,关联mes_equipment设备表主键" path="equipmentId">
|
||||
<n-input v-model:value="formData.equipmentId" placeholder="请输入设备ID,关联mes_equipment设备表主键" />
|
||||
</n-form-item>
|
||||
<n-form-item label="记录类型:maintain=保养,repair=维修" path="recordType">
|
||||
<n-select v-model:value="formData.recordType" placeholder="请选择记录类型:maintain=保养,repair=维修" :options="[]" />
|
||||
</n-form-item>
|
||||
<n-form-item label="故障现象/保养项目详情" path="itemContent">
|
||||
<n-input v-model:value="formData.itemContent" type="textarea" placeholder="请输入故障现象/保养项目详情" />
|
||||
</n-form-item>
|
||||
<n-form-item label="维修处理措施/保养执行内容" path="handleContent">
|
||||
<n-input v-model:value="formData.handleContent" type="textarea" placeholder="请输入维修处理措施/保养执行内容" />
|
||||
</n-form-item>
|
||||
<n-form-item label="执行人ID,关联sys_user系统用户表主键" path="executorId">
|
||||
<n-input v-model:value="formData.executorId" placeholder="请输入执行人ID,关联sys_user系统用户表主键" />
|
||||
</n-form-item>
|
||||
<n-form-item label="维保作业开始时间" path="startTime">
|
||||
<n-date-picker v-model:value="formData.startTime" type="datetime" clearable style="width: 100%" />
|
||||
</n-form-item>
|
||||
<n-form-item label="维保作业结束时间,待处理单据为空" path="endTime">
|
||||
<n-date-picker v-model:value="formData.endTime" type="datetime" clearable style="width: 100%" />
|
||||
</n-form-item>
|
||||
<n-form-item label="单据状态:pending=待处理,finished=已完成" path="recordStatus">
|
||||
<n-select v-model:value="formData.recordStatus" placeholder="请选择单据状态:pending=待处理,finished=已完成" :options="recordStatusOptions" />
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
<template #footer>
|
||||
<n-space justify="end">
|
||||
<n-button @click="modalVisible = false">取消</n-button>
|
||||
<n-button type="primary" @click="handleSubmit">确定</n-button>
|
||||
</n-space>
|
||||
</template>
|
||||
</n-modal>
|
||||
|
||||
<!-- 导入弹窗 -->
|
||||
<n-modal v-model:show="importModalVisible" preset="card" title="导入MES设备维修保养记录表" style="width: 500px">
|
||||
<n-space vertical>
|
||||
<n-alert type="info">
|
||||
<template #header>导入说明</template>
|
||||
<ul style="margin: 0; padding-left: 16px; line-height: 1.8">
|
||||
<li>请先下载导入模板,按模板格式填写数据</li>
|
||||
<li>支持 .xlsx 或 .xls 格式</li>
|
||||
</ul>
|
||||
</n-alert>
|
||||
<n-space>
|
||||
<n-button type="primary" @click="handleDownloadTemplate">
|
||||
<template #icon><n-icon><DownloadOutline /></n-icon></template>
|
||||
下载模板
|
||||
</n-button>
|
||||
</n-space>
|
||||
<n-upload :max="1" accept=".xlsx,.xls" :show-file-list="true" :custom-request="handleImportUpload">
|
||||
<n-upload-dragger>
|
||||
<div style="margin-bottom: 12px">
|
||||
<n-icon size="48" :depth="3"><CloudUploadOutline /></n-icon>
|
||||
</div>
|
||||
<n-text style="font-size: 16px">点击或拖拽文件到此处上传</n-text>
|
||||
<n-p depth="3" style="margin: 8px 0 0 0">支持 .xlsx 或 .xls 格式</n-p>
|
||||
</n-upload-dragger>
|
||||
</n-upload>
|
||||
</n-space>
|
||||
<template #footer>
|
||||
<n-button @click="importModalVisible = false">关闭</n-button>
|
||||
</template>
|
||||
</n-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, h, onMounted } from 'vue'
|
||||
import { NButton, NSpace, NIcon, NUpload, useMessage, useDialog, type DataTableColumns, type UploadCustomRequestOptions } from 'naive-ui'
|
||||
import { SearchOutline, RefreshOutline, AddOutline, TrashOutline, CreateOutline, CloudUploadOutline, DownloadOutline } from '@vicons/ionicons5'
|
||||
import { maintenanceRecordApi, type MaintenanceRecord } from '@/api/maintenanceRecord'
|
||||
import { dictDataApi } from '@/api/org'
|
||||
|
||||
const message = useMessage()
|
||||
const dialog = useDialog()
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = reactive({
|
||||
recordId: '',
|
||||
})
|
||||
|
||||
// 表格数据
|
||||
const tableData = ref<MaintenanceRecord[]>([])
|
||||
const loading = ref(false)
|
||||
const selectedIds = ref<number[]>([])
|
||||
const pagination = reactive({
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
itemCount: 0,
|
||||
showSizePicker: true,
|
||||
pageSizes: [10, 20, 50]
|
||||
})
|
||||
|
||||
// 弹窗
|
||||
const modalVisible = ref(false)
|
||||
const modalTitle = ref('')
|
||||
const importModalVisible = ref(false)
|
||||
const formRef = ref()
|
||||
const defaultFormData: MaintenanceRecord = {
|
||||
equipmentId: '',
|
||||
recordType: '',
|
||||
itemContent: '',
|
||||
handleContent: '',
|
||||
executorId: undefined,
|
||||
startTime: undefined,
|
||||
endTime: undefined,
|
||||
recordStatus: '',
|
||||
}
|
||||
const formData = reactive<MaintenanceRecord>({ ...defaultFormData })
|
||||
|
||||
// 字典选项(下拉框/单选框/复选框关联字典时使用)
|
||||
const recordStatusOptions = ref<{ label: string; value: any }[]>([])
|
||||
|
||||
// 表单校验规则
|
||||
const formRules = {
|
||||
equipmentId: { required: true, message: '请输入设备ID,关联mes_equipment设备表主键', trigger: 'blur' },
|
||||
recordType: { required: true, message: '请输入记录类型:maintain=保养,repair=维修', trigger: 'blur' },
|
||||
itemContent: { required: true, message: '请输入故障现象/保养项目详情', trigger: 'blur' },
|
||||
handleContent: { required: true, message: '请输入维修处理措施/保养执行内容', trigger: 'blur' },
|
||||
}
|
||||
|
||||
// 表格列
|
||||
const columns: DataTableColumns<MaintenanceRecord> = [
|
||||
{ type: 'selection' },
|
||||
{ title: '维保记录编号(后端代码自动生成,唯一主键)', key: 'recordId' },
|
||||
{ title: '设备ID,关联mes_equipment设备表主键', key: 'equipmentId' },
|
||||
{ title: '记录类型:maintain=保养,repair=维修', key: 'recordType' },
|
||||
{ title: '故障现象/保养项目详情', key: 'itemContent' },
|
||||
{ title: '维修处理措施/保养执行内容', key: 'handleContent' },
|
||||
{ title: '执行人ID,关联sys_user系统用户表主键', key: 'executorId' },
|
||||
{ title: '维保作业开始时间', key: 'startTime' },
|
||||
{ title: '维保作业结束时间,待处理单据为空', key: 'endTime' },
|
||||
{ title: '单据状态:pending=待处理,finished=已完成', key: 'recordStatus',
|
||||
render(row) {
|
||||
const val = row.recordStatus
|
||||
const opt = recordStatusOptions.value.find(o => o.value === val || String(o.value) === String(val))
|
||||
return opt ? opt.label : (val ?? '-')
|
||||
}
|
||||
},
|
||||
{ title: '单据创建时间', key: 'createTime', width: 180 },
|
||||
{ title: '单据最后更新时间', key: 'updateTime', width: 180 },
|
||||
{
|
||||
title: '操作',
|
||||
key: 'actions',
|
||||
width: 140,
|
||||
fixed: 'right',
|
||||
render(row) {
|
||||
return h('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', flexWrap: 'nowrap' } }, [
|
||||
h(NButton, { size: 'small', quaternary: true, onClick: () => handleEdit(row) }, {
|
||||
default: () => [h(NIcon, null, { default: () => h(CreateOutline) }), ' 编辑']
|
||||
}),
|
||||
h(NButton, { size: 'small', quaternary: true, type: 'error', onClick: () => handleDelete(row) }, {
|
||||
default: () => [h(NIcon, null, { default: () => h(TrashOutline) }), ' 删除']
|
||||
})
|
||||
])
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
// 加载数据
|
||||
async function loadData() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await maintenanceRecordApi.page({
|
||||
page: pagination.page,
|
||||
pageSize: pagination.pageSize,
|
||||
recordId: searchForm.recordId || undefined,
|
||||
})
|
||||
tableData.value = res.list
|
||||
pagination.itemCount = res.total
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索
|
||||
function handleSearch() {
|
||||
pagination.page = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
// 重置
|
||||
function handleReset() {
|
||||
searchForm.recordId = ''
|
||||
|
||||
handleSearch()
|
||||
}
|
||||
|
||||
// 分页
|
||||
function handlePageChange(page: number) {
|
||||
pagination.page = page
|
||||
loadData()
|
||||
}
|
||||
|
||||
function handlePageSizeChange(pageSize: number) {
|
||||
pagination.pageSize = pageSize
|
||||
pagination.page = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
// 选择
|
||||
function handleCheck(keys: Array<string | number>) {
|
||||
selectedIds.value = keys as number[]
|
||||
}
|
||||
|
||||
// 新增
|
||||
function handleAdd() {
|
||||
modalTitle.value = '新增MES设备维修保养记录表'
|
||||
Object.assign(formData, defaultFormData)
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
// 编辑
|
||||
function handleEdit(row: MaintenanceRecord) {
|
||||
modalTitle.value = '编辑MES设备维修保养记录表'
|
||||
Object.assign(formData, row)
|
||||
if (formData.startTime && typeof formData.startTime === 'string') {
|
||||
formData.startTime = new Date(formData.startTime.replace(' ', 'T')).getTime()
|
||||
}
|
||||
if (formData.endTime && typeof formData.endTime === 'string') {
|
||||
formData.endTime = new Date(formData.endTime.replace(' ', 'T')).getTime()
|
||||
}
|
||||
if (formData.createTime && typeof formData.createTime === 'string') {
|
||||
formData.createTime = new Date(formData.createTime.replace(' ', 'T')).getTime()
|
||||
}
|
||||
if (formData.updateTime && typeof formData.updateTime === 'string') {
|
||||
formData.updateTime = new Date(formData.updateTime.replace(' ', 'T')).getTime()
|
||||
}
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
// 提交
|
||||
async function handleSubmit() {
|
||||
await formRef.value?.validate()
|
||||
try {
|
||||
const submitData = { ...formData } as MaintenanceRecord
|
||||
if (typeof submitData.startTime === 'number') {
|
||||
submitData.startTime = new Date(submitData.startTime).toISOString().slice(0, 19).replace('T', ' ')
|
||||
}
|
||||
if (typeof submitData.endTime === 'number') {
|
||||
submitData.endTime = new Date(submitData.endTime).toISOString().slice(0, 19).replace('T', ' ')
|
||||
}
|
||||
if (typeof submitData.createTime === 'number') {
|
||||
submitData.createTime = new Date(submitData.createTime).toISOString().slice(0, 19).replace('T', ' ')
|
||||
}
|
||||
if (typeof submitData.updateTime === 'number') {
|
||||
submitData.updateTime = new Date(submitData.updateTime).toISOString().slice(0, 19).replace('T', ' ')
|
||||
}
|
||||
if (submitData.recordId) {
|
||||
await maintenanceRecordApi.update(submitData)
|
||||
message.success('修改成功')
|
||||
} else {
|
||||
await maintenanceRecordApi.create(submitData)
|
||||
message.success('新增成功')
|
||||
}
|
||||
modalVisible.value = false
|
||||
loadData()
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
// 删除
|
||||
function handleDelete(row: MaintenanceRecord) {
|
||||
dialog.warning({
|
||||
title: '提示',
|
||||
content: '确定要删除该记录吗?',
|
||||
positiveText: '确定',
|
||||
negativeText: '取消',
|
||||
onPositiveClick: async () => {
|
||||
try {
|
||||
await maintenanceRecordApi.delete([row.recordId!])
|
||||
message.success('删除成功')
|
||||
loadData()
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
function handleBatchDelete() {
|
||||
dialog.warning({
|
||||
title: '提示',
|
||||
content: `确定要删除选中的 ${selectedIds.value.length} 条记录吗?`,
|
||||
positiveText: '确定',
|
||||
negativeText: '取消',
|
||||
onPositiveClick: async () => {
|
||||
try {
|
||||
await maintenanceRecordApi.delete(selectedIds.value)
|
||||
message.success('删除成功')
|
||||
selectedIds.value = []
|
||||
loadData()
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 导出
|
||||
async function handleExport() {
|
||||
try {
|
||||
const params: Record<string, any> = {}
|
||||
if (selectedIds.value.length > 0) params.ids = selectedIds.value
|
||||
if (searchForm.recordId) params.recordId = searchForm.recordId
|
||||
const blob = await maintenanceRecordApi.export(params)
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = 'MES设备维修保养记录表数据.xlsx'
|
||||
link.click()
|
||||
window.URL.revokeObjectURL(url)
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
// 下载导入模板
|
||||
async function handleDownloadTemplate() {
|
||||
try {
|
||||
const blob = await maintenanceRecordApi.downloadTemplate()
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = 'MES设备维修保养记录表导入模板.xlsx'
|
||||
link.click()
|
||||
window.URL.revokeObjectURL(url)
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
// 导入上传
|
||||
async function handleImportUpload({ file }: UploadCustomRequestOptions) {
|
||||
if (!file.file) return
|
||||
try {
|
||||
const result = await maintenanceRecordApi.importData(file.file)
|
||||
if (result.fail > 0) {
|
||||
dialog.warning({
|
||||
title: '导入结果',
|
||||
content: `成功: ${result.success} 条,失败: ${result.fail} 条\n错误信息: ${(result.errors || []).join('\n') || '无'}`,
|
||||
positiveText: '确定'
|
||||
})
|
||||
} else {
|
||||
message.success(`导入成功,共 ${result.success} 条数据`)
|
||||
importModalVisible.value = false
|
||||
}
|
||||
loadData()
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
// 加载字典选项
|
||||
async function loadDictOptions() {
|
||||
try {
|
||||
const data = await dictDataApi.listByType('sys_status')
|
||||
recordStatusOptions.value = data.map(d => ({ label: d.dictLabel, value: d.dictValue }))
|
||||
} catch {}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
loadDictOptions()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.search-form {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.table-toolbar {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
</style>
|
||||
@ -1,492 +0,0 @@
|
||||
<template>
|
||||
<div class="page-container">
|
||||
<n-card>
|
||||
<!-- 搜索表单 -->
|
||||
<div class="search-form">
|
||||
<n-form inline :model="searchForm" label-placement="left">
|
||||
<n-form-item label="主键id">
|
||||
<n-input v-model:value="searchForm.id" placeholder="请输入主键id" clearable />
|
||||
</n-form-item>
|
||||
<n-form-item label="委外产品名称">
|
||||
<n-input v-model:value="searchForm.name" placeholder="请输入委外产品名称" clearable />
|
||||
</n-form-item>
|
||||
<n-form-item label="业务类型 1工序委外">
|
||||
<n-select v-model:value="searchForm.businessType" placeholder="请选择业务类型 1工序委外" clearable style="width: 150px" :options="[]" />
|
||||
</n-form-item>
|
||||
<n-form-item>
|
||||
<n-space>
|
||||
<n-button type="primary" @click="handleSearch">
|
||||
<template #icon><n-icon><SearchOutline /></n-icon></template>
|
||||
搜索
|
||||
</n-button>
|
||||
<n-button @click="handleReset">
|
||||
<template #icon><n-icon><RefreshOutline /></n-icon></template>
|
||||
重置
|
||||
</n-button>
|
||||
</n-space>
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
</div>
|
||||
|
||||
<!-- 工具栏 -->
|
||||
<div class="table-toolbar">
|
||||
<n-space>
|
||||
<n-button type="primary" @click="handleAdd">
|
||||
<template #icon><n-icon><AddOutline /></n-icon></template>
|
||||
新增
|
||||
</n-button>
|
||||
<n-button @click="importModalVisible = true">
|
||||
<template #icon><n-icon><CloudUploadOutline /></n-icon></template>
|
||||
导入
|
||||
</n-button>
|
||||
<n-button @click="handleExport">
|
||||
<template #icon><n-icon><DownloadOutline /></n-icon></template>
|
||||
导出{{ selectedIds.length > 0 ? `(${selectedIds.length})` : '' }}
|
||||
</n-button>
|
||||
<n-button type="error" :disabled="selectedIds.length === 0" @click="handleBatchDelete">
|
||||
<template #icon><n-icon><TrashOutline /></n-icon></template>
|
||||
删除
|
||||
</n-button>
|
||||
</n-space>
|
||||
</div>
|
||||
|
||||
<!-- 表格 -->
|
||||
<n-data-table
|
||||
:columns="columns"
|
||||
:data="tableData"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
:row-key="(row) => row.id"
|
||||
:scroll-x="1200"
|
||||
@update:page="handlePageChange"
|
||||
@update:page-size="handlePageSizeChange"
|
||||
@update:checked-row-keys="handleCheck"
|
||||
/>
|
||||
</n-card>
|
||||
|
||||
<!-- 新增/编辑弹窗 -->
|
||||
<n-modal v-model:show="modalVisible" preset="card" :title="modalTitle" style="width: 800px">
|
||||
<n-form ref="formRef" :model="formData" :rules="formRules" label-placement="left" label-width="100px">
|
||||
<n-grid :cols="2" :x-gap="24">
|
||||
<n-form-item-gi label="委外产品名称" path="name">
|
||||
<n-input v-model:value="formData.name" placeholder="请输入委外产品名称" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi label="委外产品编码" path="code">
|
||||
<n-input v-model:value="formData.code" placeholder="请输入委外产品编码" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi label="业务类型 1工序委外" path="businessType">
|
||||
<n-select v-model:value="formData.businessType" placeholder="请选择业务类型 1工序委外" :options="[]" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi label="业务id" path="businessId">
|
||||
<n-input v-model:value="formData.businessId" placeholder="请输入业务id" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi label="业务编码" path="businessCode">
|
||||
<n-input v-model:value="formData.businessCode" placeholder="请输入业务编码" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi label="生产订单id" path="orderItemId">
|
||||
<n-input v-model:value="formData.orderItemId" placeholder="请输入生产订单id" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi label="委外数量" path="quantity">
|
||||
<n-input v-model:value="formData.quantity" placeholder="请输入委外数量" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi label="供应商id" path="supplierId">
|
||||
<n-input v-model:value="formData.supplierId" placeholder="请输入供应商id" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi label="供应商名称" path="supplierName">
|
||||
<n-input v-model:value="formData.supplierName" placeholder="请输入供应商名称" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi label="单价" path="unitPrice">
|
||||
<n-input v-model:value="formData.unitPrice" placeholder="请输入单价" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi label="委外金额(数量*单价)" path="totalAmount">
|
||||
<n-input v-model:value="formData.totalAmount" placeholder="请输入委外金额(数量*单价)" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi label="预计委外开始时间" path="beginPreparationTime">
|
||||
<n-date-picker v-model:value="formData.beginPreparationTime" type="datetime" clearable style="width: 100%" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi label="预计委外结束时间" path="endPreparationTime">
|
||||
<n-date-picker v-model:value="formData.endPreparationTime" type="datetime" clearable style="width: 100%" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi label="实际开始时间" path="beginTime">
|
||||
<n-date-picker v-model:value="formData.beginTime" type="datetime" clearable style="width: 100%" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi label="实际结束时间" path="endTime">
|
||||
<n-date-picker v-model:value="formData.endTime" type="datetime" clearable style="width: 100%" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi label="是否超期" path="overdue">
|
||||
<n-input v-model:value="formData.overdue" placeholder="请输入是否超期" />
|
||||
</n-form-item-gi>
|
||||
</n-grid>
|
||||
</n-form>
|
||||
<template #footer>
|
||||
<n-space justify="end">
|
||||
<n-button @click="modalVisible = false">取消</n-button>
|
||||
<n-button type="primary" @click="handleSubmit">确定</n-button>
|
||||
</n-space>
|
||||
</template>
|
||||
</n-modal>
|
||||
|
||||
<!-- 导入弹窗 -->
|
||||
<n-modal v-model:show="importModalVisible" preset="card" title="导入委外记录表" style="width: 500px">
|
||||
<n-space vertical>
|
||||
<n-alert type="info">
|
||||
<template #header>导入说明</template>
|
||||
<ul style="margin: 0; padding-left: 16px; line-height: 1.8">
|
||||
<li>请先下载导入模板,按模板格式填写数据</li>
|
||||
<li>支持 .xlsx 或 .xls 格式</li>
|
||||
</ul>
|
||||
</n-alert>
|
||||
<n-space>
|
||||
<n-button type="primary" @click="handleDownloadTemplate">
|
||||
<template #icon><n-icon><DownloadOutline /></n-icon></template>
|
||||
下载模板
|
||||
</n-button>
|
||||
</n-space>
|
||||
<n-upload :max="1" accept=".xlsx,.xls" :show-file-list="true" :custom-request="handleImportUpload">
|
||||
<n-upload-dragger>
|
||||
<div style="margin-bottom: 12px">
|
||||
<n-icon size="48" :depth="3"><CloudUploadOutline /></n-icon>
|
||||
</div>
|
||||
<n-text style="font-size: 16px">点击或拖拽文件到此处上传</n-text>
|
||||
<n-p depth="3" style="margin: 8px 0 0 0">支持 .xlsx 或 .xls 格式</n-p>
|
||||
</n-upload-dragger>
|
||||
</n-upload>
|
||||
</n-space>
|
||||
<template #footer>
|
||||
<n-button @click="importModalVisible = false">关闭</n-button>
|
||||
</template>
|
||||
</n-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, h, onMounted } from 'vue'
|
||||
import { NButton, NSpace, NIcon, NUpload, useMessage, useDialog, type DataTableColumns, type UploadCustomRequestOptions } from 'naive-ui'
|
||||
import { SearchOutline, RefreshOutline, AddOutline, TrashOutline, CreateOutline, CloudUploadOutline, DownloadOutline } from '@vicons/ionicons5'
|
||||
import { outsourcingApi, type Outsourcing } from '@/api/outsourcing'
|
||||
|
||||
const message = useMessage()
|
||||
const dialog = useDialog()
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = reactive({
|
||||
id: null as number | null,
|
||||
name: '',
|
||||
businessType: null as number | null,
|
||||
})
|
||||
|
||||
// 表格数据
|
||||
const tableData = ref<Outsourcing[]>([])
|
||||
const loading = ref(false)
|
||||
const selectedIds = ref<number[]>([])
|
||||
const pagination = reactive({
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
itemCount: 0,
|
||||
showSizePicker: true,
|
||||
pageSizes: [10, 20, 50]
|
||||
})
|
||||
|
||||
// 弹窗
|
||||
const modalVisible = ref(false)
|
||||
const modalTitle = ref('')
|
||||
const importModalVisible = ref(false)
|
||||
const formRef = ref()
|
||||
const defaultFormData: Outsourcing = {
|
||||
name: '',
|
||||
code: '',
|
||||
businessType: undefined,
|
||||
businessId: undefined,
|
||||
businessCode: '',
|
||||
orderItemId: undefined,
|
||||
quantity: undefined,
|
||||
supplierId: undefined,
|
||||
supplierName: '',
|
||||
unitPrice: undefined,
|
||||
totalAmount: undefined,
|
||||
beginPreparationTime: undefined,
|
||||
endPreparationTime: undefined,
|
||||
beginTime: undefined,
|
||||
endTime: undefined,
|
||||
overdue: undefined,
|
||||
}
|
||||
const formData = reactive<Outsourcing>({ ...defaultFormData })
|
||||
|
||||
// 字典选项(下拉框/单选框/复选框关联字典时使用)
|
||||
|
||||
// 表单校验规则
|
||||
const formRules = {
|
||||
businessType: { required: true, message: '请输入业务类型 1工序委外', trigger: 'blur' },
|
||||
supplierName: { required: true, message: '请输入供应商名称', trigger: 'blur' },
|
||||
}
|
||||
|
||||
// 表格列
|
||||
const columns: DataTableColumns<Outsourcing> = [
|
||||
{ type: 'selection' },
|
||||
{ title: '主键id', key: 'id' },
|
||||
{ title: '委外产品名称', key: 'name' },
|
||||
{ title: '委外产品编码', key: 'code' },
|
||||
{ title: '业务类型 1工序委外', key: 'businessType' },
|
||||
{ title: '业务id', key: 'businessId' },
|
||||
{ title: '业务编码', key: 'businessCode' },
|
||||
{ title: '生产订单id', key: 'orderItemId' },
|
||||
{ title: '委外数量', key: 'quantity' },
|
||||
{ title: '供应商id', key: 'supplierId' },
|
||||
{ title: '供应商名称', key: 'supplierName' },
|
||||
{ title: '单价', key: 'unitPrice' },
|
||||
{ title: '委外金额(数量*单价)', key: 'totalAmount' },
|
||||
{ title: '预计委外开始时间', key: 'beginPreparationTime' },
|
||||
{ title: '预计委外结束时间', key: 'endPreparationTime' },
|
||||
{ title: '实际开始时间', key: 'beginTime' },
|
||||
{ title: '实际结束时间', key: 'endTime' },
|
||||
{ title: '备注', key: 'remark' },
|
||||
{ title: '创建时间', key: 'createTime', width: 180 },
|
||||
{ title: '创建人', key: 'createBy' },
|
||||
{ title: '是否超期', key: 'overdue' },
|
||||
{
|
||||
title: '操作',
|
||||
key: 'actions',
|
||||
width: 140,
|
||||
fixed: 'right',
|
||||
render(row) {
|
||||
return h('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', flexWrap: 'nowrap' } }, [
|
||||
h(NButton, { size: 'small', quaternary: true, onClick: () => handleEdit(row) }, {
|
||||
default: () => [h(NIcon, null, { default: () => h(CreateOutline) }), ' 编辑']
|
||||
}),
|
||||
h(NButton, { size: 'small', quaternary: true, type: 'error', onClick: () => handleDelete(row) }, {
|
||||
default: () => [h(NIcon, null, { default: () => h(TrashOutline) }), ' 删除']
|
||||
})
|
||||
])
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
// 加载数据
|
||||
async function loadData() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await outsourcingApi.page({
|
||||
page: pagination.page,
|
||||
pageSize: pagination.pageSize,
|
||||
id: searchForm.id || undefined,
|
||||
name: searchForm.name || undefined,
|
||||
businessType: searchForm.businessType || undefined,
|
||||
})
|
||||
tableData.value = res.list
|
||||
pagination.itemCount = res.total
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索
|
||||
function handleSearch() {
|
||||
pagination.page = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
// 重置
|
||||
function handleReset() {
|
||||
searchForm.id = null
|
||||
|
||||
searchForm.name = ''
|
||||
|
||||
searchForm.businessType = null
|
||||
|
||||
handleSearch()
|
||||
}
|
||||
|
||||
// 分页
|
||||
function handlePageChange(page: number) {
|
||||
pagination.page = page
|
||||
loadData()
|
||||
}
|
||||
|
||||
function handlePageSizeChange(pageSize: number) {
|
||||
pagination.pageSize = pageSize
|
||||
pagination.page = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
// 选择
|
||||
function handleCheck(keys: Array<string | number>) {
|
||||
selectedIds.value = keys as number[]
|
||||
}
|
||||
|
||||
// 新增
|
||||
function handleAdd() {
|
||||
modalTitle.value = '新增委外记录表'
|
||||
Object.assign(formData, defaultFormData)
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
// 编辑
|
||||
function handleEdit(row: Outsourcing) {
|
||||
modalTitle.value = '编辑委外记录表'
|
||||
Object.assign(formData, row)
|
||||
if (formData.beginPreparationTime && typeof formData.beginPreparationTime === 'string') {
|
||||
formData.beginPreparationTime = new Date(formData.beginPreparationTime.replace(' ', 'T')).getTime()
|
||||
}
|
||||
if (formData.endPreparationTime && typeof formData.endPreparationTime === 'string') {
|
||||
formData.endPreparationTime = new Date(formData.endPreparationTime.replace(' ', 'T')).getTime()
|
||||
}
|
||||
if (formData.beginTime && typeof formData.beginTime === 'string') {
|
||||
formData.beginTime = new Date(formData.beginTime.replace(' ', 'T')).getTime()
|
||||
}
|
||||
if (formData.endTime && typeof formData.endTime === 'string') {
|
||||
formData.endTime = new Date(formData.endTime.replace(' ', 'T')).getTime()
|
||||
}
|
||||
if (formData.createTime && typeof formData.createTime === 'string') {
|
||||
formData.createTime = new Date(formData.createTime.replace(' ', 'T')).getTime()
|
||||
}
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
// 提交
|
||||
async function handleSubmit() {
|
||||
await formRef.value?.validate()
|
||||
try {
|
||||
const submitData = { ...formData } as Outsourcing
|
||||
if (typeof submitData.beginPreparationTime === 'number') {
|
||||
submitData.beginPreparationTime = new Date(submitData.beginPreparationTime).toISOString().slice(0, 19).replace('T', ' ')
|
||||
}
|
||||
if (typeof submitData.endPreparationTime === 'number') {
|
||||
submitData.endPreparationTime = new Date(submitData.endPreparationTime).toISOString().slice(0, 19).replace('T', ' ')
|
||||
}
|
||||
if (typeof submitData.beginTime === 'number') {
|
||||
submitData.beginTime = new Date(submitData.beginTime).toISOString().slice(0, 19).replace('T', ' ')
|
||||
}
|
||||
if (typeof submitData.endTime === 'number') {
|
||||
submitData.endTime = new Date(submitData.endTime).toISOString().slice(0, 19).replace('T', ' ')
|
||||
}
|
||||
if (typeof submitData.createTime === 'number') {
|
||||
submitData.createTime = new Date(submitData.createTime).toISOString().slice(0, 19).replace('T', ' ')
|
||||
}
|
||||
if (submitData.id) {
|
||||
await outsourcingApi.update(submitData)
|
||||
message.success('修改成功')
|
||||
} else {
|
||||
await outsourcingApi.create(submitData)
|
||||
message.success('新增成功')
|
||||
}
|
||||
modalVisible.value = false
|
||||
loadData()
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
// 删除
|
||||
function handleDelete(row: Outsourcing) {
|
||||
dialog.warning({
|
||||
title: '提示',
|
||||
content: '确定要删除该记录吗?',
|
||||
positiveText: '确定',
|
||||
negativeText: '取消',
|
||||
onPositiveClick: async () => {
|
||||
try {
|
||||
await outsourcingApi.delete([row.id!])
|
||||
message.success('删除成功')
|
||||
loadData()
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
function handleBatchDelete() {
|
||||
dialog.warning({
|
||||
title: '提示',
|
||||
content: `确定要删除选中的 ${selectedIds.value.length} 条记录吗?`,
|
||||
positiveText: '确定',
|
||||
negativeText: '取消',
|
||||
onPositiveClick: async () => {
|
||||
try {
|
||||
await outsourcingApi.delete(selectedIds.value)
|
||||
message.success('删除成功')
|
||||
selectedIds.value = []
|
||||
loadData()
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 导出
|
||||
async function handleExport() {
|
||||
try {
|
||||
const params: Record<string, any> = {}
|
||||
if (selectedIds.value.length > 0) params.ids = selectedIds.value
|
||||
if (searchForm.id != null) params.id = searchForm.id
|
||||
if (searchForm.name) params.name = searchForm.name
|
||||
if (searchForm.businessType != null) params.businessType = searchForm.businessType
|
||||
const blob = await outsourcingApi.export(params)
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = '委外记录表数据.xlsx'
|
||||
link.click()
|
||||
window.URL.revokeObjectURL(url)
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
// 下载导入模板
|
||||
async function handleDownloadTemplate() {
|
||||
try {
|
||||
const blob = await outsourcingApi.downloadTemplate()
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = '委外记录表导入模板.xlsx'
|
||||
link.click()
|
||||
window.URL.revokeObjectURL(url)
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
// 导入上传
|
||||
async function handleImportUpload({ file }: UploadCustomRequestOptions) {
|
||||
if (!file.file) return
|
||||
try {
|
||||
const result = await outsourcingApi.importData(file.file)
|
||||
if (result.fail > 0) {
|
||||
dialog.warning({
|
||||
title: '导入结果',
|
||||
content: `成功: ${result.success} 条,失败: ${result.fail} 条\n错误信息: ${(result.errors || []).join('\n') || '无'}`,
|
||||
positiveText: '确定'
|
||||
})
|
||||
} else {
|
||||
message.success(`导入成功,共 ${result.success} 条数据`)
|
||||
importModalVisible.value = false
|
||||
}
|
||||
loadData()
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
// 加载字典选项
|
||||
async function loadDictOptions() {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
loadDictOptions()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.search-form {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.table-toolbar {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
</style>
|
||||
@ -335,7 +335,6 @@
|
||||
<!--异常填报弹窗-->
|
||||
<ErrorReportModal
|
||||
v-model:show="showErrorReportModal"
|
||||
:errorNotifiaction ="errorNotifiaction"
|
||||
:notice = "notice"
|
||||
/>
|
||||
</n-layout>
|
||||
@ -615,21 +614,16 @@ async function handleNoticeClick(item: SysNotice) {
|
||||
notice.value = item
|
||||
//异常填报直接弹窗
|
||||
showErrorReportModal.value = true
|
||||
// if (item.abnormalReporting) {
|
||||
//
|
||||
// }else {
|
||||
// // 标记已读
|
||||
// if (item.id) {
|
||||
// try {
|
||||
// await noticeApi.markAsRead(item.id)
|
||||
// // 刷新未读数量
|
||||
// loadUnreadCount()
|
||||
// } catch (error) {
|
||||
// // 忽略
|
||||
// }
|
||||
// }
|
||||
// router.push({ path: '/message/notice', query: { id: item.id?.toString() } })
|
||||
// }
|
||||
// 标记已读
|
||||
if (item.id) {
|
||||
try {
|
||||
await noticeApi.markAsRead(item.id)
|
||||
// 刷新未读数量
|
||||
loadUnreadCount()
|
||||
} catch (error) {
|
||||
// 忽略
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 点击聊天
|
||||
|
||||
@ -120,6 +120,7 @@
|
||||
style="width: 200px"
|
||||
/> -->
|
||||
<n-tree-select
|
||||
v-model:value="formData.sectionId"
|
||||
cascade
|
||||
checkable
|
||||
:options="sectionList"
|
||||
|
||||
@ -1103,14 +1103,13 @@ function disphand(process: ProcessPlanItemVO, order?: OrderProcessPlanVO) {
|
||||
dispatchform.workShop = entity.proWorkshop
|
||||
dispatchform.list = [{ sectionId:'',deviceId:'', quantity: '' }]
|
||||
|
||||
console.log(dispatchform)
|
||||
|
||||
|
||||
dispatchform.list = [{ sectionId: '', deviceId: '', userList: '', quantity: remainQty || '' }]
|
||||
dispatchform.list = [{ sectionId: '', deviceId: '', quantity: remainQty || '' }]
|
||||
}
|
||||
|
||||
function addpgnum() {
|
||||
dispatchform.list.push({ sectionId: '', deviceId: '', userList: '', quantity: '' })
|
||||
dispatchform.list.push({ sectionId: '', deviceId: '', quantity: '' })
|
||||
}
|
||||
|
||||
function deletenum(index: number) {
|
||||
|
||||
@ -159,10 +159,9 @@
|
||||
const res = await sectionApi.list({sectionName:props.section,workShop:props.workShop})
|
||||
const mesSection = res.MesSection;
|
||||
const mesDevice = res.MesDevice
|
||||
console.log(mesSection);
|
||||
|
||||
sectionList.push({
|
||||
label:mesSection.sectionName,
|
||||
label:mesSection.deptName,
|
||||
value:mesSection.id
|
||||
})
|
||||
props.obj.sectionId = mesSection.id
|
||||
|
||||
@ -79,13 +79,19 @@
|
||||
<n-input v-model:value="formData.deviceName" placeholder="请输入设备名称" />
|
||||
</n-form-item>
|
||||
<n-form-item label="所属工段" path="sectionId">
|
||||
<n-select
|
||||
v-model:value="formData.sectionId"
|
||||
:options="sectionList"
|
||||
placeholder="请选择所属工段"
|
||||
clearable
|
||||
style="width: 200px"
|
||||
/>
|
||||
<!-- <n-select-->
|
||||
<!-- v-model:value="formData.sectionId"-->
|
||||
<!-- :options="sectionList"-->
|
||||
<!-- placeholder="请选择所属工段"-->
|
||||
<!-- clearable-->
|
||||
<!-- style="width: 200px"-->
|
||||
<!-- />-->
|
||||
<n-tree-select
|
||||
v-model:value="formData.sectionId"
|
||||
cascade
|
||||
checkable
|
||||
:options="sectionList"
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item label="备注" path="remark">
|
||||
<n-input v-model:value="formData.remark" type="textarea" placeholder="请输入备注" />
|
||||
@ -144,8 +150,9 @@ import { NButton, NSpace,NTag, NIcon, NUpload, useMessage, useDialog, type DataT
|
||||
import { SearchOutline, RefreshOutline, AddOutline, TrashOutline, CreateOutline, CloudUploadOutline, DownloadOutline } from '@vicons/ionicons5'
|
||||
import { deviceApi, type Device } from '@/api/device'
|
||||
|
||||
import { dictDataApi } from '@/api/org'
|
||||
import {deptApi, dictDataApi} from '@/api/org'
|
||||
import {sectionApi, type Section} from '@/api/section'
|
||||
import {TreeNode} from "echarts/types/src/data/Tree";
|
||||
|
||||
|
||||
const message = useMessage()
|
||||
@ -208,6 +215,7 @@ const columns: DataTableColumns<Device> = [
|
||||
{ type: 'selection' },
|
||||
{ title: '工位编码', key: 'deviceCode' },
|
||||
{ title: '工位名称', key: 'deviceName' },
|
||||
{ title: '工位类型', key: 'deviceType' },
|
||||
{ title: '所属工段', key: 'sectionName' },
|
||||
{ title: '状态', key: 'status',
|
||||
render:(row) =>{
|
||||
@ -431,8 +439,24 @@ async function loadDictOptions() {
|
||||
|
||||
//加载工段
|
||||
async function loadSection() {
|
||||
const data = await sectionApi.listNoParam()
|
||||
sectionList = data.map((d:any)=> ({ label: d.sectionName, value: (Number(d.id) || d.id) }))
|
||||
const data = await deptApi.tree()
|
||||
sectionList = buildOptions(data);
|
||||
}
|
||||
|
||||
function buildOptions(d: any[]): TreeNode[] {
|
||||
return d.map(item => {
|
||||
// 安全id转换:0也能正常转为数字,不会被||过滤
|
||||
const idNum = Number(item.id);
|
||||
const key = !isNaN(idNum) ? idNum : item.id;
|
||||
return {
|
||||
label: item.deptName,
|
||||
key,
|
||||
// 子节点存在且为数组才递归处理
|
||||
children: Array.isArray(item.children) && item.children.length
|
||||
? buildOptions(item.children)
|
||||
: undefined
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
@ -507,7 +507,7 @@ async function loadData() {
|
||||
|
||||
async function loadRoles() {
|
||||
try {
|
||||
const roles = await roleApi.roleList()
|
||||
const roles = await roleApi.list()
|
||||
roleOptions.value = roles.map((role: SysRole) => ({
|
||||
label: role.name,
|
||||
value: role.id!
|
||||
@ -519,7 +519,7 @@ async function loadRoles() {
|
||||
|
||||
async function loadPostOptions() {
|
||||
try {
|
||||
const posts = await postApi.postList()
|
||||
const posts = await postApi.list()
|
||||
postOptions.value = posts.map(p => ({
|
||||
label: p.postName,
|
||||
value: p.id!
|
||||
|
||||
Loading…
Reference in New Issue
Block a user