Files
yudao-dev/src/views/equipment/base/inspection/Confirm/attr-add.vue
‘937886381’ 0029af4ffa 设备
2024-08-01 16:33:56 +08:00

179 lines
4.8 KiB
Vue

<template>
<el-dialog :visible.sync="visible" :width="'35%'" :append-to-body="true" :close-on-click-modal="false" class="dialog">
<template #title>
<slot name="title">
<div class="titleStyle">
{{ !dataForm.id ? '新增' : '编辑' }}
</div>
</slot>
</template>
<el-form ref="dataForm" :model="dataForm" :rules="dataRule" label-width="auto"
@keyup.enter.native="dataFormSubmit()">
<el-form-item label="设备名称" prop="equipmentId">
<el-select @change="handleChange" v-model="dataForm.equipmentId" filterable clearable placeholder="请选择设备名称"
style="width: 100%">
<el-option v-for="dict in eqList" :key="dict.id" :label="dict.name" :value="dict.id" />
</el-select>
</el-form-item>
<el-form-item label="巡检项目" prop="program">
<el-select v-model="dataForm.program" filterable style="width: 100%" placeholder="请选择巡检项目"
@change="handleDecChange">
<el-option v-for="dict in programList" :key="dict.id" :label="dict.program" :value="dict.program" />
</el-select>
</el-form-item>
<el-form-item label="默认巡检结果" prop="checkResult">
<el-input v-model="dataForm.checkResult" placeholder="请输入默认巡检结果" clearable />
</el-form-item>
</el-form>
<el-row style="text-align: right">
<el-button @click="visible = false">取消</el-button>
<el-button type="primary" @click="dataFormSubmit()">确定</el-button>
</el-row>
</el-dialog>
</template>
<script>
import { createCheckOrderDet, updateCheckOrderDet, getCheckOrderDet } from "@/api/equipment/base/inspection/settings";
import { getItemPageData } from "@/api/equipment/base/inspection/items";
import { getEquipmentPage } from '@/api/base/equipment'
export default {
props: {
orderId: {
type: String,
default: '',
},
},
data() {
return {
visible: false,
dataForm: {
id: null,
equipmentId: null,
program: null,
checkResult: null
},
eqList: [],
dataRule: {
equipmentId: [
{ required: true, message: '设备不能为空', trigger: 'blur' },
],
program: [
{ required: true, message: '巡检项目不能为空', trigger: 'blur' },
],
checkResult: [
{ required: true, message: '巡检结果不能为空', trigger: 'blur' },
]
},
};
},
mounted() {
this.getDict();
},
methods: {
async getDict() {
const res = await getEquipmentPage({
pageNo: 1,
pageSize: 100,
special: false
})
this.eqList = res.data.list
},
handleDecChange(val) {
let checkResult = undefined
this.programList.forEach((ele) => {
if (ele.program == val) {
checkResult = ele.checkResult
}
})
this.dataForm.checkResult = checkResult
},
async handleChange(val) {
console.log(val);
let equipmentTypeId = undefined
this.eqList.forEach((ele) => {
if (ele.id == val) {
equipmentTypeId = ele.equipmentTypeId
}
})
const { code, data } = await getItemPageData({
pageNo: 1,
pageSize: 99,
equipmentTypeId: equipmentTypeId,
})
this.programList = data.list
console.log(data);
},
init(id) {
this.dataForm.id = id || '';
this.visible = true;
this.$nextTick(() => {
this.$refs['dataForm'].resetFields();
if (this.dataForm.id) {
getCheckOrderDet(this.dataForm.id).then((res) => {
const { equipmentId, program, checkResult } = res.data;
this.dataForm.equipmentId = equipmentId;
this.dataForm.program = program;
this.dataForm.checkResult = checkResult;
});
}
});
},
// 表单提交
dataFormSubmit() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
// 修改的提交
if (this.dataForm.id) {
updateCheckOrderDet({
...this.dataForm,
orderId: this.orderId,
}).then((response) => {
this.$modal.msgSuccess('修改成功');
this.visible = false;
this.$emit('refreshDataList');
});
return;
}
// 添加的提交
createCheckOrderDet({
...this.dataForm,
orderId: this.orderId,
}).then((response) => {
this.$modal.msgSuccess('新增成功');
this.visible = false;
this.$emit('refreshDataList');
});
}
});
},
},
};
</script>
<style scoped>
.dialog >>> .el-dialog__body {
padding: 30px 24px;
}
.dialog >>> .el-dialog__header {
font-size: 16px;
color: rgba(0, 0, 0, 0.85);
font-weight: 500;
padding: 13px 24px;
border-bottom: 1px solid #e9e9e9;
}
.dialog >>> .el-dialog__header .titleStyle::before {
content: '';
display: inline-block;
width: 4px;
height: 16px;
background-color: #0b58ff;
border-radius: 1px;
margin-right: 8px;
position: relative;
top: 2px;
}
</style>