123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <template>
- <view class="container">
- <view class="address-list">
- <u-swipe-action v-for="(item, index) in addressList" :key="index" :index="index" @click="deleteAddress" :options="options">
- <view class="address-row" @click="setAddress(item)">
- <view class="address-first-name" :class="item.isDefault ? 'address-first-name-active' : ''">{{item.username ? item.username.slice(0,1) : ''}}</view>
- <view class="address-info">
- <view class="address-name-phone">
- <text class="address-name">{{item.username}}</text>
- <text class="address-phone">{{item.phone}}</text>
- </view>
- <view class="address-type-text">
- <view v-if="item.isDefault || item.tag" class="address-type" :class="item.isDefault? 'address-type-active' : ''">{{item.isDefault ? '默认' : item.tag}}</view>
- <text class="address-text">{{item.province}},{{item.city}},{{item.area}},{{item.address}}</text>
- </view>
- </view>
- <view class="address-edit" @click.stop="editAddress(item)">编辑</view>
- </view>
- </u-swipe-action>
- </view>
- <view class="address-handle">
- <u-button type="success" shape="circle" :ripple="true" @click="addAddress" class="handle-custom">新增地址</u-button>
- </view>
- <u-modal v-model="modalShow" content="是否将删除该地址" @confirm="submitDelete" :async-close="true" :show-cancel-button="true"></u-modal>
- <u-top-tips ref="uTips"></u-top-tips>
- </view>
- </template>
- <script>
- const NET = require('@/utils/request')
- const API = require('@/config/api')
- export default {
- data() {
- return {
- pageType: 1,
- addressList: [],
- options: [{
- text: '删除',
- style: {
- backgroundColor: '#dd524d'
- }
- }],
- modalShow: false,
- }
- },
- onLoad(options) {
- this.pageType = options.type
- },
- onShow() {
- this.getAddress()
- },
- onPullDownRefresh() {
- this.getAddress('refresh')
- },
- methods: {
- // 查询地址
- getAddress(type) {
- NET.request(API.getAddressList, {}, 'POST').then(res => {
- if (type == 'refresh') {
- uni.stopPullDownRefresh();
- }
- this.addressList = res.data
- }).catch(error => {
- this.$refs.uTips.show({
- title: '获取默认地址失败',
- type: 'warning',
- })
- })
- },
- // 设置地址
- setAddress(item) {
- if (this.pageType == 2) {
- uni.setStorage({
- key: 'defaultAddress',
- data: {
- memberAddressId: item.id,
- username: item.username,
- phone: item.phone,
- province: item.province,
- city: item.city,
- area: item.area,
- address: item.address,
- }
- });
- uni.navigateBack()
- }
- },
- // 删除地址
- deleteAddress(index, index1) {
- this.addressId = this.addressList[index].id
- this.modalShow = true
- },
- // 提交删除地址
- submitDelete() {
- NET.request(API.deleteAddress + this.addressId, {}, 'GET').then(res => {
- this.getAddress()
- this.modalShow = false
- }).catch(error => {
- this.modalShow = false
- this.$refs.uTips.show({
- title: '删除该地址失败',
- type: 'warning',
- })
- })
- },
- // 编辑地址
- editAddress(item) {
- uni.navigateTo({
- url: '/pagesMain/addressForm?addressId=' + item.id
- });
- },
- // 新增地址
- addAddress() {
- uni.navigateTo({
- url: '/pagesMain/addressForm'
- });
- }
- },
- }
- </script>
- <style lang="less" scoped>
- page {
- width: 100%;
- height: 100%;
- }
- .container {
- width: 100%;
- height: 100%;
- float: left;
- box-sizing: border-box;
- padding-bottom: 70px;
- overflow-y: auto;
- .address-list {
- width: 100%;
- float: left;
- .address-row {
- width: 100%;
- // height: 77px;
- float: left;
- border-bottom: 1px solid #DBDBDB;
- box-sizing: border-box;
- padding: 20px 15px;
- position: relative;
- .address-first-name {
- width: 36px;
- height: 36px;
- float: left;
- background: #fe9900;
- border-radius: 50%;
- color: #FFFFFF;
- font-size: 18px;
- font-family: PingFang SC;
- text-align: center;
- line-height: 36px;
- top: 50%;
- position: absolute;
- transform: translateY(-50%);
- }
- .address-first-name-active {
- background: #51A539;
- }
- .address-info {
- width: calc(100% - 103px);
- // height: 36px;
- float: left;
- margin: 0 10px 0 51px;
- .address-name-phone {
- width: 100%;
- // height: 16px;
- float: left;
- line-height: 16px;
- font-family: PingFang SC;
- .address-name {
- color: #333333;
- font-size: 15px;
- margin-right: 16px;
- }
- .address-phone {
- color: #656565;
- font-size: 12px;
- }
- }
- .address-type-text {
- width: 100%;
- // height: 16px;
- margin-top: 4px;
- float: left;
- line-height: 16px;
- font-family: PingFang SC;
- .address-type {
- height: 16px;
- padding: 0 6px;
- display: inline-block;
- border-radius: 4px;
- font-size: 12px;
- color: #FFFFFF;
- background: #fe9900;
- margin-right: 6px;
- }
- .address-type-active {
- background: #51A539;
- }
- .address-text {
- font-size: 12px;
- color: #333333;
- word-break:break-all;
- }
- }
- }
- .address-edit {
- width: 42px;
- height: 26px;
- margin: 5px 0;
- float: left;
- border-left: 1px solid #DBDBDB;
- line-height: 26px;
- text-align: right;
- font-size: 12px;
- font-family: PingFang SC;
- color: #656565;
- top: 50%;
- right: 15px;
- position: absolute;
- transform: translateY(-50%);
- }
- }
- }
- .address-handle {
- width: calc(100% - 30px);
- height: 40px;
- position: fixed;
- bottom: 20px;
- left: 15px;
- .handle-custom {
- background-color: #56a83a;
- /deep/button {
- background-color: #56a83a;
- }
- /deep/.u-btn--success--disabled {
- background-color: #74bd60 !important;
- }
- }
- }
- }
- </style>
|