const _my = require("../../__antmove/api/index.js")(my);
const wx = _my;
// pages/resitor_scence/resitor_scence.js
import international from "../../international/appointment_scence/index";
import { getBuildingAndCompanyInfo } from "../../utils/api/api";
const app = getApp();

Page({
  /**
   * 页面的初始数据
   */
  data: {
    international: international,
    //国际化语言包
    language: app.data.language,
    type: app.data.language === "ch" ? "1" : "2",
    statusBarHeight: 0,
    titleBarHeight: 0,
    adminInfo: wx.getStorageSync("adminInfo"),
    userInfo: wx.getStorageSync("userInfo"),
    // 功能列表
    component_list: [{
      id: 1,
      name_ch: "邀请人员",
      name_en: "Invite people",
      icon: "../../static/home/my_appointment.png",
      url: ""
    }, {
      id: 2,
      name_ch: "邀请记录/申请记录",
      name_en: "Visiting records",
      icon: "../../static/home/appointment_records.png",
      url: ""
    }, {
      id: 6,
      name_ch: "访客申请记录",
      name_en: "Visiting records",
      icon: "../../static/home/visitors.png",
      url: ""
    }, {
      id: 3,
      name_ch: "更改信息",
      name_en: "Change the information",
      icon: "../../static/home/company_msg.png",
      url: ""
    }, {
      id: 4,
      name_ch: "企业信息",
      name_en: "Enterprise information",
      icon: "../../static/home/change_msg.png",
      url: ""
    }]
  },
  startComponent() {
    wx.navigateTo({
      // url: "/pages/k8_ampe/k8_ampe"
      url: "/pages/web/web"
    });
  },
  // 内外宾
  changeRadio(e) {
    e.detail == 1 ? app.data.language = "ch" : app.data.language = "en";
    this.setData({
      type: e.detail + "",
      language: app.data.language
    });
  },
  // 显示提示 1-访客提示 | 2-常客提示
  showTip(e) {
    const type = e.currentTarget.dataset.type;
    let msg = this.data.international[type][this.data.language];
    wx.showModal({
      title: "提示",
      content: msg,
      showCancel: false,
      success: res => {}
    });
  },
  // 访客
  visitors() {
    wx.navigateTo({
      url: "/pages/visitor_make/visitor_make?formMain=true"
    });
  },
  // 常客
  regular() {
    wx.requestSubscribeMessage({
      entityIds: ["e3dd8fb9e84e49b4a96a1a466054ccad", "9d4ddcd78f66444482ad66c5a262ffed"],
      success(res) {
        // if(res.behavior === 'subscribe') {}
      },
      complete: res => {
        wx.navigateTo({
          url: "/pages/regular_register/regular_register"
        })
      }
    })
  },
  // 企业信息录入
  // informationInput() {
  //     if (app.data.userInfo) {
  //         wx.navigateTo({
  //             url: '/pages/company_register/company_register'
  //         })
  //     } else {
  //         wx.showToast({
  //             title: '请先到右下角"我的"里面进行实名认证',
  //             icon: 'none'
  //         })
  //     }
  // },
  // 根据扫码获取的企业id查询企业信息和楼宇信息
  getBuildingAndCompanyInfo(adminId) {
    getBuildingAndCompanyInfo(adminId).then(res => {
      app.data.temporary_adminInfo = res.data;
    });
  },
  goto(e) {
    let id = e.currentTarget.dataset.id;
    if (this.data.userInfo) {
      let url = "";
      if (id == 1) {
        wx.requestSubscribeMessage({
          entityIds: ["486ef1e5652a4629b6e95245f7cb44a9", "e3dd8fb9e84e49b4a96a1a466054ccad"],
          success(res) {
            // if(res.behavior === 'subscribe') {}
          },
          complete: res => {
            url = "/pages/regular_invite/regular_invite";
            wx.navigateTo({
              url
            })
            return
          }
        })
      } else if (id == 2) {
        url = "/pages/regular_visit_records/regular_visit_records";
      } else if (id == 3) {
        url = "/pages/changeUserInfo/index";
      } else if (id == 4) {
        url = "/pages/regular_company_manage/regular_company_manage";
      } else if (id == 6) {
        url = "/pages/visit_records/visit_records";
      }
      if(url) {
        wx.navigateTo({
          url
        });
      }
    } else {
      wx.showToast({
        icon: "none",
        title: this.data.language == "ch" ? "请先认证！" : "Please first certification!"
      });
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    // options = {
    //     adminId: 109,
    //     type: 1
    // }
    let launchOptions = my.getLaunchOptionsSync()
    if(!launchOptions.query) {
      launchOptions = my.getEnterOptionsSync()
    }
    if (launchOptions.query && launchOptions.query.adminId) {
      this.getBuildingAndCompanyInfo(parseInt(launchOptions.query.adminId));
      app.data.type = parseInt(launchOptions.query.type) || 0;
    }
    this.setData({
      statusBarHeight: app.globalData.statusBarHeight,
      titleBarHeight: app.globalData.titleBarHeight
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    // 页面加载完成
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      adminInfo: wx.getStorageSync("adminInfo"),
      userInfo: wx.getStorageSync("userInfo")
    });
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  antmoveAction: function () {
    //执行时动态赋值，请勿删除
  }
});