// pages/member/extension/extension.js
import NumberAnimate from "./NumberAnimate";
const echarts = require("../../../../ec-canvas/echarts"); //路径一定要正确否则会调用错误
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    show_member_id: "",
    language: "",
    // 会员信息
    userInfo: {},
    // 推广权限
    extension: [],
    // 更多推广
    unextension: [],
    // 收入分享页面开关
    share_page: false,
    // 领取权益页面开关
    showEarning: false,
    template: "",
    firstshow: false,
    loginshow: false,
    name_of_withdrawal: "提现",
    is_show_limit: false,
    is_show_performance: false,
    amount_num: 0,
    TemplateArray: [],

    // 新模板
    income_statistic_type: "",
    income_statistic_type_box: [{
      type: "",
      title: "全部"
    },
    {
      type: "1",
      title: "今日"
    },
    {
      type: "2",
      title: "昨日"
    },
    {
      type: "3",
      title: "本周"
    },
    {
      type: "4",
      title: "上周"
    },
    {
      type: "5",
      title: "本月"
    },
    {
      type: "6",
      title: "上月"
    },
    ],
    charts_type: "",
    fans_type: "",
    extension_type: "",
    available_type: "",

    income_page: "",
    background_color: "",
    income_statistic: [],
    income_dynamic: {},
    fans_fission: {},
    extension_order: {},
    isLoadMore: true,

    clientWidth: "375",
    clientHeight: "",
    service: "",
    showPopup: false,
    btnFlag: false,
    btnData: {
      button_size: 40,
      over_top: 500,
      position_location: "right",
      icon_url: "",
    },
    ecIncome: {
      lazyLoad: true, // 延迟加载
    },
    ecFans: {
      lazyLoad: true, // 延迟加载
    },
    moreIdentity: false,
    showLineChats: false,
    showChatsLineHeight: 0,
    showChats: false,
    showChatsHeight: 0,
    // showImg: "", echats转图片
    isshow: false, //判断二维码的显示
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      clientWidth: wx.getSystemInfoSync().windowWidth,
      clientHeight: wx.getSystemInfoSync().windowHeight,
    });
  },

  closePopup() {
    this.setData({
      showPopup: false
    });
  },

  // 获取滚动条当前位置
  onPageScroll: function (e) {
    // 节流

    if (this.data.template == "01") {
      if (this.data.showChatsLineHeight >= 30) {
        if (e.scrollTop > this.data.showChatsLineHeight) {
          if (!this.data.showLineChats) {
            this.setData({
              showLineChats: true,
            });
            if (this.data.charts_type == 1) {
              this.initPieEcharts();
            } else {
              this.initEcharts();
            }
          }
        } else {
          if (this.data.showLineChats) {
            this.setData({
              showLineChats: false,
            });
          }
        }
      }

      if (e.scrollTop > this.data.showChatsHeight) {
        if (!this.data.showChats) {
          this.setData({
            showChats: true,
          });
          if (this.data.fans_type == 1) {
            this.initOrderEcharts();
          } else {
            this.initFansEcharts();
          }
        }
      } else {
        if (this.data.showChats) {
          this.setData({
            showChats: false,
          });
        }
      }
    }

    if (e.scrollTop > 80) {
      if (!this.data.btnFlag) {
        this.setData({
          btnFlag: true,
        });
      }
    } else {
      if (this.data.btnFlag) {
        this.setData({
          btnFlag: false,
        });
      }
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let language = wx.getStorageSync("langIndex");
    this.setData({
      language: language.en
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    try {
      // 推广中心是否开启该功能，没开启跳转到指定路径
      let basic_info = wx.getStorageSync("yz_basic_info");
      let stop_info = basic_info.popularize_page.mini.vue_route;
      for (let i = 0; i < stop_info.length; i++) {
        if (stop_info[i] == "extension") {
          console.log(basic_info.popularize_page.mini.mini_url + "跳转的路径");

          wx.showToast({
            title: "未开启推广权限",
            duration: 2000,
            icon: "none",
            success: function () {
              console.log(basic_info.popularize_page.mini.mini_url);
              if (app._isTextEmpty(basic_info.popularize_page.mini.mini_url)) {
                setTimeout(() => {
                  wx.reLaunch({
                    url: "/packageG/index/index",
                  });
                }, 1000);
                return;
              }
              setTimeout(() => {
                wx.redirectTo({
                  url: basic_info.popularize_page.mini.mini_url,
                });
              }, 1000);
            },
          });
          return;
        }
      }
    } catch (e) {
      console.log(e);
    }
    if (!this.firstlogin()) {
      this._getExtensionData();
      this.customizeIncome();
    }
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.isLoadMore && this.data.template == "01") {
      this.getMoreData();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var value = wx.getStorageSync("yz_uid");
    var mid = "";
    if (value) {
      mid = value;
    }
    return {
      path: "/packageG/pages/member/extension/extension?mid=" + mid,
    };
  },
  onShareTimeline(){},

  initEcharts() {
    let echartsComponnet = this.selectComponent("#echats-income");
    let maxMoney = Math.ceil(Math.max(...this.data.income_dynamic.total_amount)) || 50;
    let maxCount = Math.max(...this.data.income_dynamic.income_count) || 50;
    let intervalMoney = maxMoney / 5 || 5;
    let intervalCount = maxCount / 5 || 5;
    let option = {
      tooltip: {
        trigger: "axis",
        axisPointer: {
          type: "cross",
          crossStyle: {
            color: "#999",
          },
        },
      },
      toolbox: {
        feature: {
          magicType: {
            show: true,
            type: ["line", "bar"]
          },
          saveAsImage: {
            show: true
          },
        },
      },
      legend: {
        data: ["金额", "笔数"],
      },
      xAxis: [{
        type: "category",
        data: this.data.income_dynamic.x_axis,
        axisPointer: {
          type: "shadow",
        },
      },],
      yAxis: [{
        type: "value",
        name: "金额",
        min: 0,
        max: maxMoney,
        interval: intervalMoney,
      },
      {
        type: "value",
        name: "笔数",
        min: 0,
        max: maxCount,
        interval: intervalCount,
      },
      ],
      series: [{
        name: "金额",
        type: "bar",
        color: "#3b84f2",
        data: this.data.income_dynamic.total_amount,
      },
      {
        name: "笔数",
        type: "line",
        yAxisIndex: 1,
        color: "#ffc11e",
        data: this.data.income_dynamic.income_count,
      },
      ],
    };

    echartsComponnet.init((canvas, width, height) => {
      // 初始化图表
      const Chart = echarts.init(canvas, null, {
        width: width,
        height: height,
      });
      Chart.setOption(option);
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return Chart;
    });
  },
  initPieEcharts() {
    let echartsComponnet = this.selectComponent("#echats-income-pie");
    let option = {
      legend: {
        top: "bottom",
      },
      toolbox: {
        show: true,
        feature: {
          saveAsImage: {
            show: true
          },
        },
      },
      series: [{
        name: "收入占比",
        type: "pie",
        radius: [15, 50],
        center: ["50%", "50%"],
        roseType: "area",
        label: {
          formatter: "{name|{b}}\n{time|{c} 元}",
          rich: {
            time: {
              fontSize: 10,
              color: "#999",
            },
          },
        },
        data: this.data.income_dynamic,
      },],
    };

    echartsComponnet.init((canvas, width, height) => {
      // 初始化图表
      const Chart = echarts.init(canvas, null, {
        width: width,
        height: height,
      });
      Chart.setOption(option);
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return Chart;
    });
  },
  initFansEcharts() {
    let echartsComponnet = this.selectComponent("#echats-fans");
    let maxMoney = Math.max(...this.data.fans_fission.totalFansSeries) || 50;
    let maxCount = Math.max(...this.data.fans_fission.fansNewSeries) || 50;
    let intervalMoney = maxMoney / 5 || 5;
    let intervalCount = maxCount / 5 || 5;
    let option = {
      tooltip: {
        trigger: "axis",
        axisPointer: {
          type: "cross",
          crossStyle: {
            color: "#999",
          },
        },
      },
      toolbox: {
        feature: {
          saveAsImage: {},
        },
      },
      legend: {
        data: ["粉丝总数", "单日新增粉丝"],
      },
      xAxis: {
        type: "category",
        boundaryGap: false,
        data: this.data.fans_fission.x_axis,
        axisPointer: {
          type: "shadow",
        },
      },
      yAxis: [{
        type: "value",
        name: "总数",
        min: 0,
        max: maxMoney,
        interval: intervalMoney,
      },
      {
        type: "value",
        name: "单日",
        min: 0,
        max: maxCount,
        interval: intervalCount,
      },
      ],
      series: [{
        name: "粉丝总数",
        type: "line",
        color: "#77c399",
        data: this.data.fans_fission.totalFansSeries,
      },
      {
        name: "单日新增粉丝",
        type: "line",
        yAxisIndex: 1,
        color: "#f19c70",
        data: this.data.fans_fission.fansNewSeries,
      },
      ],
    };

    echartsComponnet.init((canvas, width, height) => {
      // 初始化图表
      const Chart = echarts.init(canvas, null, {
        width: width,
        height: height,
      });
      Chart.setOption(option);
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return Chart;
    });
    // setTimeout(()=> {
    // 	echartsComponnet.canvasToTempFilePath({
    // 		success: res => {
    // 			this.setData({
    // 				showChats: false,
    // 				showImg: res.tempFilePath
    // 			})
    // 		},
    // 		fail: res => console.log('失败', res)
    // 	});
    // },1500)
  },
  initOrderEcharts() {
    let echartsComponnet = this.selectComponent("#echats-fans-line");
    let maxMoney = Math.max(...this.data.fans_fission.orderCountSeries) || 50;
    let maxCount = Math.max(...this.data.fans_fission.orderPriceSeries) || 50;
    let intervalMoney = maxMoney / 5 || 5;
    let intervalCount = maxCount / 5 || 5;
    let option = {
      tooltip: {
        trigger: "axis",
        axisPointer: {
          type: "cross",
          crossStyle: {
            color: "#999",
          },
        },
      },
      toolbox: {
        feature: {
          magicType: {
            show: true,
            type: ["line", "bar"]
          },
          saveAsImage: {
            show: true
          },
        },
      },
      legend: {
        data: ["订单金额", "订单数量"],
      },
      xAxis: {
        type: "category",
        boundaryGap: false,
        data: this.data.fans_fission.x_axis,
        axisPointer: {
          type: "shadow",
        },
      },
      yAxis: [{
        type: "value",
        name: "订单金额",
        min: 0,
        max: maxCount,
        interval: intervalCount,
      },
      {
        type: "value",
        name: "订单数量",
        min: 0,
        max: maxMoney,
        interval: intervalMoney,
      },
      ],
      series: [{
        name: "订单金额",
        type: "bar",
        color: "#f19c70",
        data: this.data.fans_fission.orderPriceSeries,
      },
      {
        name: "订单数量",
        type: "line",
        yAxisIndex: 1,
        color: "#77c399",
        data: this.data.fans_fission.orderCountSeries,
      },
      ],
    };

    echartsComponnet.init((canvas, width, height) => {
      // 初始化图表
      const Chart = echarts.init(canvas, null, {
        width: width,
        height: height,
      });
      Chart.setOption(option);
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return Chart;
    });
  },

  tabChange(e) {
    let type, data_type;
    type = e.currentTarget.dataset.type;
    if (type === "income_statistic_type") {
      data_type = e.currentTarget.dataset.data_type;
      this.setData({
        income_statistic_type: data_type,
      });
      this.getIncomeStatistic(data_type);
    } else if (type === "charts_type") {
      data_type = e.detail.index;
      this.setData({
        charts_type: data_type,
      });
      this.getEchats(data_type);
    } else if (type === "available_type") {
      data_type = e.detail.index;
      this.setData({
        available_type: data_type,
      });
    } else if (type === "fans_type") {
      data_type = e.detail.index;
      this.setData({
        fans_type: data_type,
      });
      this.getFans(data_type);
    } else if (type === "extension_type") {
      data_type = e.detail.index;
      this.setData({
        extension_type: data_type,
      });
      this.getExtension(data_type);
    }
  },
  getIncomeStatistic(data_type) {
    wx.showLoading({
      title: "加载中",
    });
    let urlStr = app.getNetAddresss("finance.income-page.income-statistic");
    app._getNetWork({
      url: urlStr,
      data: {
        income_statistic_type: data_type,
      },
      success: (resdata) => {
        wx.hideLoading();
        let res = resdata.data;
        if (res.result == 1) {
          this.setData({
            income_statistic: res.data,
          });
          this.countToNumber();
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1500,
          });
        }
      },
      fail: (res) => {
        wx.hideLoading();
        console.log(res);
      },
    });
  },
  getEchats(data_type) {
    let urlStr = app.getNetAddresss("finance.income-page.income-charts");
    app._getNetWork({
      url: urlStr,
      data: {
        charts_type: data_type,
      },
      success: (resdata) => {
        let res = resdata.data;
        if (res.result == 1) {
          this.setData({
            income_dynamic: res.data,
          });
          if (data_type == 1) {
            this.initPieEcharts();
          } else {
            this.initEcharts();
          }
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1500,
          });
        }
      },
      fail: (res) => {
        console.log(res);
      },
    });
  },
  getFans(data_type) {
    let urlStr = app.getNetAddresss("finance.income-page.fans-charts");
    app._getNetWork({
      url: urlStr,
      data: {
        charts_type: data_type,
      },
      success: (resdata) => {
        let res = resdata.data;
        if (res.result == 1) {
          this.setData({
            fans_fission: res.data,
          });
          if (data_type == 1) {
            this.initOrderEcharts();
          } else {
            this.initFansEcharts();
          }
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1500,
          });
        }
      },
      fail: (res) => {
        console.log(res);
      },
    });
  },
  getExtension(data_type) {
    this.setData({
      extension_order: {},
    });
    this.data.isLoadMore = false;
    let urlStr = app.getNetAddresss("finance.income-page.extension");
    app._getNetWork({
      url: urlStr,
      data: {
        extension_type: data_type,
      },
      success: (resdata) => {
        this.data.isLoadMore = true;
        let res = resdata.data;
        if (res.result == 1) {
          this.setData({
            extension_order: res.data,
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1500,
          });
        }
      },
      fail: (res) => {
        console.log(res);
      },
    });
  },
  //加载更多订单数据
  getMoreData() {
    this.data.isLoadMore = false;
    if (this.data.extension_order.current_page >= this.data.extension_order.last_page) {
      this.data.isLoadMore = false;
    } else {
      this.data.extension_order.current_page += 1;
      let urlStr = app.getNetAddresss("finance.income-page.extension");
      app._getNetWork({
        url: urlStr,
        data: {
          page: this.data.extension_order.current_page,
          extension_type: this.data.extension_type,
        },
        success: (resdata) => {
          this.data.isLoadMore = true;
          let res = resdata.data;
          if (res.result == 1) {
            let nextPageData = res.data.data;
            this.data.extension_order.data = this.data.extension_order.data.concat(nextPageData);
            this.setData({
              extension_order: this.data.extension_order,
            });
          } else {
            wx.showToast({
              title: res.msg,
              icon: "none",
              duration: 1500,
            });
          }
        },
        fail: (res) => {
          console.log(res);
        },
      });
    }
  },
  countToNumber() {
    for (let i = 0; i < this.data.income_statistic.length; i++) {
      let num1 = this.data.income_statistic[i].value;
      if (Number(num1) > 0) {
        let n1 = new NumberAnimate({
          from: num1,
          speed: 500,
          refreshTime: 100,
          decimals: 2,
          onUpdate: () => {
            this.setData({
              [`income_statistic[${i}].value`]: n1.tempValue,
            });
          },
        });
      }
    }
  },

  _getExtensionData() {
    let urlStr = app.getNetAddresss("finance.income-page.index");
    app._getNetWork({
      url: urlStr,
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          this._setTemplate(res.data.template_set);
          if (res.data.income_page.small_jump_link) {
            wx.showToast({
              title: "没有推广资格",
              icon: "none",
              duration: 2000,
              success() {
                wx.reLaunch({
                  url: res.data.income_page.small_jump_link,
                  fail: (err) => {
                    // 防止跳转不了
                    wx.reLaunch({
                      url: "/packageG/index/index",
                    });
                  }
                });
              },

            });
            return;
          }

          if (!app._isTextEmpty(res.data.income_page.info)) {
            if (this.data.template == "01") {
              if (this.data.income_page) {
                return;
              }
              this.setData({
                income_page: res.data.income_page,
                share_page: res.data.income_page.button_enabled.share_page,
                income_statistic: res.data.income_page.income_statistic,
                income_dynamic: res.data.income_page.income_dynamic,
                fans_fission: res.data.income_page.fans_fission,
                extension_order: res.data.income_page.extension_order,
                service: res.data.income_page.service,
                background_color: res.data.income_page.set.background_color || "#ffc11e",
                is_show_unable: res.data.income_page.button_enabled.is_show_unable || false,
                show_member_id: res.data.income_page.button_enabled.show_member_id || false,
                withdraw_date: res.data.income_page.button_enabled.withdraw_date || false,
              });
              wx.setNavigationBarColor({
                frontColor: "#ffffff",
                backgroundColor: this.data.background_color,
                animation: {
                  duration: 400,
                  timingFunc: "easeIn",
                },
              });

              this.data.isLoadMore = true;
              this.countToNumber();

              setTimeout(() => {
                this.calculateHeight();
              }, 500);
            } else {
              this.setData({
                share_page: res.data.income_page.parameter.share_page,
                showEarning: res.data.income_page.parameter.plugin_settle_show,
                is_show_performance: res.data.income_page.is_show_performance || false,
                is_show_unable: res.data.income_page.is_show_unable || false,
                show_member_id: res.data.income_page.show_member_id || false,
                withdraw_date: res.data.income_page.withdraw_date || false,
              });
            }

            res.data.income_page.available = res.data.income_page.available.filter((item)=> {return item.mini_url != '';});
            res.data.income_page.unavailable = res.data.income_page.unavailable.filter((item)=> {return item.mini_url != '';});
            this.setData({
              userInfo: res.data.income_page.info,
              extension: res.data.income_page.available,
              unextension: res.data.income_page.unavailable,
            });

            if (res.data.income_page && res.data.income_page.withdraw_limit) {
              this.setData({
                is_show_limit: res.data.income_page.withdraw_limit.is_show,
              });
              if (this.data.is_show_limit) {
                this.setData({
                  amount_num: res.data.income_page.withdraw_limit.amount,
                });
              }
            }
          }
        }
        this.setData({
          firstshow: true,
        });
      },
      fail: (res) => {
        console.log(res.msg);
      },
    });
  },
  _setTemplate(data) {
    if (data.extension) {
      // 02 背景图片样式 	// 01 阿里图标库样式
      this.setData({
        template: data.extension.name,
      });
    } else {
      this.setData({
        template: "01",
      });
    }

    // 从yz_basic_info获取新装修设置
    let basic_info = wx.getStorageSync("yz_basic_info");
    if (basic_info && basic_info.home.item.is_decorate === 1) {
      if (basic_info.home.item.ViewSet.extension.is_default != 0) {
        this.setData({
          template: basic_info.home.item.ViewSet.extension.code.substring(9),
        });
      } else {
        this.setData({
          template: "01",
        });
      }
    }
  },
  // 验证手机身份
  gotoIncome() {
    let urlStr = app.getNetAddresss("member.member.withdrawByMobile");
    app._getNetWork({
      url: urlStr,
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          // 商城--交易设置--开启提现绑定手机号，小程序端提现没有触发绑定手机号  任务编号51955
          if (res.data.is_bind_mobile == 1) {
            wx.navigateTo({
              url: "/packageA/member/withdrawEditmobile/withdrawEditmobile",
            });
            // withdrawEditmobile
          } else {
            wx.navigateTo({
              url: "/packageA/member/withdrawal/withdrawal",
            });
            // withdrawal
          }
        } else {
          wx.showToast({
            icon: "none",
            title: res.msg,
            duration: 1500,
          });
        }
      },
      fail: (res) => {
        console.log(res.msg);
      },
    });
  },
  //获取模板id
  getTemplate() {
    let urlStr = app.getNetAddresss("member.member.getMiniTemplateCorrespond");
    app._getNetWork({
      url: urlStr,
      data: {
        small_type: 3,
      },
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          let array = [];
          for (let i = 0; i < res.data.length; i++) {
            array.push(res.data[i].template_id);
          }
          this.setData({
            TemplateArray: array,
          });
          wx.requestSubscribeMessage({
            tmplIds: this.data.TemplateArray,
            success: (res) => {
              this.gotoIncome();
            },
            fail: (err) => {
              console.log(err);
              this.gotoIncome();
            },
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1500,
          });
        }
      },
      fail: (res) => {
        console.log(res);
      },
    });
  },
  showMoreIdentity() {
    this.setData({
      moreIdentity: !this.data.moreIdentity,
    });
  },
  calculateHeight() {
    // 计算echats显示高度
    const query_1 = wx.createSelectorQuery();
    query_1.selectAll(".eChats-box1").boundingClientRect();
    query_1.exec((res) => {
      this.setData({
        showChatsLineHeight: res[0][0].top + res[0][0].height + 250 - this.data.clientHeight,
      });
      if (this.data.showChatsLineHeight < 30) {
        // 如果屏幕高就及时画
        this.setData({
          showLineChats: true,
        });
        this.initEcharts();
      }
    });

    const query_2 = wx.createSelectorQuery();
    query_2.selectAll(".eChats-box2").boundingClientRect();
    query_2.exec((res) => {
      this.setData({
        showChatsHeight: res[0][0].top + res[0][0].height + 350 - this.data.clientHeight,
      });
    });
  },

  toToast() {
    wx.showToast({
      title: this.data.withdraw_date.day_msg,
      icon: "none",
    });
  },
  gotoIncomeBtn() {
    this.getTemplate();
  },
  // 跳转到收人分享
  gomyIncome() {
    // MyIncome
    wx.navigateTo({
      url: "/packageA/member/extension/MyIncome/MyIncome",
    });
  },
  // 跳装到领取页面
  myEarnings() {
    wx.navigateTo({
      url: "/packageA/member/extension/myEarnings/myEarnings",
    });
    // myEarnings
  },
  // 跳装到收入明细页面
  gotoDetail() {
    wx.navigateTo({
      url: "/packageA/member/extension/incomedetails/incomedetails",
    });
    // incomedetails
  },
  // 跳装到提现明细页面
  gotoRecharge() {
    wx.navigateTo({
      url: "/packageA/member/presentationRecord_v2/presentationRecord_v2?orderType=extension",
    });
    // presentationRecord
  },
  // 跳转到提现营业额页面
  gotoPerformance() {
    wx.navigateTo({
      url: "/packageA/member/extension/Performance/Performance",
    });
    // Performance
  },
  openService() {
    if (this.data.service && (typeof this.data.service) == 'string') {
      wx.navigateTo({
        url: this.data.service,
        fail: (err) => {
          app.tips("客服链接设置错误");
        }
      });
      return;
    }
    this.setData({
      showPopup: true,
    });
  },
  closeService() {
    this.setData({
      showPopup: false,
    });
  },
  pluginGoto(e) {
    // 插件跳转
    let item = e.currentTarget.dataset.item;
    let url = item.url;

    if (item.name == "courier") {
      wx.setStorage({
        key: "couriername",
        data: item.title,
      });
      wx.navigateTo({
        url: "/packageA/member/" + url + "/" + url,
      });
    } else if (item.url == "HotelManage") {
      wx.navigateTo({
        url: "/packageA/hotel/HotelManage/HotelManage?title=" + encodeURIComponent("酒店管理"),
      });
    } else if (item.url == "cloudIndex") {
      wx.navigateTo({
        url: "/packageE/others/cloudwarehouse/cloud_index/cloud_index",
      });
    } else if (item.url == "collageIndex") {
      wx.navigateTo({
        url: "/packageE/member/collage/collageIndex/collageIndex",
      });
    } else if (item.name == "m-erweima") {
      // 海报
      this.openQrCode(this.data.dataIs);
    } else if (item.mini_url) {
      wx.navigateTo({
        url: item.mini_url,
      });
    }
  },
  openQrCode(e) {
    this.setData({
      isshow: true,
    });
  },
  clicktapshow() {
    this.setData({
      isshow: false,
      lsgow: false,
    });
  },
  closeCallblack(e){
    this.setData({
      isshow:e.detail.isshow
    })
  },
  gotoBtn(e) {
    let item = e.currentTarget.dataset.item;
    if (item.url === 'withdrawal' && (this.data.withdraw_date && this.data.withdraw_date.disable || this.data.userInfo.auto_withdraw && this.data.withdraw_date && !this.data.withdraw_date.disable)) {
      if (this.data.withdraw_date && this.data.withdraw_date.disable) {
        this.toToast();
      }
      return;
    }

    if (item.mini_url) {
      wx.navigateTo({
        url: item.mini_url,
      });
    }
  },
  // 权限跳转
  gotoPage(e) {
    let item = e.currentTarget.dataset.item;
    // console.log(item, 'items323223')
    if (!item.is_relation) {
      wx.showToast({
        icon: "none",
        title: "未开放该权限！",
        duration: 1500,
      });
      return;
    }

    if (!item.is_agent) {
      wx.navigateTo({
        url: "/packageA/member/extension/ExtensionApply/ExtensionApply",
      });
      return;
    }

    if (item.mark === "point_activity") {
      if (item.url == "point_activity_award_center") {
        wx.navigateTo({
          url: "/packageB/member/enterprise/" + item.url + "/" + item.url + "?num=" + this.data.userInfo.member_id,
        });
        return;
      }
      wx.navigateTo({
        url: "/packageA/member/" + item.url + "/" + item.url + "?num=" + this.data.userInfo.member_id,
      });
    } else if (item.url == "HotelCashier") {
      wx.navigateTo({
        url: "/packageA/hotel/HotelManage/HotelManage?title=" + encodeURIComponent("收银台"),
      });
    } else if (item.mini_url) {
      wx.navigateTo({
        url: item.mini_url,
      });
    }
  },
  firstlogin() {
    let firstlogin = false;
    try {
      var value = wx.getStorageSync("wx_token");
      if (value) {
        // Do something with return value
        this.setData({
          loginshow: false,
        });
        firstlogin = false;
      } else {
        this.setData({
          loginshow: true,
        });
        firstlogin = true;
      }
    } catch (e) {
      this.setData({
        loginshow: true,
      });
      firstlogin = true;
    }
    return firstlogin;
  },
  gotologin() {
    app.seyzredirect();
    wx.navigateTo({
      url: "/pages/login/login",
    });
  },
  //自定义提现收入语言
  customizeIncome() {
    try {
      var value = wx.getStorageSync("mailLanguage");
      if (value) {
        let mailLanguage = JSON.parse(value);
        this.setData({
          income_name_text: mailLanguage.income.income_name || "收入",
          name_of_withdrawal: mailLanguage.income.name_of_withdrawal || "提现",
        });
      }
    } catch (e) {
      this.setData({
        income_name_text: "收入",
        name_of_withdrawal: "提现",
      });
    }
  },
});