123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- <template>
- <view>
- <!-- #ifdef MP-ALIPAY -->
- <u-navbar title="我的地址" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" leftIconSize="0" />
- <!-- #endif -->
- <!-- #ifndef MP-ALIPAY -->
- <u-navbar title="我的地址" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
- <!-- #endif -->
- <view class="addres-list">
- <view class="address-item" v-for="(item, index) in list" :key="index">
- <view class="contacts">
- <text class="name">{{ item.receiver }}</text>
- <text class="phone">{{ item.mobile }}</text>
- </view>
- <view class="address">
- <text class="region">{{ `${ item.province }-${ item.city }-${ item.area }` }}</text>
- <text class="detail">{{ item.addr }}</text>
- </view>
- <view class="line"></view>
- <view class="item-option">
- <view class="_left" @click.stop="handleSetDefault(item.addrId)">
- <label class="item-radio">
- <view :class="item.addrId == defaultId? 'radioon' : 'radiooff' ">√</view>
- <text class="text">{{ item.addrId == defaultId ? '默认' : '选择' }}</text>
- </label>
- </view>
- <view class="_right">
- <view class="events">
- <view class="event-item" @click="handleUpdate(item.addrId)">
- <text class="iconfont icon-edit"></text>
- <text class="title">编辑</text>
- </view>
- <view class="event-item" @click="handleRemove(item.addrId)">
- <text class="iconfont icon-delete"></text>
- <text class="title">删除</text>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- <view class="flex empty" v-if="!list.length">
- <view class="center">
- <image class="center-img" src="https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/v2/nodata_5.png" mode="scaleToFill"></image>
- <view class="center-font">暂无收货地址</view>
- </view>
- </view>
- <!-- 底部操作按钮 -->
- <view class="footer-fixed">
- <view class="btn-wrapper">
- <button type="default" @click="handleCreate">添加地址</button>
- </view>
- </view>
- </view>
- </template>
- <script>
- import $http from '@/utils/request.js'
- export default {
- data() {
- return {
- //当前页面参数
- options: {},
- // 正在加载
- isLoading: true,
- // 收货地址列表
- list: [],
- // 默认收货地址
- defaultId: null
- }
- },
- onLoad(options) {
- // 当前页面参数
- this.options = options
- },
- onShow() {
- // 获取页面数据
- this.getPageData()
- },
- methods: {
- // 获取页面数据
- getPageData() {
- uni.showLoading({
- title: '加载中'
- });
- const app = this
- app.isLoading = true
- Promise.all([app.getDefaultId(), app.getAddressList()])
- .then(() => {
- uni.hideLoading();
- // 列表排序把默认收货地址放到最前
- // app.onReorder()
- }).catch(() => {
- uni.hideLoading();
- })
- },
- // 获取收货地址列表
- getAddressList() {
- $http.post('/api/v1/mp/user/addr/list', {}).then(res => {
- if (res.code == 0) {
- this.list = res.data
- }
- })
- },
- // 获取默认的收货地址
- getDefaultId() {
- $http.post('/api/v1/mp/user/addr/queryDefault', {}).then(res => {
- if (res.code == 0) {
- this.defaultId = res && res.data && res.data.addrId
- }
- })
- },
- // 列表排序把默认收货地址放到最前
- onReorder() {
- const app = this
- app.list.sort(item => {
- return item.addrId == app.defaultId ? -1 : 1
- })
- },
- // 添加地址
- handleCreate() {
- uni.navigateTo({
- url: "/packageOperate/address/create"
- })
- },
- // 编辑地址
- handleUpdate(addressId) {
- uni.navigateTo({
- url: `/packageOperate/address/create?addrId=${ addressId }`
- })
- },
- // 删除地址
- handleRemove(addressId) {
- const _this = this
- uni.showModal({
- title: "提示",
- content: "您确定要删除当前收货地址吗?",
- success(res) {
- if (res.confirm) {
- $http.post('/api/v1/mp/user/addr/remove', {
- addrId: addressId
- }).then(res => {
- if (res.code == 0) {
- _this.getPageData()
- uni.$u.toast('删除成功');
- }
- })
- }
- }
- });
- },
- // 设置默认地址
- handleSetDefault(addressId) {
- $http.post('/api/v1/mp/user/addr/setDefault', {
- addrId: addressId
- }).then(res => {
- this.getPageData()
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .addres-list {
- padding-bottom: calc(constant(safe-area-inset-bottom) + 120rpx);
- padding-bottom: calc(env(safe-area-inset-bottom) + 120rpx);
- }
- .address-item {
- margin: 20rpx auto 20rpx auto;
- padding: 30rpx 40rpx;
- width: 95%;
- box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
- border-radius: 10rpx;
- background: #fff;
- }
- .contacts {
- font-size: 30rpx;
- margin-bottom: 16rpx;
- .name {
- margin-right: 16rpx;
- }
- }
- .address {
- font-size: 28rpx;
- .region {
- margin-right: 10rpx;
- }
- }
- .line {
- margin: 20rpx 0;
- border-bottom: 1rpx solid #f3f3f3;
- }
- .item-option {
- display: flex;
- justify-content: space-between;
- height: 48rpx;
- // 单选框
- .item-radio {
- font-size: 28rpx;
-
- .radiooff {
- display: inline-block;
- vertical-align: middle;
- height: 35rpx;
- width: 35rpx;
- border-radius: 50%;
- border:1px solid #888;
- font-size: 24rpx;
- color: #fff;
- text-align: center;
- line-height: 38rpx;
- }
- .radioon {
- display: inline-block;
- vertical-align: middle;
- height: 35rpx;
- width: 35rpx;
- background-color: red;
- border-radius: 50%;
- border: red;
- font-size: 24rpx;
- font-weight: bold;
- color: #fff;
- text-align: center;
- line-height: 38rpx;
- }
- .text {
- padding-left: 20rpx;
- vertical-align: middle;
- }
- }
- // 操作
- .events {
- display: flex;
- align-items: center;
- line-height: 48rpx;
- .event-item {
- font-size: 28rpx;
- margin-right: 26rpx;
- color: #4c4c4c;
- &:last-child {
- margin-right: 0;
- }
- .title {
- margin-left: 8rpx;
- }
- }
- }
- }
- // 底部操作栏
- .footer-fixed {
- position: fixed;
- bottom: var(--window-bottom);
- left: 0;
- right: 0;
- min-height: 120rpx;
- z-index: 11;
- box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
- background: #fff;
- // 设置ios刘海屏底部横线安全区域
- padding-bottom: constant(safe-area-inset-bottom);
- padding-bottom: env(safe-area-inset-bottom);
- .btn-wrapper {
- display: flex;
- align-items: center;
- padding: 20rpx 0;
- }
- ::v-deep button {
- width: 441rpx;
- height: 88rpx;
- line-height: 88rpx;
- font-size: 36rpx;
- color: #fff;
- background-color: #F9822C;
- border: none;
- border-radius: 44rpx;
- margin: 0 auto;
- }
- }
-
- .empty {
- height: 60vh;
-
- .center {
- text-align: center;
-
- &-img {
- width: 228rpx;
- height: 320rpx;
- }
-
- &-font {
- font-size: 30rpx;
- font-weight: 400;
- color: #999999;
- margin-bottom: 250rpx;
- }
- }
- }
- </style>
|