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/pages/address/addNewAddress/addNewAddress.vue

449 lines
10 KiB

2 years ago
<template>
2 years ago
<view class="page-bottom-fixed backcor9">
<form @submit="form_submit" class="form-container">
<view class="pd-main height100">
<view class="form-gorup backcolorfff">
<view class="form-gorup-item-left">
<view class="form-gorup-title marb10">联系人<text class="form-group-tips-must">*</text></view>
<input type="text" name="name" v-model="userAddress.name" maxlength="5"
placeholder-class="fcor666" class="fcor666 " placeholder="联系人2~5个字符">
</view>
<view class="form-gorup-item-right">
<view class="form-gorup-title marb10">联系电话<text class="form-group-tips-must">*</text></view>
2 years ago
<input type="number" name="tel" v-model="userAddress.tel" maxlength="11"
2 years ago
placeholder-class="fcor666" class="fcor666" placeholder="手机号">
</view>
2 years ago
</view>
2 years ago
<view class="form-gorup backcolorfff">
<!-- <view> -->
<!-- <view class="form-gorup-title">省市区<text class="form-group-tips-must">必选</text></view> -->
<!-- <view class="dis-flex flex-sp" @click="chooseAddress">
<input type='text' placeholder='请选择地址' :disabled="true" name='region'
:value='userAddress.region' class="fcor666 flex-1">
<view class="icon-ymt to-right font14 fcor666">
</view>
2 years ago
2 years ago
</view> -->
<!-- -->
<view class="">
<pick-regions :defaultRegion="defaultRegionCode" @getRegion="handleGetRegion">
<view class="dis-flex flex-sp form-gorup-title">
<view class=" flex-1">点击选择省市区<text class="form-group-tips-must">必选</text></view>
<!-- <input type='text' placeholder='请选择地址' :disabled="false" name='region'
v-model='userAddress.region' class=" flex-1 fcor333" placeholder-class="fcor333" style="font-size: 16px;">
-->
2 years ago
<view class="icon-ymt to-right font14 fcor666">
2 years ago
2 years ago
</view>
2 years ago
</view>
</pick-regions>
<view class="font15 fcor666" style="height: 20px;line-height: 20px;">{{userAddress.region || '请选择'}}</view>
</view>
2 years ago
2 years ago
<!-- </view> -->
<view style="clear: both;">
<view class="form-gorup-title">详细地址<text class="form-group-tips-must">*</text>
</view>
<input type="text" name="address" v-model="userAddress.address" maxlength="40"
placeholder-class="fcor666" :class="'fcor666 bs-bb '" placeholder="详细地址1~40个字符">
</view>
</view>
<view class="default-checkbox " @click="defaultChange">
<radio :checked="userAddress.is_default" style="transform:scale(0.7)" color="#FF1A34" />
<text class="">设为默认地址</text>
</view>
<view class="bottom-fixed padding-main">
<button class=" " type="default" form-type="submit">保存</button>
2 years ago
</view>
</view>
2 years ago
</form>
2 years ago
</view>
</template>
<script>
2 years ago
import pickRegions from '@/components/pick-regions/pick-regions.vue'
import {insertDeliveryAddress,findDeliveryAddressById,updateDeliveryAddress } from '@/Utils/physicalObject.js'
2 years ago
export default {
data() {
return {
userAddress: {
2 years ago
name: "",
tel: "",
region: '',
address: "",
is_default: false,
},
dataParams: null,
//
region: [],
regionId:'',
//没用上
defaultRegion: ['北京市', '市辖区', '东城区'],
defaultRegionCode: '120101',
2 years ago
2 years ago
};
2 years ago
},
2 years ago
components: {
pickRegions
2 years ago
},
2 years ago
onLoad(params) {
this.dataParams = params
},
computed: {
2 years ago
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() {
uni.setNavigationBarTitle({
title: '地址'+(((this.dataParams.id || null) == null) ? '添加' : '编辑')
});
if(this.dataParams.id){
this.findAddressById(this.dataParams.id)
2 years ago
}
2 years ago
2 years ago
},
2 years ago
2 years ago
methods: {
2 years ago
findAddressById(id){
let params = {
id:id
2 years ago
}
2 years ago
findDeliveryAddressById(params).then(res=>{
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,
}
2 years ago
// console.log(this.defaultRegionCode)
this.defaultRegionCode = resData.regionId;
this.regionId = resData.regionId;
// console.log(this.defaultRegionCode)
2 years ago
}else{
uni.showToast({
title: res.return_msg,
icon: 'none',
duration: 2000
})
}
})
2 years ago
},
2 years ago
// 获取选择的地区
handleGetRegion(region) {
this.region = region;
this.userAddress.region = this.region.map(item => item.name).join(',');
this.regionId = this.region[2].code;
console.log(this.userAddress.region,"获取选择的地区")
},
// 获取数据
init() {
2 years ago
2 years ago
},
// 默认地址设置改变
defaultChange(e) {
this.userAddress.is_default = !this.userAddress.is_default
},
// 数据提交
form_submit() {
// 数据校验
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}$/
},
{
fields: "region",
msg: "请选择省市区"
},
{
fields: "address",
msg: "请填写详细地址"
}
];
this.fields_check(this.userAddress, validation)
2 years ago
2 years ago
let isVali = this.fields_check(this.userAddress, validation);
if(isVali){
if(this.dataParams.id){
this.updateAddress(this.dataParams.id)
}else{
this.addAddress()
}
}
},
updateAddress(id){
2 years ago
let _this = this;
2 years ago
let params ={
"id": id,
"address": _this.userAddress.address,
"consignee": _this.userAddress.name,
"phone": _this.userAddress.tel,
"regionId": _this.regionId,
"regionName":_this.userAddress.region,
"whetherDefault": _this.userAddress.is_default
}
updateDeliveryAddress(params).then(res=>{
let title ;
if (res.return_code == '000000') {
title = res.return_data;
}else{
title = res.return_msg;
}
uni.showToast({
title: title,
icon: 'none',
duration: 2000
})
//调用上一个页面中的方法
this.backPageRefresh();
2 years ago
})
},
2 years ago
backPageRefresh() {
let pages = getCurrentPages(); // 当前页面
let beforePage = pages[pages.length - 2]; // 上一页
uni.navigateBack({
success:function(){
beforePage.$vm.initData();
// console.log("返回成功!");
}
})
},
addAddress(){
let _this = this;
let params={
"address": _this.userAddress.address,
"consignee": _this.userAddress.name,
"phone": _this.userAddress.tel,
"regionId": _this.regionId,
"regionName":_this.userAddress.region,
"whetherDefault": _this.userAddress.is_default
}
// console.log(params,this.userAddress)
insertDeliveryAddress(params).then(res=>{
let title ;
if (res.return_code == '000000') {
title = res.return_data;
}else{
title = res.return_msg;
}
uni.showToast({
title: title,
icon: 'none',
duration: 2000
})
//调用上一个页面中的方法
_this.backPageRefresh()
})
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))){
uni.showToast({
title: "请输入正确格式的手机号码",
duration: 1000,
icon: 'none'
});
return false;
}
}
}
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;
left: 0;
bottom: 0;
border: none;
width: 100%;
box-sizing: border-box;
z-index: 2;
2 years ago
}
2 years ago
.page-bottom-fixed {
height: 100vh;
padding-bottom: 120rpx;
box-sizing: border-box;
2 years ago
}
2 years ago
/*表单*/
.form-container {
2 years ago
height: 100%;
2 years ago
.form-gorup {
padding: 20rpx;
margin-bottom: 20rpx;
border-radius: 20rpx;
overflow: auto;
input {
border-radius: 0;
box-sizing: border-box;
font-size: 28rpx;
height: 70rpx;
line-height: 70rpx;
}
}
.form-gorup-title {
padding: 20rpx 0;
margin-bottom: 5rpx;
font-weight: 500;
font-size: 16px;
}
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
}
2 years ago
/*
* 三级联动
*/
// .select-address {
// box-sizing: border-box;
// height: 70rpx;
// line-height: 70rpx;
// padding: 0 10rpx;
// height: auto;
// overflow: auto;
// .fl{
// float: left;
// }
// }
// .select-address .section {
// width: 33.33%;
// box-sizing: border-box;
// }
// .select-address .section:not(:first-child) {
// padding: 0 5rpx;
// }
/**
* 地址信息
*/
// .default-checkbox image {
// width: 35rpx;
// height: 35rpx !important;
// }
// .address-value {
// padding-right: 110rpx;
// }
// .map-icon {
// bottom: 0;
// right: 0;
// width: 90rpx;
// height: 80rpx;
// line-height: 80rpx;
// }
// .auto-discern {
// bottom: 20rpx;
// right: 20rpx;
// z-index: 2;
// }
// .auto-discern button {
// line-height: inherit;
// padding: 5rpx 20rpx !important;
// }
/*
* 身份信息
*/
// .idcard-container {
// background: #e6e6e6;
// }
// .idcard-container .form-upload-data .item image {
// width: 256rpx;
// height: 170rpx;
// border: 1px dashed #c2c2c2;
// }
2 years ago
</style>