GoodsInfo.vue
10 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<!-- 编辑 - 上架商品及测算 -->
<template>
<div class="edit-page goods-info">
<div class="title">
<span>上架商品</span>
<!-- <span class="addBtnSpan"
><el-button
type="primary"
size="small"
icon="el-icon-plus"
@click="addPop"
>新增</el-button
></span
> -->
</div>
<div class="check-tab">
<el-tabs v-model="tabsValue" type="card" class="my-tab-pane">
<el-tab-pane v-for="(item, idx) in goodTabs" :key="item.name" :name="item.name">
<span slot="label"><i class="el-icon-warning car-error-txt" v-if="item.valiadError == 'Y'" />{{ item.title ?
item.title + (idx + 1) : item.goodsName }}
</span>
<span>
<good-tab :info="item.info" :tab-idx="item.tabIndex" />
</span>
</el-tab-pane>
<el-tab-pane v-for="(item, idx) in packageTabs" :key="item.name" :label="item.title" :name="item.name">
<span slot="label"><i class="el-icon-warning car-error-txt" v-if="item.valiadError == 'Y'" />{{ item.title ?
item.title + (idx + 1) : item.goodsName }}
</span>
<span>
<package-tab :info="item.info" :tab-idx="item.tabIndex" @packageEditInfo="getPackageEditInfo_notice" />
</span>
</el-tab-pane>
<!-- <el-tab-pane key="add"
name="add"> -->
<!-- //这是增加的按钮 -->
<!-- <span slot="label"
style="padding: 8px; font-size: 20px; font-weight: bold">+</span>
</el-tab-pane> -->
</el-tabs>
</div>
<!-- <div style="padding: 20px;">
<div>啦啦啦</div>
</div> -->
<d2-dialog title="选择商品或套餐" v-if="chooseVisible" :is-visible="chooseVisible" @closeDialog="handleSignClose"
@confirmDialog="handleConfirmSign">
<glsx-combi-form :is-block="true" class="edit-form-container" ref="editFormRef" label-width="220px"
default-width="400px" :form-obj="integralForm" :form-data="integralFormData">
</glsx-combi-form>
</d2-dialog>
</div>
</template>
<script>
import { getGoodsDetail } from "@api/shelfManage.js"
import goodTab from "./common/goodTab.vue"
import packageTab from "./common/packageTab.vue"
import { deepClone } from "@/common/util"
export default {
name: "GoodsInfo",
props: {
recordId: {
type: Number,
default: null
}
},
components: {
goodTab,
packageTab
},
data() {
// 这里存放数据
return {
chooseVisible: false,
integralForm: {
goodItem: "1"
},
integralFormData: [
{
label: "新增选择",
name: "goodItem",
type: "radio",
optionId: "confId",
optionLabel: "confName",
optionList: [
{ confId: "1", confName: "商品" },
{ confId: "2", confName: "套餐" }
],
handleRadioChange: (val) => { }
}
],
tabsValue: "1",
currentIndex: 1,
addIndex: 1,
tabIndex: 1,
goodTabs: [],
packageTabs: [],
goodInfoList: [],
packageInfoList: [],
goodsInfo: {}
}
},
computed: {
routeInfo() {
return this.$route.params
}
},
mounted() {
this.getDetail()
},
methods: {
submitParamsPackages() {
return this.goodsInfo.packageGoodsList
},
getDetail() {
console.log("getGoodsDetail")
// this.recordId
getGoodsDetail({ id: this.routeInfo.id })
.then((res) => {
console.log(res, "getGoodsDetail")
this.goodsInfo = res
const goodsList = deepClone(res.goodsList)
const packageGoodsList = deepClone(res.packageGoodsList)
goodsList.forEach((item, idx) => {
const length = this.goodTabs.length
const tabIndex =
length == 0 ? length : this.goodTabs[length - 1].tabIndex + 1
this.goodTabs.push({
goodsName: item.goodsName,
name: "good_" + tabIndex,
tabIndex: tabIndex,
// goodId: item.id,
info: item
})
this.tabsValue = "good_" + tabIndex
})
packageGoodsList.forEach((item, idx) => {
const length = this.packageTabs.length
const tabIndex =
length == 0 ? length : this.packageTabs[length - 1].tabIndex + 1
this.packageTabs.push({
goodsName: item.packageName,
name: "package_" + tabIndex,
tabIndex: tabIndex,
// goodId: item.id,
info: item
})
this.tabsValue = "package_" + tabIndex
})
this.packageNotice()
})
.catch((err) => {
console.log(err)
})
},
addPop() {
this.chooseVisible = true
},
handleSignClose() {
this.chooseVisible = false
},
handleConfirmSign() {
this.chooseVisible = false
this.addTab(this.integralForm.goodItem)
},
/* 活动标签切换时触发 */
beforeLeave(currentName, oldName) {
// console.log("currentName", currentName)
// 通过tab标签的切换事件触发增加的函数
// 如果name是add,则调用增加tab的函数
// if (currentName == "add") {
// // this.addTab()
// this.addPop()
// return false
// } else {
this.currentIndex = currentName
// }
},
addTab(goodType) {
// 根据已有的tab,再增减
if (goodType == 1) {
// 商品
const length = this.goodTabs.length
// this.tabIndex = length + 1
// this.addIndex = length + 1
// this.goodTabs = this.goodTabs.map((item, index) => {
// item.name = index + 1 + ''
// return item
// })
// const newTabIndex = ++this.tabIndex + ""
const tabIndex =
length == 0 ? length : this.goodTabs[length - 1].tabIndex + 1
this.goodTabs.push({
// title: "商品名称" + this.addIndex++,
title: "商品名称",
// name: 'good_' + newTabIndex,
name: "good_" + tabIndex,
tabIndex: tabIndex,
info: {}
})
// this.tabsValue = 'good_' + newTabIndex
// this.currentIndex = 'good_' + newTabIndex
this.tabsValue = "good_" + tabIndex
} else {
// 套餐
const length = this.packageTabs.length
// this.tabIndex = length + 1
// this.addIndex = length + 1
// const newTabIndex = ++this.tabIndex + ""
const tabIndex =
length == 0 ? length : this.packageTabs[length - 1].tabIndex + 1
this.packageTabs.push({
// title: "套餐名称" + this.addIndex++,
title: "套餐名称",
name: "package_" + tabIndex,
tabIndex: tabIndex,
info: null
})
// this.tabsValue = 'package_' + newTabIndex
// this.currentIndex = 'package_' + newTabIndex
this.tabsValue = "package_" + tabIndex
}
},
confirmRemove(targetName) {
// 删除tab
this.$confirm("确认删除标签页吗?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
closeOnClickModal: false // 是否可以点击空白处关闭弹窗
})
.then(() => {
// 确认切换标签页
this.removeTab(targetName)
})
.catch(() => {
// 取消切换标签页
this.$message({
type: "info",
message: "已取消删除"
})
})
},
removeTab(targetName) {
const self = this
let activeName = self.tabsValue
let tabs
if (targetName.split("_")[0] == "good") {
tabs = self.goodTabs
} else {
tabs = self.packageTabs
}
if (activeName === targetName) {
tabs.forEach((tab, index) => {
if (tab.name === targetName) {
const nextTab = tabs[index + 1] || tabs[index - 1]
console.log("tab.name", tab.name)
console.log("nextTab", nextTab)
if (nextTab) {
activeName = nextTab.name
} else {
if (tab.name.split("_")[0] == "good") {
if (
self.packageTabs.length > 0 &&
self.packageTabs[self.packageTabs.length - 1].name
) {
activeName =
self.packageTabs[self.packageTabs.length - 1].name
}
} else {
if (
self.goodTabs.length > 0 &&
self.goodTabs[self.goodTabs.length - 1].name
) {
activeName = self.goodTabs[self.goodTabs.length - 1].name
}
}
}
}
})
}
this.tabsValue = activeName
if (targetName.split("_")[0] == "good") {
this.goodTabs = tabs.filter((tab) => tab.name !== targetName)
} else {
this.packageTabs = tabs.filter((tab) => tab.name !== targetName)
}
this.packageNotice()
},
// 填写套餐名称时通知
getPackageEditInfo_notice(obj) {
console.log("obj", obj)
this.packageTabs.find((item) => item.tabIndex == obj.idx).info = obj.info
this.packageNotice()
},
// 初始化、填写套餐名称时、删除套餐时通知
packageNotice() {
this.packageInfoList = []
this.packageTabs.forEach((item) => {
if (item.info) {
console.log(item)
const o = {
name: item.info.val1 || item.info.packageName,
virtualCode: item.info.timeId,
id: item.info.id,
packageCode: item.info.packageCode
}
this.packageInfoList.push(o)
}
})
console.log("this.packageInfoList", this.packageInfoList)
this.$EventBus.$emit("packageInfoList", this.packageInfoList)
}
}
}
</script>
<style lang="scss" scoped>
@import "../../style/editdetailCon.scss";
.addBtnSpan {
float: right;
}
</style>