更新小程序仓库
This commit is contained in:
@@ -0,0 +1,456 @@
|
||||
// pages/editAddress/editAddress.js
|
||||
const app = getApp();
|
||||
import {editAddress,addAddress,getAddressDetail} from "../../api/address"
|
||||
import {getProvince,getCity,getCountry} from "../../api/consultExpert"
|
||||
let provinceArr=[];
|
||||
let cityArr=[];
|
||||
import {throttle} from "../../utils/util"
|
||||
Page({
|
||||
data: {
|
||||
show: false,
|
||||
navName:"添加地址",
|
||||
address_id:'',
|
||||
isEdit:false,
|
||||
consignee_name:'',
|
||||
hideConsignee_name:false,
|
||||
consignee_tel:'',
|
||||
hideConsignee_tel:false,
|
||||
consignee_zip_code:'',
|
||||
order_prescription_id:'',
|
||||
area:"",
|
||||
is_default:0,
|
||||
address:'',
|
||||
hideAddress:false,
|
||||
province_id:'',
|
||||
province_name:'',
|
||||
city_id:'',
|
||||
city_name:'',
|
||||
county_id:'',
|
||||
county_name:'',
|
||||
tag:"",
|
||||
img_host:'https://oss.prod.applets.igandanyiyuan.com/applet/patient/static',
|
||||
columns: [
|
||||
{
|
||||
values:[],
|
||||
className: 'column1',
|
||||
},
|
||||
{
|
||||
values: [],
|
||||
className: 'column2',
|
||||
defaultIndex: 1,
|
||||
},
|
||||
{
|
||||
values: [],
|
||||
className: 'column3',
|
||||
defaultIndex: 1,
|
||||
}
|
||||
]
|
||||
},
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
goBack(){
|
||||
wx.navigateBack({
|
||||
delta: 1,
|
||||
})
|
||||
},
|
||||
selectTag(event){
|
||||
let index=event.currentTarget.dataset.tag;
|
||||
if(index==this.data.tag){
|
||||
this.setData({
|
||||
tag:''
|
||||
})
|
||||
}else{
|
||||
this.setData({
|
||||
tag:index
|
||||
})
|
||||
}
|
||||
|
||||
},
|
||||
onConfirm(event) {
|
||||
const { picker, value, index } = event.detail;
|
||||
let currentPosition=''
|
||||
for (let index = 0; index < value.length; index++) {
|
||||
currentPosition+=value[index].area_name
|
||||
if(index===0){
|
||||
this.setData({
|
||||
province_id:value[index].area_id,
|
||||
province_name:value[index].area_name
|
||||
})
|
||||
}else if(index==1){
|
||||
this.setData({
|
||||
city_id:value[index].area_id,
|
||||
city_name:value[index].area_name
|
||||
})
|
||||
}else{
|
||||
this.setData({
|
||||
county_id:value[index].area_id,
|
||||
county_name:value[index].area_name,
|
||||
consignee_zip_code:value[index].zip
|
||||
})
|
||||
}
|
||||
}
|
||||
this.setData({
|
||||
show:false,
|
||||
area:currentPosition
|
||||
})
|
||||
},
|
||||
onChangePicker(event) {
|
||||
const { picker, value, index } = event.detail;
|
||||
if(index===0){
|
||||
let currentIndex=picker.getIndexes()[0]
|
||||
this.cityList(provinceArr[currentIndex].area_id);
|
||||
}else if(index===1){
|
||||
let currentIndex=picker.getIndexes()[1]
|
||||
this.countryList(cityArr[currentIndex].area_id);
|
||||
}
|
||||
},
|
||||
onCancel() {
|
||||
this.setData({
|
||||
show:false
|
||||
})
|
||||
},
|
||||
provinceList(){
|
||||
getProvince().then((res)=>{
|
||||
provinceArr= res;
|
||||
let province=[];
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
province.push(res[i]);
|
||||
};
|
||||
this.setData({
|
||||
'columns[0].values':province,
|
||||
})
|
||||
this.cityList(res[0].area_id);
|
||||
|
||||
})
|
||||
},
|
||||
cityList(area_id){
|
||||
getCity({
|
||||
area_id:area_id
|
||||
}).then((res)=>{
|
||||
this.isLoding=true;
|
||||
cityArr=res;
|
||||
let city=[];
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
city.push(res[i]);
|
||||
};
|
||||
this.setData({
|
||||
'columns[1].values':city
|
||||
})
|
||||
this.countryList(res[0].area_id);
|
||||
})
|
||||
},
|
||||
countryList(area_id){
|
||||
getCountry({
|
||||
area_id:area_id
|
||||
}).then((res)=>{
|
||||
let area=[];
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
area.push(res[i]);
|
||||
};
|
||||
this.setData({
|
||||
'columns[2].values':area
|
||||
})
|
||||
})
|
||||
},
|
||||
handleAddress:throttle(function(){
|
||||
this.data.isEdit?this.handleEditAddress():this.handleAddAddress()
|
||||
}),
|
||||
validate(){
|
||||
if (!/^[\u4E00-\u9FA5A-Za-z0-9_]{2,10}$/.test(this.data.consignee_name)) {
|
||||
wx.showToast({
|
||||
title: `姓名要求在2-10个字符`,
|
||||
icon: 'none',
|
||||
});
|
||||
return false;
|
||||
};
|
||||
if(!/^1[3456789]\d{9}$/.test(this.data.consignee_tel)){
|
||||
wx.showToast({
|
||||
title: `请输入有效的手机号码!`,
|
||||
icon: 'none',
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if(!this.data.area){
|
||||
wx.showToast({
|
||||
title: `请选择地区`,
|
||||
icon: 'none',
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if(!this.data.address){
|
||||
wx.showToast({
|
||||
title: `请输入详细地址`,
|
||||
icon: 'none',
|
||||
});
|
||||
return false;
|
||||
}
|
||||
return true
|
||||
},
|
||||
handleGetAddressDetail(id){
|
||||
getAddressDetail(id).then(data=>{
|
||||
for (const key in this.data){
|
||||
if(data[key]!=undefined){
|
||||
this.setData({
|
||||
[key]:data[key]
|
||||
})
|
||||
}
|
||||
};
|
||||
this.setData({
|
||||
area:data.province+data.city+data.county,
|
||||
province_name:data.province,
|
||||
city_name:data.city,
|
||||
county_name:data.county
|
||||
});
|
||||
if(data.consignee_name){
|
||||
this.setData({
|
||||
"hideConsignee_name":true
|
||||
})
|
||||
};
|
||||
if(data.consignee_tel){
|
||||
this.setData({
|
||||
"hideConsignee_tel":true
|
||||
})
|
||||
};
|
||||
if(data.address){
|
||||
this.setData({
|
||||
"hideAddress":true
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
handleEditAddress(){
|
||||
let {consignee_name,consignee_tel,consignee_zip_code,is_default,address,province_id,city_id,county_id,tag,address_id,order_prescription_id,province_name,city_name,county_name}=this.data;
|
||||
let dataObj={};
|
||||
if(tag){
|
||||
dataObj={
|
||||
consignee_name,
|
||||
consignee_tel,
|
||||
province_id,
|
||||
city_id,
|
||||
county_id,
|
||||
tag,
|
||||
consignee_zip_code,
|
||||
is_default,
|
||||
address:address
|
||||
}
|
||||
}else{
|
||||
dataObj={
|
||||
consignee_name,
|
||||
consignee_tel,
|
||||
province_id,
|
||||
city_id,
|
||||
county_id,
|
||||
consignee_zip_code,
|
||||
is_default,
|
||||
address:address
|
||||
}
|
||||
};
|
||||
if(this.validate()){
|
||||
editAddress(address_id,dataObj).then(data=>{
|
||||
wx.showToast({
|
||||
title:"地址修改成功",
|
||||
icon:"none"
|
||||
});
|
||||
if(order_prescription_id){
|
||||
let pages = getCurrentPages();
|
||||
let prevPage = pages[pages.length - 3]; //上上一页
|
||||
prevPage.setData({
|
||||
prevData:JSON.stringify({
|
||||
name:consignee_name,
|
||||
phone:consignee_tel,
|
||||
province:province_name,
|
||||
city:city_name,
|
||||
country:county_name,
|
||||
address,
|
||||
address_id
|
||||
})
|
||||
});
|
||||
wx.navigateBack({
|
||||
delta: 2,
|
||||
})
|
||||
}else{
|
||||
wx.navigateBack({
|
||||
delta: 1,
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
},
|
||||
inputChange(e){
|
||||
let value=e.currentTarget.dataset.value;
|
||||
console.log(value)
|
||||
if(!e.detail.value){
|
||||
this.setData({
|
||||
[value]:false,
|
||||
})
|
||||
}else{
|
||||
this.setData({
|
||||
[value]:true,
|
||||
})
|
||||
}
|
||||
this.setData({
|
||||
[e.target.dataset.id]: e.detail.value
|
||||
})
|
||||
},
|
||||
handleAddAddress(){
|
||||
let {consignee_name,consignee_tel,consignee_zip_code,is_default,address,area,province_id,city_id,county_id,tag,order_prescription_id,province_name,city_name,county_name}=this.data;
|
||||
let dataObj={};
|
||||
if(tag){
|
||||
dataObj={
|
||||
consignee_name,
|
||||
consignee_tel,
|
||||
province_id,
|
||||
city_id,
|
||||
county_id,
|
||||
tag,
|
||||
consignee_zip_code,
|
||||
is_default,
|
||||
address:address
|
||||
}
|
||||
}else{
|
||||
dataObj={
|
||||
consignee_name,
|
||||
consignee_tel,
|
||||
province_id,
|
||||
city_id,
|
||||
county_id,
|
||||
consignee_zip_code,
|
||||
is_default,
|
||||
address:address
|
||||
}
|
||||
};
|
||||
if(this.validate()){
|
||||
addAddress(dataObj).then(data=>{
|
||||
wx.showToast({
|
||||
title:"地址添加成功",
|
||||
icon:"none"
|
||||
});
|
||||
if(order_prescription_id){
|
||||
let pages = getCurrentPages();
|
||||
let prevPage = pages[pages.length - 3]; //上上一页
|
||||
prevPage.setData({
|
||||
prevData:JSON.stringify({
|
||||
name:consignee_name,
|
||||
phone:consignee_tel,
|
||||
province:province_name,
|
||||
city:city_name,
|
||||
country:county_name,
|
||||
address,
|
||||
address_id:data.address_id
|
||||
})
|
||||
});
|
||||
wx.navigateBack({
|
||||
delta: 2,
|
||||
})
|
||||
}else{
|
||||
wx.navigateBack({
|
||||
delta: 1,
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
onChange({detail}) {
|
||||
// 需要手动对 checked 状态进行更新
|
||||
this.setData({
|
||||
is_default: detail?1:0
|
||||
});
|
||||
},
|
||||
handleClose() {
|
||||
this.setData({
|
||||
show: false
|
||||
})
|
||||
},
|
||||
showArea() {
|
||||
this.setData({
|
||||
show: true
|
||||
})
|
||||
},
|
||||
handleConfirm(event) {
|
||||
let arr = event.detail.values;
|
||||
let add = '';
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
add += arr[i].name;
|
||||
};
|
||||
this.setData({
|
||||
show: false,
|
||||
area:add
|
||||
});
|
||||
|
||||
},
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad(options) {
|
||||
let address_id=options.address_id;
|
||||
if(options.order_prescription_id){
|
||||
this.setData({
|
||||
order_prescription_id:options.order_prescription_id
|
||||
})
|
||||
}
|
||||
if(address_id){
|
||||
wx.setNavigationBarTitle({
|
||||
title: "编辑地址",
|
||||
});
|
||||
this.setData({
|
||||
isEdit:true,
|
||||
navName:"编辑地址",
|
||||
address_id
|
||||
})
|
||||
this.handleGetAddressDetail(address_id)
|
||||
}
|
||||
this.provinceList();
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {
|
||||
this.setData({
|
||||
img_host:app.hostConfig().imghost
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
|
||||
})
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"van-switch": "@vant/weapp/switch/index",
|
||||
"van-picker": "@vant/weapp/picker/index",
|
||||
"van-popup": "@vant/weapp/popup/index",
|
||||
"nav":"../../components/nav/nav"
|
||||
},
|
||||
"navigationStyle":"custom",
|
||||
"navigationBarTitleText": "肝胆相照互联网医院"
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<!--pages/editAddress/editAddress.wxml-->
|
||||
<nav navName="{{navName}}"></nav>
|
||||
<view class="page">
|
||||
<view class="cellbox">
|
||||
<view class="cell">
|
||||
<view class="cellrow">
|
||||
<view class="name">
|
||||
收 货 人
|
||||
</view>
|
||||
<view class="iptbox">
|
||||
<input type="text" value="{{consignee_name}}" placeholder="" bindinput="inputChange" data-id="consignee_name" placeholder-class="placeholder" data-value="hideConsignee_name" class="ipt" />
|
||||
<text class="placeholder" hidden="{{hideConsignee_name}}">请输入收货人姓名</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="cell">
|
||||
<view class="cellrow">
|
||||
<view class="name">
|
||||
联系电话
|
||||
</view>
|
||||
<view class="iptbox">
|
||||
<input type="text" placeholder="" value="{{consignee_tel}}" bindinput="inputChange" data-id="consignee_tel" placeholder-class="placeholder" data-value="hideConsignee_tel" class="ipt" />
|
||||
<text class="placeholder" hidden="{{hideConsignee_tel}}">请输入收货人联系电话</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="cell">
|
||||
<view class="cellrow">
|
||||
<view class="name">
|
||||
所在地区
|
||||
</view>
|
||||
<view class="iptbox" bindtap="showArea">
|
||||
<input type="text" placeholder="请选择所在地区" value="{{area}}" placeholder-class="placeholdeript" class="ipt" disabled="true" style="margin-right: 4rpx;"/>
|
||||
|
||||
<image src="{{img_host+'/righticon.png'}}" class="righticon"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="cell">
|
||||
<view class="cellrow">
|
||||
<view class="name">
|
||||
详细地址
|
||||
</view>
|
||||
<view class="iptbox">
|
||||
<input type="text" placeholder="" value="{{address}}" bindinput="inputChange" data-id="address" placeholder-class="placeholder" data-value="hideAddress" class="ipt" />
|
||||
<text class="placeholder" hidden="{{hideAddress}}">请填写乡镇街道、楼牌号等</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="bottombox">
|
||||
<view class="cell">
|
||||
<view class="row">
|
||||
<div class="label">标 签 </div>
|
||||
<view class="tagbox" >
|
||||
<view class="tag {{tag==1?'active':''}}" bindtap="selectTag" data-tag="1">家</view>
|
||||
<view class="tag {{tag==2?'active':''}}" bindtap="selectTag" data-tag="2">公司</view>
|
||||
<view class="tag {{tag==3?'active':''}}" bindtap="selectTag" data-tag="3">学校</view>
|
||||
<view class="tag {{tag==4?'active':''}}" bindtap="selectTag" data-tag="4">其他</view>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
</view>
|
||||
<view class="cell" style="padding:0 32rpx">
|
||||
<view class="cellrow" >
|
||||
<view class="name" style="color: #666666;">
|
||||
设为默认
|
||||
</view>
|
||||
<view class="iptbox">
|
||||
<van-switch checked="{{is_default==1?true:false}}" active-color="#3CC7C0" inactive-color="#f2f2f2" bind:change="onChange" size="26px" />
|
||||
</view>
|
||||
</view></view>
|
||||
</view>
|
||||
<view class="btn" bindtap="handleAddress">保存地址</view>
|
||||
</view>
|
||||
<van-popup
|
||||
show="{{ show }}"
|
||||
round
|
||||
position="bottom"
|
||||
custom-style="height: 50%"
|
||||
bind:close="onClose"
|
||||
>
|
||||
<van-picker columns="{{ columns }}" show-toolbar
|
||||
title="选择地区"
|
||||
columns="{{ columns }}"
|
||||
value-key="area_name"
|
||||
bind:cancel="onCancel"
|
||||
bind:change="onChangePicker"
|
||||
bind:confirm="onConfirm"/>
|
||||
</van-popup>
|
||||
@@ -0,0 +1,132 @@
|
||||
/* pages/editAddress/editAddress.wxss */
|
||||
.page{
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.cellbox{
|
||||
margin-top:192rpx;
|
||||
}
|
||||
.cellbox .cell{
|
||||
box-sizing: border-box;
|
||||
background-color: #fff;
|
||||
align-items: center;
|
||||
display: flex;
|
||||
padding:0 32rpx;
|
||||
|
||||
|
||||
}
|
||||
.cellrow{
|
||||
height:105rpx;
|
||||
width:100%;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
border-bottom:1rpx solid #E3E4E5;
|
||||
}
|
||||
.cell:last-child .cellrow{
|
||||
border-bottom: none;
|
||||
}
|
||||
.iptbox{
|
||||
display: flex;
|
||||
flex:1;
|
||||
position: relative;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.righticon{
|
||||
width:24rpx;
|
||||
height: 48rpx;
|
||||
}
|
||||
.name{
|
||||
font-weight: 500;
|
||||
display: flex;
|
||||
color:#333;
|
||||
font-size: 30rpx;
|
||||
align-items: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.name .red{
|
||||
margin-top: 20rpx;
|
||||
color:#E34D59;
|
||||
}
|
||||
.placeholdeript{
|
||||
color: #C5C8CB;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
.placeholder{
|
||||
top:50%;
|
||||
transform:translateY(-50%);
|
||||
z-index:0;
|
||||
position: absolute;
|
||||
text-align: right;
|
||||
height:80rpx!important;
|
||||
line-height: 80rpx;
|
||||
font-size: 28rpx;
|
||||
font-weight: 400;
|
||||
color: #C5C8CB;
|
||||
}
|
||||
|
||||
.ipt{
|
||||
position: relative;
|
||||
z-index:2;
|
||||
width:100%;
|
||||
height:40rpx!important;
|
||||
line-height:40rpx!important;
|
||||
text-align: right;
|
||||
color: #666666;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
.bottombox{
|
||||
margin-top: 20rpx;
|
||||
flex:1;
|
||||
background-color: #fff;
|
||||
}
|
||||
.row{
|
||||
display: flex;
|
||||
padding:68rpx 32rpx 22rpx;
|
||||
border-bottom: 1rpx solid #E3E4E5;
|
||||
}
|
||||
.tagbox{
|
||||
display: flex;
|
||||
margin-left: 10rpx;
|
||||
|
||||
}
|
||||
|
||||
.label{
|
||||
margin-top: 14rpx;
|
||||
color: #333333;
|
||||
font-size: 30rpx;
|
||||
}
|
||||
.tag{
|
||||
width: 114rpx;
|
||||
height: 58rpx;
|
||||
background: #fff;
|
||||
border-radius: 29rpx;
|
||||
color: #999999;
|
||||
font-size: 28rpx;
|
||||
margin-left: 20rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border: 1rpx solid #999999;
|
||||
justify-content: center;
|
||||
}
|
||||
.tag.active{
|
||||
background: #3CC7C0;
|
||||
border: 1rpx solid #3CC7C0;
|
||||
color:#fff;
|
||||
}
|
||||
.btn{
|
||||
position: absolute;
|
||||
bottom:20rpx;
|
||||
left:32rpx;
|
||||
right:32rpx;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color:#fff;
|
||||
height: 80rpx;
|
||||
background: #3CC7C0;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
Reference in New Issue
Block a user