移动系统liao
2024-05-09 5d6cb15ac86d9174393cb9d1538d69b567e2c26c
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
<template>
    <view>
        <u-toast ref="uToast" /><u-no-network></u-no-network>
        <u-navbar title="订单评价" safeAreaInsetTop fixed placeholder>
            <view class="coreshop-navbar-left-slot" slot="left">
                <u-icon name="arrow-left" size="19" @click="goNavigateBack"></u-icon>
                <u-line direction="column" :hairline="false" length="16" margin="0 8px"></u-line>
                <u-icon name="home" size="22" @click="goHome"></u-icon>
            </view>
            <view slot="right">
            </view>
        </u-navbar>
        <view>
            <view class='img-list'>
                <view v-for="item in info.items" :key="item.id">
                    <view class="coreshop-bg-white coreshop-card-box coreshop-margin-10">
                        <view class="coreshop-card-view coreshop-order-view">
                            <view class="coreshop-font-md coreshop-text-bold coreshop-text-black">商品信息</view>
                            <u-line color="#eee" border-style="dashed" margin="10px 0" />
                            <view class="orderList coreshop-padding-0">
                                <view class="item" @click="goGoodsDetail(item.goodsId)">
                                    <view class="left">
                                        <u--image :showLoading="true" :src="item.imageUrl" width="80px" height="80px" mode="aspectFill"></u--image>
                                    </view>
                                    <view class="content">
                                        <view class="title u-line-4">{{item.name}}</view>
                                    </view>
                                </view>
                            </view>
                        </view>
                        <view class="coreshop-card-view coreshop-order-view">
                            <view class="coreshop-font-md coreshop-text-bold coreshop-text-black">商品评分</view>
                            <u-line color="#eee" border-style="dashed" margin="10px 0" />
                            <view>
                                <u-rate v-model="score[item.id]" @change="changeScore"></u-rate>
                            </view>
                        </view>
                        <view class="coreshop-card-view coreshop-order-view">
                            <view class="coreshop-font-md coreshop-text-bold coreshop-text-black">评价内容</view>
                            <u-line color="#eee" border-style="dashed" margin="10px 0" />
                            <view class="evaluate-c-t">
                                <textarea v-model="textarea[item.id]" placeholder="宝贝满足你的期待吗? 说说你的使用心得" />
                            </view>
                        </view>
                        <view class="coreshop-card-view coreshop-order-view">
                            <view class="coreshop-font-md coreshop-text-bold coreshop-text-black">上传图片(可上传{{maxUploadImg}}张)</view>
                            <u-line color="#eee" border-style="dashed" margin="10px 0" />
                            <view class="evaluate-c-b">
                                <view class="goods-img-item" v-if="images[item.id].length" v-for="(img, key) in images[item.id]" :key="key">
                                    <image class="del" src="/static/images/common/del.png" mode="" @click="removeImg(item.id, key)"></image>
                                    <image class="" :src="img" mode="" @click="clickImg(img)"></image>
                                </view>
                                <view class="upload-img" v-show="isupload[item.id]">
                                    <image class="icon" src="/static/images/common/camera.png" mode="" @click="uploadImg(item.id)"></image>
                                    <view class="">上传照片</view>
                                </view>
                            </view>
                        </view>
                    </view>
                </view>
            </view>
        </view>
        <view class="coreshop-foot-hight-view" />
        <view class="coreshop-bg-white coreshop-footer-fixed coreshop-foot-padding-bottom">
            <u-button type="error" size="normal" @click="toEvaluate" :disabled='submitStatus' :loading='submitStatus'>提交评论</u-button>
        </view>
    </view>
</template>
 
<script>
 
    export default {
 
        data() {
            return {
                orderId: 0,
                info: {}, // 订单详情
                images: [],
                score: [], // 商品评价
                textarea: [], // 商品评价信息
                isupload: [], // 启/禁用 图片上传按钮
                rate: 5,
                submitStatus: false
            }
        },
        onLoad(options) {
            this.orderId = options.orderId
            if (this.orderId) {
                this.orderInfo();
            } else {
                this.$refs.uToast.show({
                    message: '参数获取失败', type: 'error', complete: function () {
                        uni.navigateBack({
                            delta: 1
                        });
                    }
                });
            }
        },
        computed: {
            // 获取vuex中状态
            maxUploadImg() {
                return this.$store.state.config.imageMax
            }
        },
        methods: {
            // 获取订单详情
            orderInfo() {
                let data = {
                    id: this.orderId
                }
                this.$u.api.orderDetail(data).then(res => {
                    if (res.status && res.data.payStatus >= 2 && res.data.shipStatus >= 3 && res.data.confirmStatus >= 2 && res.data.isComment === false) {
                        const _info = res.data
                        let images = []
                        let textarea = []
                        let upload = []
                        let score = []
                        _info.items.forEach(item => {
                            images[item.id] = []
                            textarea[item.id] = ''
                            upload[item.id] = true
                            score[item.id] = 5
                        })
                        this.info = _info
                        this.images = images
                        this.textarea = textarea
                        this.score = score
                        this.isupload = upload
                    } else {
                        this.$u.toast('订单不存在或状态不可评价!')
                    }
                })
            },
            // 上传图片
            uploadImg(key) {
                this.$upload.uploadFiles(null, res => {
                    if (res.status) {
                        //this.images[key].push(res.data.src + '?x-oss-process=image/resize,m_lfit,h_200,w_200')
                        this.images[key].push(res.data.src)
                        this.$refs.uToast.show({ message: res.msg, type: 'success', back: false })
                    } else {
                        this.$u.toast(res.msg)
                    }
                })
            },
            // 删除图片
            removeImg(id, key) {
                this.images[id].splice(key, 1)
            },
            // 图片点击放大
            clickImg(img) {
                // 预览图片
                uni.previewImage({
                    urls: img.split()
                });
            },
            // 改变评分
            changeScore(e) {
                this.score[e.id] = e.value
            },
            // 提交评价
            toEvaluate() {
                this.submitStatus = true;
                let items = [];
                let _this = this;
 
                this.images.forEach((item, key) => {
                    let model = {
                        orderItemId: key,
                        images: item,
                        score: _this.score[key],
                        textarea: _this.textarea[key]
                    }
                    items.push(model);
                })
                let data = {
                    orderId: _this.orderId,
                    items: items
                }
                this.$u.api.orderEvaluate(data).then(res => {
                    if (res.status) {
                        _this.$refs.uToast.show({
                            message: '评价填写成功', type: 'success', complete: function () {
                                // 更改订单列表页的订单状态
                                let pages = getCurrentPages(); // 当前页
                                let beforePage = pages[pages.length - 2]; // 上个页面
 
                                if (beforePage !== undefined && beforePage.route === 'pages/member/order/index/index') {
                                    // #ifdef MP-WEIXIN
                                    beforePage.$vm.isReload = true
                                    // #endif
                                    // #ifdef MP-ALIPAY || MP-TOUTIAO
                                    _this.$db.set('orderUserEvaluate', true, true);
                                    // #endif
                                }
 
                                let before = pages[pages.length - 3]; // 上个页面
                                if (before !== undefined && before.route === 'pages/member/order/index/index') {
                                    // #ifdef MP-WEIXIN
                                    before.$vm.isReload = true
                                    // #endif
                                    // #ifdef MP-ALIPAY || MP-TOUTIAO
                                    _this.$db.set('orderUserEvaluate', true, true);
                                    // #endif
                                }
                                uni.navigateBack({
                                    delta: 1,
                                    animationType: 'pop-out',
                                    animationDuration: 200
                                });
                            }
                        })
                    } else {
                        _this.$u.toast(res.msg)
                    }
                });
            }
        },
        watch: {
            images: {
                handler() {
                    this.images.forEach((item, key) => {
                        this.isupload[key] = item.length >= this.maxUploadImg ? false : true
                    })
                },
                deep: true
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    @import "evaluate.scss";
</style>