Compare commits

...

2 Commits

Author SHA1 Message Date
wbb 170d0265f0 Merge branch 'master' of https://bdgit.educoder.net/pu6ej7yq9/git
2 years ago
wbb 0d3fc6f24e 收货地址
2 years ago

@ -11,8 +11,11 @@
"pages/change/change",
"pages/answer/answer",
"pages/orderdoing/orderdoing",
"pages/pay/pay",
"pages/orderdoing/orderdoing",
"pages/address/address",
"pages/turning/turning",
"pages/pay/pay"
"pages/addAddress/addAddress"
],
"tabBar": {
"custom": false,

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

@ -0,0 +1,265 @@
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 addresslist={}
addresslist.name=this.data.consigneeName
addresslist.phone=this.data.phone
addresslist.address=this.data.consigneeRegion
addresslist.detailedAddress=this.data.detailedAddress
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
this.startAddressAnimation(false)
// 将选择的城市信息显示到输入框
var consigneeRegion = that.data.provinces[value[0]].name + '-' + that.data.citys[value[1]].name + '-' + that.data.areas[value[2]].name
that.setData({
consigneeRegion: consigneeRegion,
})
},
// 处理省市县联动逻辑
cityChange: function (e) {
var value = e.detail.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]
// 如果省份选择项和之前不一样,表示滑动了省份,此时市默认是省的第一组数据,
if (this.data.value[0] != provinceNum) {
var id = provinces[provinceNum].id
this.setData({
value: [provinceNum, 0, 0],
citys: _citys[id],
areas: _areas[_citys[id][0].id],
})
} else if (this.data.value[1] != cityNum) {
// 滑动选择了第二项数据,即市,此时区显示省市对应的第一组数据
var id = citys[cityNum].id
this.setData({
value: [provinceNum, cityNum, 0],
areas: _areas[citys[cityNum].id],
})
} else {
// 滑动选择了区
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() {
}
})

@ -0,0 +1,4 @@
{
"usingComponents": {},
"initialRenderingCache": "dynamic"
}

@ -0,0 +1,81 @@
<!--pages/my/my-add-address/index.wxml-->
<view class="redact-address">
<view class="possess-layout">
<view class="mains">
<view class="address-msg">
<view class="item-msg">收货人</view>
<view class="section">
<input type="text" placeholder="请填写收货人姓名" value="{{consigneeName}}" bindblur="consigneeNameInput" placeholder-class="phcolor"></input>
</view>
<view class="address-right">
</view>
</view>
<view class="address-msg">
<view class="item-msg">手机号码</view>
<view class="section">
<input type="number" placeholder="请填写收货人手机号码" value="{{phone}}" maxlength="11" bindblur="phoneInput" placeholder-class="phcolor"></input>
</view>
</view>
<view class="address-msg">
<view class="item-msg">所在地区</view>
<view class="section" bindtap='select'>
<input disabled="disabled" placeholder="省市区县、乡镇等" value="{{consigneeRegion}}" bindblur="consigneeRegionInput" placeholder-class="phcolor"></input>
</view>
<view class="address-rights" bindtap='select'>
<view>定位</view>
</view>
</view>
<view class="address-msg">
<view class="item-msg">详细地址</view>
<view class="section">
<input type="text" placeholder="街道、楼牌号等" value="{{detailedAddress}}" bindblur="detailedAddressInput" placeholder-class="phcolor"></input>
</view>
</view>
<view class="label">
<view class="label-title">标签</view>
<view class="label-list">
<block wx:for="{{labelList}}" wx:key="index">
<view class="labels {{labelDefault==index? 'labels-active': ''}}" data-index="{{index}}" bindtap="chooseLabelSelect">{{item}}</view>
</block>
</view>
</view>
<view class="default-setting">
<view class="defaul-setting-left">
<view>设置默认地址</view>
<view>提醒:每次下单会默认推荐使用该地址</view>
</view>
</view>
</view>
</view>
</view>
<view class="btn" bindtap="submit">保存</view>
<view class="picker" animation="{{animationAddressMenu}}" style="visibility:{{addressMenuIsShow ? 'visible':'hidden'}}">
<view class="picker-view" animation="{{animationAddressMenu}}" style="visibility:{{addressMenuIsShow ? 'visible':'hidden'}}">
<!-- 确认取消按钮 -->
<view class='gangedBtn'>
<text class="city-cancel" catchtap="cityCancel">取消</text>
<text style="float: right" catchtap="citySure">确定</text>
</view>
<!-- 选择地址 -->
<picker-view class='cont' bindchange="cityChange" value="{{value}}" wx:key="">
<!-- 省 -->
<picker-view-column>
<view wx:for="{{provinces}}" class="picker-item" wx:key="index">{{item.name}}</view>
</picker-view-column>
<!-- 市 -->
<picker-view-column>
<view wx:for="{{citys}}" class="picker-item" wx:key="index">{{item.name}}</view>
</picker-view-column>
<!-- 区 -->
<picker-view-column>
<view wx:for="{{areas}}" class="picker-item" wx:key="index">{{item.name}}</view>
</picker-view-column>
</picker-view>
</view>
</view>

@ -0,0 +1,198 @@
/* pages/my/my-add-address/index.wxss */
.redact-address {
background: white;
margin-bottom: 20rpx;
}
.address-msg {
height: 128rpx;
display: flex;
align-items: center;
background: #FFFFFF;
border-top: 2rpx solid #efefef;
font-size: 28.68rpx;
color: #333333;
padding: 0 20rpx;
}
.address-right image {
width: 32rpx;
height: 32rpx;
}
.address-rights {
display: flex;
align-items: center;
}
.address-rights image {
width: 26rpx;
height: 32rpx;
margin-right: 13rpx;
}
.address-rights view {
font-size: 28.68rpx;
}
.address-msg:last-child {
border-bottom: none;
}
.section {
width: 58%;
}
.phcolor {
color: #999999;
}
.item-msg {
width: 25%;
margin-right: 25rpx;
}
.img {
width: 35rpx;
height: 35rpx;
align-self: center;
}
.address-right {
width: 100rpx;
display: flex;
flex-direction: row-reverse;
}
/* 标签 */
.label {
display: flex;
height: 128rpx;
align-items: center;
margin-top: 73rpx;
border-top: 1px solid #EEEEEE;
border-bottom: 1px solid #EEEEEE;
padding: 0 20rpx;
}
.label-title {
font-size: 28.68rpx;
color: #333333;
margin-right: 83rpx;
}
.label .label-list {
display: flex;
}
.label .label-list .labels{
height: 40rpx;
width: 96rpx;
border: 1px solid #EEEEEE;
margin-right: 37rpx;
text-align: center;
line-height: 40rpx;
font-size: 24rpx;
color: #000000;
border-radius: 20rpx;
}
.labels-active {
background: #F73C41 !important;
color: #FFFFFF !important;
}
/* 默认设置 */
.default-setting {
display: flex;
justify-content: space-between;
align-items: center;
height: 160rpx;
padding: 0 20rpx;
}
.defaul-setting-left view:nth-child(1){
font-size: 28.68rpx;
color: #333333;
margin-bottom: 25rpx;
}
.defaul-setting-left view:nth-child(2) {
font-size: 20rpx;
color: #333333;
}
.defaul-setting-right {
height: 64rpx;
width: 105rpx;
}
.btn {
width: 680rpx;
height: 88rpx;
background: #F73C41;
color: #FFFFFF;
position: fixed;
bottom: 55rpx;
left: 35rpx;
border-radius: 41.5rpx;
font-size: 36rpx;
text-align: center;
line-height: 88rpx;
}
/* 城市选择 */
.picker {
width: 100%;
height: 100%;
display: flex;
z-index: 12;
background-color: #fff;
background: rgba(0, 0, 0, 0.2);
flex-direction: column;
justify-content: center;
align-items: center;
position: fixed;
bottom: 0;
left: 0rpx;
}
.picker-view {
width: 100%;
display: flex;
z-index: 12;
background-color: #fff;
flex-direction: column;
justify-content: center;
align-items: center;
position: fixed;
bottom: 0;
left: 0rpx;
height: 40vh;
border-top-left-radius: 30rpx;
border-top-right-radius: 30rpx;
}
.gangedBtn {
border-top: 1px solid #efefef;
border-top-left-radius: 30rpx;
border-top-right-radius: 30rpx;
width: 100%;
height: 90rpx;
padding: 0 66rpx;
box-sizing: border-box;
line-height: 90rpx;
text-align: center;
color: black;
font-size: 0.8rem;
display: flex;
background: white;
justify-content: space-between;
}
.cont {
width: 100%;
height: 389rpx;
}
.picker-item {
line-height: 70rpx;
margin-left: 5rpx;
margin-right: 5rpx;
text-align: center;
}
.address {
width: 100%;
height: 90rpx;
line-height: 90rpx;
text-align: center;
border-bottom: 1rpx solid #f1f1f1;
}
.city-cancel {
color: gray;
}

@ -0,0 +1,123 @@
// pages/address/address.js
const db = wx.cloud.database({});
const app=getApp()
const userid=app.globalData.openid
Page({
/**
* 页面的初始数据
*/
data: {
addressList:[]
},
//增加地址
addAddress:function(){
wx.navigateTo({ url: '/pages/addAddress/addAddress' });
},
delAddress:function(event){
var that = this;
const index = event.currentTarget.id;
console.log(index)
let addressList = this.data. addressList;//购物车所有的商品数据
wx.showModal({
title: '温馨提示',
content: '确定删除当前地址吗?',
confirmColor: "#f00",
success: (res) => {
if (res.confirm) {
addressList.splice(index, 1);
this.setData({
addressList:addressList
})
db.collection('user')//回调回云数据库
.where({
"_openid":userid
})
.update(
{
data:{
['address']:this.data.addressList
}
}
)
}}
})
console.log(addressList)
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
db.collection('user').
where({
"_openid":userid
}) //还需修改
.get({
success: res => {
console.log(res.data.address)
console.log(res.data)
//这一步很重要给ne赋值没有这一步的话前台就不会显示值
this.setData({
addressList: res.data[0].address
})
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

@ -0,0 +1,4 @@
{
"usingComponents": {},
"navigationBarTitleText": "管理地址"
}

@ -0,0 +1,41 @@
<!--pages/address/address.wxml-->
<scroll-view class="scroll" scroll-y="true">
<view wx:for="{{addressList}}">
<view class="product-name-wrap">
<view class="ui-list-item-info">{{item.address}}
<text decode="{{true}}" space="{{true}}">&nbsp;&nbsp;</text> {{item.phone}}
</view>
<view class="ui-list-item-address">
{{item.detailAddress}}
</view>
<view class="ui-list-item-time">
<p>{{item.name}}</p>
<p class="ui-list-item-del" data-id="{{index}}" bindtap="delAddress">删除</p>
</view>
<view class="separate"></view>
</view>
</view>
</scroll-view>
<view class="add-address" bindtap="addAddress">
<image class="add-img" src="/images/add.jpg"></image>新增地址
</view>

@ -0,0 +1,92 @@
/* pages/address/address.wxss */
page{
display: flex;
flex-direction: column;
height: 100%;
}
.product-name-wrap{
margin: 0px 10px;
font-size: 14px;
color: #404040;
}
.ui-list-item-info{
margin: 5px 0px;
}
.ui-list-item-address{
color: #585c64;
}
.ui-list-item-time{
margin: 5px 0px;
}
.ui-list-item-del{
position: absolute;
right: 10px;
color: #585c64;
}
/* 分割线 */
.separate {
margin: 5px 0px;
height: 2rpx;
background-color: #f2f2f2;
}
.add-address{
margin: 0 auto;
margin-top: 30px;
width: 150px;
height: 35px;
border: 1px #000 solid;
line-height: 35px;
text-align: center;
color: #000;
border-radius: 5rpx;
display: block;
}
.add-img{
margin-right: 15rpx;
width: 15px;
height: 15px;}

@ -116,6 +116,7 @@ where({
}
}
)
this.getTotalPrice()
},
reduceButtonClick: function(event) {
var that = this;
@ -149,6 +150,7 @@ db.collection('user')//回调回云数据库
}
}
)
this.getTotalPrice()
}
},
//删除单个商品
@ -173,7 +175,7 @@ let foodid=cartlistsee[index]._id
db.collection('user')//回调回云数据库
. where({
"_openid":userid
}) //还需修改
})
.update(
{
data:{
@ -184,7 +186,7 @@ let foodid=cartlistsee[index]._id
db.collection('user')//回调回云数据库
.where({
"_openid":userid
}) //还需修改
})
.update(
{
data:{
@ -194,7 +196,7 @@ let foodid=cartlistsee[index]._id
)
}}
})
this.getTotalPrice()
console.log(cartlistsee)
},
/**
@ -261,7 +263,22 @@ let foodid=cartlistsee[index]._id
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
console.log("下拉刷新...");
this.onRefresh();
},
onRefresh:function(){
//导航条加载动画
wx.showNavigationBarLoading({
title:'loading'
})
;
setTimeout(function () {
wx.hideNavigationBarLoading();
//停止下拉刷新
wx.stopPullDownRefresh();
}, 2000);
},
/**

@ -25,7 +25,7 @@
<!--item就相当于数组名+下标的结合体,适用于调用数组所有数据-->
<view catchtap="toDetail" data-foodid="{{item._id}}">
<view class='img'>
<image src="{{item.url}}" ></image>
<image src="{{item.url}}" style="border-radius:20px;"></image>
</view>
<view class='info'>
<view class='title'>{{item.food_name}}</view>

@ -4,7 +4,8 @@ Page({
userInfo:'',
avatarUrl:'',
nickName:'',
cartlist:[]
cartlist:[],
address:[]
},
onLoad(){
/*
@ -38,12 +39,14 @@ Page({
if (!res.data.length) {
// 没有存在同样的内容
var cartlist=[]
var address=[]
wx.cloud.database().collection('user').add({
data: {
userInfo:user,
avatarUrl:user.avatarUrl,
nickName:user.nickName,
cartlist:cartlist
cartlist:cartlist,
address:address
}
})
}

@ -22,9 +22,6 @@ Page({
nickName:wx.getStorageSync('nickName')
})
console.log(avatarUrl)
console.log(nickName)
},
/**

@ -44,7 +44,7 @@
<view class="line"></view>
<view class="list-item">
<image class="item-image" src="/images/test6.jpg"></image>
<text class="item-text">收货地址</text>
<navigator class="item-text" url="/pages/address/address">收货地址</navigator>
</view>
<view class="line"></view>

@ -65,6 +65,20 @@
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "",
"pathName": "pages/address/address",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "",
"pathName": "pages/addAddress/addAddress",
"query": "",
"launchMode": "default",
"scene": null
}
]
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save