zhao_js
2023-11-28 4d2bb20eecf42af8c0b29fda38b02df0f6c9895d
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
<template>
    <view class="container">
        <view class="orders-list d-flex flex-column w-100" style="padding: 20rpx; padding-bottom: 0;">
            <view class="order-item" v-for="(item, index) in orders" :key="index" style="margin-bottom: 30rpx;" @tap="detail(item.id)">
                <list-cell :hover="false">
                    <view class="w-100 d-flex align-items-center">
                        <view class="flex-fill d-flex flex-column">
                            <view class="font-size-lg text-color-base" style="margin-bottom: 20rpx;">
                                {{ item.store.name }}
                            </view>
                            <view class="font-size-sm text-color-assist">订单编号:{{ item.order_no }}</view>
                        </view>
                        <view class="font-size-lg text-color-primary">
                            {{ item.status_text }}
                        </view>
                    </view>
                </list-cell>
                <list-cell :hover="false" last>
                    <view class="w-100 d-flex flex-column">
                        <view class="w-100 text-truncate font-size-lg text-color-base" style="margin-bottom: 20rpx;">
                            {{ orderGoodsName(item.goods) }}
                        </view>
                        <view class="d-flex justify-content-between align-items-center" style="margin-bottom: 30rpx;">
                            <view class="font-size-sm text-color-assist">
                                {{ $util.formatDateTime(item.created_at) }}
                            </view>
                            <view class="d-flex font-size-sm text-color-base align-items-center">
                                <view style="margin-right: 10rpx;">共{{ item.goods_num }}件商品,实付</view>
                                <view class="font-size-lg">¥{{ item.amount }}</view>
                            </view>
                        </view>
                        <view class="d-flex align-items-center justify-content-end">
                            <view style="margin-right: 10rpx;">
                                <button type="primary" plain size="mini" v-if="item.invoice_status > 0">查看发票</button>
                                <button type="primary" plain size="mini" v-else @tap.stop="goToInvoice">开发票</button>
                            </view>
                            <view>
                                <button type="primary" plain size="mini" @tap.stop="review(item)">去评价</button>
                            </view>
                        </view>
                    </view>
                </list-cell>
            </view>
        </view>
    </view>
</template>
 
<script>
    import listCell from '@/components/list-cell/list-cell'
    
    export default {
        components: {
            listCell
        },
        data() {
            return {
                page: 1,
                pageSize: 5,
                orders: []
            }
        },
        computed: {
            orderGoodsName() {
                return (goods) => {
                    let arr = []
                    goods.forEach(good => arr.push(good.name + '*' + good.number))
                    return arr.join(',')
                }
            }
        },
        async onLoad() {
            if(!this.$store.getters.isLogin) {
                uni.navigateTo({url: '/pages/login/login'})
            }
            await this.getOrders(false)
        },
        async onReachBottom() {
            await this.getOrders(false)
        },
        async onPullDownRefresh() {
            await this.getOrders(true)
        },
        methods: {
            async getOrders(isRefresh = false) {
                uni.showLoading({
                    title: '加载中'
                })
                
                let orders = await this.$api('orders')
                if(isRefresh) {
                    this.orders = []
                    this.page = 1
                }
                orders = orders.slice(this.pageSize * (this.page - 1), this.pageSize * this.page)
                if(orders.length) {
                    this.orders = this.orders.concat(orders)
                    this.page += 1
                }
                
                uni.hideLoading()
            },
            detail(id) {
                uni.navigateTo({
                    url: '/pages/orders/detail?id=' + id
                })
            },
            review(order) {
                const date = order.completed_time.split(' ')[0]
                uni.navigateTo({
                    url: '/pages/review/review?storename=' + order.store.name + '&typeCate=' + order.typeCate + '&date=' + date
                })
            },
            goToInvoice() {
                uni.navigateTo({
                    url: '/pages/invoice/invoice'
                })
            }
        }
    }
</script>
 
<style lang="scss" scoped>
 
</style>