closeStoreDialog.vue
7.11 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<!-- 关店确认弹窗 -->
<template>
<el-dialog title="关店确认" class="close-dialog" :visible.sync="visible" width="700px" @close="handleClose"
:close-on-click-modal="false">
<glsx-combi-form ref="editFormRef" class="edit-form-container" default-width="400px" :default-width="defaultWidth"
:form-data="editFormData" :form-obj="addForm" :form-ref="editChildRef" :form-rules="formRules" :is-block="isBlock"
:label-width="labelWidth">
<template #confirmResultHtml>
<el-radio-group v-model="addForm.confirmResult" @change="handleResultChange">
<el-radio :label="1">是</el-radio>
<el-radio :label="2">否</el-radio>
</el-radio-group>
</template>
</glsx-combi-form>
<div slot="footer" class="dialog-footer">
<el-button @click="handleClose">取消</el-button>
<el-button type="primary" @click="handleSubmit" :loading="loading">确定</el-button>
</div>
</el-dialog>
</template>
<script>
import { closeStoreConfirm } from '@api/salesManagement'
export default {
name: 'CloseStoreDialog',
props: {
dialogVisible: {
type: Boolean,
default: false
},
recordInfo: {
type: Object,
default: () => null
}
},
data() {
return {
loading: false,
labelWidth: "140px",
defaultWidth: "400px",
editChildRef: "editChildRef",
isBlock: true,
addForm: {
confirmResult: 1, // 默认选是
confirmReason: '合作渗透率连续未达标,终止合作', // 默认原因
confirmRemark: ''
},
editFormData: [
{
label: "是否关闭此门店",
name: "confirmResult",
addHtml: "confirmResultHtml",
},
{
label: "关店原因",
name: "confirmReason",
type: "select",
isClear: true,
optionList: [
{ label: '合作渗透率连续未达标,终止合作', value: '合作渗透率连续未达标,终止合作' },
{ label: '无人员稳定在岗', value: '无人员稳定在岗' },
{ label: '三方切换', value: '三方切换' },
{ label: '其他', value: '其他' }
],
optionId: "value",
optionLabel: "label",
isHide: false,
changeAttr: (value) => {
const index = this.editFormData.findIndex(item => item.name === 'confirmRemark');
if (index > -1) {
if (value !== '其他') {
this.addForm.confirmRemark = ''
}
this.$set(this.editFormData[index], 'isHide', value !== '其他');
}
}
},
{
label: "关店原因",
name: "confirmRemark",
placeholder: "请输入",
type: "textarea",
showLimit: true,
isClear: true,
maxlength: 100,
rows: 4,
isHide: true
}
],
formRules: {
confirmResult: [
{ required: true, message: '请选择是否关闭此门店', trigger: 'change' }
],
confirmReason: [
{
required: true, validator: (rule, value, callback) => {
if (this.addForm.confirmResult === 1 && !value) {
callback(new Error('请选择关店原因'));
} else {
callback();
}
}, trigger: 'change'
}
],
// confirmRemark: [
// {
// required: true, validator: (rule, value, callback) => {
// if (this.addForm.confirmResult === 1 && this.addForm.confirmReason === '其他' && !value) {
// callback(new Error('请输入关店原因'));
// } else {
// callback();
// }
// }, trigger: 'blur'
// }
// ]
}
}
},
computed: {
visible: {
get() {
return this.dialogVisible
},
set(val) {
this.$emit('update:dialogVisible', val)
}
}
},
watch: {
dialogVisible(val) {
if (val) {
this.addForm = {
confirmResult: 1,
confirmReason: '合作渗透率连续未达标,终止合作',
confirmRemark: ''
}
// 重置时也需要恢复动态显示状态
const reasonIdx = this.editFormData.findIndex(item => item.name === 'confirmReason');
const remarkIdx = this.editFormData.findIndex(item => item.name === 'confirmRemark');
if (reasonIdx > -1) this.$set(this.editFormData[reasonIdx], 'isHide', false);
if (remarkIdx > -1) this.$set(this.editFormData[remarkIdx], 'isHide', true);
if (this.$refs.editFormRef && this.$refs.editFormRef.$refs[this.editChildRef]) {
this.$refs.editFormRef.$refs[this.editChildRef].clearValidate()
}
}
}
},
methods: {
handleClose() {
this.visible = false
},
handleResultChange(val) {
const reasonIdx = this.editFormData.findIndex(item => item.name === 'confirmReason');
const remarkIdx = this.editFormData.findIndex(item => item.name === 'confirmRemark');
if (val === 2) {
if (reasonIdx > -1) this.$set(this.editFormData[reasonIdx], 'isHide', true);
if (remarkIdx > -1) this.$set(this.editFormData[remarkIdx], 'isHide', true);
this.addForm.confirmReason = '';
this.addForm.confirmRemark = '';
} else {
if (reasonIdx > -1) this.$set(this.editFormData[reasonIdx], 'isHide', false);
this.addForm.confirmReason = '合作渗透率连续未达标,终止合作';
if (remarkIdx > -1) this.$set(this.editFormData[remarkIdx], 'isHide', true);
}
if (this.$refs.editFormRef && this.$refs.editFormRef.$refs[this.editChildRef]) {
this.$refs.editFormRef.$refs[this.editChildRef].clearValidate();
}
},
handleSubmit() {
this.$refs.editFormRef.$refs[this.editChildRef].validate((valid) => {
if (valid) {
this.loading = true
const params = {
id: this.recordInfo.id,
confirmResult: this.addForm.confirmResult,
}
if (this.addForm.confirmResult === 1) {
params.confirmReason = this.addForm.confirmReason
if (this.addForm.confirmReason === '其他' && this.addForm.confirmRemark !== '') {
params.confirmReason = '其他-' + this.addForm.confirmRemark
// params.confirmRemark = this.addForm.confirmRemark
}
}
closeStoreConfirm(params).then(() => {
this.$message.success('操作成功')
this.loading = false
this.visible = false
this.$emit('refresh')
}).catch(() => {
this.loading = false
})
}
})
}
}
}
</script>
<style scoped lang="scss">
.close-dialog {
::v-deep {
.el-input__count {
right: 10px !important;
bottom: 1px !important;
font-size: 12px;
color: #999999;
}
}
::v-deep {
.el-dialog__footer {
border-top: 1px solid #e5e5e5 !important;
}
}
::v-deep .el-dialog__header {
border-bottom: 1px solid #e5e5e5;
}
}
</style>