Merge pull request '实现存在多地址时选择实际地址的设置' (#49) from Brunch_DBK into main

pull/52/head
pikvyz67s 1 month ago
commit 237e186172

@ -58,3 +58,7 @@ export const addressListApi = (parm) => {
export const editAddressApi = (parm) => {
return http.put("/wxapi/address", parm)
}
//默认地址查询
export const getAddressApi = (parm) => {
return http.get("/wxapi/address/getAddress", parm)
}

@ -1,6 +1,9 @@
<template>
<view>
<radio-group @change="radioChange">
<view class="item" v-for="(res, index) in siteList.list" :key="res.id">
<radio :value="JSON.stringify(res)" :checked="res.addressId == store.checkedId" />
<view style="flex-grow: 1;">
<view class="top">
<view class="name">{{ res.userName }}</view>
<view class="phone">{{ res.phone }}</view>
@ -13,6 +16,8 @@
<u-icon @click="update(res)" name="edit-pen" :size="40" color="#999999"></u-icon>
</view>
</view>
</view>
</radio-group>
<view class="addSite" @tap="toAddSite">
<view class="add">
<u-icon name="plus" color="#ffffff" class="icon" :size="30"></u-icon>
@ -30,9 +35,13 @@
reactive,
ref
} from 'vue'
import {
addressStore
} from '../../store/address.js'
import {
addressListApi
} from '../../api/user.js'
const store = addressStore()
//
const siteList = reactive({
list: []
@ -57,9 +66,23 @@
const update = (item) => {
console.log(item)
uni.navigateTo({
url: '../address/address'
url: '../address/address?item=' + JSON.stringify(item)
});
}
//
const radioChange = (e) => {
console.log(e)
if (e.detail.value) {
let item = JSON.parse(e.detail.value)
store.checkedId = item.addressId
store.userName = item.userName
store.phone = item.phone
store.area = item.area
store.address = item.address
//
uni.navigateBack()
}
}
onShow(() => {
getList()
})
@ -68,6 +91,8 @@
<style lang="scss" scoped>
.item {
padding: 40rpx 20rpx;
display: flex;
align-items: center;
.top {
display: flex;

@ -3,14 +3,14 @@
<view>
<view class="info">
<view class="name">
张明
{{astore.userName}}
</view>
<view class="phone">
18681xxxxx
{{astore.phone}}
</view>
</view>
<view>
北京工业大学
{{astore.area}}{{astore.address}}
</view>
</view>
<u-icon name="arrow-right" color="#c8c9cc"></u-icon>
@ -53,8 +53,18 @@
import {
orderStore
} from '../../store/order.js'
import {
addressStore
} from '../../store/address.js'
import {
getAddressApi
} from '../../api/user.js'
import {
onLoad
} from '@dcloudio/uni-app';
//store
const store = orderStore()
const astore = addressStore()
const goods = computed(() => {
return store.orderList
})
@ -119,9 +129,26 @@
//
const toAddress = (item) => {
uni.navigateTo({
url: '../address/address'
url: '../addresslist/addresslist'
});
}
//
const getAddress = async () => {
let res = await getAddressApi({
openid: uni.getStorageSync('openid')
})
console.log(res)
if (res && res.code == 200) {
astore.checkedId = res.data.addressId
astore.userName = res.data.userName
astore.phone = res.data.phone
astore.area = res.data.area
astore.address = res.data.address
}
}
onLoad(() => {
getAddress()
})
</script>
<style lang="scss">

@ -0,0 +1,22 @@
// 引入
import {
defineStore
} from 'pinia';
//通过defineStore定义一个store,
// defineStore 第一个参数是唯一的
export const addressStore = defineStore('addressStore', {
state: () => {
return {
checkedId: '',
userName: '',
phone: '',
area: '',
address: ''
};
},
// 也可以这样定义
// state: () => ({ count: 0 })
actions: {
},
});
Loading…
Cancel
Save