代码提交
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
<template>
|
||||
<layout>
|
||||
<uv-navbar
|
||||
:fixed="false"
|
||||
:title="title"
|
||||
left-arrow
|
||||
@leftClick="$onClickLeft"
|
||||
:fixed="false"
|
||||
:title="title"
|
||||
left-arrow
|
||||
@leftClick="goBack"
|
||||
/>
|
||||
<view class="create-address">
|
||||
|
||||
@ -15,10 +15,10 @@
|
||||
</view>
|
||||
<view class="list-content">
|
||||
<city-select
|
||||
ref="cityselect"
|
||||
:defaultValue="defaultAddress"
|
||||
@callback="result"
|
||||
:items="main.areaList"
|
||||
ref="cityselect"
|
||||
:defaultValue="defaultAddress"
|
||||
@callback="result"
|
||||
:items="main.areaList"
|
||||
></city-select>
|
||||
|
||||
</view>
|
||||
@ -31,9 +31,9 @@
|
||||
</view>
|
||||
<view class="list-content">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="请输入详细地址"
|
||||
v-model="addressData.detail"
|
||||
type="text"
|
||||
placeholder="请输入详细地址"
|
||||
v-model="addressData.detail"
|
||||
>
|
||||
|
||||
</view>
|
||||
@ -46,9 +46,9 @@
|
||||
</view>
|
||||
<view class="list-content">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="请输入姓名"
|
||||
v-model="addressData.realName"
|
||||
type="text"
|
||||
placeholder="请输入姓名"
|
||||
v-model="addressData.realName"
|
||||
>
|
||||
|
||||
</view>
|
||||
@ -61,52 +61,48 @@
|
||||
</view>
|
||||
<view class="list-content">
|
||||
<input
|
||||
type="number"
|
||||
placeholder="请输入电话"
|
||||
v-model="addressData.phone"
|
||||
type="number"
|
||||
placeholder="请输入电话"
|
||||
v-model="addressData.phone"
|
||||
>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="form-checkbox">
|
||||
<uv-checkbox
|
||||
shape="circle"
|
||||
label="设为默认地址"
|
||||
name="isDefault"
|
||||
labelColor="#999999"
|
||||
activeColor="#EE6D46"
|
||||
v-model="addressData.isDefault"
|
||||
></uv-checkbox>
|
||||
<uv-checkbox-group v-model="isDefaultList">
|
||||
<uv-checkbox
|
||||
shape="circle"
|
||||
label="设为默认地址"
|
||||
name="isDefault"
|
||||
labelColor="#999999"
|
||||
activeColor="#EE6D46"
|
||||
@change="changeDefault"
|
||||
></uv-checkbox>
|
||||
</uv-checkbox-group>
|
||||
</view>
|
||||
<div class="form-buttons">
|
||||
|
||||
<view class="form-buttons">
|
||||
<uv-button
|
||||
type="primary"
|
||||
text="提交"
|
||||
customStyle="margin-top: 10px"
|
||||
@click="onSave"
|
||||
type="primary"
|
||||
text="提交"
|
||||
customStyle="margin-top: 10px"
|
||||
@click="onSave"
|
||||
></uv-button>
|
||||
</div>
|
||||
</view>
|
||||
|
||||
</layout>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue'
|
||||
import { navigateTo, back } from '@/utils/router'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { useMainStore } from '@/store/store'
|
||||
import {
|
||||
getAddressDel,
|
||||
getAddressDefault,
|
||||
getAddressAddAndEdit,
|
||||
getAddressList,
|
||||
getAddressCityList,
|
||||
} from '@/api/address'
|
||||
// import { closeToast, showLoadingToast, showToast, showSuccessToast, showFailToast } from 'vant'
|
||||
import { getAddressAddAndEdit, getAddressDel, } from '@/api/address'
|
||||
import { useRouter } from "@/hooks/useRouter";
|
||||
|
||||
const main = useMainStore()
|
||||
const {getParams, push, goBack} = useRouter()
|
||||
|
||||
|
||||
const areaList = ref(main.areaList)
|
||||
const title = ref('')
|
||||
@ -117,7 +113,7 @@ const defaultAddress = ref('')
|
||||
const addressData = ref({
|
||||
"realName": '',
|
||||
"postCode": '',
|
||||
"isDefault": '',
|
||||
"isDefault": false,
|
||||
"detail": '',
|
||||
"phone": '',
|
||||
"cityId": '',
|
||||
@ -126,15 +122,48 @@ const addressData = ref({
|
||||
"province": '',
|
||||
});
|
||||
|
||||
|
||||
const isDefaultList = ref([])
|
||||
const changeDefault = (props) => {
|
||||
addressData.value.isDefault = props
|
||||
}
|
||||
const actionType = ref('')
|
||||
const onSave = async () => {
|
||||
|
||||
if (!addressData.value.address?.cityId) {
|
||||
uni.showToast({
|
||||
title: "请选择收货地址",
|
||||
icon: "none",
|
||||
duration: 2000
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!addressData.value.detail) {
|
||||
uni.showToast({
|
||||
title: "请输入详细地址!",
|
||||
icon: "none",
|
||||
duration: 2000
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!addressData.value.realName) {
|
||||
uni.showToast({
|
||||
title: "请输入姓名!",
|
||||
icon: "none",
|
||||
duration: 2000
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!addressData.value.phone || !(/^1[34578]\d{9}$/.test(addressData.value.phone))) {
|
||||
uni.showToast({
|
||||
title: "请输入正确手机号!",
|
||||
icon: "none",
|
||||
duration: 2000
|
||||
});
|
||||
return;
|
||||
}
|
||||
uni.showLoading({
|
||||
title: '保存中',
|
||||
mask: true,
|
||||
})
|
||||
|
||||
|
||||
try {
|
||||
let res = await getAddressAddAndEdit({
|
||||
id: editId.value,
|
||||
@ -144,10 +173,10 @@ const onSave = async () => {
|
||||
detail: addressData.value.detail,
|
||||
phone: addressData.value.phone,
|
||||
address: {
|
||||
cityId: addressData.value.cityId,
|
||||
city: addressData.value.city,
|
||||
district: addressData.value.district,
|
||||
province: addressData.value.province,
|
||||
cityId: addressData.value.address.cityId,
|
||||
city: addressData.value.address.city,
|
||||
district: addressData.value.address.district,
|
||||
province: addressData.value.address.province,
|
||||
}
|
||||
})
|
||||
|
||||
@ -157,9 +186,14 @@ const onSave = async () => {
|
||||
duration: 2000
|
||||
});
|
||||
uni.hideLoading()
|
||||
main.getAddressList()
|
||||
|
||||
main.restAddress()
|
||||
if (actionType.value == 'select') {
|
||||
push({url: '/pages/address/address'}, {data: {type: 'select'}})
|
||||
} else {
|
||||
push({url: '/pages/address/address'})
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error, 'err')
|
||||
// closeToast()
|
||||
if (error.msg) {
|
||||
// showFailToast(error.msg);
|
||||
@ -171,18 +205,16 @@ const onSave = async () => {
|
||||
|
||||
const onDelete = async () => {
|
||||
getAddressDel()
|
||||
main.getAddressList()
|
||||
main.getAddressList(1)
|
||||
|
||||
};
|
||||
|
||||
const result = (values) => {
|
||||
console.log(this)
|
||||
console.log(values)
|
||||
addressData.value.address = {
|
||||
province: values.province.name || '',
|
||||
city: values.city.name || '',
|
||||
district: values.district.name || '',
|
||||
city_id: values.city.id,
|
||||
cityId: values.city.id,
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,32 +228,35 @@ watch(() => main.address, (next) => {
|
||||
addressData.value = {
|
||||
realName: data.realName,
|
||||
phone: data.phone,
|
||||
province: data.province,
|
||||
city: data.city,
|
||||
district: data.district,
|
||||
detail: data.detail,
|
||||
cityId: data.cityId,
|
||||
isDefault: data.isDefault,
|
||||
}
|
||||
defaultAddress.value = {
|
||||
province: {
|
||||
name: data.province
|
||||
},
|
||||
city: {
|
||||
name: data.city
|
||||
},
|
||||
district: {
|
||||
name: data.district
|
||||
isDefault: data.isDefault ? 1 : 0,
|
||||
address: {
|
||||
cityId: data.cityId,
|
||||
district: data.district,
|
||||
province: data.province,
|
||||
city: data.city
|
||||
}
|
||||
}
|
||||
isDefaultList.value = data.isDefault ? ['isDefault'] : [],
|
||||
defaultAddress.value = {
|
||||
province: {
|
||||
name: data.province
|
||||
},
|
||||
city: {
|
||||
name: data.city
|
||||
},
|
||||
district: {
|
||||
name: data.district
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
onLoad((option) => {
|
||||
const { id } = option
|
||||
|
||||
main.getAddressCityList()
|
||||
main.getAddressList()
|
||||
|
||||
onLoad(async (options) => {
|
||||
const params = getParams(options)
|
||||
let id = params.id
|
||||
actionType.value = params.type
|
||||
// main.restAddress()
|
||||
await main.getAddressCityList()
|
||||
if (id) {
|
||||
editId.value = id
|
||||
title.value = '编辑地址'
|
||||
@ -230,12 +265,14 @@ onLoad((option) => {
|
||||
addressData.value = {
|
||||
realName: data.realName,
|
||||
phone: data.phone,
|
||||
province: data.province,
|
||||
city: data.city,
|
||||
county: data.county,
|
||||
detail: data.detail,
|
||||
cityId: data.cityId,
|
||||
isDefault: data.isDefault,
|
||||
address: {
|
||||
cityId: data.cityId,
|
||||
city: data.city,
|
||||
district: data.district,
|
||||
province: data.province,
|
||||
}
|
||||
}
|
||||
defaultAddress.value = {
|
||||
province: {
|
||||
@ -248,7 +285,7 @@ onLoad((option) => {
|
||||
name: data.district
|
||||
}
|
||||
}
|
||||
|
||||
isDefaultList.value = data.isDefault ? ['isDefault'] : []
|
||||
} else {
|
||||
title.value = '新增地址'
|
||||
|
||||
@ -257,11 +294,15 @@ onLoad((option) => {
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
<style lang="scss">
|
||||
.create-address {
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.form-checkbox {
|
||||
padding-left: 35rpx;
|
||||
}
|
||||
|
||||
.w-158 {
|
||||
flex: 0 0 158rpx;
|
||||
}
|
||||
|
Reference in New Issue
Block a user