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.
git/scr/food/pages/paying/paying.js

192 lines
4.2 KiB

// pages/paying/paying.js
const db = wx.cloud.database({});
const app=getApp()
const userid=app.globalData.openid
Page({
/**
* 页面的初始数据
*/
data: {
showPayPwdInput: false, //是否展示密码输入层
pwdVal: '', //输入的密码
payFocus: true, //文本框焦点
addresslist:[],
buylist:[],
orderlist:{},
totalprice:0,
Selection_address:[]
},
allCheckbox: function(tap) {
var index = tap.currentTarget.dataset.index
console.log(index)//获取索引值
let address = this.data.addresslist //获取地址列表
const check = address[index].check; //获取当前地址的选中状态
address[index].check = !check //改变当前商品的状态
console.log(check)
this.setData({
addresslist: address
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
console.log(options.totalprice)
console.log(JSON.parse(options.info))
var buylist=JSON.parse(options.info)
this.setData({
buylist:buylist,
totalprice:options.totalprice
})
console.log(buylist)
db.collection("user")
.where({
"_openid":userid
})
.get()
.then(res => {
console.log("地址", res.data);
console.log(res.data[0].address)
//再次显示数据
this.setData({
addresslist:res.data[0].address
})
})
},
/**
* 显示支付密码输入层
*/
showInputLayer(){
this.setData({ showPayPwdInput: true, payFocus: true });
},
/**
* 隐藏支付密码输入层
*/
hidePayLayer(){
/**获取输入的密码**/
var val = this.data.pwdVal;
/**在这调用支付接口**/
this.setData({ showPayPwdInput: false, payFocus: false, pwdVal: '' }, );
},
/**
* 获取焦点
*/
getFocus(){
this.setData({ payFocus: true });
},
/**
* 输入密码监听
*/
inputPwd(e){
this.setData({ pwdVal: e.detail.value });
if (e.detail.value.length >= 6){
this.hidePayLayer();
wx.showModal({
title:'支付成功',
success: (res) => {
var addresslist=this.data.addresslist
console.log(addresslist)
var addresslist_one1 = {}
var buylist=this.data.buylist
addresslist_one1.food_name=buylist[0].food_name
addresslist_one1.food_shop=buylist[0].food_shop
addresslist_one1.num=buylist[0].num
addresslist_one1.price=this.data.totalprice
addresslist_one1.url=buylist[0].url
for (var i = 0; i < this.data.addresslist.length; i++) { //循环地址列表中的地址
if (addresslist[i].check == true) {
var Selection_address=[]
addresslist_one1.address=addresslist[i].address
addresslist_one1.detailedAddress=addresslist[i].detailedAddress
addresslist_one1.name=addresslist[i].name
addresslist_one1.phone=addresslist[i].phone
console.log(addresslist_one1)
}
}
var time=new Date().toJSON().substring(0, 10) + ' ' + new Date().toTimeString().substring(0,8)
addresslist_one1.time=time
console.log(time)
db.collection('user').where({
"_openid":userid
}).update({
data:{
Orderlist:db.command.push(addresslist_one1)
},
})
if (res.confirm) {
wx.navigateTo({
url:'/pages/orderlist/orderlist?info='+JSON.stringify(addresslist_one1)
})}
}
})
}},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})