From 52e26a4b285ac4027ff10cc2a07faac3836eba3e Mon Sep 17 00:00:00 2001 From: A0010407 Date: Wed, 12 Jun 2024 17:07:32 +0800 Subject: [PATCH] =?UTF-8?q?2024-06-12=20=E8=AE=BE=E5=A4=87-=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E9=A1=B9=E7=BB=B4=E6=8A=A4-=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/device/item/index.vue | 691 +++++++++++++++++++++++--------- 1 file changed, 508 insertions(+), 183 deletions(-) diff --git a/src/views/device/item/index.vue b/src/views/device/item/index.vue index 0a2d3de..6cbe2f8 100644 --- a/src/views/device/item/index.vue +++ b/src/views/device/item/index.vue @@ -1,6 +1,13 @@ @@ -418,54 +663,80 @@ import { addItem, updateItem, } from "@/api/device/item"; -import { Loading } from 'element-ui'; +import { Loading } from "element-ui"; +import { getToken } from "@/utils/auth"; export default { name: "Item", - dicts: ['device_item_type','device_loop_type'], + dicts: ["device_item_type", "device_loop_type"], data() { return { - activePage: 'check', + // 导入数据 + upload: { + // 是否显示弹出层(用户导入) + open: false, + // 弹出层标题(用户导入) + title: "", + // 是否禁用上传 + isUploading: false, + // 是否更新已经存在的用户数据 + updateSupport: 0, + // 设置上传的请求头部 + headers: { + poolName: localStorage.getItem("USER_POOL_NAME_CURRENT"), + Authorization: "Bearer " + getToken(), + }, + // 上传的地址 + url: process.env.VUE_APP_BASE_API + "/device/item/importFile", + }, + + activePage: "check", // 加载 itemLoading: false, // 设备选择穿梭框 equipmentList: [], selectEquipmentList: [], // 标准列表 - formStandard: [{ - standardType: 'qualitative', - standardName: null, - detailUpLimit: null, - detailDownLimit: null, - detailUnit: null, - }], + formStandard: [ + { + standardType: "qualitative", + standardName: null, + detailUpLimit: null, + detailDownLimit: null, + detailUnit: null, + }, + ], // 日期范围选择快捷 pickerOptions: { - shortcuts: [{ - text: '最近一周', - onClick(picker) { - const end = new Date(); - const start = new Date(); - start.setTime(start.getTime() - 3600 * 1000 * 24 * 7); - picker.$emit('pick', [start, end]); - } - }, { - text: '最近一个月', - onClick(picker) { - const end = new Date(); - const start = new Date(); - start.setTime(start.getTime() - 3600 * 1000 * 24 * 30); - picker.$emit('pick', [start, end]); - } - }, { - text: '最近三个月', - onClick(picker) { - const end = new Date(); - const start = new Date(); - start.setTime(start.getTime() - 3600 * 1000 * 24 * 90); - picker.$emit('pick', [start, end]); - } - }] + shortcuts: [ + { + text: "最近一周", + onClick(picker) { + const end = new Date(); + const start = new Date(); + start.setTime(start.getTime() - 3600 * 1000 * 24 * 7); + picker.$emit("pick", [start, end]); + }, + }, + { + text: "最近一个月", + onClick(picker) { + const end = new Date(); + const start = new Date(); + start.setTime(start.getTime() - 3600 * 1000 * 24 * 30); + picker.$emit("pick", [start, end]); + }, + }, + { + text: "最近三个月", + onClick(picker) { + const end = new Date(); + const start = new Date(); + start.setTime(start.getTime() - 3600 * 1000 * 24 * 90); + picker.$emit("pick", [start, end]); + }, + }, + ], }, // 遮罩层 loading: true, @@ -492,9 +763,9 @@ export default { itemCode: null, itemName: null, itemMethod: null, - itemTools:null, - itemLoop:null, - itemLoopType:null, + itemTools: null, + itemLoop: null, + itemLoopType: null, itemType: null, itemTypeName: null, itemRemark: null, @@ -512,9 +783,9 @@ export default { }, // 表单参数 form: { - itemTools:null, - itemLoop:null, - itemLoopType:null, + itemTools: null, + itemLoop: null, + itemLoopType: null, itemName: null, itemType: null, itemMethod: null, @@ -523,7 +794,7 @@ export default { equipmentCodeList: [], }, // 表单校验 - rules: {} + rules: {}, }; }, created() { @@ -532,12 +803,16 @@ export default { methods: { // 获取设备List-置入穿梭框信息 setTransfer() { - getEquipmentList().then(response => { + getEquipmentList().then((response) => { for (let i = 0; i < response.data.length; i++) { this.equipmentList.push({ - label: response.data[i].equipmentName + '(' + response.data[i].equipmentCode + ')', + label: + response.data[i].equipmentName + + "(" + + response.data[i].equipmentCode + + ")", key: response.data[i].equipmentCode, - }) + }); } }); }, @@ -547,21 +822,21 @@ export default { // 动态增加表单 addStandard() { this.formStandard.push({ - standardType: 'qualitative', + standardType: "qualitative", standardName: null, detailUpLimit: null, detailDownLimit: null, detailUnit: null, - }) + }); }, // 动态删除表单 removeStandard(index) { - this.formStandard.splice(index, 1) + this.formStandard.splice(index, 1); }, /** 查询检查项维护列表 */ getList() { this.loading = true; - listItem(this.queryParams).then(response => { + listItem(this.queryParams).then((response) => { this.itemList = response.rows; this.total = response.total; this.loading = false; @@ -592,15 +867,17 @@ export default { updateTime: null, updateBy: null, formStandard: [], - itemTools:null, + itemTools: null, }; - this.formStandard = [{ - standardType: 'qualitative', - standardName: null, - detailUpLimit: null, - detailDownLimit: null, - detailUnit: null, - }]; + this.formStandard = [ + { + standardType: "qualitative", + standardName: null, + detailUpLimit: null, + detailDownLimit: null, + detailUnit: null, + }, + ]; this.selectEquipmentList = []; this.equipmentList = []; this.resetForm("form"); @@ -621,17 +898,17 @@ export default { }, // 多选框选中数据 handleSelectionChange(selection) { - this.ids = selection.map(item => item.itemId) - this.single = selection.length !== 1 - this.multiple = !selection.length + this.ids = selection.map((item) => item.itemId); + this.single = selection.length !== 1; + this.multiple = !selection.length; }, /** 新增按钮操作 */ handleAdd() { this.reset(); this.setTransfer(); this.form.itemLoop = 1; - this.form.itemLoopType = 'day'; - this.activePage = 'check'; + this.form.itemLoopType = "day"; + this.activePage = "check"; this.open = true; this.title = "新增检查项"; }, @@ -639,16 +916,16 @@ export default { handleUpdate(row) { this.loading = true; this.reset(); - this.activePage = 'check'; + this.activePage = "check"; this.setTransfer(); - const itemId = row.itemId || this.ids - getItem(itemId).then(response => { + const itemId = row.itemId || this.ids; + getItem(itemId).then((response) => { this.form = response.data; - getEquipmentCodeList(row.itemCode).then(response => { + getEquipmentCodeList(row.itemCode).then((response) => { for (let i = 0; i < response.data.length; i++) { this.selectEquipmentList.push(response.data[i]); } - }) + }); this.formStandard = response.data.formStandard; this.loading = false; @@ -662,23 +939,23 @@ export default { if (this.form.itemName == null) { this.$message({ message: "请输入检查项名称!", - type: "warning" - }) - return + type: "warning", + }); + return; } if (this.form.itemType == null) { this.$message({ message: "请选择维护类型!", - type: "warning" - }) - return + type: "warning", + }); + return; } if (this.form.itemMethod == null) { this.$message({ message: "请输入检查方法!", - type: "warning" - }) - return + type: "warning", + }); + return; } // if (this.selectEquipmentList.length == 0) { // this.$message({ @@ -689,55 +966,55 @@ export default { // } for (let i = 0; i < this.formStandard.length; i++) { // 如果为定性 - if (this.formStandard[i].standardType == 'qualitative') { + if (this.formStandard[i].standardType == "qualitative") { if (this.formStandard[i].standardName == null) { this.$message({ message: "请输入标准名称!", - type: "warning" - }) - return + type: "warning", + }); + return; } } // 如果为定量 - if (this.formStandard[i].standardType == 'quantify') { + if (this.formStandard[i].standardType == "quantify") { if (this.formStandard[i].standardName == null) { this.$message({ message: "请输入标准名称!", - type: "warning" - }) - return + type: "warning", + }); + return; } if (this.formStandard[i].detailUpLimit == null) { this.$message({ message: "请输入上限!", - type: "warning" - }) - return + type: "warning", + }); + return; } if (this.formStandard[i].detailDownLimit == null) { this.$message({ message: "请输入下限!", - type: "warning" - }) - return + type: "warning", + }); + return; } if (this.formStandard[i].detailUnit == null) { this.$message({ message: "请输入单位!", - type: "warning" - }) - return + type: "warning", + }); + return; } } } - this.$refs["form"].validate(valid => { + this.$refs["form"].validate((valid) => { if (valid) { this.itemLoading = true; if (this.form.itemId != null) { this.form.formStandard = this.formStandard; this.form.equipmentCodeList = this.selectEquipmentList; - updateItem(this.form).then(response => { + updateItem(this.form).then((response) => { this.itemLoading = false; if (response.code != 500) { this.$modal.msgSuccess("修改成功"); @@ -748,9 +1025,9 @@ export default { } else { this.form.formStandard = this.formStandard; this.form.equipmentCodeList = this.selectEquipmentList; - addItem(this.form).then(response => { + addItem(this.form).then((response) => { this.itemLoading = false; - if (response.code != 500){ + if (response.code != 500) { this.$modal.msgSuccess("新增成功"); this.open = false; this.getList(); @@ -764,17 +1041,17 @@ export default { handleDelete(row) { const itemIds = row.itemId || this.ids; - var itemCodes = ''; + var itemCodes = ""; // 处理信息 for (let i = 0; i < this.itemList.length; i++) { for (let j = 0; j < itemIds.length; j++) { if (itemIds[j] == this.itemList[i].itemId) { - itemCodes = itemCodes + this.itemList[i].itemCode + ','; + itemCodes = itemCodes + this.itemList[i].itemCode + ","; } } } - if (itemCodes == '') { + if (itemCodes == "") { for (let i = 0; i < this.itemList.length; i++) { if (itemIds == this.itemList[i].itemId) { itemCodes = this.itemList[i].itemCode; @@ -782,24 +1059,72 @@ export default { } } - this.$modal.confirm('是否确认删除检查项维护编号为"' + itemCodes + '"的数据项?').then(function () { - return delItem(itemIds); - }).then(response => { - if (response.code != 500) { - this.$modal.msgSuccess("删除成功"); - this.getList(); - } - }).catch(() => { - }); - + this.$modal + .confirm('是否确认删除检查项维护编号为"' + itemCodes + '"的数据项?') + .then(function () { + return delItem(itemIds); + }) + .then((response) => { + if (response.code != 500) { + this.$modal.msgSuccess("删除成功"); + this.getList(); + } + }) + .catch(() => {}); }, /** 导出按钮操作 */ handleExport() { - this.download('device/item/export', { - ...this.queryParams - }, `item_${new Date().getTime()}.xlsx`) - } - } + this.download( + "device/item/export", + { + ...this.queryParams, + }, + `item_${new Date().getTime()}.xlsx` + ); + }, + + // 导入-导入窗口打开 + handleImport() { + console.log("导入按钮"); + this.upload.title = "检查项导入"; + this.upload.open = true; + }, + + // 导入-文件上传中处理 + handleFileUploadProgress(event, file, fileList) { + this.upload.isUploading = true; + }, + + // 导入-文件上传成功处理 + handleFileSuccess(response, file, fileList) { + debugger; + this.upload.open = false; + this.upload.isUploading = false; + this.$refs.upload.clearFiles(); + this.$alert( + "
" + + response.msg + + "
", + "导入结果", + { dangerouslyUseHTMLString: true } + ); + this.getList(); + }, + + // 导入-提交上传文件 + submitFileForm() { + this.$refs.upload.submit(); + }, + + // 导入-下载模板 + importTemplate() { + this.download( + "/device/item/importTemplate", + {}, + `item_template_${new Date().getTime()}.xlsx` + ); + }, + }, };