songguoqiang
12 months ago
10 changed files with 1146 additions and 144 deletions
@ -0,0 +1,548 @@ |
|||
<template> |
|||
<Dialog v-model="dialogVisible" title="导入" width="1200"> |
|||
<el-form |
|||
:inline="true" |
|||
:model="queryParams" |
|||
class="demo-form-inline" |
|||
style="margin-bottom: 10px" |
|||
label-width="100px" |
|||
> |
|||
<el-form-item label="项目" style="width: calc(22%)"> |
|||
<el-select |
|||
v-model="queryParams.proCode" |
|||
placeholder="请选择项目" |
|||
clearable |
|||
style="width: 100%" |
|||
@change="detectionProjectChange" |
|||
> |
|||
<el-option v-for=" (item) in projectList" :key="item" :label="item.name" :value="item.code" /> |
|||
</el-select> |
|||
</el-form-item> |
|||
<el-form-item label="物料" style="width: calc(22%)"> |
|||
<el-select |
|||
v-model="queryParams.itemCode" |
|||
placeholder="请选择物料" |
|||
clearable |
|||
style="width: 100%" |
|||
@change="detectionItemChange" |
|||
> |
|||
<el-option v-for=" (item) in itemList" :key="item" :label="item.name" :value="item.code" /> |
|||
</el-select> |
|||
</el-form-item> |
|||
<el-form-item label="检测类型" style="width: calc(22%)"> |
|||
<el-select |
|||
v-model="queryParams.detectionType" |
|||
placeholder="请选择检测类型" |
|||
clearable |
|||
style="width: 100%" |
|||
@change="detectionTypeChange" |
|||
> |
|||
<el-option v-for="dict in dictTypeList" :key="dict.value" :label="dict.label" :value="dict.value" /> |
|||
</el-select> |
|||
</el-form-item> |
|||
|
|||
<el-form-item style="width: calc(22%)"> |
|||
<el-button :disabled="formLoading" type="primary" @click="submitForm">解析校验</el-button> |
|||
<el-button @click="dialogVisible = false">提 交</el-button> |
|||
</el-form-item> |
|||
</el-form> |
|||
<el-upload v-if="false" ref="uploadRef" v-model:file-list="fileList" :action="importUrl + '?mode=' + mode + '&file=' + file + '&updatePart=' + updatePart + '&outFile=' + outFile" |
|||
:auto-upload="false" :disabled="formLoading" :headers="uploadHeaders" :limit="1" :on-error="submitFormError" |
|||
:on-exceed="handleExceed" :on-success="submitFormSuccess" :accept="accept" drag |
|||
style="width:300px;margin:0 auto"> |
|||
<Icon icon="ep:upload-filled" color="#c0c4cc" size="60" /> |
|||
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div> |
|||
|
|||
<!-- 列表头部 --> |
|||
<TableHead |
|||
:HeadButttondata="HeadButttondata" |
|||
@button-base-click="buttonBaseClick" |
|||
:routeName="routeName" |
|||
@updataTableColumns="updataTableColumns" |
|||
@searchFormClick="searchFormClick" |
|||
:allSchemas="RecordsDetails.allSchemas" |
|||
/> |
|||
<!-- 列表 --> |
|||
<ContentWrap> |
|||
<Table |
|||
:columns="tableColumns" |
|||
:data="tableObject.tableList" |
|||
:loading="tableObject.loading" |
|||
:pagination="{ |
|||
total: tableObject.total |
|||
}" |
|||
v-model:pageSize="tableObject.pageSize" |
|||
v-model:currentPage="tableObject.currentPage" |
|||
v-model:sort="tableObject.sort" |
|||
> |
|||
<template #code="{row}"> |
|||
<el-button type="primary" link @click="openDetail(row, '代码', row.code)"> |
|||
<span>{{ row.code }}</span> |
|||
</el-button> |
|||
</template> |
|||
<template #action="{ row }"> |
|||
<ButtonBase :Butttondata="butttondata" @button-base-click="buttonTableClick($event,row)" /> |
|||
</template> |
|||
</Table> |
|||
</ContentWrap> |
|||
|
|||
</el-upload> |
|||
<template #footer> |
|||
<div class="flex items-center"> |
|||
<div class="flex-1 text-left"> |
|||
<el-button type="primary" plain @click="importTemplate"> |
|||
<Icon icon="ep:download" /> |
|||
下载模板 |
|||
</el-button> |
|||
</div> |
|||
<!-- <el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> |
|||
<el-button @click="dialogVisible = false">取 消</el-button> --> |
|||
</div> |
|||
</template> |
|||
</Dialog> |
|||
</template> |
|||
<script setup lang="ts"> |
|||
import download from '@/utils/download' |
|||
import { RecordsDetails,RecordsDetailsRules } from '@/views/detection/recordsDetails/importRecordsDetails.data' |
|||
import * as RecordsDetailsApi from '@/api/detection/recordsDetails' |
|||
import * as defaultButtons from '@/utils/disposition/defaultButtons' |
|||
import * as ProjecAPI from '@/api/spc/project' |
|||
import * as ItembasicApi from '@/api/spc/itembasic' |
|||
import * as TemplateItemDetailsApi from '@/api/spc/templateItemDetails' |
|||
import {formatDate} from '@/utils/formatTime' |
|||
|
|||
defineOptions({ name: 'RecordsDetails' }) |
|||
const { t } = useI18n() // 国际化 |
|||
|
|||
const route = useRoute() // 路由信息 |
|||
const routeName = ref() |
|||
routeName.value = route.name |
|||
const tableColumns = ref(RecordsDetails.allSchemas.tableColumns) |
|||
|
|||
// 字段设置 更新主列表字段 |
|||
const updataTableColumns = (val) => { |
|||
tableColumns.value = val |
|||
} |
|||
|
|||
// 查询列表页面参数设置 |
|||
const searchTableParams = ref([ |
|||
//{ |
|||
// formField: 'productItemCode', |
|||
// searchTableTitle: '物料信息', |
|||
// searchTableAllSchemas: Itembasic.allSchemas, |
|||
// searchTablePage: ItembasicApi.getItembasicPage |
|||
//} |
|||
]) |
|||
|
|||
const { tableObject, tableMethods } = useTable({ |
|||
getListApi: RecordsDetailsApi.getRecordsDetailsPage // 分页接口 |
|||
}) |
|||
|
|||
// 获得表格的各种操作 |
|||
const { getList, setSearchParams } = tableMethods |
|||
const message = useMessage() // 消息弹窗 |
|||
|
|||
const dialogVisible = ref(false) // 弹窗的是否展示 |
|||
const formLoading = ref(false) // 表单的加载中 |
|||
const uploadRef = ref() |
|||
const uploadHeaders = ref() // 上传 Header 头 |
|||
const fileList = ref([]) // 文件列表 |
|||
const file = ref('') |
|||
|
|||
// 列表头部按钮 |
|||
const HeadButttondata = [ |
|||
defaultButtons.defaultAddBtn({hasPermi:'wms:recordsDetails:create'}), // 新增 |
|||
defaultButtons.defaultImportBtn({hasPermi:'wms:recordsDetails:import'}), // 导入 |
|||
defaultButtons.defaultExportBtn({hasPermi:'wms:recordsDetails:export'}), // 导出 |
|||
defaultButtons.defaultFreshBtn(null), // 刷新 |
|||
defaultButtons.defaultFilterBtn(null), // 筛选 |
|||
defaultButtons.defaultSetBtn(null), // 设置 |
|||
] |
|||
|
|||
// 头部按钮事件 |
|||
const buttonBaseClick = (val, item) => { |
|||
if (val == 'add') { // 新增 |
|||
openForm('create') |
|||
} else if (val == 'import') { // 导入 |
|||
handleImport() |
|||
} else if (val == 'export') { // 导出 |
|||
handleExport() |
|||
} else if (val == 'refresh') { // 刷新 |
|||
getList() |
|||
} else if (val == 'filtrate') { // 筛选 |
|||
} else { // 其他按钮 |
|||
console.log('其他按钮', item) |
|||
} |
|||
} |
|||
|
|||
// 列表-操作按钮 |
|||
const butttondata = [ |
|||
defaultButtons.mainListEditBtn({hasPermi:'wms:recordsDetails:update'}), // 编辑 |
|||
defaultButtons.mainListDeleteBtn({hasPermi:'wms:recordsDetails:delete'}), // 删除 |
|||
] |
|||
|
|||
// 列表-操作按钮事件 |
|||
const buttonTableClick = async (val, row) => { |
|||
if (val == 'edit') { // 编辑 |
|||
openForm('update', row) |
|||
} else if (val == 'delete') { // 删除 |
|||
handleDelete(row.id) |
|||
} |
|||
} |
|||
|
|||
/** 添加/修改操作 */ |
|||
const basicFormRef = ref() |
|||
const openForm = (type: string, row?: any) => { |
|||
basicFormRef.value.open(type, row) |
|||
} |
|||
|
|||
// 查询页面返回 |
|||
const searchTableSuccess = (formField, searchField, val, formRef) => { |
|||
nextTick(() => { |
|||
const setV = {} |
|||
setV[formField] = val[0][searchField] |
|||
formRef.setValues(setV) |
|||
}) |
|||
} |
|||
|
|||
/** 详情操作 */ |
|||
const detailRef = ref() |
|||
const openDetail = (row: any, titleName: any, titleValue: any) => { |
|||
detailRef.value.openDetail(row, titleName, titleValue, 'basicRecordsDetails') |
|||
} |
|||
|
|||
/** 删除按钮操作 */ |
|||
const handleDelete = async (id: number) => { |
|||
try { |
|||
// 删除的二次确认 |
|||
await message.delConfirm() |
|||
// 发起删除 |
|||
await RecordsDetailsApi.deleteRecordsDetails(id) |
|||
message.success(t('common.delSuccess')) |
|||
// 刷新列表 |
|||
await getList() |
|||
} catch {} |
|||
} |
|||
|
|||
/** 导出按钮操作 */ |
|||
const exportLoading = ref(false) // 导出的加载中 |
|||
const handleExport = async () => { |
|||
try { |
|||
// 导出的二次确认 |
|||
await message.exportConfirm() |
|||
// 发起导出 |
|||
exportLoading.value = true |
|||
const data = await RecordsDetailsApi.exportRecordsDetails(setSearchParams) |
|||
download.excel(data, '检测记录详细.xls') |
|||
} catch { |
|||
} finally { |
|||
exportLoading.value = false |
|||
} |
|||
} |
|||
|
|||
/** 导入 */ |
|||
const importFormRef = ref() |
|||
const handleImport = () => { |
|||
importFormRef.value.open() |
|||
} |
|||
// 导入附件弹窗所需的参数 |
|||
// const importTemplateData = reactive({ |
|||
// templateUrl: '', |
|||
// templateTitle: '检测记录详细导入模版.xls' |
|||
// }) |
|||
// 导入成功之后 |
|||
const importSuccess = () => { |
|||
getList() |
|||
} |
|||
|
|||
// 筛选提交 |
|||
const searchFormClick = (searchData) => { |
|||
tableObject.params = { |
|||
isSearch: true, |
|||
filters: searchData.filters |
|||
} |
|||
getList() // 刷新当前列表 |
|||
} |
|||
|
|||
/** 初始化 **/ |
|||
onMounted(async () => { |
|||
getList() |
|||
|
|||
}) |
|||
|
|||
const queryParams = reactive({ |
|||
proCode: '', |
|||
itemCode: '', |
|||
detectionType: '', |
|||
detectionItemContentId: null, |
|||
ecTab: '1' |
|||
}) |
|||
const uploadOpen=ref(false) |
|||
|
|||
const props = defineProps({ |
|||
importTemplateData: { |
|||
type: Object, |
|||
required: true |
|||
}, |
|||
// 可以导入的文件类型 |
|||
accept: { |
|||
type: String, |
|||
required: false, |
|||
default:'.xlsx,.xls' |
|||
}, |
|||
// 是否更新已经存在的用户数据.默认值是1 |
|||
mode: { |
|||
type: Number, |
|||
required: false, |
|||
default: 1 |
|||
}, |
|||
// 更新是否禁用,默认值不禁用 |
|||
updateIsDisable: { |
|||
type: Boolean, |
|||
required: false, |
|||
default: false |
|||
}, |
|||
// 追加是否禁用,默认值不禁用 |
|||
appendIsDisable: { |
|||
type: Boolean, |
|||
required: false, |
|||
default: false |
|||
}, |
|||
// 覆盖是否禁用,默认值不禁用 |
|||
coverIsDisable: { |
|||
type: Boolean, |
|||
required: false, |
|||
default: false |
|||
}, |
|||
// 是否部门保存,默认是 |
|||
updatePart: { |
|||
type: Boolean, |
|||
required: false, |
|||
default: false |
|||
}, |
|||
url:{ |
|||
type: String, |
|||
required: false, |
|||
}, |
|||
// 显示是否外部资源 |
|||
isShowOut: { |
|||
type: Boolean, |
|||
required: false, |
|||
default: false |
|||
}, |
|||
outFile: { |
|||
type: Boolean, |
|||
required: false, |
|||
default: false |
|||
}, |
|||
}) |
|||
const importTemplateData= ref(props.importTemplateData) |
|||
const accept= ref(props.accept) |
|||
const mode = ref(props.mode)//是否更新已经存在的用户数据.默认值是1 |
|||
const updateIsDisable = ref(props.updateIsDisable)//更新是否禁用,默认值不禁用 |
|||
const appendIsDisable = ref(props.appendIsDisable)//追加是否禁用,默认值不禁用 |
|||
const coverIsDisable = ref(props.coverIsDisable)//覆盖是否禁用,默认值不禁用 |
|||
const updatePart = ref(props.updatePart)//是否部门保存 |
|||
const outFile = ref(props.outFile)//是否引入外部资源 |
|||
|
|||
|
|||
|
|||
// 项目列表 |
|||
const projectList = ref() |
|||
// 物料列表 |
|||
const itemList = ref() |
|||
|
|||
// 类型列表 |
|||
const dictTypeList = ref() |
|||
|
|||
|
|||
|
|||
const getProject = async () => {//获取所有项目数据列表 |
|||
const _projectList = await ProjecAPI.selectAllPros() |
|||
if (_projectList != null && _projectList.length != 0) { |
|||
projectList.value = _projectList |
|||
let code = projectList.value[0].code; |
|||
queryParams.proCode = code; |
|||
await _itemList(code); |
|||
} |
|||
} |
|||
|
|||
|
|||
//根据项目code获取物料列表 |
|||
const _itemList =async (projectCode)=>{ |
|||
itemList.value = [] |
|||
const _itemList = await ItembasicApi.selectItemsByProjectCode(projectCode); |
|||
if (_itemList != null && _itemList.length != 0) { |
|||
itemList.value = _itemList |
|||
queryParams.itemCode = itemList.value[0].code |
|||
dictOptions(); |
|||
} |
|||
|
|||
} |
|||
|
|||
const dictOptions = async () => {//获取物料类型 |
|||
dictTypeList.value = [] |
|||
const dictOptions = await getIntDictOptions(DICT_TYPE.ITEMBASIC_TYPE); |
|||
if (dictOptions != null && dictOptions.length != 0) { |
|||
dictTypeList.value = dictOptions; |
|||
queryParams.detectionType = dictOptions[0].value + '' |
|||
uploadOpen.value = true; |
|||
} |
|||
} |
|||
|
|||
|
|||
const detectionProjectChange =async ()=>{//项目修改 |
|||
if(queryParams.proCode==''){ |
|||
queryParams.itemCode='' |
|||
queryParams.detectionType='' |
|||
itemList.value = []; |
|||
dictTypeList.value = []; |
|||
uploadOpen.value = false; |
|||
}else{ |
|||
_itemList(queryParams.proCode); |
|||
} |
|||
} |
|||
|
|||
const detectionTypeChange=async()=>{ |
|||
if(queryParams.detectionType==''){ |
|||
uploadOpen.value = false; |
|||
}else{ |
|||
uploadOpen.value = true; |
|||
} |
|||
} |
|||
|
|||
const detectionItemChange = async ()=>{//物料修改 |
|||
if(queryParams.itemCode==''){ |
|||
queryParams.detectionType='' |
|||
dictTypeList.value = []; |
|||
uploadOpen.value = false; |
|||
}else{ |
|||
dictOptions(); |
|||
uploadOpen.value =true; |
|||
} |
|||
} |
|||
onMounted(()=>{ |
|||
getProject() |
|||
}) |
|||
|
|||
const importUrl = |
|||
import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + props.url |
|||
|
|||
/** 打开弹窗 */ |
|||
const open = () => { |
|||
dialogVisible.value = true |
|||
getList() // 刷新当前列表 |
|||
setSearchParams({ |
|||
decRecId:55, |
|||
saveStatus:1, |
|||
result:"Warning", |
|||
}); |
|||
resetForm() |
|||
} |
|||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗 |
|||
|
|||
/** 提交表单 */ |
|||
const submitForm = async () => { |
|||
|
|||
if (fileList.value.length == 0) { |
|||
message.error('请上传文件') |
|||
return |
|||
} |
|||
file.value = fileList.value[0].name |
|||
// 提交请求 |
|||
uploadHeaders.value = { |
|||
Authorization: 'Bearer ' + getAccessToken(), |
|||
'tenant-id': getTenantId(), |
|||
} |
|||
formLoading.value = true |
|||
uploadRef.value!.submit() |
|||
} |
|||
|
|||
/** 文件上传成功 */ |
|||
const emits = defineEmits(['success']) |
|||
const submitFormSuccess = (response: any) => { |
|||
formLoading.value = true |
|||
if(response){ |
|||
if(response.code == 500){ |
|||
message.error('导入失败') |
|||
return; |
|||
} else if (response.data.errorCount > 0) { |
|||
message.confirm('文件中有部分数据导入失败,是否下载失败数据?').then(() => { |
|||
// download.excel(file, 'file_' + new Date().getTime()) |
|||
// 通过url下载文件 |
|||
// const downloadElement = document.createElement('a') |
|||
// console.log(172, import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/' + response.data.errorFile) |
|||
// console.log(172, import.meta.env.VITE_BASE_URL + '/admin-api/opt/profile/' + response.data.errorFile) |
|||
window.open(import.meta.env.VITE_BASE_URL + '/admin-api/profile/' + response.data.errorFile ,'222') |
|||
// downloadElement.setAttribute('href', import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + response.data.errorFile ) |
|||
// 点击下载 |
|||
// downloadElement.click() |
|||
}) |
|||
} |
|||
}else{ |
|||
console.info("response",response); |
|||
message.success('导入成功') |
|||
|
|||
} |
|||
// 发送操作成功的事件 |
|||
formLoading.value = false |
|||
emits('success') |
|||
const decRecId = response.data.decRecId;//主记录id |
|||
const role = response.data.decRecId;//是否为admin |
|||
const waring = response.data.decRecId;//是否有超出公差范围数据 |
|||
//dialogVisible.value = false |
|||
//文件导入成功之后隐藏导入框展示告警信息列表 |
|||
setSearchParams({ |
|||
decRecId:decRecId, |
|||
saveStatus:1, |
|||
result:"Warning", |
|||
}); |
|||
uploadOpen.value = false; |
|||
} |
|||
/** 上传错误提示 */ |
|||
const submitFormError = (): void => { |
|||
message.error('上传失败,请您重新上传!') |
|||
formLoading.value = false |
|||
} |
|||
|
|||
/** 重置表单 */ |
|||
const resetForm = () => { |
|||
// 重置上传状态和文件 |
|||
formLoading.value = false |
|||
uploadRef.value?.clearFiles() |
|||
fileList.value = [] |
|||
} |
|||
|
|||
/** 文件数超出提示 */ |
|||
const handleExceed = (): void => { |
|||
message.error('最多只能上传一个文件!') |
|||
} |
|||
|
|||
/** 下载模板操作 */ |
|||
const importTemplate = () => { |
|||
const res = importTemplateData.value.templateUrl |
|||
download.excel(res, importTemplateData.value.templateTitle) |
|||
} |
|||
|
|||
</script> |
|||
|
|||
<style scoped lang="scss"> |
|||
.tips { |
|||
div { |
|||
position: relative; |
|||
padding-left: 22px; |
|||
|
|||
&::before { |
|||
width: 4px; |
|||
height: 4px; |
|||
border-radius: 50%; |
|||
content: ''; |
|||
background: #c2c2c2; |
|||
position: absolute; |
|||
top: 50%; |
|||
margin-top: -2px; |
|||
left: 4px; |
|||
} |
|||
} |
|||
} |
|||
</style> |
@ -0,0 +1,65 @@ |
|||
import type { CrudSchema } from '@/hooks/web/useCrudSchemas' |
|||
import { dateFormatter } from '@/utils/formatTime' |
|||
|
|||
|
|||
export const RecordsDetails = useCrudSchemas(reactive<CrudSchema[]>([ |
|||
|
|||
{ |
|||
label: '检测内容', |
|||
field: 'contents', |
|||
isSearch: true, |
|||
isTable:true, |
|||
}, |
|||
{ |
|||
label: '检测值', |
|||
field: 'detectValue', |
|||
isSearch: false, |
|||
isTable:true, |
|||
}, |
|||
{ |
|||
label: '检测结果', |
|||
field: 'result', |
|||
isSearch: false, |
|||
isTable:true, |
|||
}, |
|||
{ |
|||
label: '上限', |
|||
field: 'upLimit', |
|||
isSearch: false, |
|||
isTable:false, |
|||
}, |
|||
{ |
|||
label: '下限', |
|||
field: 'downLimit', |
|||
isSearch: false, |
|||
isTable:false, |
|||
}, |
|||
{ |
|||
label: '行号', |
|||
field: 'recodeLines', |
|||
isSearch: false, |
|||
isTable:true, |
|||
}, |
|||
{ |
|||
label: '列号', |
|||
field: 'recodeColumns', |
|||
isSearch: false, |
|||
isTable:true, |
|||
}, |
|||
{ |
|||
label: '创建时间', |
|||
field: 'createTime', |
|||
formatter: dateFormatter, |
|||
isSearch: true, |
|||
isTable:true, |
|||
search: { |
|||
component: 'DatePicker', |
|||
componentProps: { |
|||
valueFormat: 'YYYY-MM-DD HH:mm:ss', |
|||
type: 'daterange', |
|||
defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')] |
|||
} |
|||
}, |
|||
isForm: false |
|||
} |
|||
])) |
Loading…
Reference in new issue