移动系统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
<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 class="content">
            <view v-if="list.length">
                <view class="item  coreshop-display-flex coreshop-flex-nowrap" v-for="(item, key) in list" :key="key">
                    <view @click="isSelect(item)">
                        <view class="top">
                            <view class="name">{{ item.name }}</view>
                            <view class="phone">{{ item.mobile }}</view>
                            <view class="tag">
                                <text class="red" v-if="item.isDefault">默认</text>
                            </view>
                        </view>
                        <view class="bottom">
                            {{item.areaName }} {{item.street}} {{item.address}}
                        </view>
                    </view>
                    <u-icon name="edit-pen-fill" :size="20" color="#999999" v-show="type != 'order'" @click="toEdit(item.id)"></u-icon>
 
                </view>
            </view>
            <!-- 无数据时默认显示 -->
            <view class="coreshop-emptybox" v-else>
                <u-empty :icon="$globalConstVars.apiFilesUrl+'/static/images/empty/address.png'" icon-size="150" text="暂无地址信息" mode="list"></u-empty>
            </view>
 
            <!--按钮-->
            <view class="coreshop-bg-white coreshop-footer-fixed coreshop-foot-padding-bottom">
                <u-button class="coreshop-percent-100" type="error" size="normal" @click="toAdd">新增收货地址</u-button>
            </view>
        </view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                list: [],// 用户收货地址列表
                type: ''
            }
        },
        onLoad(e) {
            if (e.type) {
                this.type = e.type;
            }
        },
        onShow() {
            this.userShipList();
        },
        methods: {
            // 获取收货地址列表
            userShipList() {
                this.$u.api.userShip().then(res => {
                    if (res.status) {
                        this.list = res.data
                    }
                })
            },
            //编辑
            toEdit(id) {
                this.$u.route('/pages/member/address/index/index?shipId=' + id);
            },
            //添加
            toAdd() {
                this.$u.route('/pages/member/address/index/index');
            },
            //选择
            isSelect(data) {
                if (this.type == 'order') {
                    let pages = getCurrentPages();//当前页
                    let beforePage = pages[pages.length - 2];//上个页面
 
                    // #ifdef MP-ALIPAY || MP-TOUTIAO
                    this.$db.set('addressUserShip', data, true);
                    // #endif
 
                    // #ifdef APP-PLUS || APP-PLUS-NVUE
                    this.$store.commit("userShip", data)
                    // #endif
 
                    // #ifdef MP-WEIXIN
                    beforePage.$vm.userShip = data;
                    beforePage.$vm.params.userShipId = data.id;
                    beforePage.$vm.params.areaId = data.areaId;
                    // #endif
 
                    uni.navigateBack({
                        delta: 1
                    });
                    // this.$u.route("/pages/placeOrder/index/index")
                }
            },
            // #ifdef MP-WEIXIN
            wechatAddress: function () {
                let _that = this;
                wx.chooseAddress({
                    success: res => {
                        if (res.errMsg == "chooseAddress:ok") {
                            //获取成功
                            //存储这个收获地区信息到数据库
                            let data = {
                                provinceName: res.provinceName,
                                cityName: res.cityName,
                                countyName: res.countyName,
                                postalCode: res.postalCode
                            };
                            let areaId = 0;
                            this.$u.api.getAreaId(data).then(res1 => {
                                if (res1.status) {
                                    //存储用户收货信息
                                    let userShipId = 0;
                                    let userShipData = {
                                        areaId: res1.data,
                                        name: res.userName,
                                        address: res.detailInfo,
                                        mobile: res.telNumber,
                                        isDefault: 2
                                    }
                                    this.$u.api.saveUserShipWx(userShipData).then(res2 => {
                                        if (res2.status) {
                                            this.$refs.uToast.show({
                                                title: '存储微信地址成功', type: 'success', complete: function () {
                                                    _that.userShipList();
                                                }
                                            });
                                        } else {
                                            this.$refs.uToast.show({ message: '存储微信地址失败', type: 'error' });
                                        }
                                    });
                                } else {
                                    this.$refs.uToast.show({ message: '获取微信地址失败', type: 'error' });
                                }
                            });
                        } else {
                            this.$refs.uToast.show({ message: '获取微信地址失败', type: 'error' });
                        }
                    }
                });
            },
            // #endif
        }
    }
</script>
 
<style lang="scss" scoped>
    @import "list.scss";
</style>