const { getProjectNameLang } = require("../common");

// packageH/project_verification/StoreVerification/StoreVerification.js
const App = getApp();
const ProjectNameLang = getProjectNameLang();
const navs = [
  {
    name: ProjectNameLang + "大全",
    icon: "icon-fontclass-jianglijilu",
    url: "/packageH/project_verification/VerificationProjectList/VerificationProjectList",
  },
  {
    name: "我的" + ProjectNameLang,
    icon: "icon-fontclass-shangpindingdan",
    url: "/packageH/project_verification/MyProject/MyProject",
  },
  {
    name: "使用记录",
    icon: "icon-fontclass-dingdanguanli",
    url: "/packageH/project_verification/WriteOffRecord/WriteOffRecord?type=used",
  },
];
const storeNav = {
  name: "商户记录",
  icon: "icon-massage_apply",
  url: "/packageH/project_verification/WriteOffRecord/WriteOffRecord?type=store",
};
const workerNav = {
  name: "核销员记录",
  icon: "icon-yq_massage",
  url: "/packageH/project_verification/WriteOffRecord/WriteOffRecord?type=staff",
};
Page({
  /**
   * 页面的初始数据
   */
  data: {
    navs: [],
    userInfo: {
      avatarUrl: "",
      uid: "",
      nickName: "",
    },
    auths: {
      is_boss: 0,
      is_worker: 0,
    },
    projectNameLang: ProjectNameLang,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getUserBaseInfo();
  },

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

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

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

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

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

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

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  getUserBaseInfo() {
    const url = App.getNetAddresss("plugin.store-projects.frontend.index.get-base-info");
    App._getNetWork({
      url,
      data: {},
      success: ({ data: { data } }) => {
        let localNavs = JSON.parse(JSON.stringify(navs));
        if (data.is_boss) {
          localNavs.push(storeNav);
        }
        if (data.is_worker) {
          localNavs.push(workerNav);
        }
        this.setData({
          navs: localNavs,
          userInfo: {
            avatarUrl: data.member_avatar_image,
            uid: data.member_uid,
            nickName: data.member_nickname,
          },
        });
        // wx.setStorageSync("projectVerificationUserAuth", data);
      },
    });
  },
});
