yudao-dev/src/views/equipment/base/maintain/items/components/basic-add.js
2024-12-27 15:38:14 +08:00

111 lines
3.1 KiB
JavaScript

/*
* @Author: zwq
* @Date: 2022-08-24 11:19:43
* @LastEditors: zwq
* @LastEditTime: 2024-12-13 15:50:49
* @Description:
*/
export default {
data() {
/* eslint-disable */
return {
urlOptions: {
createURL: '',
updateURL: '',
infoURL: '',
codeURL: '',
getOption: false,
isGetCode: false,
optionArrUrl: [],
optionArr: {}
},
visible: false,
setData: false
}
},
created() {
},
activated() {
},
methods: {
init(id) {
this.dataForm.id = id || "";
this.visible = true;
if (this.urlOptions.getOption) {
this.getArr()
}
this.$nextTick(() => {
this.$refs["dataForm"].resetFields();
if (this.dataForm.id) {
this.urlOptions.infoURL(this.dataForm.id).then(res => {
this.dataForm.id = res.data.id
this.dataForm.program = res.data.program
this.dataForm.resultType = res.data.resultType
// console.log(this.dataForm.maintainResult.search('~'))
if (res.data.resultType === 2 || res.data.maintainResult.search('~') != -1) {
this.dataForm.minValue = res.data.maintainResult.substring(0, res.data.maintainResult.search('~'))
this.dataForm.maxValue = res.data.maintainResult.substring(res.data.maintainResult.search('~') + 1, res.data.maintainResult.length)
this.dataForm.maintainResult = undefined
// = this.dataForm.minValue + '-' + this.dataForm.maxValue
} else {
this.dataForm.minValue = undefined
this.dataForm.maxValue = undefined
this.dataForm.maintainResult = res.data.maintainResult
}
console.log(this.dataForm);
});
}
});
},
getCode() {
this.urlOptions.codeURL()
.then(({ data: res }) => {
this.dataForm.code = res;
})
.catch(() => {});
},
getArr() {
const params = {
pageSize: 100,
pageNo: 1,
}
this.urlOptions.optionArrUrl.forEach((item, index) => {
item(params).then(({ data: res }) => {
this.$set(this.urlOptions.optionArr, `arr${index}`, res.list)
})
.catch(() => {
});
});
},
// 表单提交
dataFormSubmit() {
this.$refs["dataForm"].validate((valid) => {
if (this.dataForm.resultType === 2) {
this.dataForm.maintainResult = this.dataForm.minValue + '~' + this.dataForm.maxValue
}
if (!valid) {
return false;
}
// 修改的提交
if (this.dataForm.id) {
this.urlOptions.updateURL(this.dataForm).then(response => {
this.$modal.msgSuccess("修改成功");
this.visible = false;
this.$emit("refreshDataList");
});
return;
}
// 添加的提交
this.urlOptions.createURL(this.dataForm).then(response => {
this.$modal.msgSuccess("新增成功");
this.visible = false;
this.$emit("refreshDataList");
});
});
},
formClear() {
this.$refs.dataForm.resetFields()
}
}
}