Page({
  data: {
    eyes: false,
    isSelected: false,
    showwifiDialog: false,
    focus: '',
    wifiList: [
      {
        "BSSID": '28:01:1c8034:99',
        "SSID": 'ChinaNet-tcGJ-5G',
        "frequency": 5240,
        "secure": 'false',
        "signalStrength": 0,
      },
      {
        "BSSID": '28:01:1c8034:99',
        "SSID": 'ChinaNet-tcGJ-5G',
        "frequency": 5240,
        "secure": 'false',
        "signalStrength": 1,
      },
      {
        "BSSID": '28:01:1c8034:99',
        "SSID": '心灵之境',
        "frequency": 5240,
        "secure": 'false',
        "signalStrength": 4,
      },
      {
        "BSSID": '28:01:1c8034:99',
        "SSID": 'ChinaNet-tcGJ-5G',
        "frequency": 5240,
        "secure": 'false',
        "signalStrength": 2,
      },
      {
        "BSSID": '28:01:1c8034:99',
        "SSID": 'ChinaNet-tcGJ-5G',
        "frequency": 5240,
        "secure": 'false',
        "signalStrength": 3,
      },
    ],
    wifiData: [
      {
        name: 'wifi',
        value: 'dsasfaf',
      },
      {
        name: 'password',
        value: '15151',
      },
    ],
    rules: [
      {
        name: 'wifi',
        rules: { required: true, message: 'wifi is required' },
      },
      {
        name: 'password',
        rules: { required: true, message: 'password is required' },
      },
    ],
  },

  onShow() {
    this.setData({
      hasHiddenTabBar: true
      // wifiData: [],
    })
    ty.hideMenuButton();
  },

  formInputChange(e) {
    const { field } = e.currentTarget.dataset
    this.setData({
      [`wifiData.${field}`]: e.detail.value,
    })
  },

  handleSubmit(ev) {
    const value = ev.detail.value;
    console.log("test")
    // if(!value.wifi || !value.password) {
    //   ty.showToast({
    //     title: '请输入wifi和密码',
    //     icon: 'none',
    //   })
    //   return;
    // }
    // const wifiData = [];
    // for (let name in value) {
    //   resultData.push({
    //     name,
    //     value: value[name],
    //   });
    // }
    // this.setData({
    //   resultData,
    // });
    // console.log(resultData)
  },

  submitForm() {
    // this.selectComponent('#wifiform').validate((valid, errors) => {
    //   if (!valid) {
    //     const firstError = Object.keys(errors)
    //     if (firstError.length) {
    //       this.setData({
    //         error: errors[firstError[0]].message,
    //       })
    //     }
    //   } else {
    //     this.setData({
    //       isSelected: !this.data.isSelected,
    //       focus: 'green'
    //     })
    //     ty.showToast({
    //       title: 'Check passed',
    //     })
    //   }
    // })
    // this.selectComponent('#form').validateField('mobile', (valid, errors) => {
    //     console.log('valid', valid, errors)
    // })
    ty.navigateTo({url: '/pages/connectdevice/index'})
  },

  getWifi() {
    // ty.getWifiList()
    var wifiList = this.data.wifiList;
    this.setData({
      isSelected: !this.data.isSelected,
      showwifiDialog: true,
    })
  },
  selectWifiItem(e) {
    const index = e.currentTarget.dataset.index;
    let wifiList = this.data.wifiList
    let wifiData = this.data.wifiData
    wifiData[0].value = wifiList[index].SSID
    this.setData({
      wifiData: wifiData,
      showwifiDialog: false,
    })
  },

  onClosSelectWifi() {
    this.setData({
      showwifiDialog: false,
    })
  },
  inputfocus() {
    this.setData({
      focus: 'orange',
    })
  },
  inputBlur() {
    this.setData({
      focus: '',
    })
  },

  changeEyes() {
    this.setData({
      eyes: !this.data.eyes
    })
  },

})
