const { api, imgName, getUserInfo, wxLogin, alertTip, authAgainByUser, userLocation } = require('../../lib/util.js')
Page({
  data: {
    imgCheckOff: imgName('security_settings_unchecked.png'),
    imgCheckOn: imgName('security_settings_unchecked_active.png'),
    ignorealarmtimelen:0,
    remindtimelength:0,
    alarmSettings: [
      {
        id:0,
        name: '无'
      }, {
        id:1,
        name: '1分钟'
      }, {
        id:2,
        name: '2分钟'
      }, {
        id:3,
        name: '3分钟'
      }, {
        id: 4,
        name: '4分钟'
      }, {
        id: 5,
        name: '5分钟'
      }],
  /**  alarmTimeSettings: [
      {
        id: 1,
        name: '1分钟'
      },
      {
        id: 3,
        name: '3分钟'
      }, 
      {
        id: 5,
        name: '5分钟'
      },
      {
        id: 10,
        name: '10分钟'
      }, 
      {
        id: 0,
        name: '持续直到我处理报警提醒'
      }
    ]*/
  },
  onLoad: function () {
    
  },
  onShow: function () {
    this.getAlarmSetting() 
  },
  getAlarmSetting() {
    let that = this
    api.post('api/user/userConfigInfo.json')
      .then(res => {
        let datamodel = res.data
        that.setData({
            ignorealarmtimelen: datamodel.ignorealarmtimelen,
            remindtimelength: datamodel.remindtimelength
        })
      })
      .catch(err => {
        alertTip(err)
      })
  },
  setSecure(e){
    let that = this
    let t = e.currentTarget
    let data={}
    data[t.dataset.type] = t.id
    api.post('api/user/updateUserConfig.json', Object.assign({},data, { userid: wx.getStorageSync('user').userId }))
      .then(res => {
        that.getAlarmSetting() 
      })
      .catch(err => {
        alertTip(err)
      })
  }
})