设备修改
This commit is contained in:
parent
ea1683e42e
commit
94f0bfcf58
|
@ -357,53 +357,27 @@
|
|||
<!-- 代理商、运营区、车辆型号一行 -->
|
||||
<el-col :span="8" v-if="userName == 'admin'">
|
||||
<el-form-item label="代理商" prop="deptId">
|
||||
<el-select
|
||||
v-model="form.deptId"
|
||||
clearable
|
||||
filterable
|
||||
placeholder="请选择代理商"
|
||||
@change="handleDeptChange"
|
||||
<el-select v-model="form.deptId" clearable filterable placeholder="请选择代理商" @change="handleDeptChange"
|
||||
style="width: 100%">
|
||||
<el-option
|
||||
v-for="item in deptOptions"
|
||||
:key="item.deptId"
|
||||
:label="item.deptName"
|
||||
:value="item.deptId">
|
||||
<el-option v-for="item in deptOptions" :key="item.deptId" :label="item.deptName" :value="item.deptId">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="运营区" prop="areaId">
|
||||
<el-select
|
||||
v-model="form.areaId"
|
||||
clearable
|
||||
filterable
|
||||
placeholder="请选择运营区"
|
||||
@change="handleAreaChange"
|
||||
<el-select v-model="form.areaId" clearable filterable placeholder="请选择运营区" @change="handleAreaChange"
|
||||
style="width: 100%">
|
||||
<el-option
|
||||
v-for="item in areaOptions"
|
||||
:key="item.areaId"
|
||||
:label="item.areaName"
|
||||
:value="item.areaId">
|
||||
<el-option v-for="item in areaOptions" :key="item.areaId" :label="item.areaName" :value="item.areaId">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="车辆型号" prop="modelId">
|
||||
<el-select
|
||||
v-model="form.modelId"
|
||||
clearable
|
||||
placeholder="请选择车辆型号"
|
||||
@change="handleModelChange"
|
||||
<el-select v-model="form.modelId" clearable placeholder="请选择车辆型号" @change="handleModelChange"
|
||||
style="width: 100%">
|
||||
<el-option
|
||||
v-for="item in modelOptions"
|
||||
:key="item.modelId"
|
||||
:label="item.model"
|
||||
:value="item.modelId">
|
||||
<el-option v-for="item in modelOptions" :key="item.modelId" :label="item.model" :value="item.modelId">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
@ -413,19 +387,11 @@
|
|||
<el-row :gutter="20">
|
||||
<!-- 硬件版本 -->
|
||||
<el-col :span="8">
|
||||
<el-form-item label="硬件版本" prop="hardwareVersionId" v-if="hardwareVersionOptions.length > 0 && userName == 'admin'">
|
||||
<el-select
|
||||
v-model="form.hardwareVersionId"
|
||||
clearable
|
||||
placeholder="请选择硬件版本"
|
||||
:disabled="userName != 'admin'"
|
||||
@change="handleHardwareVersionChange"
|
||||
style="width: 100%">
|
||||
<el-option
|
||||
v-for="item in hardwareVersionOptions"
|
||||
:key="item.id"
|
||||
:label="item.version"
|
||||
:value="item.id">
|
||||
<el-form-item label="硬件版本" prop="hardwareVersionId"
|
||||
v-if="hardwareVersionOptions.length > 0 && userName == 'admin'">
|
||||
<el-select v-model="form.hardwareVersionId" clearable placeholder="请选择硬件版本"
|
||||
:disabled="userName != 'admin'" @change="handleHardwareVersionChange" style="width: 100%">
|
||||
<el-option v-for="item in hardwareVersionOptions" :key="item.id" :label="item.version" :value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
@ -1349,11 +1315,22 @@ handleAreaChange(val) {
|
|||
// this.fetchData(response.data.deptId)
|
||||
// this.open = true;
|
||||
// this.title = "修改设备1";
|
||||
// this.open = true;
|
||||
// this.title = "修改设备";
|
||||
let deptId = '100';
|
||||
if (response.data.deptId == null) {
|
||||
console.log('判断1');
|
||||
|
||||
selectAreaListByDeptId(response.data.deptId).then((res) => {
|
||||
deptId = '100'
|
||||
} else {
|
||||
console.log('判断2');
|
||||
deptId = response.data.deptId;
|
||||
}
|
||||
console.log(deptId, 'deptIddeptIddeptIddeptId');
|
||||
selectAreaListByDeptId(deptId).then((res) => {
|
||||
// 方案1: 使用Vue.set确保响应式更新
|
||||
setTimeout(() => {
|
||||
console.log('=调用了11');
|
||||
|
||||
|
||||
this.$set(this, 'modelOptions', []);
|
||||
this.$set(this, 'areaOptions', []);
|
||||
|
@ -1373,6 +1350,7 @@ handleAreaChange(val) {
|
|||
|
||||
// 不再需要setTimeout和$forceUpdate
|
||||
}).finally(() => {
|
||||
|
||||
this.isUpdating = false;
|
||||
});
|
||||
|
||||
|
@ -1503,20 +1481,59 @@ handleAreaChange(val) {
|
|||
},
|
||||
/** 提交按钮 */
|
||||
submitForm() {
|
||||
this.$refs["form"].validate((valid) => {
|
||||
this.$refs["form"].validate(async (valid) => {
|
||||
if (valid) {
|
||||
try {
|
||||
// 1. 如果选择了运营区,验证运营区与代理商的关系
|
||||
if (this.form.areaId) {
|
||||
const areaResponse = await selectDeptByAreaId(this.form.areaId);
|
||||
const areaDeptId = areaResponse.data.sysDept?.deptId;
|
||||
|
||||
if (this.form.deptId && areaDeptId && this.form.deptId !== areaDeptId) {
|
||||
this.$modal.msgError("所选运营区不属于当前代理商,请重新选择!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 如果选择了代理商,验证车型是否属于该代理商
|
||||
if (this.form.deptId && this.form.modelId) {
|
||||
const deptResponse = await selectAreaListByDeptId(this.form.deptId);
|
||||
const validModels = deptResponse.data.modelList || [];
|
||||
const isValidModel = validModels.some(model => model.modelId === this.form.modelId);
|
||||
|
||||
if (!isValidModel) {
|
||||
this.$modal.msgError("所选车型不属于当前代理商,请重新选择!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 如果选择了运营区和车型,验证车型是否属于该运营区
|
||||
if (this.form.areaId && this.form.modelId) {
|
||||
const areaResponse = await selectDeptByAreaId(this.form.areaId);
|
||||
const validModels = areaResponse.data.modelList || [];
|
||||
const isValidModel = validModels.some(model => model.modelId === this.form.modelId);
|
||||
|
||||
if (!isValidModel) {
|
||||
this.$modal.msgError("所选车型不属于当前运营区,请重新选择!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 所有验证通过后,执行提交操作
|
||||
if (this.form.deviceId != null) {
|
||||
updateDevice(this.form).then((response) => {
|
||||
const response = await updateDevice(this.form);
|
||||
this.$modal.msgSuccess("修改成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
});
|
||||
} else {
|
||||
addDevice(this.form).then((response) => {
|
||||
const response = await addDevice(this.form);
|
||||
this.$modal.msgSuccess("新增成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("提交表单时发生错误:", error);
|
||||
this.$modal.msgError("操作失败:" + (error.message || "未知错误"));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1548,6 +1565,8 @@ handleAreaChange(val) {
|
|||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
<style lang="scss">
|
||||
.el-dialog {
|
||||
.el-form {
|
||||
|
|
Loading…
Reference in New Issue
Block a user