You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
high-mini/physical-merchants/address/addNewAddress/addNewAddress.vue

569 lines
13 KiB

2 years ago
<template>
1 year ago
<view class="page-bottom-fixed backcor9" >
2 years ago
<form @submit="form_submit" class="form-container">
1 year ago
<view class="pd-main border-box height100" :style="'overflow-y: auto;transform: translateY(-0px);'" >
2 years ago
<view class="form-gorup backcolorfff">
<view class="dis-flex">
<view class="form-gorup-title marRight10">收货人:
2 years ago
</view>
<input type="text" name="name" v-model="userAddress.name" placeholder-class="corf6"
1 year ago
class=" flex-1 bs-bb" placeholder="名字">
</view>
2 years ago
<view class="width100 mart10 border-b">
2 years ago
</view>
<view class="dis-flex">
<view class="form-gorup-title marRight10">手机号码:
</view>
<input type="number" name="tel" v-model="userAddress.tel" maxlength="11"
1 year ago
placeholder-class="corf6" class=" flex-1" placeholder="手机号">
2 years ago
</view>
2 years ago
<!-- -->
2 years ago
</view>
2 years ago
<view class="form-gorup backcolorfff">
<view class="">
<pick-regions :defaultRegion="defaultRegionCode" @getRegion="handleGetRegion">
<view class="dis-flex ">
<view class=" form-gorup-title">所在地区:</view>
<view class="dis-flex flex-1 flex-end">
1 year ago
<view class=" pickRes ">{{userAddress.region || '请选择'}}</view>
<view class="icon-ymt to-right font14 fcor666"></view>
2 years ago
</view>
</view>
2 years ago
</pick-regions>
2 years ago
</view>
<view class="width100 mart10 border-b">
2 years ago
</view>
<!-- <view style="clear: both;"> -->
1 year ago
<view class="dis-flex scrol-t mart10">
<view class="form-gorup-title marRight10">详细地址:</view>
1 year ago
<uni-combox :height="height" @focus="focusMethod" @blur="blurMethod" :cursorSpacing="50" placeholderClass="corf6" :candidates="candidates" class="flex-1" :isAddress="true" :isShowIcon="false" placeholder="请输入详细地址" v-model="userAddress.address">
<view class="selector-item" v-for="(item,index) in candidates" :key="index" @click="getSelect(item)">
<view class="text1 name">
{{item.name}}
</view>
<view class="text1 address mart5">
{{item.address}}
</view>
</view>
</uni-combox>
<!-- <input type="text" name="address" v-model="userAddress.address" maxlength="40"
placeholder-class="corf6" :class="'fcor666 bs-bb flex-1'" placeholder="详细地址1~40个字符"> -->
</view>
<!-- </view> -->
2 years ago
</view>
<view class="default-checkbox " @click="defaultChange">
2 years ago
<radio :checked="userAddress.is_default" style="transform:scale(1.1)" color="#FF1A34" />
<text class="font18">设为默认地址</text>
2 years ago
</view>
1 year ago
2 years ago
</view>
1 year ago
<view class="bottom-fixed ">
<button class="btn " type="default" form-type="submit">保存</button>
</view>
2 years ago
</form>
2 years ago
</view>
</template>
<script>
2 years ago
import pickRegions from '@/components/pick-regions/pick-regions.vue'
import UniCombox from '@/components/uni-combox/components/uni-combox/uni-combox.vue'
2 years ago
import {
insertDeliveryAddress,
findDeliveryAddressById,
updateDeliveryAddress,
baiduApiMapSearch
} from '@/Utils/physicalObject.js'
let app = getApp();
2 years ago
export default {
data() {
return {
userAddress: {
2 years ago
name: "",
tel: "",
region: '',
address: "",
is_default: false,
1 year ago
2 years ago
},
dataParams: null,
//
region: [],
regionId: '',
2 years ago
//没用上
// defaultRegion: ['北京市', '市辖区', '东城区'],
defaultRegionCode: '',
2 years ago
candidates:[
// {"name": "重庆国贸中心-东北门","address": "重庆市渝中区中华路189号",},
// {"name": "重庆国贸中心-东北门","address": "重庆市渝中区中华路189号",},
// {"name": "重庆国贸中心-东北门","address": "重庆市渝中区中华路189号",}
],
1 year ago
top:0,
top1:0,
height:0,
2 years ago
};
2 years ago
},
2 years ago
components: {
pickRegions,
"uni-combox":UniCombox
2 years ago
2 years ago
},
2 years ago
onLoad(params) {
1 year ago
// console.log(params)
2 years ago
this.dataParams = params
},
watch: {
'userAddress.name': {
2 years ago
handler(n) {
if (n.length > 5) {
setTimeout(() => {
this.userAddress.name = this.userAddress.name.substr(0, 5)
}, 0)
}
},
2 years ago
},
},
2 years ago
computed: {
2 years ago
// regionName() {
// // 转为字符串
// // console.log('==============='+this.region.map(item => item))
// // this.userAddress.region = this.region.map(item => item.name).join(',')
// return this.region.map(item => item.name).join(',')
2 years ago
// }
},
2 years ago
onReady() {
let str = ""
if (this.dataParams && this.dataParams.id) {
str = "地址编辑"
} else {
str = "地址添加"
}
2 years ago
uni.setNavigationBarTitle({
title: str,
2 years ago
});
if (this.dataParams && this.dataParams.id) {
2 years ago
this.findAddressById(this.dataParams.id)
2 years ago
}
2 years ago
2 years ago
},
2 years ago
1 year ago
async mounted() {
await this.getRect('.scrol-t').then(res => {
this.top = res.top;
})
await this.getRect('.bottom-fixed').then(res => {
this.top1 = res.top;
})
this.height = this.top1 - this.top - 120;
// console.log(this.top1,this.top,this.height)
},
2 years ago
2 years ago
methods: {
1 year ago
focusMethod(){
},
blurMethod(){
this.baiduApiMap(this.userAddress.address)
},
getRect(selector, all) {
return new Promise(resolve => {
uni.createSelectorQuery()
.in(this)
[all ? 'selectAll' : 'select'](selector)
.boundingClientRect(rect => {
if (all && Array.isArray(rect) && rect.length) {
resolve(rect);
}
if (!all && rect) {
resolve(rect);
}
})
.exec();
});
},
findAddressById(id) {
2 years ago
let params = {
id: id
2 years ago
}
findDeliveryAddressById(params).then(res => {
2 years ago
if (res.return_code == '000000') {
let resData = res.return_data;
this.userAddress = {
name: resData.consignee,
tel: resData.phone,
region: resData.regionName,
address: resData.address,
is_default: resData.whetherDefault,
}
// console.log(this.defaultRegionCode)
this.defaultRegionCode = resData.regionId;
this.regionId = resData.regionId;
// console.log(this.defaultRegionCode)
} else {
2 years ago
uni.showToast({
title: res.return_msg,
icon: 'none',
duration: 2000
})
}
})
2 years ago
},
2 years ago
// 获取选择的地区
handleGetRegion(region) {
// let region = JSON.parse(JSON.stringify(reg))
2 years ago
this.region = region;
this.regionId = this.region[2].code;
if (region[0].code == region[1].code && region[0].code == region[2].code) {
this.userAddress.region = this.region[0].name
} else {
this.userAddress.region = this.region.map(item => item.name).join(',');
}
1 year ago
// console.log(this.userAddress.region, "获取选择的地区", this.regionId, this.region)
2 years ago
},
// 获取数据
init() {
2 years ago
},
1 year ago
//监听详细地址的onInput事件
location(n){
// this.userAddress.address = this.userAddress.address.replace(/\s+/g, "")
},
1 year ago
baiduApiMap(query){
query = query.replace(/\s+/g, "")
let params={
query:query
}
1 year ago
// console.log(params,"params")
baiduApiMapSearch(params).then(res=>{
console.log(res)
if (res.return_code == '000000') {
if(res.return_data&&res.return_data.length>0){
this.candidates = res.return_data;
}else{
this.candidates=[]
}
}else{
this.candidates=[]
uni.showToast({
title: res.return_msg,
icon: 'none',
duration: 2000
})
}
})
},
1 year ago
// 点击获取的详细地址
getSelect(desc){
1 year ago
// console.log(desc)
this.defaultRegionCode = desc.adcode ;
this.userAddress.address = desc.address;
1 year ago
uni.showToast({
icon:'none',
title:"所在地区同步修改"
})
},
2 years ago
// 默认地址设置改变
defaultChange(e) {
this.userAddress.is_default = !this.userAddress.is_default
},
// 数据提交
form_submit() {
this.userAddress.name = this.userAddress.name.replace(/\s+/g, "")
this.userAddress.tel = this.userAddress.tel.replace(/\s+/g, "")
this.userAddress.address = this.userAddress.address.replace(/\s+/g, "")
2 years ago
// 数据校验
var validation = [{
fields: "name",
msg: "请填写联系人"
},
{
fields: "tel",
msg: "请填写联系电话",
vali: /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
2 years ago
},
{
fields: "region",
msg: "请选择省市区"
},
{
fields: "address",
msg: "请填写详细地址"
}
];
this.fields_check(this.userAddress, validation)
2 years ago
let isVali = this.fields_check(this.userAddress, validation);
if (isVali) {
if (this.dataParams.id) {
2 years ago
this.updateAddress(this.dataParams.id)
} else {
2 years ago
this.addAddress()
}
2 years ago
}
},
updateAddress(id) {
2 years ago
let _this = this;
let params = {
2 years ago
"id": id,
"address": _this.userAddress.address,
"consignee": _this.userAddress.name,
"phone": _this.userAddress.tel,
"regionId": _this.regionId,
"regionName": _this.userAddress.region,
2 years ago
"whetherDefault": _this.userAddress.is_default
}
updateDeliveryAddress(params).then(res => {
let title;
2 years ago
if (res.return_code == '000000') {
title = res.return_data;
} else {
2 years ago
title = res.return_msg;
}
uni.showToast({
title: title,
icon: 'none',
duration: 2000
})
//调用上一个页面中的方法
this.backPageRefresh();
2 years ago
})
},
backPageRefresh() {
uni.navigateBack({})
2 years ago
},
addAddress() {
2 years ago
let _this = this;
let params = {
2 years ago
"address": _this.userAddress.address,
"consignee": _this.userAddress.name,
"phone": _this.userAddress.tel,
"regionId": _this.regionId,
"regionName": _this.userAddress.region,
2 years ago
"whetherDefault": _this.userAddress.is_default
}
// console.log(params,this.userAddress)
insertDeliveryAddress(params).then(res => {
let title;
2 years ago
if (res.return_code == '000000') {
title = res.return_data;
} else {
2 years ago
title = res.return_msg;
}
uni.showToast({
title: title,
icon: 'none',
duration: 2000
})
2 years ago
//调用上一个页面中的方法
_this.backPageRefresh()
2 years ago
})
2 years ago
},
2 years ago
/**
* 字段数据校验
* data 待校验的数据, 一维json对象
* validation 待校验的字段, 格式 [{fields: 'mobile', msg: '请填写手机号码', is_can_zero: 1(是否可以为0)}, ...]
*/
fields_check(data, validation) {
for (var i in validation) {
var temp_value = data[validation[i]["fields"]];
if (!temp_value) {
uni.showToast({
title: validation[i]['msg'],
duration: 1000,
icon: 'none'
});
return false;
}
if (validation[i]["vali"]) {
// console.log(validation[i]["vali"].test(this.userAddress.tel),this.userAddress.tel)
if (!(validation[i]["vali"].test(this.userAddress.tel))) {
2 years ago
uni.showToast({
title: "请输入正确格式的手机号码",
duration: 1000,
icon: 'none'
});
return false;
}
}
2 years ago
}
return true;
},
}
};
2 years ago
</script>
<style lang="scss" scoped>
2 years ago
.padding-main {
padding: 20rpx;
2 years ago
}
2 years ago
.bottom-fixed {
position: fixed;
2 years ago
left: 10%;
bottom: var(--window-bottom);
2 years ago
border: none;
2 years ago
width: 80%;
2 years ago
box-sizing: border-box;
z-index: 2;
.btn {
2 years ago
height: 60px;
border-radius: 30px;
background-color: #3da7e7;
margin-bottom: 15px;
color: #ffffff;
line-height: 60px;
font-size: 18px;
}
2 years ago
}
2 years ago
2 years ago
2 years ago
.page-bottom-fixed {
2 years ago
height: calc(100vh - var(--window-top));
padding-bottom: 75px;
2 years ago
box-sizing: border-box;
overflow-y: auto;
2 years ago
}
2 years ago
/*表单*/
.form-container {
2 years ago
height: 100%;
1 year ago
/* display: flex;
flex-direction: column; */
2 years ago
.form-gorup {
padding: 20rpx;
margin-bottom: 20rpx;
border-radius: 20rpx;
// overflow: auto;
2 years ago
.pickRes,
input {
2 years ago
border-radius: 0;
box-sizing: border-box;
2 years ago
font-size: 18px;
2 years ago
// height: 30px;
// min-height: 60px;
// line-height: 30px;
// padding: 8px 0;
2 years ago
}
}
.form-gorup-title {
padding: 20rpx 0;
margin-bottom: 5rpx;
font-weight: 500;
2 years ago
font-size: 18px;
width: 74px;
white-space: nowrap;
text-align: right;
2 years ago
}
2 years ago
}
2 years ago
.form-gorup-item-left {
float: left;
padding-right: 20rpx;
2 years ago
}
2 years ago
.form-group-tips-must {
margin-left: 20rpx;
font-size: 24rpx;
color: #f00;
2 years ago
}
.selector-item {
font-size: 16px;
text-align: center;
border-bottom: solid 1px #DDDDDD;
padding: 10px;
cursor: pointer;
text-align: left;
.name{
height: 18px;
line-height: 18px;
color: #3da7e7;
font-size: 16px;
font-weight: bold;
}
.address{
font-size: 14px;
height: 16px;
line-height: 16px;
color: #666666;
}
}
2 years ago
</style>