addDialog.vue
6.31 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
<!-- 新增/编辑类目 -->
<template>
<baseDialog :dialog-config="dialogConfig"
:is-show.sync="visible"
class="accountDailog"
@handleClick="handleAddConfirm">
<div class="add-dialog">
<glsx-combi-form class="edit-form-container"
ref="addFormRef"
label-width="150px"
default-width="400px"
:form-ref="editChildRef"
:form-obj="infoForm"
:form-data="editFormData"
:form-rules="formRules">
<div slot="parentCategoryHtml"
slot-scope="scope">
<el-cascader v-model="infoForm.parentId"
:options="baseData.parentCategory"
:props="cascader_props"
style="width: 400px"></el-cascader>
</div>
</glsx-combi-form>
</div>
</baseDialog>
</template>
<script>
import { addGoodsCategory_new, updateGoodsCategory, queryParent } from '@api/sceneCategory'
import { Util, deepClone } from '@/common/util'
export default {
name: 'AddDialog',
data() {
return {
infoForm: {
categoryName: '',
parentId: ''
},
dialogConfig: {
title: '新增类目',
width: '720px'
},
editChildRef: 'editChildRef',
formRules: {
categoryName: [{ required: true, message: '请填写类目名', trigger: 'blur' }]
},
editFormData: [{
label: '所属类目',
name: 'parentId',
isHide: true,
addHtml: 'parentCategoryHtml',
rules: [{ required: true, message: '请选择所属类目', trigger: 'change' }]
}, {
label: '类目名',
name: 'categoryName',
type: 'input',
maxlength: 20,
showLimit: true,
isClear: true
}],
baseData: {
// pointClassificationOpt: [],
parentCategory: []
},
cascader_props: {
checkStrictly: true,
children: 'children',
value: 'id',
label: 'categoryName'
}
}
},
props: {
addVisible: {
type: Boolean,
default: false
},
categoryInfo: {
type: Object,
default: () => { }
}
},
watch: {
},
computed: {
visible: {
get() {
return this.addVisible
},
set(newVal) {
this.$emit('dialogClose', { flag: newVal, attrName: 'addVisible' })
}
}
},
mounted() {
this.showTitle()
},
methods: {
getOptionsList(formName, hasAll = true, refreshSigle) {
if (refreshSigle) {
var item = this[formName].find(k => k.name == refreshSigle)
var index = this[formName].findIndex(k => k.name == refreshSigle)
this.$set(this[formName][index], 'optionList', deepClone(this.baseData[item.optionsName]))
if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
const temp = {}
temp[this[formName][index].optionId] = ''
temp[this[formName][index].optionLabel] = '全部'
this[formName][index].optionList.unshift(temp)
}
} else {
this[formName].forEach((item, index) => {
if (item.type === 'select' && this.baseData[item.optionsName].length) {
this.$set(this[formName][index], 'optionList', deepClone(this.baseData[item.optionsName]))
if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
const temp = {}
temp[this[formName][index].optionId] = ''
temp[this[formName][index].optionLabel] = '全部'
this[formName][index].optionList.unshift(temp)
}
}
})
}
},
showTitle() {
console.log('this.categoryInfo', this.categoryInfo)
if (this.categoryInfo) {
if (this.categoryInfo.type == 'edit') {
this.dialogConfig.title = '编辑类目'
this.infoForm.categoryName = this.categoryInfo.categoryName
if (this.categoryInfo.level == 3) {
this.showOrHideAttr('editFormData', '所属类目', false)
this.queryParent()
}
} else if (this.categoryInfo.type == 'addChild') {
this.dialogConfig.title = '添加子类目'
}
}
},
queryParent() {
var params = {}
params.categoryType = this.categoryInfo.categoryType
params.level = 2
queryParent(params).then((res) => {
this.baseData.parentCategory.push(res)
this.infoForm.parentId = this.categoryInfo.parentId
// this.getOptionsList('editFormData', false)
})
},
showOrHideAttr(formName, label, isHide) {
const idx = this[formName].findIndex(item => item.label == label)
this[formName][idx].isHide = isHide
},
handleAddConfirm() {
this.$refs.addFormRef.$refs[this.editChildRef].validate(valid => {
if (valid) {
let api = addGoodsCategory_new
// var params = deepClone(this.infoForm)
var params = {}
params.categoryName = this.infoForm.categoryName
if (this.categoryInfo.type == 'addChild') {
params.parentId = this.categoryInfo.id
} else if (this.categoryInfo.type == 'edit') {
params.id = this.categoryInfo.id
if (this.categoryInfo.level == 3) { // 编辑三级类目时需要传所属类目id
// return console.log(this.infoForm.parentId.length)
if (this.infoForm.parentId.length && this.infoForm.parentId.length > 0) {
params.parentId = this.infoForm.parentId.pop()
} else {
params.parentId = this.infoForm.parentId
}
}
api = updateGoodsCategory
}
api(params).then(res => {
this.notice.okTips('操作成功')
this.visible = true
})
}
})
}
}
}
</script>
<style lang="scss" scoped>
.add-dialog {
margin: 20px 0;
.reject-input {
::v-deep .el-textarea__inner {
height: 70px;
}
}
.el-textarea .el-input__count {
right: 90px;
bottom: -10px;
font-size: 12px;
color: #999999;
}
.tips {
color: #999999;
}
}
</style>