Feat(地址管理):自动识别对接
This commit is contained in:
@@ -273,6 +273,13 @@ export function postAddress(data) {
|
||||
return request.post("/address/edit", data);
|
||||
}
|
||||
|
||||
/*
|
||||
* 自动识别收货地址
|
||||
* */
|
||||
export function analysisAddress(data) {
|
||||
return request.post("/address/analysis", data);
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取收藏产品
|
||||
* */
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</view>
|
||||
<view class="item acea-row row-between-wrapper">
|
||||
<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 class="item acea-row row-between-wrapper">
|
||||
<view class="name">所在地区</view>
|
||||
@@ -29,6 +29,31 @@
|
||||
<!-- <textarea v-model="userAddress.detail" placeholder="请填写具体地址" /> -->
|
||||
</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="select-btn">
|
||||
<view class="checkbox-wrapper">
|
||||
@@ -48,13 +73,12 @@
|
||||
</template>
|
||||
|
||||
<script type="text/babel">
|
||||
import CitySelect from "@/components/CitySelect";
|
||||
import config from '@/utils/mapConfig';
|
||||
import {getAddress, getCity, postAddress} from "@/api/user";
|
||||
import attrs, {chs_extphone, required} from "@/utils/validate";
|
||||
import {validatorDefaultCatch} from "@/utils/dialog";
|
||||
// import { openAddress } from "@/libs/wechat";
|
||||
import {isWeixin} from "@/utils";
|
||||
import CitySelect from '@/components/CitySelect'
|
||||
import config from '@/utils/mapConfig'
|
||||
import { getAddress, getCity, postAddress, analysisAddress } from '@/api/user'
|
||||
import attrs, { chs_extphone, required } from '@/utils/validate'
|
||||
import { validatorDefaultCatch } from '@/utils/dialog'
|
||||
import { isWeixin } from '@/utils'
|
||||
import { pageListenMixins } from '@/mixins/pageListenMixins'
|
||||
|
||||
export default {
|
||||
@@ -67,54 +91,76 @@ export default {
|
||||
return {
|
||||
district: [],
|
||||
id: 0,
|
||||
userAddress: {isDefault: 0},
|
||||
userAddress: {
|
||||
realName: '',
|
||||
phone: '',
|
||||
detail: '',
|
||||
isDefault: 0
|
||||
},
|
||||
address: {},
|
||||
isWechat: isWeixin(),
|
||||
addressText: "",
|
||||
pageKeyId: Object.freeze('userAddressEdit')
|
||||
pageKeyId: Object.freeze('userAddressEdit'),
|
||||
addressInput: ''
|
||||
};
|
||||
},
|
||||
mounted: function () {
|
||||
let id = this.$yroute.query.id;
|
||||
this.id = id;
|
||||
const id = this.$yroute.query.id
|
||||
this.id = id
|
||||
if (this.id) {
|
||||
uni.setNavigationBarTitle({
|
||||
title: '编辑地址'
|
||||
})
|
||||
}
|
||||
this.getUserAddress();
|
||||
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;
|
||||
|
||||
// //}
|
||||
// }
|
||||
this.getUserAddress()
|
||||
this.getCityList()
|
||||
},
|
||||
methods: {
|
||||
|
||||
getIndex(value, arr) {
|
||||
var idx = -1;
|
||||
var idx = -1
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if (arr[i].n == value) {
|
||||
idx = i;
|
||||
break;
|
||||
idx = i
|
||||
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() {
|
||||
@@ -256,8 +302,7 @@ export default {
|
||||
let that = this;
|
||||
getAddress(that.id).then(res => {
|
||||
that.userAddress = res.data;
|
||||
that.addressText =
|
||||
res.data.province + " " + res.data.city + " " + res.data.district;
|
||||
that.addressText = res.data.province + " " + res.data.city + " " + res.data.district;
|
||||
that.address.province = res.data.province;
|
||||
that.address.city = res.data.city;
|
||||
that.address.district = res.data.district;
|
||||
@@ -281,11 +326,11 @@ export default {
|
||||
getAddress() {
|
||||
},
|
||||
async submit() {
|
||||
let name = this.userAddress.realName,
|
||||
phone = this.userAddress.phone,
|
||||
addressText = this.addressText,
|
||||
detail = this.userAddress.detail,
|
||||
isDefault = this.userAddress.isDefault;
|
||||
const name = this.userAddress.realName || ''
|
||||
const phone = this.userAddress.phone || ''
|
||||
const addressText = this.addressText || ''
|
||||
const detail = this.userAddress.detail || ''
|
||||
const isDefault = this.userAddress.isDefault
|
||||
|
||||
if (phone.length < 11) {
|
||||
uni.showToast({
|
||||
@@ -374,4 +419,34 @@ export default {
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user