fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<template>
  <div class="product" :class="{ pd: !flag }">
    <img class="banner" v-if="flag" src="../../assets/images/product/banner.png" alt="" />
    <div class="img_box sure" v-if="flag && product">
      <img class="img" src="../../assets/images/product/sure.png" alt="" />
      <div class="t">
        查询成功!
      </div>
    </div>
    <div class="content mr">
      <div class="scanCount" v-if="flag && product">
        第
        <div class="count">{{ product.scanCount }}</div>
        次查询
      </div>
      <template v-if="flag">
        <div class="title title_p">商品信息</div>
        <ul v-if="product">
          <li class="item-style">
            <label class="label">商品名称:</label>
            <span class="text">{{ product.orderItems.spuName }}</span>
          </li>
          <template v-if="propMetas">
            <li class="item-style" v-for="item in propMetas" :key="item.propName">
              <label class="label">{{ item.propName }}:</label>
              <span class="text">{{ item.propValueName }}{{ item.propUnit }}</span>
            </li>
          </template>
          <li class="item-style">
            <label class="label">鉴别编码:</label>
            <span class="text codeId">{{ product.codeId}}</span>
          </li>
          <li class="item-style">
            <label class="label">首次查询时间:</label>
            <span class="text">{{ product.firstScanTime }}</span>
          </li>
          <li class="item-style">
            <label class="label">订单编号:</label>
            <span class="text">{{ product.orderId }}</span>
          </li>
          <li class="item-style">
            <label class="label">下单时间:</label>
            <span class="text">{{ product.submitTime}}</span>
          </li>
          <li class="item-style">
            <label class="label">物流编号:</label>
            <span class="text">{{ product.logisticsId}}</span>
          </li>
          <li class="item-style">
            <label class="label">公司名称:</label>
            <span class="text">{{ product.companyName }}</span>
          </li>
          <li class="item-style">
            <label class="label">生产地址:</label>
            <span class="text">{{ product.prodtAddress }}</span>
          </li>
          <li class="item-style">
            <label class="label">服务电话:</label>
            <span class="text">{{ product.serviceLine }}</span>
          </li>
        </ul>
        <div class="noData" v-else>{{ msg }}</div>
      </template>
      <div class="container" v-else>
        <div class="title">查询结果</div>
        <div class="msg" :style="{ height: height }">
          <div class="img_box">
            <img class="img" src="../../assets/images/product/error.png" alt="" />
            <div class="t">查询失败</div>
          </div>
          <div>该二维码不存在</div>
          <!-- 非五粮液原厂商品,请谨慎购买 -->
        </div>
      </div>
    </div>
    <!-- <div class="scan-btn" @click="scanClick">
      <img class="scan-icon" src="../../assets/images/product/scan-icon.png" alt="">
      扫一扫查防伪
    </div> -->
    <div class="msg" v-if="flag">
      提示:若首次购买扫码查询次数大于1,请谨慎购买。
    </div>
    <!-- <div class="fixed-msg" v-if="flag && (!msg || msg === '努力加载中...')">
      该产品为原厂正品
    </div> -->
  </div>
</template>
<script>
import {
  getWxSignature,
  scanVerify,
  scanVerifyInfoAdd
} from '@/api/oauth/index'
import axios from 'axios'
const wx = require('weixin-js-sdk')
export default {
  name: 'product',
  data() {
    return {
      product: null,
      flag: true,
      msg: '努力加载中...',
      propMetas: null
    }
  },
  created() {
    if (this.$route.query.uuid) {
      this._scanVerify()
      const ua = navigator.userAgent.toLowerCase()
      const isWeixin = ua.indexOf('micromessenger') !== -1
      if (isWeixin) {
        this._getWxSignature()
      }
    }
  },
  computed: {
    height() {
      if (!this.flag) {
        return window.screen.height - 100 + 'px'
      }
      return 'auto'
    }
  },
  methods: {
    async _scanVerify() {
      try {
        const res = await scanVerify({
          uuid: this.$route.query.uuid
        })
        if (res.code === '0') {
          this.flag = res.data.boolState
          this.product = res.data
          if (this.product.orderItems.propMetas) {
            this.propMetas = JSON.parse(this.product.orderItems.propMetas)
          }
        } else {
          this.flag = false
        }
      } catch (error) {
        this.msg = error
      }
    },
    loadScript(url) {
      return new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.onload = resolve
        script.onerror = reject
        document.head.appendChild(script)
      })
    },
    async _getWxSignature() {
      const res = await getWxSignature({
        url: encodeURIComponent(window.location.href.split('#')[0])
      })
      if (res.code === '0') {
        this.wxscan(res.data)
      }
    },
    async scanClick() {
      const ua = navigator.userAgent.toLowerCase()
      const isWeixin = ua.indexOf('micromessenger') !== -1
      if (isWeixin) {
        // this._getWxSignature()
        wx.scanQRCode({
          needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
          scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
          success: res => {
            var result = res.resultStr // 当needResult 为 1 时,扫码返回的结果
            const flag = result.indexOf('//app.wlyxls.com') > -1
            if (flag) {
              window.location.replace(result)
            } else {
              setTimeout(() => {
                this.$alert(result, '检测到以下文本')
              }, 600)
            }
          }
        })
      } else {
        await this.loadScript(
          'https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js'
        )
        /* eslint-disable */
        document.addEventListener('UniAppJSBridgeReady', function () {
          uni.postMessage({
            data: {
              action: 'message'
            }
          })
        })
        /* eslint-enable */
      }
    },
    wxscan(wxSignature) {
      const _this = this
      wx.config({
        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
        appId: wxSignature.appId, // 必填,公众号的唯一标识
        timestamp: wxSignature.timestamp, // 必填,生成签名的时间戳
        nonceStr: wxSignature.nonceStr, // 必填,生成签名的随机串
        signature: wxSignature.signature, // 必填,签名
        jsApiList: ['scanQRCode', 'getLocation'] // 必填,需要使用的JS接口列表
      })
      wx.ready(function () {
        // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
        wx.getLocation({
          type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
          success: function (res) {
            axios
              .get(
                `https://restapi.amap.com/v3/geocode/regeo?key=e7db0357f03c05b67c4a0e0297b02dbc&&location=${res.longitude},${res.latitude}`
              )
              .then(r => {
                scanVerifyInfoAdd({
                  uuid: _this.$route.query.uuid,
                  scanAddress: r.data.regeocode.formatted_address
                })
              })
          }
        })
      })
    }
  }
}
</script>
<style scoped lang="stylus">
.product {
  padding-bottom: 30px;
 
  .img_box {
    .img {
      width: 140px;
      height: 140px;
    }
 
    .t {
      font-size: 48px;
      font-weight: 600;
      color: #333333;
      margin: 30px 0 60px;
    }
 
    &.sure {
      text-align: center;
      width: 711px;
      background: #FFFFFF;
      border-radius: 20px;
      padding: 52px 0 60px;
      margin: 30px auto;
 
      .t {
        margin-bottom: 0;
      }
    }
  }
 
  .banner {
    width: 100%;
  }
 
  .title {
    margin: 20px;
    font-size: 32px;
    font-weight: 600;
    color: #333333;
 
    &.title_p {
      margin: 20px 0 40px 0;
    }
  }
 
  .noData {
    margin: 40px 0;
    text-align: center;
  }
 
  .msg {
    font-size: 24px;
    font-weight: 400;
    color: #FF4615;
    margin: 30px 20px 0;
  }
 
  .scanCount {
    text-align: center;
    margin: 20px auto 30px;
 
    .count {
      display: inline-block;
      text-align: center;
      font-size: 36px;
      font-weight: 500;
      color: #A01E18;
      margin: 0 20px;
    }
  }
 
  .content {
    background: white;
    padding: 18px 20px;
    box-sizing: border-box;
    margin-bottom: 20px;
    border-radius: 20px;
 
    &.mr {
      margin: 30px 20px;
    }
 
    .item-style {
      font-size: 28px;
      font-weight: 400;
      margin-bottom: 40px;
      vertical-align: top;
 
      &:last-child {
        margin-bottom: 0;
      }
 
      .label {
        color: #666;
        display: inline-block;
        line-height: 1.8;
      }
 
      .text {
        color: #333333;
        // flex: 1;
        display: inline-block;
        line-height: 1.8;
 
        &.codeId {
          width: 530px;
          word-wrap: break-word;
          vertical-align: top;
        }
      }
    }
  }
 
  .scan-btn {
    width: 710px;
    height: 88px;
    background: linear-gradient(270deg, #FB5B6D 0%, #FF4309 100%);
    border-radius: 10px;
    margin: 0 20px 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 28px;
    font-weight: 400;
    color: white;
 
    .scan-icon {
      width: 44px;
      height: 44px;
      margin-right: 10px;
    }
  }
 
  .fixed-msg {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 80px;
    background: #A01E18;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 400;
    color: #FFFFFF;
  }
 
  .container {
    .msg {
      color: #A01E18;
      font-size: 32px;
      font-weight: 400;
      text-align: center;
      height: 500px;
      display: flex;
      align-items: center;
      flex-direction: column;
      justify-content: center;
    }
  }
}
</style>
<style lang="stylus">
body {
  background: #f2f2f2;
}
</style>