zhaojs
2023-06-10 69ea24e8fdfb41fc48c3fdb8c444645c13b1bbc4
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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<template>
    <view class="queryHistory-wrapper wrapperLayer">
        <titleBar :titleText='"查询历史价格"' :pageForm='"queryHistory"'></titleBar>
        <view class="query-container colCen">
            <view class="box-title">
                查询历史价格
            </view>
            <view class="textareabox">
                <textarea class="textarea" v-model="linkstr" placeholder="目前只支持查询淘系商品历史价格,请输入商品淘口令或者商品链接;如:https://detail.tmall.com/item.htm?id=631204160899&skuId=4527267480503"
                 placeholder-class="plastyle" />
                <view class="clean-btn" @tap='clean()'>
                    清空
                </view>
            </view>
            
            <view class="confirm-btn-box">
                <view class="confirm-btn rowCenCen" @tap='query()'>
                    <view>查询历史价格</view>
                </view>
            </view>
        </view>
        
        <view class="goods-container pd20" v-if="goodsinfo">
            <view class="card-container rowCen" @click="targetTb(goodsinfo.goodsId)">
                <image class="goods-pic" :src="goodsinfo.mainPic" mode="aspectFill"></image>
                <view class="goods-info colCenBet">
                    <view class="info-top-box">
                        <view class="goodsnameinfo-content rowSta">
                            <view class="tradename">
                                {{goodsinfo.title}}
                            </view>
                        </view>
                    </view>
                    
                    <view class="info-btm-box">
                        <view class="discounts-container rowCen borderBox">
                            <view class="coupon-box rowCenCen">
                                <view>
                                    {{goodsinfo.couponPrice}}元券
                                </view>
                            </view>
                            <view class="back-box rowCenCen">
                                <view>
                                    返{{goodsinfo.fanli}}元
                                </view>
                            </view>
                        </view>
                        <view class="btm-price-info rowCenBet">
                            <view class="pri-info rowEnd">
                                <view class="rmb">
                                    ¥
                                </view>
                                <view class="price">
                                    {{goodsinfo.actualPrice}}
                                </view>
                                <s>¥{{goodsinfo.originalPrice}}</s>
                            </view>
                            <view class="saleNum-box">
                                爆卖{{goodsinfo.monthSales}}件
                            </view>
                        </view>
                    </view>
                </view>
            </view>
        </view>
        
        <view class="price-trend-container pd20" v-if="goodsinfo">
            <view class="price-trend colCen">
                <view class="box-title ">
                    价格走势
                </view>
                <view class="charts-box">
                    <canvas canvas-id="canvasColumn" id="canvasColumn" class="charts" @touchstart="touchLineA" @touchmove="moveLineA" @touchend="touchEndLineA"></canvas>
                </view>
            </view>
        </view>
    </view>
</template>
 
<script>
    import {
        mapMutations
    } from "vuex";
    import uCharts from '../../js_sdk/u-charts/u-charts/u-charts.js';
    import titleBar from '../../components/backTitlebar.vue'
    var canvasColumn=null;
    export default {
        components: {
            titleBar
        },
        data(){
            return{
                linkstr:'',
                goodsinfo:'',
                
                cWidth:'',
                cHeight:'',
                pixelRatio:1,
                serverData:'',
                chartData: {
                    categories: [],
                    series: [{
                        name: '价格',
                        data: [],
                        color: '#000000'
                    }]
                },
                
                profshake:true
            }
        },
        onLoad() {
            if(!this.hasLogin){
                uni.reLaunch({
                    url:"/pages/login/wxlogin"
                })
            }else{
                this.cWidth=uni.upx2px(670);
                this.cHeight=uni.upx2px(300);
            }
            
        },
        methods:{
            targetTb(goodsid){
                 uni.navigateTo({
                                  url: '/pages/goods/goodsDetail?id=' + goodsid
                 });
            },
            showColumn(canvasId,chartData){
                var _self = this
                canvasColumn=new uCharts({
                    $this:_self,
                    canvasId: 'canvasColumn',
                    type: 'line',
                    legend:true,
                    fontSize:11,
                    background:'#FFFFFF',
                    pixelRatio:_self.pixelRatio,
                    animation: true,
                    categories: _self.chartData.categories,
                    series: _self.chartData.series,
                    enableScroll: true,
                    xAxis: {
                        type:'grid',
                        gridType:'dash',
                        disabled:false,
                        disableGrid:true,
                        itemCount:4,//x轴单屏显示数据的数量,默认为5个
                        scrollShow:true,//新增是否显示滚动条,默认false
                        scrollAlign:'left',//滚动条初始位置
                    },
                    yAxis: {
                        disableGrid:true,
                        splitNumber:4,
                        min:0,
                        format:(val)=>{return val.toFixed(0)}
                    },
                    dataLabel: true,
                    width: _self.cWidth*_self.pixelRatio,
                    height: _self.cHeight*_self.pixelRatio,
                    extra: {
                        line:{
                            type: 'straight'
                        }
                    }
                });
            },
            
            query(){
                var that = this;
                if(this.profshake){
                    this.profshake = false
                    this.$u.api.getHistory({
                        content: this.linkstr
                    }).then(e => {
                        that.profshake = true
                        if(e.code != 0) return that.$alert(e.msg)
                        if(e.data.length == 0)return that.$alert('暂未查询到商品信息');
                        uni.showToast({
                            title:'查询成功',
                            icon:'none'
                        })
                        that.goodsinfo = e.data.goodsInfo
                        that.chartData.categories = e.data.qushi.dateList
                        that.chartData.series[0].data = e.data.qushi.priceList
                        that.showColumn();
                    }).catch(function (err) {
                        that.profshake = true
                    })
                    
                }
            },
            
            clean(){
                this.linkstr = ''
                this.goodsinfo = ''
            },
            
            touchLineA(e){
                canvasColumn.scrollStart(e);
            },
            moveLineA(e) {
                canvasColumn.scroll(e);
            },
            touchEndLineA(e) {
                canvasColumn.scrollEnd(e);
                //下面是toolTip事件,如果滚动后不需要显示,可不填写
                canvasColumn.showToolTip(e, {
                    format: function (item, category) {
                    return category + ' ' + item.name + ':' + item.data 
                    }
                });
            },
        }
    }
</script>
 
<style lang="scss">
    .queryHistory-wrapper{
        width: 100%;
        .query-container{
            width: 100%;
            padding: 30rpx 20rpx;
            background-color: #FFFFFF;
            .box-title{
                width: 100%;
                font-size: 30rpx;
                font-weight: 500;
                color: #333333;
                margin-bottom: 40rpx;
            }
            .textareabox{
                width: 100%;
                height: 260rpx;
                background: #F8F8F8;
                border-radius: 16rpx;
                position: relative;
                .plastyle{
                    font-size: 26rpx;
                    font-weight: 500;
                    color: #888888;
                }
                .textarea{
                    width: 100%;
                    height: 100%;
                    font-size: 26rpx;
                    font-weight: 500;
                    color: #222222;
                    padding: 20rpx;
                }
                .clean-btn{
                    font-size: 26rpx;
                    font-weight: 500;
                    color: #666666;
                    position: absolute;
                    right: 16rpx;
                    bottom: 20rpx;
                }
            }
            
            .confirm-btn-box{
                width: 100%;
                padding: 0 40rpx;
                margin-top: 30rpx;
                .confirm-btn{
                    width: 100%;
                    height: 86rpx;
                    background: #FF900B;
                    border-radius: 43rpx;
                    font-size: 30rpx;
                    font-weight: 500;
                    color: #FFFFFF;
                }
            }
        }
        
        .goods-container{
            width: 100%;
            .card-container{
                width: 100%;
                height: 262rpx;
                background: #FFFFFF;
                border-radius: 16rpx;
                margin-top: 20rpx;
                padding: 0 10rpx;
                .goods-pic{
                    width:222rpx;
                    height: 222rpx;
                    border-radius: 16rpx;
                }
                .goods-info{
                    margin-left: 20rpx;
                    width: 420rpx;
                    height: 222rpx;
                    .info-top-box{
                        width: 100%;
                        .goodsnameinfo-content {
                            width: 100%;
                            margin-bottom: 15rpx;
                        
                            .typeIcon-content {
                                width: 60rpx;
                                height: 24rpx;
                                margin-right: 5rpx;
                                margin-top: 8rpx;
                            }
                        
                            .tradename {
                                width: 400rpx;
                                overflow: hidden;
                                text-overflow: ellipsis;
                                white-space: nowrap;
                                font-size: 28rpx;
                                font-weight: 400;
                                color: #333333;
                            }
                        }
                    }
                    
                    .info-btm-box{
                        width: 100%;
                        .discounts-container {
                            width: 100%;
                            margin-bottom: 15rpx;
                        
                            .coupon-box {
                                width: 102rpx;
                                height: 30rpx;
                                background: url(../../static/images/goods/couponbac.png)no-repeat;
                                background-size: 100% 100%;
                                font-size: 20rpx;
                                font-weight: 500;
                                color: #FF4242;
                            }
                        
                            .back-box {
                                height: 30rpx;
                                padding: 0 10rpx;
                                background: linear-gradient(-90deg, #7619EC, #A429F3);
                                border-radius: 5rpx;
                                margin-left: 8rpx;
                                font-size: 20rpx;
                                font-weight: 500;
                                color: #FFFFFF;
                            }
                        }
                        .btm-price-info{
                            width: 100%;
                            margin-top: 15rpx;
                            .pri-info{
                                .rmb{
                                    font-size: 24rpx;
                                    font-weight: 500;
                                    color: #FE3738;
                                    line-height: 40rpx;
                                }
                                .price{
                                    font-size: 30rpx;
                                    font-weight: bold;
                                    color: #FE3738;
                                }
                                s{                                
                                    font-size: 24rpx;
                                    font-weight: 500;
                                    color: #999999;
                                    line-height: 40rpx;
                                    margin-left: 5rpx;
                                }
                            }
                            
                            .saleNum-box{
                                font-size: 24rpx;
                                font-weight: 500;
                                color: #999999;
                            }
                        }
                    }
                }
            }
        }
        
        .price-trend-container{
            width: 100%;
            margin-top: 20rpx;
            .price-trend{
                width: 100%;
                height: 420rpx;
                background: #FFFFFF;
                border-radius: 16rpx;
                padding: 20rpx;
                .box-title{
                    width: 100%;
                    font-size: 28rpx;
                    font-weight: 500;
                    color: #333333;
                    margin: 20rpx 0;
                }
                .charts-box{
                    width: 670rpx;
                    height: 300rpx;
                    margin-top: 20rpx;
                    background-color: #FFFFFF;
                    .charts{
                        width: 100%;
                        height: 100%;
                    }
                }
            }
        }
    }
</style>