import {
  isPhone,
  getWaterDrop
} from '../../utils/index/index'
const app = getApp()

import {
  viceBroadcast
} from '../../utils/index/callAmpe'
Page({
  data: {
    toTitleRef: null,
    numVal: '',
    numList: [1, 2, 3, 4, 5, 6, 7, 8, 9, ' ', 0, ]
  },
  onLoad() {
    viceBroadcast(app.globalData.snDisposition.inputPhoneVoice)
    my.hideBackHome();
    this.setData({
      snDisposition: app.globalData.snDisposition
    })
  },
  clickAudio() {
    getWaterDrop()
  },
  //操作倒计时结束
  finish(event) {
    if (event == 'finish') {
      this.backToSpecifiedPage('/pages/resultPage/index?result=结果页超时')
    }
  },
  getVal(e) {
    let val = e.currentTarget.dataset.item
    let numVal = this.data.numVal
    if (this.data.numVal.length >= 11 && val != '退格') {
      return
    }
    if (val != undefined) {
      switch (val) {
        case '退格':
          this.setData({
            numVal: numVal.substr(0, numVal.length - 1)
          })
          break;
        default:
          this.setData({
            numVal: numVal + val
          })
          break;
      }
    } else {
      this.setData({
        numVal: e.detail.value
      })
    }
  },
  bindlongtap(e) {
    let val = e.currentTarget.dataset.item
    if (val == '退格') {
      this.setData({
        numVal: ''
      })
    }
  },
  // 确认
  sure(e) {
    if (!this.data.numVal) {
      my.showToast({
        content: '请输入手机号',
        duration: 3000,
      });
      return
    }
    app.data.inputPhone = this.data.numVal
    console.log(app.data.userInfo.xm);
    if (!app.data.userInfo.xm) {
      this.backToSpecifiedPage('/pages/resultPage/index?result=联网查询')
    } else {
      this.backToSpecifiedPage('/pages/resultPage/index?result=1:1比对&type=手输1:1')
    }
  },
  saveRef(ref){
    // 将ref存起来，在想要调用的地方使用
    this.toTitleRef = ref
  },
  /**
   * 跳转指定页面 并清除顶部计时器
   */
  backToSpecifiedPage(url) {
    this.toTitleRef && this.toTitleRef.clearIntervalAll()
    my.reLaunch({
      url: url,
    })
  },
});
