warningSet.vue
4.85 KB
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
<template>
<d2-dialog
title="预警设置"
:is-visible="warningVisible"
class="warningDailog"
width="750px"
btn-ok-label="确定"
@closeDialog="handleClose"
@confirmDialog="handleAddConfirm"
>
<p class="title">延保</p>
<glsx-combi-form
label-width="150px"
default-width="400px"
:form-obj="warningForm"
:form-data="warningFormData"
></glsx-combi-form>
<p class="title">权益</p>
<glsx-combi-form
label-width="150px"
default-width="400px"
:form-obj="warningForm"
:form-data="warningFormData2"
></glsx-combi-form>
<div class="explain">
说明:设置业务兜底指标,按每月进行实时监测,一旦低于设置的指标+3%时,系统自动进行预警。
</div>
</d2-dialog>
</template>
<script>
import { limitPrice } from "@/common/format"
import {
saveOrUpdateWarningConfig,
findWarningConfig
} from "@/api/shopConfig.js"
export default {
data() {
return {
isFlag: true,
warningForm: {
id: "",
merchantNo: "",
ewConRate: "", //延保转化率
ewAxbConRate: "", //延保安心包转化率
ewLtConRate: "", //延保轮胎转化率
riConRate: "" //权益转化率
},
oldVal: {
ewConRate: "", //延保转化率
ewAxbConRate: "", //延保安心包转化率
ewLtConRate: "", //延保轮胎转化率
riConRate: "" //权益转化率
},
warningFormData: [
{
label: "转化率",
name: "ewConRate",
type: "input",
append: "%",
listeners: {
input: () => {
this.handleInput(this.warningForm.ewConRate, "ewConRate")
}
}
},
{
label: "安心包转化率",
name: "ewAxbConRate",
type: "input",
append: "%",
listeners: {
input: () => {
this.handleInput(this.warningForm.ewAxbConRate, "ewAxbConRate")
}
}
},
{
label: "轮胎转化率",
name: "ewLtConRate",
type: "input",
append: "%",
listeners: {
input: (e) => {
this.handleInput(this.warningForm.ewLtConRate, "ewLtConRate")
}
}
}
],
warningFormData2: [
{
label: "转化率",
name: "riConRate",
type: "input",
append: "%",
listeners: {
input: (e) => {
this.handleInput(this.warningForm.riConRate, "riConRate")
}
}
}
]
}
},
props: {
warningVisible: {
type: Boolean,
default: false
},
info: {
type: Object,
default: () => {}
}
},
watch: {
warningVisible(val) {
if (val) {
this.getData()
}
}
},
mounted() {
// console.log(this.info)
// this.warningForm.merchantNo = this.info.merchantId
// this.getData()
},
methods: {
async getData() {
const details = await findWarningConfig({
merchantNo: this.info.merchantId
})
if (details) {
this.warningForm = details
} else {
this.warningForm = {
id: "",
merchantNo: "",
ewConRate: "", //延保转化率
ewAxbConRate: "", //延保安心包转化率
ewLtConRate: "", //延保轮胎转化率
riConRate: ""
}
}
},
handleInput(newVal, name) {
newVal = newVal.replace(/[^\d.]/g, "") // 清除“数字”和“.”以外的字符
this.warningForm[name] = limitPrice(
newVal,
this.oldVal[name],
3,
2,
0,
100
)
this.oldVal[name] = this.warningForm[name]
},
async handleAddConfirm() {
if (this.isFlag) {
this.isFlag = false
try {
let params = {
id: this.warningForm.id,
merchantNo: this.warningForm.merchantNo || this.info.merchantId,
ewConRate: this.warningForm.ewConRate,
ewAxbConRate: this.warningForm.ewAxbConRate,
ewLtConRate: this.warningForm.ewLtConRate,
riConRate: this.warningForm.riConRate
}
const res = await saveOrUpdateWarningConfig(params)
if (res) {
this.$message.success("保存成功")
this.warningVisible = false
this.$emit("confirmWarnDialog")
}
} catch (error) {
this.$message.error(error)
} finally {
this.isFlag = true
}
}
},
handleClose() {
this.$emit("closeWarnDialog")
}
}
}
</script>
<style scoped lang="scss">
.warningDailog {
.title {
color: #292d33;
font-size: 15px;
font-weight: bold;
}
.explain {
color: #999ea8;
font-size: 14px;
}
}
</style>