// pages/report/report.ts
import { etcData, etcChoose } from '../../apis/phone'
const app = getApp<IAppOption>()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    listQuery: {
      current: 1
    },
    list: [],
    phone: ''
  },
  handleDetail(e) {
    let { item } = e.currentTarget.dataset
    item.phone = this.data.phone;
    const { id } = this.data
    console.log(item);
    // if (item.electronicCertificateDataList.find(f => f.electronicCertificateId === id)) {

    // }
    item.electronicCertificateDataList.map(item => {
      if (item.electronicCertificateId === id) {
        item.checked = true
      } else {
        item.checked = false
      }
    })
    wx.setStorageSync('etcList', item)
    wx.redirectTo({
      url: "/pages/reportDetail/reportDetail"
    })
  },
  goChrivc() {
    wx.navigateToMiniProgram({
      appId: 'wx1da91ccb94c17c99',
      path: '/pages/information/information',
      success(res) {
        // 打开成功
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      phone: options.phone,
      id: options.id
    })
    this.getList()
  },

  getList() {
    const { phone, id } = this.data
    etcData(phone).then((res: any) => {
      console.log(res)
      let temp = res.d
      temp.map(item => {
        if (item.electronicCertificateDataList.find(f => f.electronicCertificateId === id)) {
          item.checked = true
        } else {
          item.checked = false
        }
      })

      this.setData({
        list: temp
      })
    })
  },
  // handleCheck(e) {
  //   console.log(e);
  //   const { phone } = this.data
  //   etcChoose({
  //     electronicCertificateId: e.currentTarget.dataset.id,
  //     phone,
  //   }).then(res => {
  //     console.log(res);

  //   })
  // },
  jumpDetail(e: WechatMiniprogram.BaseEvent) {
    const { item } = e.currentTarget.dataset
    wx.navigateTo({
      url: `/pages/reportDetail/reportDetail?id=${item.id}&name=${item.name}&createDate=${item.createDate}&remark=${item.remark}`
    })
  },
  generateReport() {
    wx.navigateTo({
      url: '/pages/generateReport/generateReport'
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // console.log('onshow',app.certificationVerify());

    // this.setData({
    //   list: [],
    //   ['listQuery.current']: 1,
    //   isCer: app.certificationVerify()
    // })
    // if(this.data.isCer){
    //   this.getList()
    // }

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.setData({
      ['listQuery.current']: this.data.listQuery.current + 1
    })
    this.getList()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})