Commit 0aa317a6 authored by lizhan's avatar lizhan

📝 【TASK-20240808-03】TASK:地址页面增删改逻辑完善

parent 3a078783
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
></dHeader> ></dHeader>
<view class="container"> <view class="container">
<view class="address-list"> <view class="address-list">
<view class="address-item" v-for="item in 3" :key="item"> <view class="address-item" v-for="item in addressList" :key="item.id">
<view class="item-header"> <view class="item-header">
<view class="item-name">张三</view> <view class="item-name">{{ item.name }}</view>
<view class="item-phone">+86 18888888888</view> <view class="item-phone">+{{ item.areaCode }}&ensp;{{ item.phone }}</view>
</view> </view>
<view class="item-content"> <view class="item-content">
辽宁省大连市甘井子区广贤路56号星光大道甘井子区广贤路56号星光大道 {{ item.address }}
</view> </view>
<view class="item-footer"> <view class="item-footer">
<view <view
...@@ -25,18 +25,17 @@ ...@@ -25,18 +25,17 @@
><radio ><radio
class="radio" class="radio"
color="#ff4d4f" color="#ff4d4f"
value="r1" :checked="check == item.id"
:value="item + ''" :value="item.name"
:checked="check == item"
/>设为默认地址</label />设为默认地址</label
> >
</view> </view>
<view class="item-footer-right"> <view class="item-footer-right">
<view class="right-box" @click="toEditAddress"> <view class="right-box" @click="toEditAddress(item.id)">
<image class="item-img" src="../../static/img/edit.png"></image> <image class="item-img" src="../../static/img/edit.png"></image>
编辑</view 编辑</view
> >
<view class="right-box"> <view class="right-box" @click="deleteAddress(item.id)">
<image class="item-img" src="../../static/img/delete_pail.png"></image> <image class="item-img" src="../../static/img/delete_pail.png"></image>
删除</view 删除</view
> >
...@@ -56,23 +55,68 @@ export default { ...@@ -56,23 +55,68 @@ export default {
}, },
data() { data() {
return { return {
check: 1 check: null,
addressList: []
} }
}, },
onShow() {
this.getAddressList()
},
methods: { methods: {
toAddressAdd() { toAddressAdd() {
uni.navigateTo({ uni.navigateTo({
url: '/pages/address_add/address_add' url: '/pages/address_add/address_add'
}) })
}, },
toEditAddress() { toEditAddress(id) {
uni.navigateTo({ uni.navigateTo({
url: '/pages/address_edit/address_edit' url: '/pages/address_edit/address_edit?id=' + id
}) })
}, },
// 切换默认地址 // 切换默认地址
bindCheck(e, item) { async bindCheck(e, item) {
this.check = item this.check = item.id
try {
await this.$request.post('/app-api/member/user-address/update', {
...item,
isDefault: 0
})
} catch (err) {}
},
// 获取地址列表
async getAddressList() {
try {
const id = this.$store.getters.id
const { code, data } = await this.$request.get('/app-api/member/user-address/member/list', {
id
})
if (code == 0 && data) {
// console.log(data)
this.addressList = data
const i = this.addressList.findIndex((item) => item.isDefault === 0)
if (i >= 0) this.check = this.addressList[i].id
}
} catch (err) {}
},
// 删除地址
async deleteAddress(id) {
const that = this
uni.showModal({
title: that.$lang.lang.notices.notice,
content: that.$lang.lang.notices.delAddress,
success: async (res) => {
if (res.confirm) {
try {
const { code } = await that.$request.post(
`/app-api/member/user-address/delete?id=${id}`
)
if (code == 0) {
that.getAddressList()
}
} catch (err) {}
}
}
})
} }
} }
} }
......
...@@ -3,18 +3,23 @@ ...@@ -3,18 +3,23 @@
<dHeader :title="$lang.lang.addressInfo.addInfo"></dHeader> <dHeader :title="$lang.lang.addressInfo.addInfo"></dHeader>
<view class="container"> <view class="container">
<uni-forms ref="form" :model="form" :label-width="80" :rules="rules"> <uni-forms ref="form" :model="form" :label-width="80" :rules="rules">
<uni-forms-item :label="$lang.lang.addressInfo.consignee" required name="consignee"> <uni-forms-item :label="$lang.lang.addressInfo.consignee" required name="name">
<uni-easyinput <uni-easyinput
class="input" class="input"
:trim="true" :trim="true"
:inputBorder="false" :inputBorder="false"
v-model="form.consignee" v-model="form.name"
:placeholder="$lang.lang.notices.consignee" :placeholder="$lang.lang.notices.consignee"
/> />
</uni-forms-item> </uni-forms-item>
<uni-forms-item :label="$lang.lang.addressInfo.phone" required name="phone"> <uni-forms-item :label="$lang.lang.addressInfo.phone" required name="phone">
<view class="phone-box"> <view class="phone-box">
<view class="phone-code">+86</view> <picker :value="areaIndex" :range="areaName" @change="areaChange">
<view class="phone-code">
+{{ areaCode }}
<uni-icons type="down" class="code-icon" size="10"></uni-icons>
</view>
</picker>
<uni-easyinput <uni-easyinput
class="input" class="input"
:trim="true" :trim="true"
...@@ -28,7 +33,7 @@ ...@@ -28,7 +33,7 @@
class="item" class="item"
:label="$lang.lang.addressInfo.fullAddress" :label="$lang.lang.addressInfo.fullAddress"
required required
name="fullAddress" name="address"
> >
<view class="textarea-box"> <view class="textarea-box">
<uni-easyinput <uni-easyinput
...@@ -38,7 +43,7 @@ ...@@ -38,7 +43,7 @@
autoHeight autoHeight
:inputBorder="false" :inputBorder="false"
:maxlength="100" :maxlength="100"
v-model.trim="form.fullAddress" v-model.trim="form.address"
:placeholder="$lang.lang.notices.fullAddress" :placeholder="$lang.lang.notices.fullAddress"
> >
</uni-easyinput> </uni-easyinput>
...@@ -60,22 +65,31 @@ export default { ...@@ -60,22 +65,31 @@ export default {
data() { data() {
return { return {
form: { form: {
consignee: '', name: '',
phone: '', phone: '',
fullAddress: '' address: ''
} },
areaCode: this.$store.getters.areaCode,
areaIndex: 0,
areaName: []
} }
}, },
computed: { computed: {
rules() { rules() {
return { return {
consignee: { name: {
rules: [{ required: true, errorMessage: this.$lang.lang.notices.consignee }] rules: [{ required: true, errorMessage: this.$lang.lang.notices.consignee }]
}, },
phone: { phone: {
rules: [{ required: true, errorMessage: this.$lang.lang.notices.phone }] rules: [
{ required: true, errorMessage: this.$lang.lang.notices.phone },
{
validateFunction: (rule, value) => /^\d+$/.test(value),
errorMessage: this.$lang.lang.notices.nophone
}
]
}, },
fullAddress: { address: {
rules: [ rules: [
{ required: true, errorMessage: this.$lang.lang.notices.fullAddress }, { required: true, errorMessage: this.$lang.lang.notices.fullAddress },
{ maxLength: 100, errorMessage: this.$lang.lang.notices.fullAddressLength } { maxLength: 100, errorMessage: this.$lang.lang.notices.fullAddressLength }
...@@ -84,12 +98,55 @@ export default { ...@@ -84,12 +98,55 @@ export default {
} }
} }
}, },
created() {
this.getCountry()
},
methods: { methods: {
saveAddress() { saveAddress() {
// console.log(this.form) this.$refs.form.validate().then(async (valid) => {
this.$refs.form.validate().then((res) => { if (valid) {
console.log(res) try {
const params = {
...this.form,
areaCode: this.areaCode,
memberId: this.$store.getters.id
}
const { code, data } = await this.$request.post(
'/app-api/member/user-address/create',
params
)
if (code == 0) {
this.$router.back()
}
} catch (error) {}
}
}) })
},
// 获取国家区号
async getCountry() {
try {
const { code, data } = await this.$request.get('/app-api/ecw/country/list-all')
if (code == 0 && data.length > 0) {
// 查询用户区号下标
const i = data.findIndex((item) => {
return item.tel == this.areaCode
})
if (i >= 0) this.areaIndex = i
data.forEach((item) => {
const str = item.tel + ' ' + item.nameZh
if (this.$lang.locale == 'zh') {
this.areaName.push(str)
} else {
this.areaName.push(str)
}
})
}
} catch (error) {}
},
// 区号选择切换
areaChange(e) {
this.areaIndex = e.detail.value
this.areaCode = this.areaName[this.areaIndex].split(' ')[0]
} }
} }
} }
...@@ -134,12 +191,17 @@ page { ...@@ -134,12 +191,17 @@ page {
align-items: center; align-items: center;
} }
.phone-code { .phone-code {
display: flex;
align-items: center;
margin-right: 10upx; margin-right: 10upx;
padding-right: 10upx; padding-right: 10upx;
border-right: 1px solid #e6e6e6; border-right: 1px solid #e6e6e6;
font-size: 24upx; font-size: 24upx;
color: #000; color: #000;
} }
.code-icon {
margin-left: 6upx;
}
.btn { .btn {
width: 100%; width: 100%;
height: 80upx; height: 80upx;
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
<dHeader :title="$lang.lang.addressInfo.editInfo"></dHeader> <dHeader :title="$lang.lang.addressInfo.editInfo"></dHeader>
<view class="container"> <view class="container">
<uni-forms ref="form" :model="form" :label-width="80" :rules="rules"> <uni-forms ref="form" :model="form" :label-width="80" :rules="rules">
<uni-forms-item :label="$lang.lang.addressInfo.consignee" required name="consignee"> <uni-forms-item :label="$lang.lang.addressInfo.consignee" required name="name">
<uni-easyinput <uni-easyinput
class="input" class="input"
:trim="true" :trim="true"
:inputBorder="false" :inputBorder="false"
v-model="form.consignee" v-model="form.name"
:placeholder="$lang.lang.notices.consignee" :placeholder="$lang.lang.notices.consignee"
/> />
</uni-forms-item> </uni-forms-item>
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
class="item" class="item"
:label="$lang.lang.addressInfo.fullAddress" :label="$lang.lang.addressInfo.fullAddress"
required required
name="fullAddress" name="address"
> >
<view class="textarea-box"> <view class="textarea-box">
<uni-easyinput <uni-easyinput
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
autoHeight autoHeight
:inputBorder="false" :inputBorder="false"
:maxlength="100" :maxlength="100"
v-model.trim="form.fullAddress" v-model.trim="form.address"
:placeholder="$lang.lang.notices.fullAddress" :placeholder="$lang.lang.notices.fullAddress"
> >
</uni-easyinput> </uni-easyinput>
...@@ -60,22 +60,31 @@ export default { ...@@ -60,22 +60,31 @@ export default {
data() { data() {
return { return {
form: { form: {
consignee: '', name: '',
phone: '', phone: '',
fullAddress: '' address: ''
} }
} }
}, },
onLoad(route) {
this.getAddress(route.id)
},
computed: { computed: {
rules() { rules() {
return { return {
consignee: { name: {
rules: [{ required: true, errorMessage: this.$lang.lang.notices.consignee }] rules: [{ required: true, errorMessage: this.$lang.lang.notices.consignee }]
}, },
phone: { phone: {
rules: [{ required: true, errorMessage: this.$lang.lang.notices.phone }] rules: [
{ required: true, errorMessage: this.$lang.lang.notices.phone },
{
validateFunction: (rule, value) => /^\d+$/.test(value),
errorMessage: this.$lang.lang.notices.nophone
}
]
}, },
fullAddress: { address: {
rules: [ rules: [
{ required: true, errorMessage: this.$lang.lang.notices.fullAddress }, { required: true, errorMessage: this.$lang.lang.notices.fullAddress },
{ maxLength: 100, errorMessage: this.$lang.lang.notices.fullAddressLength } { maxLength: 100, errorMessage: this.$lang.lang.notices.fullAddressLength }
...@@ -87,9 +96,28 @@ export default { ...@@ -87,9 +96,28 @@ export default {
methods: { methods: {
saveAddress() { saveAddress() {
// console.log(this.form) // console.log(this.form)
this.$refs.form.validate().then((res) => { this.$refs.form.validate().then(async (res) => {
console.log(res) if (res) {
try {
const { code } = await this.$request.post(
'/app-api/member/user-address/update',
this.form
)
if (code == 0) {
this.$router.back()
}
} catch (err) {}
}
}) })
},
// 获取地址信息 回显
async getAddress(id) {
try {
const { code, data } = await this.$request.get('/app-api/member/user-address/get', { id })
if (code == 0 && data) {
this.form = data
}
} catch (err) {}
} }
} }
} }
......
...@@ -381,6 +381,10 @@ export default { ...@@ -381,6 +381,10 @@ export default {
// #endif // #endif
} }
that.userInfo = res.data that.userInfo = res.data
// 存储信息节点
const { id, areaCode } = res.data
that.$store.commit('SET_ID', id)
that.$store.commit('SET_AREACODE', areaCode)
} }
}) })
}, },
......
...@@ -233,6 +233,7 @@ ...@@ -233,6 +233,7 @@
</template> </template>
<script> <script>
import storage from '../../utils/storage'
export default { export default {
data() { data() {
return { return {
...@@ -445,6 +446,7 @@ export default { ...@@ -445,6 +446,7 @@ export default {
}, },
loginOut() { loginOut() {
uni.removeStorageSync('Authorization') uni.removeStorageSync('Authorization')
storage.clean()
uni.navigateTo({ uni.navigateTo({
url: '../login/login' url: '../login/login'
}) })
...@@ -564,6 +566,7 @@ export default { ...@@ -564,6 +566,7 @@ export default {
if (res.confirm) { if (res.confirm) {
that.$request.deleted('/app-api/member/member/cancellation').then((res) => { that.$request.deleted('/app-api/member/member/cancellation').then((res) => {
if (res.code == 0 && res.data) { if (res.code == 0 && res.data) {
storage.clean()
uni.showToast({ uni.showToast({
title: that.$lang.lang.site.offSuccess, title: that.$lang.lang.site.offSuccess,
icon: 'none' icon: 'none'
......
...@@ -134,7 +134,8 @@ export default { ...@@ -134,7 +134,8 @@ export default {
country: 'Please select a country', country: 'Please select a country',
city: 'Please select a city', city: 'Please select a city',
fullAddress: 'Please enter the detailed address', fullAddress: 'Please enter the detailed address',
fullAddressLength: 'Enter up to 100 words' fullAddressLength: 'Enter up to 100 words',
delAddress: 'Are you sure you want to delete the address?'
}, },
auth: { auth: {
auth: 'Real-name certification', auth: 'Real-name certification',
......
...@@ -133,7 +133,8 @@ export default { ...@@ -133,7 +133,8 @@ export default {
country: '请选择国家', country: '请选择国家',
city: '请选择城市', city: '请选择城市',
fullAddress: '请输入详细地址', fullAddress: '请输入详细地址',
fullAddressLength: '最多输入100字' fullAddressLength: '最多输入100字',
delAddress: '确定删除地址吗?'
}, },
auth: { auth: {
auth: '实名认证', auth: '实名认证',
......
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import http from '@/utils/request' import http from '@/utils/request'
import user from './modules/user'
import storage from '../utils/storage'
Vue.use(Vuex) Vue.use(Vuex)
let userInfo = null let userInfo = null
...@@ -16,13 +17,14 @@ try { ...@@ -16,13 +17,14 @@ try {
const store = new Vuex.Store({ const store = new Vuex.Store({
state: { state: {
userInfo: userInfo || null, userInfo: userInfo || null,
config: null, config: null
}, },
mutations: { mutations: {
logout(state) { logout(state) {
state.userInfo = null state.userInfo = null
uni.removeStorageSync('userInfo'); uni.removeStorageSync('userInfo')
uni.removeStorageSync('token'); uni.removeStorageSync('token')
storage.clean()
// uni.switchTab({ // uni.switchTab({
// url: '/pages/tabbar/user/user.vue' // url: '/pages/tabbar/user/user.vue'
// }) // })
...@@ -38,16 +40,24 @@ const store = new Vuex.Store({ ...@@ -38,16 +40,24 @@ const store = new Vuex.Store({
} }
}, },
actions: { actions: {
updateUserInfo({ updateUserInfo({ commit }) {
commit http
}) { .get('/profile')
http.get("/profile").then(res => { .then((res) => {
console.log('更新用户信息', res) console.log('更新用户信息', res)
commit('setUser', res.data) commit('setUser', res.data)
}).catch(res => { })
console.log("更新用户信息error", res) .catch((res) => {
console.log('更新用户信息error', res)
}) })
} }
},
getters: {
id: (state) => state.user.id,
areaCode: (state) => state.user.areaCode
},
modules: {
user
} }
}) })
export default store export default store
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment