<!--
* @Description:
* @Author: Ran junlin
* @Date: 2023-08-05 15:16:55
* @LastEditTime: 2023-09-19 17:13:33
* @LastEditors: Ran junlin
-->
<template>
<el-form
style="width: 100%"
size="mini"
:model="form"
:rules="rules"
ref="form"
label-width="220px"
label-position="right"
>
<!-- 基本信息 -->
<div class="font_16 font_bold l_h_100_per flex-between">
<span class="title-red">设置设备库存在低于配置的该数量时,进行预警</span>
<el-button size="small" type="primary" :loading="pending" @click="save">保存</el-button>
</div>
<el-form-item label="是否开启预警:" prop="openStatus">
<el-radio-group v-model="form.openStatus">
<el-radio label="Y">开启</el-radio>
<el-radio label="N">不开启</el-radio>
</el-radio-group>
</el-form-item>
<!-- v-if="form.openStatus === 'Y'" -->
<template>
<div class="dis_grid grid_tem_col_rep_2_1fr">
<el-form-item
v-for="(item, index) in form.earlyWarningConfig"
:key="index"
:label="item.earlyWarningTypeName + '预警库存数:'"
:prop="'earlyWarningConfig.' + index + '.earlyWarningNum'"
:rules="getValidationRules(item)"
>
<!-- @change="handleInputChange(index)" -->
<el-input-number
:ref="`earlyWarningConfig.${index}.earlyWarningNum`"
v-model="item.earlyWarningNum"
@change="handleInputChange(index)"
:min="0"
></el-input-number>
</el-form-item>
</div>
</template>
</el-form>
</template>
<script>
import { engineersEarlyWarning, engineersEarlyWarningSave } from '@/api/customer/engineer';
export default {
name: 'chargeWarn',
props: {
infoForm: {
type: Object,
default: () => ({})
}
},
computed: {
rules() {
return {
earlyWarningNum: [{ required: true, message: '请输入', trigger: 'blur' }],
openStatus: [{ required: true, message: '请输入选择', trigger: 'blur' }]
};
}
},
data() {
return {
pending: false,
form: {
openStatus: 'N',
earlyWarningConfig: [
{ earlyWarningNum: 0, earlyWarningType: 'WIRELESS', earlyWarningTypeName: '无线设备' },
{ earlyWarningNum: 0, earlyWarningType: 'WIRED', earlyWarningTypeName: '有线设备' },
{ earlyWarningNum: 0, earlyWarningType: 'WIRELESS_REPLENISH', earlyWarningTypeName: '无线设备补货' },
{ earlyWarningNum: 0, earlyWarningType: 'WIRED_REPLENISH', earlyWarningTypeName: '有线设备补货' }
]
}
};
},
created() {
},
methods: {
getValidationRules(item) {
return [
{ required: true, message: '请输入数量', trigger: 'change' },
{
validator: (rule, value, callback) => {
const wiredReplenishNum = this.form.earlyWarningConfig.find(
config => config.earlyWarningType === 'WIRED_REPLENISH'
).earlyWarningNum;
const wirelessReplenishNum = this.form.earlyWarningConfig.find(
config => config.earlyWarningType === 'WIRELESS_REPLENISH'
).earlyWarningNum;
const WIREDNum = this.form.earlyWarningConfig.find(
config => config.earlyWarningType === 'WIRED'
).earlyWarningNum;
const WIRELESSNum = this.form.earlyWarningConfig.find(
config => config.earlyWarningType === 'WIRELESS'
).earlyWarningNum;
if (item.earlyWarningType === 'WIRED' && value >= wiredReplenishNum) {
callback(new Error('有线设备数量必须小于有线设备补货'));
}
if (item.earlyWarningType === 'WIRELESS' && value >= wirelessReplenishNum) {
callback(new Error('无线设备数量必须小于无线设备补货'));
}
if (item.earlyWarningType === 'WIRED_REPLENISH' && value <= WIREDNum) {
callback(new Error('有线设备数量必须大于有线设备补货'));
}
if (item.earlyWarningType === 'WIRELESS_REPLENISH' && value <= WIRELESSNum) {
callback(new Error('无线设备数量必须大于无线设备补货'));
}
callback();
},
trigger: 'blur'
}
];
},
handleInputChange() {
this.$refs.form.validate();
},
async getEngineersEarlyWarning() {
try {
this.pending = true;
const { engineerNo } = this.infoForm;
const data = await engineersEarlyWarning(engineerNo);
console.log(data);
const { openStatus, earlyWarningConfig } = data;
this.form = {
openStatus,
earlyWarningConfig
};
} catch (error) {
this.$message.error(error);
} finally {
this.pending = false;
}
},
async save() {
try {
const validationResult = await this.$refs.form.validate();
if (!validationResult) {
throw new Error('请检查表单数据');
}
this.pending = true;
const { engineerNo } = this.infoForm;
await engineersEarlyWarningSave({ ...this.form, engineerNo });
await this.getEngineersEarlyWarning();
this.msg({
type: 'success',
content: '保存成功'
});
} catch (error) {
this.msg({
type: 'error',
content: error || '请检查表单数据'
});
} finally {
this.pending = false;
}
}
}
};
</script>
<style lang="scss" scoped>
.title-red {
color: red;
margin-bottom: 10px;
font-size: 15px;
}
</style>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205