import { doNavigateWithUser } from '../../../utils/helper';
import indexApiArr from '../../../api/water_filter';
import { postUrl } from '../../../utils/util';
const __staticUrl = require('../../../config/env.js').static_url
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfoList: [
      {
        pic: (__staticUrl + '/User/_assets/Group_422.png'),
        desc: '上传头像',
        url: "/packages/user/uploadAvatar/index",
        isShowPic: true,
      },
      {
        pic: (__staticUrl + '/User/_assets/Classroom.png'),
        desc: '当前账户',
        url: "",
        text: "微信用户"
      },
      {
        pic: (__staticUrl + '/User/_assets/Group_423.png'),
        desc: '修改登录密码',
        type: 'login',
        url: "/packages/user/resetPwd/index",
        isShowPic: true,
      },
      {
        pic: (__staticUrl + '/User/_assets/Group_424.png'),
        desc: '修改支付密码',
        type: 'pay',
        url: "/packages/user/resetPwd/index",
        isShowPic: true,
        isLast: true,
      },
    ],
    userInfo: {},
    phoneNum: wx.getStorageSync('phone'),
  },

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

  async init() {
    wx.showLoading({
      title: '加载中',
    })
    await postUrl(indexApiArr.loginInfo,{},res=>{
      wx.hideLoading();
      this.setData({
        userInfo: res
      })
    })
  },

  // 跳转指定页面url
  handleSelectClick(event) {
    const { url, title, type } = event.currentTarget.dataset
    console.log('eventeventevent', event);
    if (!url) return;
    doNavigateWithUser({ url:`${url}?title=${title}&type=${type}`});
  },
  /**
   * 退出登录
  */
  handleQuitLoginClick() {
    console.log('退出登录');
    wx.removeStorageSync('ctoken');
    wx.removeStorageSync('userId');
    wx.removeStorageSync('phone');
    wx.removeStorageSync('device_id');
    wx.removeStorageSync('dealerId');
    wx.removeStorageSync('is_deal');
    wx.removeStorageSync('is_dev');
    wx.removeStorageSync('is_shop');
    wx.removeStorageSync('openId');
    wx.removeStorageSync('shopArea');
    wx.removeStorageSync('shopId');
    wx.reLaunch({
      url: '/pages/index/newIndex/newIndex'
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})