examineCertificate.js 5.01 KB
// pack-activity/pack/examineCertificate.js
import App from '../../utils/api'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        id: '',
        detail: {
            qrcode: null,
        },
        sellerObj: {
            sellername: '',
            seller_image: '',
            real_address: '',
            cateStr: '',
        },
        certificateDetail: {},
        exp_date: {},
        is_time: false, //是否继续执行
        timeList: [], //定时器列表
        timers: null,
    },
    stopWaiting() {
        for (var i = 0; i < this.data.timeList.length; i++) {
            clearTimeout(this.data.timeList[i]); //清除了所有定时器
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            id: options.id
        })
        console.log(this.data.id);
        this.getDetail('1')
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

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

    },
    getDetail(num) {
        App.Activity.GetOrderRechargeByid({
            id: this.data.id
        }).then(res => {
            let detail = res.data;
            let exp_date = detail.exp_date ? JSON.parse(detail.exp_date) : '';
            let date = Date.now() * 1;
            if (date > detail.etime) {
                detail.is_expire = '0';
            } else {
                detail.is_expire = '1';
            }
            this.setData({
                detail,
                exp_date
            })
            console.log('is_examine', detail.is_examine);
            if (detail.is_examine == '0') {
                this.setData({
                    is_time: true,
                    detail,
                    exp_date
                })
                this.myUpdate()
            } else {
                this.setData({
                    is_time: false,
                    detail,
                    exp_date
                })
                wx.showModal({
                    title: '已核销',
                    cancelText: '取消',
                    confirmText: '朕知道了',
                    content: '核销成功!',
                    success: function (res) {
                        if (res.confirm) { //这里是点击了确定以后
                            wx.reLaunch({
                                url: '/pages/me/coupon_news'
                            })
                        }
                    }
                })
            }
            if (num == '1') {
                this.getSeller(res.data.sellerid)
            }
        })
    },
	// 关注公众号
	wananchi() {
		wx.navigateTo({
			url: '/pages/me/wananchi'
		})
	},
    // 轮询查询是否核销
    myUpdate() {
        var is_time = this.data.is_time //是否继续执行
        console.log('is_time', is_time)
        if (!is_time) {
            console.log('已核销!轮询停止')
            clearTimeout(this.timers)
        } else {
            console.log("继续轮询");
            this.timers = setTimeout(() => {
                this.getDetail()
            }, 5000);
        }
    },
    // 获取商家信息
    getSeller(sid) {
        App.Customer.GetSellerDetail({
            sid,
        }).then(res => {
            let data = res.data;
            let cate = data.cate;
            let cateStr;
            if (cate && cate.length > 0) {
                cateStr = [];
                cate.some(cate => {
                    cateStr.push(cate);
                    if (cateStr.length > 2) {
                        return true
                    }
                })
                cateStr = cateStr.join('/')
            }
            let sellerObj = {
                sellername: data.sellername,
                seller_image: data.seller_image,
                real_address: data.real_address,
                cateStr
            }

            this.setData({
                sellerObj
            })
            console.log('sellerObj', {
                ...sellerObj
            });
        })
    },
    // 申请退款
    subscribeDrawback() {
        clearTimeout(this.timers)
        wx.navigateTo({
            url: '/pack-activity/pack/subscribeDrawback?detail=' + JSON.stringify(this.data.detail),
        })
    },
    // 跳转到商家详情
    getReserve() {
        clearTimeout(this.timers)
        wx.reLaunch({
            url: '/pages/reserve/detail?id=' + this.data.detail.sellerid
        })
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {
        clearTimeout(this.timers)
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {
        clearTimeout(this.timers)
    },

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

    },

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

    },

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

    }
})