|
|
|
|
|
|
|
|
|
var address=require('../../utils/mock.js');
|
|
|
|
|
const db = wx.cloud.database({});
|
|
|
|
|
const app=getApp();
|
|
|
|
|
const userid=app.globalData.openid;
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面的初始数据
|
|
|
|
|
*/
|
|
|
|
|
data: {
|
|
|
|
|
animationAddressMenu: {},
|
|
|
|
|
addressMenuIsShow: false,
|
|
|
|
|
value: [0, 0, 0],
|
|
|
|
|
provinces: [],
|
|
|
|
|
citys: [],
|
|
|
|
|
areas: [],
|
|
|
|
|
consigneeName: "",
|
|
|
|
|
phone: "",
|
|
|
|
|
consigneeRegion: "",
|
|
|
|
|
detailedAddress: "",
|
|
|
|
|
labelList: ["家", "公司", "学校"], //标签
|
|
|
|
|
labelDefault: 0, // 标签默认,
|
|
|
|
|
addresslist:{}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
consigneeNameInput: function(e) {
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
consigneeName: e.detail.value
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
phoneInput: function(e) {
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
phone: e.detail.value
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
consigneeRegionInput: function (e) {
|
|
|
|
|
this.setData({
|
|
|
|
|
consigneeRegion: e.detail.value
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
detailedAddressInput: function (e) {
|
|
|
|
|
this.setData({
|
|
|
|
|
detailedAddress: e.detail.value
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
chooseLabelSelect: function(e) {
|
|
|
|
|
var index = e.currentTarget.dataset.index;
|
|
|
|
|
this.setData({
|
|
|
|
|
labelDefault: index
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
submit: function() {
|
|
|
|
|
var consigneeName = this.data.consigneeName;
|
|
|
|
|
console.log(consigneeName)
|
|
|
|
|
var phone = this.data.phone;
|
|
|
|
|
console.log(phone)
|
|
|
|
|
var consigneeRegion = this.data.consigneeRegion;
|
|
|
|
|
console.log(consigneeRegion)
|
|
|
|
|
var detailedAddress = this.data.detailedAddress
|
|
|
|
|
console.log(detailedAddress)
|
|
|
|
|
if (consigneeName == "") {
|
|
|
|
|
wx: wx.showToast({
|
|
|
|
|
title: '请输入姓名',
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
else if (phone == "") {
|
|
|
|
|
wx: wx.showToast({
|
|
|
|
|
title: '请输入手机号码'
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
else if (consigneeRegion == "") {
|
|
|
|
|
wx: wx.showToast({
|
|
|
|
|
title: '请选择所在地区'
|
|
|
|
|
})
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
else if (detailedAddress == "") {
|
|
|
|
|
wx: wx.showToast({
|
|
|
|
|
title: '请输入详细地址',
|
|
|
|
|
})
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
var check=false
|
|
|
|
|
var addresslist={}
|
|
|
|
|
addresslist.name=this.data.consigneeName
|
|
|
|
|
addresslist.phone=this.data.phone
|
|
|
|
|
addresslist.address=this.data.consigneeRegion
|
|
|
|
|
console.log(this.data.consigneeRegion)
|
|
|
|
|
addresslist.detailedAddress=this.data.detailedAddress
|
|
|
|
|
addresslist.check=check
|
|
|
|
|
this.setData({
|
|
|
|
|
addresslist:addresslist
|
|
|
|
|
})
|
|
|
|
|
db.collection('user').where({
|
|
|
|
|
"_openid":userid
|
|
|
|
|
})
|
|
|
|
|
.update(
|
|
|
|
|
{
|
|
|
|
|
data:{
|
|
|
|
|
address:db.command.push(addresslist)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
console.log(addresslist)
|
|
|
|
|
db.collection('user').where({
|
|
|
|
|
"_openid":userid
|
|
|
|
|
})
|
|
|
|
|
.get({
|
|
|
|
|
success: res => {
|
|
|
|
|
console.log(res.data)}
|
|
|
|
|
})
|
|
|
|
|
console.log(userid)
|
|
|
|
|
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url: '/pages/address/address',
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
|
*/
|
|
|
|
|
onLoad: function (options) {
|
|
|
|
|
// 默认联动显示北京
|
|
|
|
|
|
|
|
|
|
var id = address._provinces[0].id
|
|
|
|
|
console.log(address._provinces[0].id)
|
|
|
|
|
this.setData({
|
|
|
|
|
provinces: address._provinces,
|
|
|
|
|
citys: address._citys[id],
|
|
|
|
|
areas: address._areas[address._citys[id][0].id],
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
// 点击所在地区弹出选择框
|
|
|
|
|
select: function (e) {
|
|
|
|
|
// 如果已经显示,不在执行显示动画
|
|
|
|
|
if (this.data.addressMenuIsShow) {
|
|
|
|
|
return false
|
|
|
|
|
} else {
|
|
|
|
|
// 执行显示动画
|
|
|
|
|
this.startAddressAnimation(true)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 执行动画
|
|
|
|
|
startAddressAnimation: function (isShow) {
|
|
|
|
|
if (isShow) {
|
|
|
|
|
// vh是用来表示尺寸的单位,高度全屏是100vh
|
|
|
|
|
this.animation.translateY(0 + 'vh').step()
|
|
|
|
|
} else {
|
|
|
|
|
this.animation.translateY(40 + 'vh').step()
|
|
|
|
|
}
|
|
|
|
|
this.setData({
|
|
|
|
|
animationAddressMenu: this.animation.export(),
|
|
|
|
|
addressMenuIsShow: isShow,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
// 点击地区选择取消按钮
|
|
|
|
|
cityCancel: function (e) {
|
|
|
|
|
this.startAddressAnimation(false)
|
|
|
|
|
},
|
|
|
|
|
// 点击地区选择确定按钮
|
|
|
|
|
citySure: function (e) {
|
|
|
|
|
var that = this
|
|
|
|
|
var city = that.data.city
|
|
|
|
|
var value = that.data.value
|
|
|
|
|
that.startAddressAnimation(false)
|
|
|
|
|
console.log(value)
|
|
|
|
|
// 将选择的城市信息显示到输入框
|
|
|
|
|
var consigneeRegion = that.data.provinces[value[0]].name + '-' + that.data.citys[value[1]].name + '-' + that.data.areas[value[2]].name
|
|
|
|
|
console.log(consigneeRegion)
|
|
|
|
|
that.setData({
|
|
|
|
|
consigneeRegion: consigneeRegion
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
// 处理省市县联动逻辑
|
|
|
|
|
cityChange: function (e) {
|
|
|
|
|
var value = e.detail.value
|
|
|
|
|
console.log(value)
|
|
|
|
|
var provinces = this.data.provinces
|
|
|
|
|
var citys = this.data.citys
|
|
|
|
|
var areas = this.data.areas
|
|
|
|
|
var provinceNum = value[0]
|
|
|
|
|
var cityNum = value[1]
|
|
|
|
|
var countyNum = value[2]
|
|
|
|
|
console.log(provinceNum)
|
|
|
|
|
|
|
|
|
|
// 如果省份选择项和之前不一样,表示滑动了省份,此时市默认是省的第一组数据,
|
|
|
|
|
if (this.data.value[0] != provinceNum) {
|
|
|
|
|
var pid = provinces[provinceNum].id
|
|
|
|
|
console.log(pid)
|
|
|
|
|
console.log(address._citys[pid][0])
|
|
|
|
|
console.log(address._citys[pid][0].id)
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
value: [provinceNum, 0, 0],
|
|
|
|
|
citys: address._citys[pid],
|
|
|
|
|
areas: address._areas[address._citys[pid][0].id],
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
} else if (this.data.value[1] != cityNum) {
|
|
|
|
|
// 滑动选择了第二项数据,即市,此时区显示省市对应的第一组数据
|
|
|
|
|
var id = citys[cityNum].id
|
|
|
|
|
this.setData({
|
|
|
|
|
value: [provinceNum, cityNum, 0],
|
|
|
|
|
areas: address.areas[citys[cityNum].id],
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(provinceNum)
|
|
|
|
|
console.log(cityNum)
|
|
|
|
|
console.log(countyNum)
|
|
|
|
|
// 滑动选择了区
|
|
|
|
|
this.setData({
|
|
|
|
|
value: [provinceNum, cityNum, countyNum]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
|
*/
|
|
|
|
|
onReady() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
|
*/
|
|
|
|
|
onShow: function() {
|
|
|
|
|
var animation = wx.createAnimation({
|
|
|
|
|
duration: 500,
|
|
|
|
|
timingFunction: 'linear',
|
|
|
|
|
})
|
|
|
|
|
this.animation = animation
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
|
*/
|
|
|
|
|
onHide() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
|
*/
|
|
|
|
|
onUnload() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
|
*/
|
|
|
|
|
onPullDownRefresh() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
|
*/
|
|
|
|
|
onReachBottom() {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户点击右上角分享
|
|
|
|
|
*/
|
|
|
|
|
onShareAppMessage() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
})
|