list.vue
4.7 KB
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
<template>
<view class="page_box">
<view class="head_box"></view>
<view class="content_box">
<view class="address-list" v-for="address in addressList" :key="address.id" @tap="useAddress(address)">
<view class="top x-f">
<text class="name">{{ address.consignee }}</text>
<text class="phone">{{ address.phone }}</text>
<text class="tag" v-if="address.is_default === '1'">默认</text>
</view>
<view class="detail">{{ address.province_name }}{{ address.city_name }}{{ address.area_name }}{{ address.address }}</view>
<button class="cu-btn set-btn" @tap.stop="jump('/pages/user/address/edit', { id: address.id })">编辑</button>
</view>
</view>
<view class="foot_box x-ac">
<!-- <button class="cu-btn sync-wxaddress mr20" @tap="getWXaddress" v-if="platform == 'wxMiniProgram' || platform == 'wxOfficialAccount'">
<text class="cuIcon-weixin"></text>
导入微信地址
</button> -->
<button class="cu-btn add-btn" @tap="jump('/pages/user/address/edit', { id: 0, from: from })">添加新的收货地址</button>
</view>
<!-- 自定义底部导航 -->
<shopro-tabbar></shopro-tabbar>
<!-- 关注弹窗 -->
<!-- <shopro-float-btn></shopro-float-btn> -->
<!-- 连续弹窗提醒 -->
<shopro-notice-modal></shopro-notice-modal>
<!-- 登录提示 -->
<shopro-login-modal></shopro-login-modal>
</view>
</template>
<script>
export default {
components: {},
data() {
return {
addressList: [],
from: '',
platform: uni.getStorageSync('platform')
};
},
computed: {},
onLoad() {
if (this.$Route.query.from) {
this.from = this.$Route.query.from;
}
},
onShow() {
this.init();
},
methods: {
init() {
return Promise.all([this.getAddressList()]);
},
useAddress(address) {
let pages = getCurrentPages();
// #ifdef MP-WEIXIN || APP-PLUS
let currPage = pages[pages.length - 1].$vm;
let prevPage = pages[pages.length - 2].$vm; //上一个页面
// #endif
// #ifdef H5
let currPage = pages[pages.length - 1];
let prevPage = pages[pages.length - 2]; //上一个页面
// #endif
prevPage.address = address;
uni.navigateBack({
delta: 1
});
},
// 获取微信收货地址
async getWXaddress() {
// #ifdef MP-WEIXIN || MP-TOUTIAO || MP-QQ
let status = await this.getSetting();
if (status === 2) {
this.openSetting();
return;
}
// #endif
this.openWXaddress();
},
openWXaddress() {
// #ifdef MP-WEIXIN
uni.chooseAddress({
success: res => {
let data = JSON.stringify(res);
this.jump('/pages/user/address/edit', { addressData: data });
},
fail: err => {}
});
// #endif
// #ifdef H5
this.$wxsdk.openAddress(res => {
let data = JSON.stringify(res);
this.jump('/pages/user/address/edit', { addressData: data });
});
// #endif
},
getSetting: function() {
return new Promise((resolve, reject) => {
uni.getSetting({
success: res => {
if (res.authSetting['scope.address'] === undefined) {
resolve(0);
return;
}
if (res.authSetting['scope.address']) {
resolve(1);
} else {
resolve(2);
}
}
});
});
},
openSetting: function() {
uni.openSetting({
success: res => {
if (res.authSetting && res.authSetting['scope.address']) {
this.openWXaddress();
}
},
fail: err => {}
});
},
// 路由跳转
jump(path, parmas) {
this.$Router.push({
path: path,
query: parmas
});
},
getAddressList() {
this.$api('address.list').then(res => {
if (res.code === 1) {
this.addressList = res.data;
}
});
}
}
};
</script>
<style lang="scss">
.address-list {
padding: 40rpx;
position: relative;
background: #fff;
margin-bottom: 20rpx;
.name,
.phone {
font-size: 30rpx;
font-weight: 600;
}
.phone {
margin: 0 20rpx;
}
.tag {
background: rgba(233, 191, 113, 0.2);
border-radius: 6rpx;
padding: 0 16rpx;
line-height: 38rpx;
color: #a8700d;
font-size: 22rpx;
}
.detail {
margin-top: 25rpx;
width: 543rpx;
font-size: 26rpx;
font-family: PingFang SC;
font-weight: 400;
color: rgba(153, 153, 153, 1);
line-height: 40rpx;
}
.set-btn {
background: none;
position: absolute;
font-size: 26rpx;
color: #a8700d;
top: 40rpx;
right: 20rpx;
}
}
.foot_box {
padding: 20rpx;
.sync-wxaddress {
flex: 1;
height: 80rpx;
background: rgba(255, 255, 255, 1);
border-radius: 40rpx;
.cuIcon-weixin {
color: #1ea907;
margin-right: 10rpx;
font-size: 40rpx;
}
}
.add-btn {
height: 80rpx;
flex: 1;
background: linear-gradient(90deg, rgba(233, 180, 97, 1), rgba(238, 204, 137, 1));
border: 1rpx solid rgba(238, 238, 238, 1);
border-radius: 40rpx;
color: rgba(#fff, 0.9);
}
}
</style>