index.js 3.33 KB
const restapi = require('../restapi');
// const filter = require('../../../../utils/filter.js');
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    // authToast:false,
    shebList: [{
      title: "车娱乐",
      items: [{
        icon: "../../../resources/images/bind_ydh.png",
        name: "云导航",
        isBind: 1, //1代表暂不支持,true已绑定,false未绑定
        bindMethod: "bindDevice",
        deviceType: 2,
      }, {
        icon: "../../../resources/images/bind_znyj.png",
        name: "智能云镜",
        isBind: 1,
        bindMethod: "bindDevice",
        deviceType: 12134
      }]
    }, {
        title: "车诊断",
      items: [{
        icon: "../../../resources/images/bind_jbhz.png",
        name: "驾宝盒子",
        isBind: false,
        bindMethod: "jumpWebpageBox",
        deviceType: 1
      }]
    }, {
      title: "车安全",
      items: [{
        icon: "../../../resources/images/bind_zny.png",
        name: "GPS",
        isBind: false,
        bindMethod: "jumpWebpageBox",
        deviceType: 8
      }, {
        icon: "../../../resources/images/bind_xcjly.png",
        name: "行车记录仪",
        isBind: false,
        bindMethod: "jumpWebpageBox",
        deviceType: 6
      }]
    }],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({
      title: '',
      mask: true
    })
    // console.log(this.data.authToast)
    // if (!this.data.authToast) {
		// 	wx.navigateTo({
		// 		url: "../../../../pages/auth/index/index"
		// 	})
		// }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let sourcefrom = '';
    let self = this;
    restapi.getDeviceBindInfo(sourcefrom, function (response) {
      wx.hideLoading();
      if (response && response.returnCode == 0) {
        let bindInfoList = response.bindInfoList;
        if (bindInfoList) {
          let shebList1 = self.data.shebList;
          for (let i = 0; i < bindInfoList.length; i++) {
            for (let j = 0; j < shebList1.length; j++) {
              for (let k = 0; k < shebList1[j].items.length; k++) {
                let curItem = shebList1[j].items[k];
                if (curItem.deviceType == bindInfoList[i].deviceType) {
                  curItem.isBind = true
                }
              }
            }
          }
          self.setData({
            shebList: shebList1
          })
        }
      } else {
        app.showMessage("获取设备绑定信息失败!");
      }
    })
  },
  onLogin() {
    
  },
  jumpWebpageBox: function (e) {
    let type = e.currentTarget.dataset.type;
    let typeid = e.currentTarget.dataset.typeid;
    let bind = e.currentTarget.dataset.bind;
    if (bind) {
      return;
    }
    wx.navigateTo({
      url: `/packageSmartPlus/pages/bindingDevice/bind/bind?type=${type}&typeid=${typeid}`
    })
  },

  /**
   * 扫码
   */
  bindDevice: function (e) {
    let bind = e.currentTarget.dataset.bind;   
    if (bind) {
      return;
    }
    // 允许从相机和相册扫码
    wx.scanCode({
      success: (res) => {
        wx.reLaunch({
          url: "/packageServices/pages/index/index"
        });
      }
    })
  }
})