Files
cardtest/pages/activityInfo/activityInfo.js
zhangmanman 540d76bdb8 [更新]
2021-08-09 15:57:37 +08:00

183 lines
4.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 本时生活
*/
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
isUser : false, //用户登录状态
indexId : '', //tab状态
indexArr : '', //商品列表
page : '', //下一页
address : '', //收货地址
goodId : '', //商品id
goodCont : '', //商品信息
params : '', //商品数量组
paramsIndex : 0,
platIndex : 0, //选择提交方式下标
platformCp :[ //选择提交数组
{
id : 0,
name : '快递'
},
{
id : 1,
name : '自提'
}
],
},
/**
* 生命周期函数--监听页面加载
*/
onLoad (options) {
// this.setData({
// goodId: options.id
// })
if(app.globalData.isUser){
this.setData({
isUser: app.globalData.isUser
})
}
// 活动商品列表
wx.$api.index.redwine().then(res=>{
this.setData({
indexArr : res.data.data,
indexId : res.data.data[1].id,
page : res.data.page
})
// 获取商品信息
this.redwineInfo(res.data.data[1].id)
}).catch(err => {});
},
/**
* 商品信息
*/
redwineInfo(id) {
wx.$api.index.redwinePay(id).then(res=>{
this.setData({
address : res.data.address,
goodCont : res.data.good,
params : res.data.params,
paramsIndex : res.data.params.findIndex(val => val.def == 1)
})
}).catch(err => {});
},
/**
* 商品数量选择
*/
goodsNumber(e) {
let onType = e.currentTarget.dataset.type,
atIndex = this.data.paramsIndex
// atIndex = this.data.params.findIndex(val => val.number == this.data.qty)
if(onType == 'plus' && atIndex < this.data.params.length - 1){
atIndex++
}else if(onType == 'remove' && atIndex >= 1){
atIndex--
}else{
return
}
this.setData({
paramsIndex: atIndex
})
},
/**
* 选择提交方式
*/
platBind(e) {
this.setData({
platIndex : e.detail.value
})
},
/**
* 订单提交
*/
submitOrder() {
let good_id = this.data.indexId,
param_id = this.data.params[this.data.paramsIndex].id,
address_id = this.data.address.id,
islogistics = this.data.platIndex
wx.login({
success: res=> {
wx.$api.index.payment(good_id, param_id, address_id, islogistics).then(res=>{
let payInfo = JSON.parse(res.data.json)
wx.requestPayment({
timeStamp: payInfo.timeStamp,
nonceStr : payInfo.nonceStr,
package : payInfo.package,
paySign : payInfo.paySign,
signType : payInfo.signType,
success : res=>{
if(res.errMsg == "requestPayment:ok"){
wx.showToast({
title: '支付成功',
icon : 'success'
})
setTimeout(()=>{
wx.reLaunch({
url: '/pages/activityOrder/activityOrder',
})
},2000)
}
},
fail : res=>{
wx.reLaunch({
url: '/pages/activityOrder/activityOrder',
})
}
})
}).catch(err => {});
}
})
},
/**
* 选择tab
*/
orderTab(e) {
let indexId = e.currentTarget.dataset.id
if (indexId != this.data.indexId) {
this.setData({
indexId : indexId
})
}
// 获取商品信息
this.redwineInfo(indexId)
},
/**
* 点击图片放大
*/
clickImg(e) {
let imgUrl = e.currentTarget.dataset.img
wx.previewImage({
urls : [imgUrl], //需要预览的图片http链接列表注意是数组
current : '' // 当前显示图片的http链接默认是第一个
})
},
/**
* 处理未登录时的转跳
*/
loginGo(e){
wx.navigateTo({
url: "/pages/login/login?way=activity"
})
}
})