import Router from '../../../utils/routes'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: 'scan'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.camera = wx.createCameraContext()
  },
  takePhoto () {
    this.camera.takePhoto({
      success: (res) => {
        const tempImagePath = res.tempImagePath
        this.setData({
          filePath: tempImagePath,
          show: 'confirm'
        })
      }
    })
  },
  selectPhoto () {
    wx.chooseImage({
      count: 1,
      success: (res) => {
        const tempImagePath = res.tempFilePaths[0]
        this.setData({
          filePath: tempImagePath,
        })
        this.recongnize()
      }
    })
  },
  recongnize () {
    Router.push({
      url: 'scanResult',
      query: {
        filePath: this.data.filePath
      }
    })
  },
  reTake () {
    this.setData({
      show: 'scan'
    })
  }
})