Feat(地址管理):自动识别对接

This commit is contained in:
lifizer
2024-06-26 16:45:48 +08:00
parent d4f61842fb
commit 28ffaee0ce
2 changed files with 127 additions and 45 deletions
+7
View File
@@ -273,6 +273,13 @@ export function postAddress(data) {
return request.post("/address/edit", data); return request.post("/address/edit", data);
} }
/*
* 自动识别收货地址
* */
export function analysisAddress(data) {
return request.post("/address/analysis", data);
}
/* /*
* 获取收藏产品 * 获取收藏产品
* */ * */
+120 -45
View File
@@ -7,7 +7,7 @@
</view> </view>
<view class="item acea-row row-between-wrapper"> <view class="item acea-row row-between-wrapper">
<view class="name">联系电话</view> <view class="name">联系电话</view>
<input type="text" placeholder="请输入联系电话" v-model="userAddress.phone" required :maxlength="11"/> <input type="number" placeholder="请输入联系电话" v-model="userAddress.phone" required :maxlength="11"/>
</view> </view>
<view class="item acea-row row-between-wrapper"> <view class="item acea-row row-between-wrapper">
<view class="name">所在地区</view> <view class="name">所在地区</view>
@@ -29,6 +29,31 @@
<!-- <textarea v-model="userAddress.detail" placeholder="请填写具体地址" /> --> <!-- <textarea v-model="userAddress.detail" placeholder="请填写具体地址" /> -->
</view> </view>
</view> </view>
<view class="address-analysis-wrap">
<view class="inp">
<textarea
v-model.trim="addressInput"
placeholder="请粘贴收件人手机号、姓名、收货地址并用空格区分,系统将自动识别地址信息"
placeholder-style="font-size:24rpx;color:#C2C5CC;"
class="inp-textarea"
/>
</view>
<view class="btn-wrap">
<view
class="txt"
@click="clearHandle"
>
清空
</view>
<view
:class="addressInput ? '' : 'disable'"
class="btn"
@click="distinguishHandle"
>
识别
</view>
</view>
</view>
<view class="default acea-row row-middle"> <view class="default acea-row row-middle">
<view class="select-btn"> <view class="select-btn">
<view class="checkbox-wrapper"> <view class="checkbox-wrapper">
@@ -48,13 +73,12 @@
</template> </template>
<script type="text/babel"> <script type="text/babel">
import CitySelect from "@/components/CitySelect"; import CitySelect from '@/components/CitySelect'
import config from '@/utils/mapConfig'; import config from '@/utils/mapConfig'
import {getAddress, getCity, postAddress} from "@/api/user"; import { getAddress, getCity, postAddress, analysisAddress } from '@/api/user'
import attrs, {chs_extphone, required} from "@/utils/validate"; import attrs, { chs_extphone, required } from '@/utils/validate'
import {validatorDefaultCatch} from "@/utils/dialog"; import { validatorDefaultCatch } from '@/utils/dialog'
// import { openAddress } from "@/libs/wechat"; import { isWeixin } from '@/utils'
import {isWeixin} from "@/utils";
import { pageListenMixins } from '@/mixins/pageListenMixins' import { pageListenMixins } from '@/mixins/pageListenMixins'
export default { export default {
@@ -67,54 +91,76 @@ export default {
return { return {
district: [], district: [],
id: 0, id: 0,
userAddress: {isDefault: 0}, userAddress: {
realName: '',
phone: '',
detail: '',
isDefault: 0
},
address: {}, address: {},
isWechat: isWeixin(), isWechat: isWeixin(),
addressText: "", addressText: "",
pageKeyId: Object.freeze('userAddressEdit') pageKeyId: Object.freeze('userAddressEdit'),
addressInput: ''
}; };
}, },
mounted: function () { mounted: function () {
let id = this.$yroute.query.id; const id = this.$yroute.query.id
this.id = id; this.id = id
if (this.id) { if (this.id) {
uni.setNavigationBarTitle({ uni.setNavigationBarTitle({
title: '编辑地址' title: '编辑地址'
}) })
} }
this.getUserAddress(); this.getUserAddress()
this.getCityList(); this.getCityList()
},
watch: {
// addressText(nextModel2) {
// console.log(nextModel2, 8585858585);
// }
//定位成功后回调
// province(newVal,oldVal){
// uni.hideLoading();
// //if(newVal!=oldVal){
// this.addressText =
// this.province + " " + this.city + " " + this.county;
// this.address.province = this.province;
// this.address.city = this.city;
// this.address.district = this.county;
// this.userAddress.detail = this.detailAddress;
// //}
// }
}, },
methods: { methods: {
getIndex(value, arr) { getIndex(value, arr) {
var idx = -1; var idx = -1
for (var i = 0; i < arr.length; i++) { for (var i = 0; i < arr.length; i++) {
if (arr[i].n == value) { if (arr[i].n == value) {
idx = i; idx = i
break; break
} }
} }
return idx; return idx
},
clearHandle() {
if (!this.addressInput) return
this.addressInput = ''
},
// 识别
distinguishHandle() {
if (!this.addressInput) return
uni.showLoading()
analysisAddress({
content: this.addressInput
}).then((res) => {
uni.hideLoading()
console.log(res)
const { success, data } = res
if (success) {
this.address = {
province: data.province || '',
city: data.city || '',
district: data.district || '',
city_id: data.cityId
}
this.userAddress.realName = data.realName || ''
this.userAddress.phone = data.phone || ''
this.userAddress.detail = data.detail || ''
this.addressText = `${this.address.province} ${this.address.city} ${this.address.district}`
}
}).catch((err) => {
uni.hideLoading()
uni.showToast({
title: err.msg + '',
icon: 'none',
mask: false,
duration: 1500
})
})
}, },
//获取当前定位地址 //获取当前定位地址
getCurAddress() { getCurAddress() {
@@ -256,8 +302,7 @@ export default {
let that = this; let that = this;
getAddress(that.id).then(res => { getAddress(that.id).then(res => {
that.userAddress = res.data; that.userAddress = res.data;
that.addressText = that.addressText = res.data.province + " " + res.data.city + " " + res.data.district;
res.data.province + " " + res.data.city + " " + res.data.district;
that.address.province = res.data.province; that.address.province = res.data.province;
that.address.city = res.data.city; that.address.city = res.data.city;
that.address.district = res.data.district; that.address.district = res.data.district;
@@ -281,11 +326,11 @@ export default {
getAddress() { getAddress() {
}, },
async submit() { async submit() {
let name = this.userAddress.realName, const name = this.userAddress.realName || ''
phone = this.userAddress.phone, const phone = this.userAddress.phone || ''
addressText = this.addressText, const addressText = this.addressText || ''
detail = this.userAddress.detail, const detail = this.userAddress.detail || ''
isDefault = this.userAddress.isDefault; const isDefault = this.userAddress.isDefault
if (phone.length < 11) { if (phone.length < 11) {
uni.showToast({ uni.showToast({
@@ -374,4 +419,34 @@ export default {
display: block; display: block;
} }
} }
.address-analysis-wrap {
padding: 20rpx;
margin: 20rpx;
border-radius: 15rpx;
background-color: #fff;
font-size: 24rpx;
.inp-textarea {
width: 100%;
height: 120rpx;
}
.btn-wrap {
display: flex;
justify-content: flex-end;
align-items: center;
margin: 20rpx 0 0 0;
.txt {
color: #999;
}
.btn {
padding: 12rpx 25rpx;
margin: 0 0 0 20rpx;
border-radius: 8rpx;
color: #fff;
background-color: #FE5261;
&.disable {
opacity: 0.75;
}
}
}
}
</style> </style>