import {
  getWaterDrop
} from '../../../utils/index/index'
const app = getApp()
Page({
  data: {
    roleList: [
      // {
      //   id: 1,
      //   name: '服务员'
      // },
      // {
      //   id: 2,
      //   name: '管理员'
      // },
      {
        id: 3,
        name: '厂商管理员'
      }
    ],
    roleName: '厂商管理员',
    roleId: 3,
    isShowRole: false,
    password: '',
    isPortraitScreen: false,// 是否为竖屏：true竖屏 false横屏
    screenIntervalId: null, //定时器
  },
  onLoad() {
    my.hideBackHome();
    const _this = this
    this.initScreenType().then(isPortraitScreenRes=>{
      console.log('isPortraitScreenRes', isPortraitScreenRes)
      _this.setData({
        isPortraitScreen: isPortraitScreenRes
      })
    })
  },
  initScreenType() {
    let that = this
    return new Promise((resolve,reject) => {
      if (app.globalData.isPortraitScreen) {
        if (app.globalData.isPortraitScreen != null) {
          resolve(app.globalData.isPortraitScreen)
        }
      } else {
        that.data.screenIntervalId = setInterval(function () {
          console.log('asdasdsaddasdad', app.globalData)
          if (app.globalData.isPortraitScreen != null) {
            resolve(app.globalData.isPortraitScreen)
            clearInterval(that.data.screenIntervalId);
          }
        }, 1000);
      }
    })
  },
  sure() {
    let {
      password
    } = this.data
    if (!password) {
      my.showToast({
        icon: 'none',
        content: '请输入密码'
      });
      return
    }
    if (app.globalData.snDisposition.mpassword == password) {
      my.reLaunch({
        url: '/pages/settings/index/index',
      })
    } else {
      my.showToast({
        icon: 'none',
        content: '密码错误，请重试'
      });
    }

  },
  openChoose(e) {
    this.setData({
      isShowRole: !this.data.isShowRole
    })
  },
  closeRole() {
    getWaterDrop()
    this.setData({
      isShowRole: false
    })
  },
  getVal(e) {
    let item = e.currentTarget.dataset.item
    let key = e.currentTarget.dataset.key
    if (key) {
      this.setData({
        password: e.detail.value,
      })
    } else {
      this.setData({
        roleName: item.name,
        roleId: item.id,
        isShowRole: false
      })
    }
  },
});
