import { getWaterDrop } from '../../../utils/index/index'
import {closeCycleSecondaryScreen} from "../../../utils/index/callAmpe";
const app = getApp()
Page({
  data: {
    list: [{
        name: '基本设置',
        path: '/pages/settings/basicPage/index',
        icon: 'https://tx.hz-hanghui.com:8088/yx-fyzd/file/upload/imagesnew/static/settings/one.png'
      },
      {
        name: '辖区设置',
        path: '/pages/settings/jurisdiction/index',
        icon: 'https://tx.hz-hanghui.com:8088/yx-fyzd/file/upload/imagesnew/static/settings/two.png'
      },
      {
        name: '高级设置',
        path: '/pages/settings/advanced/index',
        icon: 'https://tx.hz-hanghui.com:8088/yx-fyzd/file/upload/imagesnew/static/settings/three.png'
      },
      {
        name: '超时时长设置',
        path: '/pages/settings/timeoutDuration/index',
        icon: 'https://tx.hz-hanghui.com:8088/yx-fyzd/file/upload/imagesnew/static/settings/four.png'
      },
      {
        name: '语音设置',
        path: '/pages/settings/voice/index',
        icon: 'https://tx.hz-hanghui.com:8088/yx-fyzd/file/upload/imagesnew/static/settings/five.png'
      },
      {
        name: '密码设置',
        path: '/pages/settings/cipher/index',
        icon: 'https://tx.hz-hanghui.com:8088/yx-fyzd/file/upload/imagesnew/static/settings/six.png'
      },
      {
        name: '受访人列表',
        path: '/pages/settings/interviewee/index',
        icon: 'https://tx.hz-hanghui.com:8088/yx-fyzd/file/upload/imagesnew/static/settings/seven.png'
      },
      {
        name: '访客记录',
        path: '/pages/settings/visitorLog/index',
        icon: 'https://tx.hz-hanghui.com:8088/yx-fyzd/file/upload/imagesnew/static/settings/eight.png'
      },
      {
        name: '退出应用',
        path: '',
        icon: 'https://tx.hz-hanghui.com:8088/yx-fyzd/file/upload/imagesnew/static/settings/quitTheApp.png'
      },
      {
        name: '显示/隐藏导航栏',
        path: '',
        icon: 'https://tx.hz-hanghui.com:8088/yx-fyzd/file/upload/imagesnew/static/settings/hideNavigationBar.png'
      },
    ],
    cusModalObj: {
      visible: false,
    },
    hideNavigationBarStatus: true,
    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);
      }
    })
  },
  clickAudio(){
    getWaterDrop()
  },
  goto(e) {
    let item = e.currentTarget.dataset.item
    console.log(item)
    const _this = this;
    switch (item.name) {
      case '退出应用':
        _this.setData({
          'cusModalObj.visible': true
        })
        break;
      case '显示/隐藏导航栏':
        _this.onHideNavigationBarFuc()
        break;
      default:
        my.reLaunch({
          url: item.path,
        })
        break
    }
  },
  // 退出应用
  onQuitTheAppFuc() {
    closeCycleSecondaryScreen()
    let params = {
      "action": "deviceConfig",
      "event": "open",
      "params": {
        "deviceConfig": {
          "exitApplet": 1
        }
      }
    }
    try {
      my.call("ampeHHCommunication", params, res => {
        console.log(res, '退出应用')
        // if (res.success) {
        // }
      })
    } catch (error) {
      console.log(error);
    }
  },
  // 隐藏底部导航栏
  onHideNavigationBarFuc() {
    let params = {
      "action": "deviceConfig",
      "event": "open",
      "params": {
        "deviceConfig": {
          "hideNavigationBar": this.data.hideNavigationBarStatus?1:2
        }
      }
    }

    try {
      let _this = this;
      my.call("ampeHHCommunication", params, res => {
        console.log(res, '显示/隐藏导航栏', this.data.hideNavigationBarStatus)
        if (res.success){
          _this.setData({
            hideNavigationBarStatus: !_this.data.hideNavigationBarStatus
          })
        }
      })
    } catch (error) {
      console.log(error);
    }
  },
  sure() {},
  onOk() {
    this.onQuitTheAppFuc()
    this.setData({
      'cusModalObj.visible': false
    })
  },
  onCancel() {
    this.setData({
      'cusModalObj.visible': false
    })
  }
});
