index.vue
5.5 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
<!-- 选择商品弹窗 -->
<template>
<GLDialog class="muti-pro" bigTitle="选择商品" mode="big" :visible.sync="isMutiSelectVisible" :before-close="handleMutiSelectClose" :okText="productList.length ? '确定' : '创建商品'" @onOk="handleMutiSelectConfirm" @onCancel="handleMutiSelectClose" v-loading="loading">
<div class="noproDiv" v-show="!productList.length && fnCallBack">
<img src="@/assets/noPro.png" />
<p class="noproP">系统暂无已创建的商品</p>
</div>
<div v-show="productList.length">
<slot name="search"></slot>
<GLTable v-loading="loading" ref="mutiProRef" :tableData="productList" :hasPage="false" :noDataImg="url" :tableParams="tableParams" @refreshTable="getList">
<span slot="goodsImage" slot-scope="scope">
<img class="m-t-10 img-60" :src="scope.scope.goodsImage" />
</span>
</GLTable>
</div>
</GLDialog>
</template>
<script>
// import { getGoodsList } from '@/api/modules/common'
import url from '@/assets/empty.png'
export default {
name: 'selectMutiProDialog',
data() {
return {
// 表格组件
userInfo: {},
productList: [],
fnCallBack: false,
url: url,
loading: true,
// pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
// 表格参数
tableParams: {
listName: 'list',
// 行数据的key
mutiSelectUniqueKey: 'id',
// 多选ref的名称
mutiSelectName: 'list',
tableColumns: [
{
label: '商品名称',
prop: 'goodsName'
},
{
label: '缩略图',
prop: 'goodsImage',
addHtml: 'goodsImage'
},
{
label: '价格(元)',
prop: 'retailPrice'
},
{
label: '来源门店',
prop: 'merchantName'
}
]
}
}
},
props: {
isMutiSelectVisible: {
type: Boolean,
default: false
},
searchForm: {
type: Object,
default: () => {}
},
selectedProList: {
type: Array,
default: () => []
}
},
mounted() {
this.userInfo = this.$globalState.session
this.getList({}, true)
},
methods: {
getList(page, isReset = false) {
var params = {
...this.searchForm,
goodsStatus: 1,
goodsSource: 1,
pageNum: isReset ? 1 : this.$refs.mutiProRef.page.pageNum,
pageSize: isReset ? 10 : this.$refs.mutiProRef.page.pageSize
}
var that = this
this.loading = true
this.$apis.common.getGoodsListApi(params).then(res => {
this.productList = res
this.loading = false
this.fnCallBack = true
// this.$refs.mutiProRef.tableTotal = res.total
this.productList.forEach(function(item) {
item.saleAmount = item.goodsStatistics.saleAmount
if (item.specificationDetailList.length > 1) {
let retailPriceList = JSON.parse(JSON.stringify(item.specificationDetailList))
retailPriceList.sort((a, b) => {
return a.retailPrice - b.retailPrice
})
let stockeList = JSON.parse(JSON.stringify(item.specificationDetailList))
stockeList.sort((a, b) => {
return a.stock - b.stock
})
let minRatilPrice = retailPriceList[0].retailPrice / 100
let maxRatilPrice = retailPriceList[retailPriceList.length - 1].retailPrice / 100
let minStock = stockeList[0].stock
let maxStock = stockeList[stockeList.length - 1].stock
item.retailPrice = minRatilPrice == maxRatilPrice ? minRatilPrice.toFixed(2) : minRatilPrice.toFixed(2) + '-' + maxRatilPrice.toFixed(2)
item.minRatilPrice = minRatilPrice.toFixed(2)
item.goodsStock = minStock == maxStock ? minStock : minStock + '-' + maxStock
} else if (item.specificationDetailList.length == 1) {
item.retailPrice = (item.specificationDetailList[0].retailPrice / 100).toFixed(2)
item.minRatilPrice = item.retailPrice
item.goodsStock = item.specificationDetailList[0].stock
} else {
item.retailPrice = (item.retailPrice / 100).toFixed(2)
item.minRatilPrice = item.retailPrice
}
})
this.recoverySelected()
this.$refs.mutiProRef.tableHeightValues = '50vh'
})
},
recoverySelected() {
if (this.selectedProList && this.selectedProList.length) {
this.selectedProList.forEach(row => {
this.$refs.mutiProRef.$refs[this.tableParams.mutiSelectName + 'MutiTable'].toggleRowSelection(row)
})
}
},
handleMutiSelectConfirm() {
if (!this.productList.length) {
var params = {
addOrEdit: 1,
groupOrStore: this.userInfo.accountLevel == 4 ? 2 : 1,
$title: '新建商品'
}
this.$router.push({
path: '/productGroup/editProduct',
query: params
})
return true
}
var selectedData = this.$refs.mutiProRef.mutiSelectArr[this.tableParams.mutiSelectName]
this.$emit('handleMutiSelectConfirm', selectedData)
},
handleMutiSelectClose() {
this.$emit('handleMutiSelectClose')
}
}
}
</script>
<style>
.muti-pro .m-t-10 {
margin-top: 10px;
}
.muti-pro .noproP {
width: 100%;
height: 20px;
font-family: PingFangSC-Medium;
font-size: 16px;
color: #666666;
line-height: 20px;
font-weight: 500;
text-align: center;
}
</style>