index.js 3.42 KB
// pages/customer/index.js
import App from '../../utils/api';
const {regeneratorRuntime} = global
Page({

    /**
     * 页面的初始数据
     */
    data: {},

    /**
     * 生命周期函数--监听页面加载
     */
    async onLoad(opt) {
        console.log('onLoad', opt);
        //转化场景值到opt
        this.selectComponent("#network").debug(opt, 'opt');
        if (opt.scene) {//扫码进入
            let query = decodeURIComponent(opt.scene);
            query.split('&').forEach(q => {
                let _q = q.split('=');
                opt[_q[0]] = _q[1];
            })
            this.selectComponent("#network").debug(opt, 'scene');
        }

        opt.openid = await this.getOpenid();
        if (!opt.openid) {
            console.log('App.Orders.CheckOrder no openid');
            this.selectComponent("#network").refresh();
            return;
        }

        let url = '/pages/customer/list';
        if (opt.id > 0 || opt.sms_code) {
            if(opt.invite_name){
                let invite_names=wx.getStorageSync('invite_names') ||{};
                invite_names[opt.id]=opt.invite_name;
                wx.setStorage({
                    key:'invite_names',
                    data:invite_names
                });
            }
            let param={
                openid: opt.openid,
            }
            if(opt.sms_code){
                param.code=opt.sms_code;
            }else{
                param.rid=opt.id
            }

            App.Reserve.Detail(param).then(res => {
                //设置关系
                App.Reserve.SetRelaOpenid({
                    rid:res.data.id,
                    openid:opt.openid,
                    fromid:opt.fromid?opt.fromid:''
                })

                if (!res.data.openid) {//无预订人
                    url = '/pages/customer/detail_owner';
                } else {
                    url = '/pages/customer/detail_customer';
                    if (res.data.openid == opt.openid) {
                        url = '/pages/customer/detail_owner';
                    }
                }
                url+='?id='+res.data.id
                console.log('wx.redirectTo',url,res);
                this.redirectTo({url: url});
            }).catch(res=>{
                this.redirectTo({url: url});
            })
        } else {
            console.log('url',url);
            this.redirectTo({url: url});
        }

    },
    redirectTo(red){
        console.log('this.redirectTo',red);
        if(red.url.indexOf('list')>0){
            wx.switchTab(red);
        }else{
            wx.redirectTo(red);
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

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

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

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

    },

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

    },

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

    },

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

    },
    async getOpenid(){
        let openid = getApp().openid;
        return openid;
    },
})