confirmPayment.js 4.25 KB
// pack-activity/pack/confirmPayment.js
import util from '../../utils/util';
import App from '../../utils/api';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        opt:{
            detail:{},
            orderId:'',
            totalize:'',
        },
        type: '',
        price:'',
        detail:{},
        time: 300,
        countdown: '',
        tip: '',
        date: "",
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            opt:{
                detail:options.detail?JSON.parse(options.detail):'',
                orderId:options.orderId,
                totalize:options.totalize?options.totalize:''
            },
            type:options.type
        })
        console.log('onLoad',{...this.data.opt});
        this.countdown()
        this.modal = this.selectComponent("#payModal"); //通过给组件所起的id调用组件
    },
    showModal() {
        this.modal.showModal() //调用组件中打开模态框方法
    },
    recharge(){
        console.log('11111111111111111',this.data.opt.detail.oid);
        this.closeModal() 
        wx.reLaunch({
            url: `/miniprogram/pages/customer/detail_owner_invitation_new.wxml?id=${this.data.opt.detail.oid}&hasInvitation=1&hasSellerShare=1&tplid=1`
        })
    },
    certificate(){
        console.log('11111111111111111',this.data.opt.detail.oid);
        this.closeModal() 
        wx.reLaunch({
            url: '/miniprogram/pages/me/coupon_news'
        })
    },
    confirmPayment(){
        console.log(11111);
        App.PayOnline.CombineTransactionsByRecharge({
            id:this.data.opt.orderId
        }).then(res=>{
            console.log(res.ret);
            if(res.ret=='200'){
                console.log(res.ret);
                this.setData({
                    price:res.data.price
                })
                wx.requestPayment({
                    timeStamp: res.data.timeStamp+'',
                    nonceStr: res.data.nonceStr,
                    package: res.data.package,
                    signType: res.data.signType,
                    paySign: res.data.paySign,
                    success (ress) { 
                        this.showModal()
                    },
                    fail (ress) {
                        console.log(ress);
                    }
                })
            }
        })
        
    },
    closeModal() {
        this.modal.closeModal() //调用组件中关闭模态框方法
    },
    // 充值————点击确认支付
    formSubmit(e) {
        console.log(this.data.type);
        if(this.data.type=='2'){
            let form=e.detail.value
            if (!form.name) {
                util.toast('未填写姓名', 'none')
                return;
            }
            if (!form.phone) {
                util.toast('未填写手机号码', 'none')
                return;
            }
            if (!/^1\d{10}$/.test(form.phone)) {
                util.toast('手机号码错误', 'none')
                return;
            }
        }
        console.log(1111);
        this.confirmPayment()
    },
    // 选择日期
    bind_ChangeDate(event) {
        console.log();
        let date = event.detail.value
        this.setData({
            date
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },
    // 倒计时
    countdown() {
        var minute = Math.floor(this.data.time / 60);
        var second = this.data.time % 60
        second < 10 ? second = '0' + second : '';
        this.setData({
            countdown: minute + ':' + second,
            time: this.data.time - 1
        })
        setTimeout(this.countdown, 1000);
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})