【收货地址添加】

1. 功能实现
pull/1/MERGE
YunaiV 2023-06-26 20:06:29 +08:00
parent 6442fc5c11
commit e08f65b4cb
11 changed files with 257 additions and 16266 deletions

View File

@ -199,21 +199,6 @@ export function getTemlIds(data)
return request.get('wechat/program/my/temp/list', data , { noAuth:true});
}
/**
* 首页拼团数据
*/
export function pink()
{
return request.get('pink', {}, { noAuth:true});
}
/**
* 获取城市信息
*/
export function getCity() {
return request.get('city/list', { }, { noAuth: true });
}
/**
* 获取小程序直播列表
*/

View File

@ -1,10 +1,22 @@
import request from "@/utils/request.js";
// 获得用户收件地址
export function getAddress(id) {
return request.get('app-api/member/address/get', {
id
});
}
// 获得用户收件地址列表
export function getAddressList() {
return request.get('app-api/member/address/list', {});
}
// 创建用户收件地址
export function createAddress(data) {
return request.post('app-api/member/address/create', data);
}
// 更新用户收件地址
export function updateAddress(data) {
return request.put('app-api/member/address/update', data);

8
api/system/area.js Normal file
View File

@ -0,0 +1,8 @@
import request from "@/utils/request.js";
// 获得地区树
export function getAreaTree() {
return request.get("app-api/system/area/tree", {}, {
noAuth: true // TODO 芋艿:后续要做调整
});
}

View File

@ -1,6 +1,6 @@
<template>
<view>
<view class="address-window" :class="address.address==true?'on':''">
<view class="address-window" :class="address.address ? 'on' : ''">
<view class='title'>选择地址<text class='iconfont icon-guanbi' @tap='close'></text></view>
<view class='list'>
<view class='item acea-row row-between-wrapper' :class='active==index?"font-color":""' v-for="(item,index) in addressList"
@ -19,7 +19,7 @@
</view>
<view class='addressBnt bg-color' @tap='goAddressPages'>选择其地址</view>
</view>
<view class='mask' catchtouchmove="true" :hidden='address.address==false' @tap='close'></view>
<view class='mask' catchtouchmove="true" :hidden='!address.address' @tap='close' />
</view>
</template>
@ -37,7 +37,7 @@
type: Object,
default: function() {
return {
address: true,
address: true, //
addressId: 0,
};
}
@ -54,13 +54,12 @@
addressList: []
};
},
methods: {
tapAddress: function(e, addressid) {
this.active = e;
let a = {};
for (let i = 0, leng = this.addressList.length; i < leng; i++) {
if (this.addressList[i].id == addressid) {
if (this.addressList[i].id === addressid) {
a = this.addressList[i];
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,139 +0,0 @@
/* eslint-disable */
var provinceData = [{
"label": "北京市",
"value": "11"
},
{
"label": "天津市",
"value": "12"
},
{
"label": "河北省",
"value": "13"
},
{
"label": "山西省",
"value": "14"
},
{
"label": "内蒙古自治区",
"value": "15"
},
{
"label": "辽宁省",
"value": "21"
},
{
"label": "吉林省",
"value": "22"
},
{
"label": "黑龙江省",
"value": "23"
},
{
"label": "上海市",
"value": "31"
},
{
"label": "江苏省",
"value": "32"
},
{
"label": "浙江省",
"value": "33"
},
{
"label": "安徽省",
"value": "34"
},
{
"label": "福建省",
"value": "35"
},
{
"label": "江西省",
"value": "36"
},
{
"label": "山东省",
"value": "37"
},
{
"label": "河南省",
"value": "41"
},
{
"label": "湖北省",
"value": "42"
},
{
"label": "湖南省",
"value": "43"
},
{
"label": "广东省",
"value": "44"
},
{
"label": "广西壮族自治区",
"value": "45"
},
{
"label": "海南省",
"value": "46"
},
{
"label": "重庆市",
"value": "50"
},
{
"label": "四川省",
"value": "51"
},
{
"label": "贵州省",
"value": "52"
},
{
"label": "云南省",
"value": "53"
},
{
"label": "西藏自治区",
"value": "54"
},
{
"label": "陕西省",
"value": "61"
},
{
"label": "甘肃省",
"value": "62"
},
{
"label": "青海省",
"value": "63"
},
{
"label": "宁夏回族自治区",
"value": "64"
},
{
"label": "新疆维吾尔自治区",
"value": "65"
},
{
"label": "台湾",
"value": "66"
},
{
"label": "香港",
"value": "67"
},
{
"label": "澳门",
"value": "68"
}
]
export default provinceData;

View File

@ -1,680 +0,0 @@
const forMatNum=(num)=>{
return num<10?'0'+num:num+'';
}
const initPicker={
//日期
date:{
init(start,end,mode="date",step,value,flag,disabled,hasSecond){
let aToday=new Date();
let tYear,tMonth,tDay,tHours,tMinutes,tSeconds,defaultVal=[];
let initstartDate=new Date(start.toString());
let endDate=new Date(end.toString());
if(start>end){
initstartDate=new Date(end.toString());
endDate=new Date(start.toString());
};
let startYear=initstartDate.getFullYear();
let startMonth=initstartDate.getMonth()+1;
let endYear=endDate.getFullYear();
let years=[],months=[],days=[],hours=[],minutes=[],seconds=[],areas=[],returnArr=[],dvalDate=[];
switch(mode){
case "half":
dvalDate=flag?[...value.split(" ")[0].split("-"),...value.split(" ")[1].split(":")]:[...value.split(" ")[0].split("-"),value.split(" ")[1]];
break;
case "date":
case "yearMonth":
dvalDate=value.split("-");
break;
case "dateTime":
dvalDate=[...value.split(" ")[0].split("-"),...value.split(" ")[1].split(":")];
break;
case "time":
dvalDate=value.split(":");
break;
}
let curMonth=flag?dvalDate[1]*1:(dvalDate[1]+1);
let dYear=aToday.getFullYear();
let dMonth=aToday.getMonth()+1;
let dDate=aToday.getDate();
let totalDays=new Date(startYear,curMonth,0).getDate();
let dvalObj={};
switch(mode){
case "half":
case "date":
case "yearMonth":
let curYear=dvalDate[0];
let curMonth=dvalDate[1];
if(disabled){
for(let s=startYear;s<=dYear;s++){
years.push(s+'');
};
if(curYear==dYear){
for(let m=1;m<=dMonth;m++){
months.push(forMatNum(m));
};
}else{
for(let m=1;m<=12;m++){
months.push(forMatNum(m));
};
}
if(curMonth==dMonth){
for(let d=1;d<=dDate;d++){
days.push(forMatNum(d));
}
}else{
for(let d=1;d<=totalDays;d++){
days.push(forMatNum(d));
}
}
}else{
for(let s=startYear;s<=endYear;s++){
years.push(s+'');
};
for(let m=1;m<=12;m++){
months.push(forMatNum(m));
};
for(let d=1;d<=totalDays;d++){
days.push(forMatNum(d));
}
};
break;
default:
for(let s=startYear;s<=endYear;s++){
years.push(s+'');
};
for(let m=1;m<=12;m++){
months.push(forMatNum(m));
};
for(let d=1;d<=totalDays;d++){
days.push(forMatNum(d));
}
break;
}
for(let h=0;h<24;h++){
hours.push(forMatNum(h));
}
for(let m=0;m<60;m+=step*1){
minutes.push(forMatNum(m));
}
for(let s=0;s<60;s++){
seconds.push(forMatNum(s));
}
if(flag){
returnArr=[
years.indexOf(dvalDate[0]),
months.indexOf(dvalDate[1]),
days.indexOf(dvalDate[2]),
hours.indexOf(dvalDate[3]),
minutes.indexOf(dvalDate[4])==-1?0:minutes.indexOf(dvalDate[4]),
seconds.indexOf(dvalDate[5])
]
}
switch(mode){
case "date":
if(flag){
defaultVal=[returnArr[0],returnArr[1],returnArr[2]];
return {years,months,days,defaultVal}
}else{
defaultVal=[
years.indexOf(dvalDate[0])==-1?0:years.indexOf(dvalDate[0]),
months.indexOf(dvalDate[1])==-1?0:months.indexOf(dvalDate[1]),
days.indexOf(dvalDate[2])==-1?0:days.indexOf(dvalDate[2])
];
return {years,months,days,defaultVal}
}
break;
case "half":
areas=[{
label:"上午",
value:0
},{
label:"下午",
value:1
}];
if(flag){
defaultVal=[returnArr[0],returnArr[1],returnArr[2],returnArr[3]];
return {years,months,days,areas,defaultVal}
}else{
let idx=0;
areas.map((v,k)=>{
if(v.label==dvalDate[3]){
idx=v.value;
}
})
defaultVal=[
years.indexOf(dvalDate[0])==-1?0:years.indexOf(dvalDate[0]),
months.indexOf(dvalDate[1])==-1?0:months.indexOf(dvalDate[1]),
days.indexOf(dvalDate[2])==-1?0:days.indexOf(dvalDate[2]),
idx
];
return {years,months,days,areas,defaultVal}
}
break;
case "yearMonth":
if(flag){
defaultVal=[returnArr[0],returnArr[1]];
return {years,months,defaultVal}
}else{
defaultVal=[
years.indexOf(dvalDate[0])==-1?0:years.indexOf(dvalDate[0]),
months.indexOf(dvalDate[1])==-1?0:months.indexOf(dvalDate[1])
];
return {years,months,defaultVal}
}
break;
case "dateTime":
if(flag){
defaultVal=returnArr;
}else{
if(hasSecond){
defaultVal=[
years.indexOf(dvalDate[0])==-1?0:years.indexOf(dvalDate[0]),
months.indexOf(dvalDate[1])==-1?0:months.indexOf(dvalDate[1]),
days.indexOf(dvalDate[2])==-1?0:days.indexOf(dvalDate[2]),
hours.indexOf(dvalDate[3])==-1?0:hours.indexOf(dvalDate[3]),
minutes.indexOf(dvalDate[4])==-1?0:minutes.indexOf(dvalDate[4]),
seconds.indexOf(dvalDate[5])==-1?0:seconds.indexOf(dvalDate[5])
];
}else{
defaultVal=[
years.indexOf(dvalDate[0])==-1?0:years.indexOf(dvalDate[0]),
months.indexOf(dvalDate[1])==-1?0:months.indexOf(dvalDate[1]),
days.indexOf(dvalDate[2])==-1?0:days.indexOf(dvalDate[2]),
hours.indexOf(dvalDate[3])==-1?0:hours.indexOf(dvalDate[3]),
minutes.indexOf(dvalDate[4])==-1?0:minutes.indexOf(dvalDate[4])
];
}
}
if(hasSecond){
return {years,months,days,hours,minutes,seconds,defaultVal}
}else{
return {years,months,days,hours,minutes,defaultVal}
}
break;
case "time":
if(flag){
defaultVal=[returnArr[3],returnArr[4],returnArr[5]];
}else{
if(hasSecond){
defaultVal=[
hours.indexOf(dvalDate[0])==-1?0:hours.indexOf(dvalDate[0]),
minutes.indexOf(dvalDate[1])==-1?0:minutes.indexOf(dvalDate[1]),
seconds.indexOf(dvalDate[2])==-1?0:seconds.indexOf(dvalDate[2])
];
}else{
defaultVal=[
hours.indexOf(dvalDate[0])==-1?0:hours.indexOf(dvalDate[0]),
minutes.indexOf(dvalDate[1])==-1?0:minutes.indexOf(dvalDate[1])
];
}
}
return {hours,minutes,seconds,defaultVal}
break;
}
},
initMonths:(year,disabled)=>{
let aDate=new Date();
let dYear=aDate.getFullYear();
let dMonth=aDate.getMonth()+1;
let dDate=aDate.getDate();
let flag=dYear==year?true:false;
let months=[];
if(disabled){
if(flag){
for(let m=1;m<=dMonth;m++){
months.push(forMatNum(m));
};
}else{
for(let m=1;m<=12;m++){
months.push(forMatNum(m));
};
}
}else{
for(let m=1;m<=12;m++){
months.push(forMatNum(m));
};
};
return months;
},
initDays:(year,month,disabled)=>{
let aDate=new Date();
let dYear=aDate.getFullYear();
let dMonth=aDate.getMonth()+1;
let dDate=aDate.getDate();
let flag=(dYear==year&&dMonth==month)?true:false;
let totalDays=new Date(year,month,0).getDate();
let dates=[];
if(flag&&disabled){
for(let d=1;d<=dDate;d++){
dates.push(forMatNum(d));
};
}else{
for(let d=1;d<=totalDays;d++){
dates.push(forMatNum(d));
};
};
return dates;
},
},
//短期日期上下午
limitHour:{
init(dayStep=7,dVal){
let startDate=new Date();
let date=[],areas=[],hours=[];
let hour=new Date().getHours();
let weeks=["周日","周一","周二","周三","周四","周五","周六"];
let arrs=[];
let defaultVal=[];
let d=0,a=0,h=0;
for(let i=0;i<dayStep;i++){
let year,month,day,weekday;
year=startDate.getFullYear();
month=forMatNum(startDate.getMonth()+1);
day=forMatNum(startDate.getDate());
weekday=weeks[startDate.getDay()];
let label="";
switch(i){
case 0:
label="今天";
break;
case 1:
label="明天"
break;
case 2:
label="后天"
break;
default:
label=month+"月"+day+"日"+" "+weekday;
break;
}
date.push({
label:label,
value:year+"-"+month+"-"+day,
today:i==0?true:false
})
startDate.setDate(startDate.getDate()+1);
}
if(hour>12){
areas=[{
label:"下午",
value:1
}]
}else{
areas=[{
label:"上午",
value:0
},{
label:"下午",
value:1
}]
};
for(let k=hour>12?hour-12:hour;k<=12;k++){
hours.push({
label:forMatNum(k),
value:forMatNum(hour>12?k+12:k)
})
};
date.map((v,k)=>{
if(v.label==dVal[0]){
d=k
}
})
if(d!=0){
areas=this.initAreas(date[d]);
hours=this.initHours(date[d],areas[a]);
}
areas.map((v,k)=>{
if(v.label==dVal[1]){
a=k
}
})
hours.map((v,k)=>{
if(v.label==dVal[2]){
h=k
}
});
defaultVal=[d,a,h]
return {date,areas,hours,defaultVal};
},
initAreas(date){
let areas=[];
let hour=new Date().getHours();
if(date.today){
if(hour>12){
areas=[{
label:"下午",
value:1
}]
}else{
areas=[{
label:"上午",
value:0
},{
label:"下午",
value:1
}]
};
}else{
areas=[{
label:"上午",
value:0
},{
label:"下午",
value:1
}]
}
return areas;
},
initHours(dateCol,hourCol){
let hours=[];
let hour=new Date().getHours();
if(dateCol.today){
if(hourCol.value==1&&hour<=12){
for(let k=1;k<=12;k++){
hours.push({
label:forMatNum(k),
value:forMatNum(hourCol.value==1?k+12:k)
})
};
}else{
for(let k=hour>12?hour-12:hour;k<=12;k++){
hours.push({
label:forMatNum(k),
value:forMatNum(hourCol.value==1?k+12:k)
})
};
}
}else{
for(let k=1;k<=12;k++){
hours.push({
label:forMatNum(k),
value:forMatNum(hourCol.value==1?k+12:k)
})
};
};
return hours
}
},
//短期日期时间初始化
limit:{
init(dayStep=7,startHour=8,endHour=20,minuteStep=1,afterStep=30,dVal){
let startDate=new Date();
let bsDate=new Date(new Date().getTime()+afterStep*60*1000);
let date=[],hours=[],minutes=[];
let hour=bsDate.getHours();
let minute=Math.floor(bsDate.getMinutes()/minuteStep)*minuteStep;
let weeks=["周日","周一","周二","周三","周四","周五","周六"];
let d=0,h=0,m=0;
let defaultVal=[];
for(let i=0;i<dayStep;i++){
let year,month,day,weekday;
year=startDate.getFullYear();
month=forMatNum(startDate.getMonth()+1);
day=forMatNum(startDate.getDate());
weekday=weeks[startDate.getDay()];
let label="";
switch(i){
case 0:
label="今天";
break;
case 1:
label="明天"
break;
case 2:
label="后天"
break;
default:
label=month+"月"+day+"日"+" "+weekday;
break;
}
date.push({
label:label,
value:year+"-"+month+"-"+day,
flag:i==0?true:false
})
startDate.setDate(startDate.getDate()+1);
}
if(hour<startHour){
hour=startHour;
};
if(hour>endHour){
hour=endHour;
};
for(let k=hour*1;k<=endHour*1;k++){
hours.push({
label:forMatNum(k),
value:forMatNum(k),
flag:k==hour?true:false
})
};
for(let j=minute;j<60;j+=minuteStep*1){
minutes.push({
label:forMatNum(j),
value:forMatNum(j)
});
}
date.map((v,k)=>{
if(v.label==dVal[0]){
d=k
}
})
if(d!=0){
hours=this.initHours(startHour=8,endHour=20,minuteStep=1,afterStep=30,date[d].value);
}
hours.map((v,k)=>{
if(v.label==dVal[1]){
h=k
}
})
minutes.map((v,k)=>{
if(v.label==dVal[2]){
m=k
}
})
defaultVal=[d,h,m];
return {date,hours,minutes,defaultVal};
},
initHours(startHour=8,endHour=20,minuteStep=1,afterStep=30,date){
let hours=[];
let arr=date.split("-");
let aDate=new Date();
let dYear=aDate.getFullYear();
let dMonth=aDate.getMonth()+1;
let dDate=aDate.getDate();
let bsDate=new Date(new Date().getTime()+afterStep*60*1000);
let hour=bsDate.getHours();
let flag=(dYear==arr[0]&&dMonth==arr[1]&&dDate==arr[2])?true:false;
if(hour>endHour){
hour=endHour;
};
if(flag){
for(let k=hour*1;k<=endHour*1;k++){
hours.push({
label:forMatNum(k),
value:forMatNum(k),
flag:k==hour?true:false
})
};
}else{
for(let k=startHour*1;k<=endHour*1;k++){
hours.push({
label:forMatNum(k),
value:forMatNum(k),
flag:false
})
}
};
return hours;
},
initMinutes(startHour=8,endHour=20,minuteStep=1,afterStep=30,date,hour){
let minutes=[];
let bsDate=new Date(new Date().getTime()+afterStep*60*1000);
let arr=date.split("-");
let aDate=new Date();
let dYear=aDate.getFullYear();
let dMonth=aDate.getMonth()+1;
let dDate=aDate.getDate();
let dHour=bsDate.getHours();;
let minute=Math.floor(bsDate.getMinutes()/minuteStep)*minuteStep;
let flag=(dYear==arr[0]&&dMonth==arr[1]&&dDate==arr[2])?true:false;
if(flag){
if(hour==dHour){
for(let j=minute;j<60;j+=minuteStep*1){
minutes.push({
label:forMatNum(j),
value:forMatNum(j)
});
}
}else{
for(let j=0;j<60;j+=minuteStep*1){
minutes.push({
label:forMatNum(j),
value:forMatNum(j)
})
}
}
}else{
for(let j=0;j<60;j+=minuteStep*1){
minutes.push({
label:forMatNum(j),
value:forMatNum(j)
})
}
}
return minutes;
}
},
//选择区间初始化
range:{
init(start,end,value,flag){
let aToday=new Date();
let tYear,tMonth,tDay,tHours,tMinutes,tSeconds,defaultVal=[];
let initstartDate=new Date(start.toString());
let endDate=new Date(end.toString());
if(start>end){
initstartDate=new Date(end.toString());
endDate=new Date(start.toString());
};
let startYear=initstartDate.getFullYear();
let startMonth=initstartDate.getMonth()+1;
let endYear=endDate.getFullYear();
let fyears=[],fmonths=[],fdays=[],tyears=[],tmonths=[],tdays=[],returnArr=[],startDVal=[],endDVal=[];
startDVal=value[0].split("-");
endDVal=value[1].split("-");
let curMonth=flag?startDVal[1]*1:(startDVal[1]+1);
let totalDays=new Date(startYear,curMonth,0).getDate();
for(let s=startYear;s<=endYear;s++){
fyears.push(s+'');
};
for(let m=1;m<=12;m++){
fmonths.push(forMatNum(m));
};
for(let d=1;d<=totalDays;d++){
fdays.push(forMatNum(d));
};
for(let s=startDVal[0];s<=endYear;s++){
tyears.push(s+'');
};
if(endDVal[0]>startDVal[0]){
for(let m=1;m<=12;m++){
tmonths.push(forMatNum(m));
};
for(let d=1;d<=totalDays;d++){
tdays.push(forMatNum(d));
};
}else{
for(let m=startDVal[1];m<=12;m++){
tmonths.push(forMatNum(m));
};
for(let d=startDVal[2];d<=totalDays;d++){
tdays.push(forMatNum(d));
};
};
defaultVal=[
fyears.indexOf(startDVal[0])==-1?0:fyears.indexOf(startDVal[0]),
fmonths.indexOf(startDVal[1])==-1?0:fmonths.indexOf(startDVal[1]),
fdays.indexOf(startDVal[2])==-1?0:fdays.indexOf(startDVal[2]),
0,
tyears.indexOf(endDVal[0])==-1?0:tyears.indexOf(endDVal[0]),
tmonths.indexOf(endDVal[1])==-1?0:tmonths.indexOf(endDVal[1]),
tdays.indexOf(endDVal[2])==-1?0:tdays.indexOf(endDVal[2])
];
return {
fyears,
fmonths,
fdays,
tyears,
tmonths,
tdays,
defaultVal
}
},
initStartDays(year,month){
let totalDays=new Date(year,month,0).getDate();
let dates=[];
for(let d=1;d<=totalDays;d++){
dates.push(forMatNum(d));
};
return dates;
},
initEndYears(curYear,startYear,endYear){
let years=[];
for(let y=curYear;y<=endYear;y++){
years.push(forMatNum(y));
};
return years;
},
initEndMonths(curMonth){
let months=[];
for(let m=curMonth*1;m<=12;m++){
months.push(forMatNum(m));
};
return months;
},
initEndDays(curYear,curMonth,curDate,tYear,tMonth){
let totalDays=new Date(curYear,curMonth,0).getDate();
let days=[];
for(let d=curDate*1;d<=totalDays;d++){
days.push(forMatNum(d));
};
return days;
},
initToMonths(curYear,curMonth,curDate,tYear){
let aDate=new Date(curYear,curMonth,curDate).getTime();
let bDate=new Date(tYear,curMonth,curDate).getTime();
let months=[];
if(bDate-aDate>0){
for(let m=1;m<=12;m++){
months.push(forMatNum(m));
};
}else{
for(let m=curMonth*1;m<=12;m++){
months.push(forMatNum(m));
};
}
return months;
},
initToDays(curYear,curMonth,curDate,tYear,tMonth){
let aDate=new Date(curYear,curMonth,curDate).getTime();
let bDate=new Date(tYear,tMonth,curDate).getTime();
let totalDays=new Date(tYear,tMonth,0).getDate();
let days=[];
if(bDate-aDate>0){
for(let d=1;d<=totalDays;d++){
days.push(forMatNum(d));
};
}else{
for(let d=curDate*1;d<=totalDays;d++){
days.push(forMatNum(d));
};
}
return days;
}
}
}
export default initPicker

File diff suppressed because it is too large Load Diff

View File

@ -291,8 +291,10 @@
let list = data[0]
this.getElementData(`#tab_item`, (data) => {
let el = data[this.listActive]
if (el) {
lineLeft = el.width / 2 + (-list.left) + el.left - list.width / 2 - this.scrollLeft
this.tabsScrollLeft = this.scrollLeft + lineLeft
}
})
})
},

View File

@ -5,19 +5,19 @@
<view class='list borRadius14'>
<view class='item acea-row row-between-wrapper' style="border: none;">
<view class='name'>姓名</view>
<input type='text' placeholder='请输入姓名' placeholder-style="color:#ccc;" name='realName' :value="userAddress.realName"
placeholder-class='placeholder' maxlength="4"></input>
<input type='text' placeholder='请输入姓名' placeholder-style="color:#ccc;" name='name'
:value="userAddress.name" placeholder-class='placeholder' maxlength="4" />
</view>
<view class='item acea-row row-between-wrapper'>
<view class='name'>联系电话</view>
<input type='number' placeholder='请输入联系电话' placeholder-style="color:#ccc;" name="phone" :value='userAddress.phone'
placeholder-class='placeholder' maxlength="11"></input>
<input type='number' placeholder='请输入联系电话' placeholder-style="color:#ccc;" name="mobile"
:value='userAddress.mobile' placeholder-class='placeholder' maxlength="11" />
</view>
<view class='item acea-row row-between-wrapper relative'>
<view class='name'>所在地区</view>
<view class="address">
<picker mode="multiSelector" @change="bindRegionChange"
@columnchange="bindMultiPickerColumnChange" :value="valueRegion" :range="multiArray">
@columnchange="bindMultiPickerColumnChange" :range="multiArray">
<view class='acea-row'>
<view class="picker line1">{{region[0]}}{{region[1]}}{{region[2]}}</view>
<view class='iconfont icon-xiangyou abs_right'></view>
@ -27,14 +27,14 @@
</view>
<view class='item acea-row row-between-wrapper relative'>
<view class='name'>详细地址</view>
<input type='text' placeholder='请填写具体地址' placeholder-style="color:#ccc;" name='detail' placeholder-class='placeholder'
v-model='userAddress.detail' maxlength="18"></input>
<view class='iconfont icon-dizhi font-color abs_right' @tap="chooseLocation"></view>
<input type='text' placeholder='请填写具体地址' placeholder-style="color:#ccc;" name='detailAddress'
placeholder-class='placeholder' v-model='userAddress.detailAddress' maxlength="18" />
<view class='iconfont icon-dizhi font-color abs_right' @tap="chooseLocation" />
</view>
</view>
<view class='default acea-row row-middle borRadius14'>
<checkbox-group @change='ChangeIsDefault'>
<checkbox :checked="userAddress.isDefault" />设置为默认地址
<checkbox :checked="userAddress.defaultStatus" />设置为默认地址
</checkbox-group>
</view>
@ -47,63 +47,40 @@
<!-- #endif -->
</view>
</form>
<!-- #ifdef MP -->
<!-- <authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize> -->
<!-- #endif -->
<!-- <home></home> -->
</view>
</template>
<script>
import {
editAddress,
getAddressDetail
} from '@/api/user.js';
import {
getCity
} from '@/api/api.js';
import {
toLogin
} from '@/libs/login.js';
import {
mapGetters
} from "vuex";
// #ifdef MP
import authorize from '@/components/Authorize';
// #endif
import { editAddress } from '@/api/user.js';
import * as AddressApi from '@/api/member/address.js';
import * as AreaApi from '@/api/system/area.js';
import { toLogin } from '@/libs/login.js';
import { mapGetters } from "vuex";
import home from '@/components/home';
// import city from '@/utils/cityData';
let app = getApp();
export default {
components: {
// #ifdef MP
authorize,
// #endif
home
},
data() {
return {
regionDval: ['浙江省', '杭州市', '滨江区'],
cartId: '', //id
pinkId: 0, //id
couponId: 0, //id
id: 0, //id
id: 0, // id
district: [], //
userAddress: {
isDefault: false
}, //
region: ['省', '市', '区'],
valueRegion: [0, 0, 0],
isAuto: false, //
isShowAuth: false, //
district: [],
multiArray: [],
multiIndex: [0, 0, 0],
cityId: 0,
defaultRegion: ['广东省', '广州市', '番禺区'],
defaultRegionCode: '440113',
bargain: false, //
combination: false, //
secKill: false, //
defaultStatus: false
}, //
region: ['省', '市', '区'], // userAddress
multiArray: [], //
multiIndex: [0, 0, 0], // index index index
cityId: 0, // ~
// TODO
cartId: '', // id
pinkId: 0, // id
couponId: 0, // id
bargain: false, //
combination: false, //
secKill: false, //
};
},
computed: mapGetters(['isLogin']),
@ -119,105 +96,208 @@
}
},
onLoad(options) {
if (this.isLogin) {
if (!this.isLogin) {
toLogin();
return
}
this.preOrderNo = options.preOrderNo || 0;
this.id = options.id || 0;
uni.setNavigationBarTitle({
title: options.id ? '修改地址' : '添加地址'
})
//
this.getUserAddress();
if(this.$Cache.has('cityList')){
//
//
if (this.$Cache.has('cityList')) {
this.district = this.$Cache.getItem('cityList')
this.initialize();
}else{
this.getCityList();
}
} else {
toLogin();
this.getCityList();
}
},
methods: {
// #ifdef APP-PLUS
//
handleGetRegion(region) {
this.region = region
/**
* 获得地址
*/
getUserAddress: function() {
if (!this.id) {
return false;
}
AddressApi.getAddress(this.id).then(res => {
this.$set(this, 'userAddress', res.data);
this.$set(this, 'region', res.data.areaName.split(' '));
this.city_id = res.data.areaId
});
},
/**
* 提交用户添加地址
*/
formSubmit: function(e) {
//
const value = e.detail.value;
if (!value.name) {
return this.$util.Tips({
title: '请填写收货人姓名'
});
}
if (!value.mobile) {
return this.$util.Tips({
title: '请填写联系电话'
});
}
if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(value.mobile)) {
return this.$util.Tips({
title: '请输入正确的手机号码'
});
}
if (this.region === '省-市-区') {
return this.$util.Tips({
title: '请选择所在地区'
});
}
if (!value.detailAddress) {
return this.$util.Tips({
title: '请填写详细地址'
});
}
value.id = this.id;
value.areaId = this.cityId;
value.defaultStatus = this.userAddress.defaultStatus;
//
uni.showLoading({
title: '保存中',
mask: true
})
const saveOrUpdateAddress = this.id > 0 ? AddressApi.updateAddress : AddressApi.createAddress;
saveOrUpdateAddress(value).then(res => {
if (this.id) {
this.$util.Tips({
title: '修改成功',
icon: 'success'
});
} else {
this.$util.Tips({
title: '添加成功',
icon: 'success'
});
}
setTimeout(() => {
if (this.preOrderNo > 0) {
uni.redirectTo({
url: '/pages/users/order_confirm/index?preOrderNo=' + this.preOrderNo + '&addressId=' + (this.id ? this.id : res.data)
})
} else {
// #ifdef H5
return history.back();
// #endif
//
getCityList: function() {
let that = this;
getCity().then(res => {
this.district = res.data;
let oneDay = 24 * 3600 * 1000;
// this.$Cache.set('cityList', JSON.stringify(res.data)); //
this.$Cache.setItem({name:'cityList',value:res.data,expires:oneDay * 7}); //
that.initialize();
// #ifndef H5
return uni.navigateBack({
delta: 1,
})
// #endif
}
}, 1000);
}).catch(err => {
return this.$util.Tips({
title: err
});
})
},
// TODO
ChangeIsDefault: function(e) {
this.$set(this.userAddress, 'defaultStatus', !this.userAddress.defaultStatus);
},
/**
* 获取地址数据
*/
getCityList: function() {
AreaApi.getAreaTree().then(res => {
this.district = res.data;
let oneDay = 24 * 3600 * 1000;
this.$Cache.setItem({name: 'cityList', value:res.data, expires:oneDay * 7}); //
this.initialize();
})
},
/**
* 初始化当前的 multiArray
*/
initialize: function() {
let that = this,province = [],city = [],area = [];
if (that.district.length) {
let cityChildren = that.district[0].child || [];
let areaChildren = cityChildren.length ? (cityChildren[0].child || []) : [];
that.district.forEach(function(item) {
const province = [];
const city = [];
const area = [];
if (this.district.length) {
//
this.district.forEach(item => {
province.push(item.name);
});
cityChildren.forEach(function(item) {
//
const cityChildren = this.district[0].children || [];
cityChildren.forEach(item => {
city.push(item.name);
});
areaChildren.forEach(function(item) {
//
const areaChildren = cityChildren.length ? (cityChildren[0].children || []) : [];
areaChildren.forEach(item => {
area.push(item.name);
});
this.multiArray = [province, city, area]
}
},
/**
* 提交省市区的选择
*/
bindRegionChange: function(e) {
let multiIndex = this.multiIndex,
province = this.district[multiIndex[0]] || {
child: []
},
city = province.child[multiIndex[1]] || {
cityId: 0
},
multiArray = this.multiArray,
value = e.detail.value;
const multiIndex = this.multiIndex;
const multiArray = this.multiArray;
const value = e.detail.value;
const province = this.district[multiIndex[0]] || {
children: []
};
const city = province.children[multiIndex[1]] || {
children: []
};
const area = city.children[multiIndex[2]] || {
id: 0
};
this.region = [multiArray[0][value[0]], multiArray[1][value[1]], multiArray[2][value[2]]]
this.cityId = city.cityId
this.valueRegion = [0, 0, 0]
this.initialize();
this.cityId = area.id
},
/**
* 选择省市区的滚动
*/
bindMultiPickerColumnChange: function(e) {
let that = this,
column = e.detail.column,
value = e.detail.value,
currentCity = this.district[value] || {
child: []
},
multiArray = that.multiArray,
multiIndex = that.multiIndex;
const column = e.detail.column; // multiArray
const value = e.detail.value; // multiArray
const multiArray = this.multiArray;
const multiIndex = this.multiIndex;
multiIndex[column] = value;
switch (column) {
case 0:
let areaList = currentCity.child[0] || {
case 0: //
const currentCity = this.district[value] || {
child: []
};
multiArray[1] = currentCity.child.map((item) => {
const areaList = currentCity.children[0] || {
child: []
};
multiArray[1] = currentCity.children.map((item) => {
return item.name;
});
multiArray[2] = areaList.child.map((item) => {
multiArray[2] = areaList.children.map((item) => {
return item.name;
});
break;
case 1:
let cityList = that.district[multiIndex[0]].child[multiIndex[1]].child || [];
multiArray[2] = cityList.map((item) => {
case 1: //
const cityList = this.district[multiIndex[0]].children[multiIndex[1]].children || [];
multiArray[2] = cityList.map(item => {
return item.name;
});
break;
case 2:
case 2: //
break;
}
// #ifdef MP || APP-PLUS
@ -229,40 +309,19 @@
this.multiArray = multiArray;
// #endif
this.multiIndex = multiIndex
// this.setData({ multiArray: multiArray, multiIndex: multiIndex});
},
//
onLoadFun: function() {
this.getUserAddress();
},
//
authColse: function(e) {
this.isShowAuth = e
},
toggleTab(str) {
this.$refs[str].show();
},
onConfirm(val) {
this.region = val.checkArr[0] + '-' + val.checkArr[1] + '-' + val.checkArr[2];
},
getUserAddress: function() {
if (!this.id) return false;
let that = this;
getAddressDetail(this.id).then(res => {
let region = [res.data.province, res.data.city, res.data.district];
that.$set(that, 'userAddress', res.data);
that.$set(that, 'region', region);
that.city_id = res.data.cityId
});
},
/**
* 通过地图选择到具体的地址
* TODO 芋艿需要测试下
*/
chooseLocation: function () {
uni.chooseLocation({
success: (res) => {
this.$set(this.userAddress,'detail',res.address.replace(/.+?(省|市|自治区|自治州|县|区)/g,''));
this.$set(this.userAddress, 'detailAddress', res.address.replace(/.+?(省|市|自治区|自治州|县|区)/g,''));
}
})
},
//
// TODO
getWxAddress: function() {
let that = this;
uni.authorize({
@ -277,10 +336,10 @@
addressP.cityId = 0;
editAddress({
address: addressP,
isDefault: 1,
realName: res.userName,
defaultStatus: 1,
name: res.userName,
postCode: res.postalCode,
phone: res.telNumber,
mobile: res.telNumber,
detail: res.detailInfo,
id: 0
}).then(res => {
@ -354,15 +413,15 @@
},
})
},
//
// TODO
getAddress() {
let that = this;
that.$wechat.openAddress().then(userInfo => {
// open();
editAddress({
id: this.id,
realName: userInfo.userName,
phone: userInfo.telNumber,
name: userInfo.userName,
mobile: userInfo.telNumber,
address: {
province: userInfo.provinceName,
city: userInfo.cityName,
@ -370,7 +429,7 @@
cityId: 0
},
detail: userInfo.detailInfo,
isDefault: 1,
defaultStatus: 1,
postCode: userInfo.postalCode
})
.then(() => {
@ -414,78 +473,6 @@
console.log(err);
});
},
/**
* 提交用户添加地址
*
*/
formSubmit: function(e) {
let that = this,
value = e.detail.value;
if (!value.realName) return that.$util.Tips({
title: '请填写收货人姓名'
});
if (!value.phone) return that.$util.Tips({
title: '请填写联系电话'
});
if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(value.phone)) return that.$util.Tips({
title: '请输入正确的手机号码'
});
if (that.region == '省-市-区') return that.$util.Tips({
title: '请选择所在地区'
});
if (!value.detail) return that.$util.Tips({
title: '请填写详细地址'
});
value.id = that.id;
let regionArray = that.region;
value.address = {
province: regionArray[0],
city: regionArray[1],
district: regionArray[2],
cityId: that.cityId,
};
value.isDefault = that.userAddress.isDefault;
uni.showLoading({
title: '保存中',
mask: true
})
editAddress(value).then(res => {
if (that.id)
that.$util.Tips({
title: '修改成功',
icon: 'success'
});
else
that.$util.Tips({
title: '添加成功',
icon: 'success'
});
setTimeout(function() {
if (that.preOrderNo>0) {
uni.redirectTo({
url: '/pages/users/order_confirm/index?preOrderNo=' + that.preOrderNo + '&addressId=' + (that.id ? that.id : res.data.id)
})
} else {
// #ifdef H5
return history.back();
// #endif
// #ifndef H5
return uni.navigateBack({
delta: 1,
})
// #endif
}
}, 1000);
}).catch(err => {
return that.$util.Tips({
title: err
});
})
},
ChangeIsDefault: function(e) {
this.$set(this.userAddress, 'isDefault', !this.userAddress.isDefault);
}
}
}
</script>