| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <template>
- <view class="page">
- <NoData v-if="!loading&&list.length<1"></NoData>
- <view class="list" v-else>
- <AddressCard v-for="item in list" :key="item.id" :address="item" :selected="item.id==selectId"
- @delete="deletePopup" @success="getAddressList" @tapItem="handleSelectAddr" :isSelect="isSelect">
- </AddressCard>
- </view>
- <view class="bottom-fixed-con">
- <u-button class="flex-1" type="primary"
- @click="$u.route({ url: '/pages-mine/pages/address/add-or-update' })">
- <text>添加地址</text>
- </u-button>
- </view>
- <common-dialog ref="deleteDialog" title="温馨提示" @confirm="confirmDelete">
- <text>确定删除此地址信息吗?</text>
- </common-dialog>
- </view>
- </template>
- <script>
- import AddressCard from '@/pages-mine/components/address-card.vue';
- import commonDialog from '@/components/common-dialog.vue';
- export default {
- components: {
- AddressCard,
- commonDialog
- },
- data() {
- return {
- selectId: '',
- deleteId: '', //要删除的id
- isBack: false,
- loading: false,
- list: [],
- options: [{
- text: '设为默认',
- style: {
- backgroundColor: '#22ac38'
- }
- },
- {
- text: '删除',
- style: {
- backgroundColor: '#dd524d'
- }
- }
- ],
- isSelect: false, //是否是选择地址
- };
- },
- onLoad(ops) {
- if (ops.id) {
- this.selectId = ops.id
- this.isSelect = ops.isSelect
- }
- },
- onShow(ops) {
- this.getAddressList();
- },
- methods: {
- //选择地址
- handleSelectAddr(item) {
- uni.$emit('selectAddr', item)
- uni.navigateBack({
- delta: 1
- })
- },
- //打开删除弹窗
- deletePopup(id) {
- this.deleteId = id
- this.$refs.deleteDialog?.openPopup()
- },
- // 删除
- confirmDelete() {
- uni.$u.http.post(`/token/user/address/remove/${this.deleteId}`).then((res) => {
- if (res.code == 200) {
- this.$u.toast(`删除成功`);
- this.getAddressList()
- }
- })
- },
- // 设为默认
- setDefaultAddress({
- id
- }) {
- uni.$u.http.post(`/token/user/address/setDefault/${id}`).then(res => {
- if (res.code == 200) {
- uni.showToast({
- icon: "none",
- title: "设置默认地址成功"
- })
- this.getAddressList()
- } else {
- uni.showToast(res.msg)
- }
- })
- },
- getAddressList() {
- this.loading = true;
- uni.$u.http.get('/token/user/address/list?content=' + '').then(res => {
- if (res.code == 200) {
- this.list = res.data;
- }
- }).finally(() => this.loading = false)
- }
- },
- };
- </script>
- <style lang="scss" scoped>
- .list {
- padding: 20rpx 30rpx 180rpx;
- box-sizing: border-box;
- }
- </style>
|