productHead.vue
5.98 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
<template>
<div class="productHead">
<div class="head">
<div class="store">
<img :src="collectData.shopLogo" @click="toStore(collectData.shopId)" alt="">
<div class="desc">
<p class="storeName">{{collectData.shopName}}</p>
<div class="sales">
<span class="species">商品种类:<span>{{collectData.classifyNumber}}</span></span>
<span class="sold">已售:<span>{{collectData.number}}</span></span>
</div>
</div>
<div class="service" v-show="hasService">
<div class="item">
<icon-svg style="font-size: 30px;" icon-class="shop-service" />
<span class="fs12">微信客服</span>
</div>
<canvas class="qrcode" ref="headQrcode"></canvas>
</div>
</div>
<div class="search">
<div class="searchSelect">
<el-dropdown @command="searchCommand" trigger="click">
<span class="el-dropdown-link">{{searchVal}}
<i class="el-icon-arrow-down cur-poi el-icon--right"></i>
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="宝贝">宝贝</el-dropdown-item>
<el-dropdown-item command="店铺">店铺</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
<div class="searchRight">
<input type="text" v-model="keyword" @keyup.enter="searchPro" placeholder="请输入搜索商品">
</div>
<span class="btn cur-poi" @click="searchPro"><i class="icon el-icon-search"></i></span>
</div>
</div>
</div>
</template>
<script>
import {mapMutations, mapGetters} from 'vuex'
import QRCode from 'qrcode'
import {
getServiceURL
} from '@/api/product.js'
export default {
name: 'productHead',
data () {
return {
searchVal: '宝贝',
keyword: '',
hasService: false
}
},
watch: {
'collectData.shopId': {
handler (nVal, oVal) {
if (nVal !== oVal) {
this.hasService = false // 初始化微信客服框
this.getSercvice(this.collectData.shopId)
}
},
deep: true
}
},
computed: {
...mapGetters([
'collectData'
])
},
mounted () {
this.getSercvice(this.collectData.shopId)
},
methods: {
...mapMutations({
setSearchObj: 'SET_SEARCHOBJ'
}),
searchCommand (command) {
this.searchVal = command
},
// 搜索商品
searchPro () {
this.setSearchObj({
keyword: this.keyword,
searchVal: this.searchVal
})
if (this.$route.name !== 'search') {
this.$router.push({
path: '/activity/search'
})
}
},
// 跳转到店铺
toStore (id) {
this.$router.push({
path: '/store', query: {shopId: id}
})
},
async getSercvice (shopid) {
const shopids = JSON.parse(sessionStorage.getItem('service_shopds')) || []
const serviceUrl = JSON.parse(sessionStorage.getItem('service_url')) || []
let url = null
const index = shopids.indexOf(shopid)
if (index === -1) { // 没用该店铺客服
const response = await getServiceURL({id: shopid})
const res = response.data
url = res.data.url
if (!url) { return }
// 缓存处理
shopids.push(shopid)
serviceUrl.push(url)
this.hasService = true
sessionStorage.setItem('service_shopds', JSON.stringify(shopids))
sessionStorage.setItem('service_url', JSON.stringify(serviceUrl))
} else {
this.hasService = true
url = serviceUrl[index]
}
if (!url) { return }
QRCode.toCanvas(this.$refs.headQrcode, url, error => {
console.log(error)
})
}
}
}
</script>
<style lang="scss" scoped>
.productHead{
width: 100%;
background-color: #fff;
height: 80px;
margin-bottom: 20px;
display: flex;
justify-content: center;
.head{
width: 1250px;
height: 100%;
display: flex;
justify-content: space-between;
align-items: center;
.store{
display: flex;
img{
width: 60px;
height: 60px;
margin-right: 10px;
border: 1px solid #F3F4F5;
cursor: pointer;
}
.desc{
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 5px 0;
.storeName{
font-size: 18px;
color: #333;
}
.sales{
font-size: 12px;
.species,.sold{
color: #999;
margin-right: 15px;
span{
color: #333;
}
}
}
}
.service{
width: 58px;
height: 58px;
color: #C5AA7B;
background-color: #FAF8F5;
// overflow: hidden;
cursor: pointer;
&:hover{
.qrcode{
display: block;
}
}
.item{
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
span{
margin-top: 6px;
}
}
.qrcode{
width: 100px !important;
height: 100px !important;
display: none;
}
}
}
.search{
width: 394px;
height: 39px;
border: 2px solid #F3F4F5;
display: flex;
.searchSelect{
width: 82px;
height: 30px;
margin-top: 2px;
border-right: 1px solid #CCCCCC;
text-align: center;
line-height: 30px;
.el-dropdown{
color: #C5AA7B;
}
}
.searchRight{
flex: 1;
input{
padding-left: 15px;
font-size: 14px;
color: #333;
line-height: 35px;
}
}
.btn{
font-size: 20px;
line-height: 35px;
padding-right: 15px;
}
}
}
}
</style>