// pages/call/call.js
let app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        name:'姓名',
        dhh:'13188888888',
        pai:'',
        switch:'',
        avatar:'',
        scene:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log(options)

        let t = this;



        let u = "index/cheZhu";
        let d = {
            scene: options.id,
        }
        console.log(options.id);
        if(options.id=='' || options.id==undefined){
            wx.showModal({
                content: '当前号码牌已失效',
                showCancel:false,
               success (res) {
                     wx.reLaunch({
                url: '/pages/index/index'
                })
 
                return false;
              }
            })
        }
       t.setData({
        scene:options.id
       })
        app.post(u, d).then(r=>{
            console.log(r)
            if(r.code==1){
                t.setData({
                  username:r.data.name,
                  dhh:r.data.phone,
                  pai:r.data.pai0name,
                  switch:r.data.switch,
                  avatar:r.data.avatar,
                })
            }else{
                wx.showModal({
                    title: '提示',
                    content: r.msg,
                    showCancel:false,
                    success (res) {
                        wx.reLaunch({
                            url: '/pages/index/index'
                          })
                    }
                  })
            }

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

    },

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

    },

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

    },

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

    },

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

    },

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

    },

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

    },
    /**
     * 打电话
     */
    lianXi:function(e){
        let t = this;
        var scene=t.data.scene;
    

        console.log(e)
        console.log(e.data)
        console.log(e.target.dataset.dh)
        var switch_sta=e.target.dataset.switch
        switch (switch_sta) {
            case 0:
                //查询调取绑定
                let u = "index/callUser";
                let d = {
                    scene: scene,
                }
                app.post(u, d).then(r=>{
                    if(r.code==1){
                        wx.makePhoneCall({
                            phoneNumber: r.data.xiao
                        })
                    }else{
                        wx.showToast({
                            title: r.msg,
                            icon: 'none',
                            duration: 2000
                          })
                    }
                })
              
                break;
            case 1:
                  wx.showModal({
                    title: '当前用户开启了免打扰',
                    showCancel:false,
                    success (res) {
                     wx.reLaunch({
                       url: '/pages/index/index',
                     })
                    }
                  })


               break;     
            default:
                break;
        }
      
    },
    getShengq:function(){
        wx.navigateTo({
            url: '/pages/buyshangpin/buyshangpin'
        })
    }


})