// 获取全局应用程序实例对象
// const app = getApp();
var util = require('../../utils/util')
var Counter = 0;
var take_Count = 0;
// 创建页面实例对象
Page({
  // 页面的初始数据
  data: {
    image: '',
    windowWidth: '',
    windowHeight: '',
    notice: '',
    src: '',
    userInfo: {},
    hasUserInfo: false,
    mybase64: '',
    temfilePath: "",
    tag: false,
    datajson: '',
    labelCode: '',
    left: '',
    right: '',
    on: '',
    down: '',
    state: '',
    state_x: '',
    takephoto_count: '',
    once_takephoto: '',
    frame: {},
    kongfileimage: '',
    bigfileimage: '',
    text_succes: '',
    snsMsgWait: 7,
    camera_state: '',
    snsMsgWait_1: 4,
    // time_state: false,
    singe_state: false,
    take_state: '',
    longtime_state: false,
    take_photo_1: '',
    dongtaishuju_chuan: 0,
    snsMsgWait_one: 7,
    snsMsgWait_twotime: 8,
    snsMsgWait_three: 10,
    takephoto2_state: '',
    all_state: false,
    hint_phone: false,
    res_errMsg: '',
    icon: '',
    sameCodeState: 0,
    result_zoom: 0,
    labelInfo: null,
    one_zoom: 0,
    yuan_file: '',
    longTimeOnce: false,
    longTimeTwo: false,
    longTimeThree: false,
    longTimeTakephoto: false,
    all_finish: false,
    small_finish: false,
    // status_zhi:''
  },
  onLoad: function (options) {
    const param = options.param;
    console.log('param1',param)
    wx.setStorage({
      key: 'param',
      data: param
    })
    var that = this
    this.Sounds();
    const dongtaishuju_chuan = wx.getStorageSync('dongtaishuju')
    switch (dongtaishuju_chuan) {
      case 1:
        this.Countone_Time();
        break;
      case 2:
        this.Counttwo_Time();
        break;
      case 3:
        this.Countthree_Time();
        break;
      default:
        console.log('不等于1,2,3次')
        this.setData({
          longtime_state: true
        })
    }
    var nCounter = 0
    const labelInfo = wx.getStorageSync('extraData')
    // console.log('labelInfo', labelInfo)
    if (labelInfo) {
      const labelCode = labelInfo.cpid_jm || labelInfo.cpid
      this.setData({
        labelCode,
        dongtaishuju_chuan,
        param,
      })
      // console.log('labelCode', labelCode)
    }
    var that = this
    const {
      screenWidth,
      screenHeight
    } = wx.getSystemInfoSync()
    const windowWidth = 750
    const windowHeight = screenHeight / screenWidth * windowWidth
    this.setData({
      windowWidth,
      windowHeight,
    })
    // console.log('wind', windowWidth, 'height', windowHeight)
    this.ctx = wx.createCameraContext()
    this.listener = this.ctx.onCameraFrame((frame) => {
      if (nCounter == 25) {
        if (this.data.tag) return
        this.data.tag = true
        setTimeout(() => {
          this.data.tag = false
        }, 1000)
        this.setData({
          ['frame.width']: frame.width,
          ['frame.height']: frame.height,
        })
        var data = new Uint8Array(frame.data);
        // console.log('data', data)
        var clamped = new Uint8ClampedArray(data);
        // console.log('clamped', clamped)
        // 实时帧数据添加到Canvas上
        // console.log('===========')
        wx.canvasPutImageData({
          canvasId: 'myCanvas',
          x: 0,
          y: 0,
          width: frame.width, //288  288 
          height: frame.height, //512 381 
          data: clamped,
          success: (res) => {
            var inter = setInterval(function () {
              that.setData({
                smsFlag: true,
                sendTime: that.data.snsMsgWait,
                snsMsgWait: that.data.snsMsgWait - 1
              });
              if (that.data.snsMsgWait === -6 && !that.data.take_state && that.data.longtime_state === true) {
                let fail_text = '长时间不拍照1'
                // console.log('fail_text', fail_text)
                that.setData({
                  longTimeTakephoto: true
                })
                // console.log('that.data.takephoto',that.data.takephoto)
                if (fail_text !== '' && that.data.takephoto !== 'succes') {
                  // console.log('进行第一次拍照')
                  that.takePhoto()
                  let take_photo_1 = '长时间不拍照2'
                  let takephoto = 'succes'
                  that.setData({
                    take_photo_1,
                    takephoto
                  });
                }
                // console.log('that.data.takephoto',that.data.takephoto)
                if (fail_text !== '' && that.data.takephoto === 'succes' && that.data.all_state !== true) {
                  setTimeout(() => {
                    // console.log('进行第二次拍照')
                    that.takePhoto2()
                  }, 3500)
                  let take_state = true
                  that.setData({
                    take_state,
                    all_state: true
                  });
                }
              }
              if (that.data.snsMsgWait < 0) {
                clearInterval(inter)
                that.setData({
                  snsMsgWait: -5,
                  snsFlag: false
                })
              }
            }, 1000);
            // 转换临时文件 
            wx.canvasToTempFilePath({
              canvasId: 'myCanvas',
              x: 0,
              y: (frame.height - frame.width) / 2,
              width: frame.width, //288
              height: frame.width, //352
              fileType: 'jpg',
              destWidth: frame.width,
              destHeight: frame.width,
              // 精度修改
              quality: 'high',
              success: (res) => {
                // console.log('成功成功成功')
                //进行编码
                const base = wx.getFileSystemManager().readFileSync(res.tempFilePath, 'base64')
                // console.log('base',base)
                that.setData({
                  src: res.tempFilePath
                });
                wx.request({
                  url: 'https://ai.tj5.cc:35437/object/',
                  // url: 'https://tj5.cc:4433/object/',
                  // url:'https://ai.china315net.com:35437/object/',
                  method: "POST",
                  data: {
                    base
                  },
                  success: (res) => {
                    var result = res.data.result;
                    var minindex = -1;
                    var mindistance = 2;
                    for (var i = 0; i < result.length; i++) {
                      var sublist = result[i];
                      var distance = Math.abs(sublist[0] - 0.5) + Math.abs(sublist[1] - 0.5);
                      if (distance < mindistance) {
                        mindistance = distance;
                        minindex = i;
                      }
                    }
                    var result_zy = result[minindex][0]
                    var result_sx = result[minindex][1]
                    var result_w = result[minindex][2]
                    var result_zoom = parseFloat((0.85 / result_w).toFixed(1))
                    that.setData({
                      result_zoom: result_zoom
                    })
                    let state = ''
                    let status = ''
                    let state_x = ''
                    if (result_zy > 0.588) { //0.568
                      state = 'left'
                    } else if (result_zy < 0.405) { //0.425
                      state = 'right'
                    } else if (result_sx > 0.577) { //0.547
                      state = 'on'
                    } else if (result_sx < 0.401) { //0.411
                      state = 'down'
                    } else {
                      let text = '大框参数已经完善'
                      var take_Count = 0;
                      // console.log('大框参数已经完善', text)
                      let singe_state = true
                      take_Count++,
                      wx.removeStorageSync('singe_state')
                      that.setData({
                        singe_state,
                        small_finish: true
                      })
                      status = 'true'
                      // console.log('that.data.takephoto', that.data.takephoto)
                      if (text == text && that.data.takephoto !== 'succes' && that.data.take_photo_1 === '') {
                        // console.log('大框参数完成进行拍照')
                        that.takePhoto();
                        let takephoto = 'succes'
                        let d_takephoto = '大框拍照完成'
                        // console.log('d_takephoto', d_takephoto)
                        that.setData({
                          takephoto,
                          text,
                          d_takephoto,
                        })
                        // console.log('that.data.takephoto', that.data.takephoto)
                        // console.log('that.data.all_state', that.data.all_state)
                      }
                      //新修改
                      else if (that.data.takephoto === 'succes' && that.data.all_state === false) {
                        // console.log('进入小框判断')
                        var result = res.data.result;
                        var d_result_zy = result[minindex][0];
                        var d_result_sx = result[minindex][1];
                        if (d_result_zy > 0.546) { //0.546
                          state_x = 'left'
                        } else if (d_result_zy < 0.445) { //0.445
                          state_x = 'right'
                        } else if (d_result_sx > 0.571) { //0.531
                          state_x = 'on'
                        } else if (d_result_sx < 0.450) { //0.410
                          state_x = 'down'
                        } else {
                          // console.log('全部完成')
                          // console.log('this.data.all_state', this.data.all_state)
                          this.setData({
                            all_finish: true
                          });
                          that.takePhoto2()
                          that.setData({
                            all_state: true
                          })
                          that.listener.stop()
                          // if (this.data.all_state === false) {
                          //   console.log('全部完成后进行放大拍照')
                          //   that.takePhoto2()
                          //   that.setData({
                          //     all_state: true
                          //   })
                          //   that.listener.stop()
                          // }
                        }
                      } else {
                        console.log('拍照失败')
                        // that.takePhoto2()
                      }
                    }
                    that.setData({
                      state: state,
                      status: status,
                      state_x: state_x
                    })
                  },
                  fail: (error) => {
                    console.log('目标检测失败', error)
                  }
                })
              },
              fail: (error) => {
                console.log('转换临时文件失败:', error);
              }
            }, that)
          },
          fail: (error) => {
            console.log('绘制图像数据失败', error)
          }
        })
      }
      nCounter++
      if (nCounter >= 50) {
        nCounter = 0
      }
    }, 100)
    this.listener.start()
  },

  //获取相机请求
  onShow: function () {
    // wx.authorize({
    //   scope: 'scope.camera',
    //   success: function (res) {
    //     that.setData({
    //       isShowCamera: true,
    //     })
    //     console.log('走权限1')
    //     console.log('that.data.isShowCamera', that.data.isShowCamera)
    //     let res_errMsg = res.errMsg
    //     that.setData({
    //       res_errMsg: res_errMsg
    //     })
    //     wx.removeStorageSync('res_errMsg')
    //     //倒计时
    //     var inter = setInterval(function () {
    //       that.setData({
    //         smsFlag: true,
    //         sendTime: that.data.snsMsgWait_1,
    //         snsMsgWait_1: that.data.snsMsgWait_1 - 1
    //       });
    //       console.log('this.data.snsMsgWait_1', that.data.snsMsgWait_1)
    //       console.log('res_errMsg', res_errMsg)
    //       if (that.data.snsMsgWait_1 === -6 && res_errMsg != '') {
    //         console.log('长时间未响应')
    //         setTimeout(() => {
    //           that.takePhoto2()
    //         }, 2500)
    //         that.setData({
    //           longtime_state: true
    //         })
    //       }
    //       if (that.data.snsMsgWait_1 < 0) {
    //         clearInterval(inter)
    //         that.setData({
    //           snsMsgWait_1: -5,
    //           snsFlag: false
    //         })
    //         console.log('that.data.snsMsgWait_2', that.data.snsMsgWait_1)
    //       }
    //     }.bind(that), 1000);
    //     let camera_state = res.errMsg
    //     that.setData({
    //       camera_state
    //     })
    //   },
    //   fail: function (res) {
    //     console.log("" + res);
    //     console.log('走权限2')
    //     wx.showModal({
    //       title: '请求授权您的摄像头',
    //       content: '如需正常使用此小程序功能，请您按确定并在设置页面授权用户信息',
    //       confirmText: '确定',
    //       success: function (res) {
    //         if (res.confirm) {
    //           wx.openSetting({
    //             success: function (res) {
    //               if (res.authSetting['scope.camera']) { //设置允许获取摄像头
    //                 console.log('设置允许获取摄像头')
    //                 wx.showToast({
    //                   title: '授权成功',
    //                   icon: 'success',
    //                   duration: 1000
    //                 })
    //                 that.setData({
    //                   isShowCamera: true,
    //                   icon: icon
    //                 })
    //               } else { //不允许
    //                 wx.showToast({
    //                   title: '授权失败',
    //                   icon: 'none',
    //                   duration: 1000
    //                 })
    //                 wx.navigateBack({
    //                   delta: 1
    //                 })
    //               }
    //             }
    //           })
    //         } else { //取消
    //           wx.showToast({
    //             title: '授权失败',
    //             icon: 'none',
    //             duration: 1000
    //           })
    //           wx.navigateBack({
    //             delta: 1
    //           })
    //         }
    //       }
    //     })
    //   },
    // })
    var that = this
    wx.authorize({
      scope: 'scope.camera',
      success: function (res) {
        that.setData({
          isShowCamera: true,
        })
        // console.log('走权限1')
        let res_errMsg = res.errMsg
        that.setData({
          res_errMsg: res_errMsg
        })
        wx.removeStorageSync('res_errMsg')
        //倒计时
        var inter = setInterval(function () {
          that.setData({
            smsFlag: true,
            sendTime: that.data.snsMsgWait_1,
            snsMsgWait_1: that.data.snsMsgWait_1 - 1
          });
          if (that.data.snsMsgWait_1 === -6 && res_errMsg != '') {
            // console.log('长时间未响应')
            setTimeout(() => {
              that.takePhoto2()
            }, 2500)
            that.setData({
              longtime_state: true
            })
          }
          if (that.data.snsMsgWait_1 < 0) {
            clearInterval(inter)
            that.setData({
              snsMsgWait_1: -5,
              snsFlag: false
            })
            // console.log('that.data.snsMsgWait_2', that.data.snsMsgWait_1)
          }
        }.bind(that), 1000);
        let camera_state = res.errMsg
        that.setData({
          camera_state
        })
      },
      fail: function (res) {
        console.log("" + res);
        // console.log('走权限2')
        wx.showModal({
          title: '请求授权您的摄像头',
          content: '如需正常使用此小程序功能，请您按确定并在设置页面授权用户信息',
          confirmText: '确定',
          success: function (res) {
            if (res.confirm) {
              wx.openSetting({
                success: function (res) {
                  if (res.authSetting['scope.camera']) { //设置允许获取摄像头
                    // console.log('设置允许获取摄像头')
                    wx.showToast({
                      title: '授权成功',
                      icon: 'success',
                      duration: 1000
                    })
                    that.setData({
                      isShowCamera: true,
                      icon: icon
                    })
                  } else { //不允许
                    wx.showToast({
                      title: '授权失败',
                      icon: 'none',
                      duration: 1000
                    })
                    wx.navigateBack({
                      delta: 1
                    })
                  }
                }
              })
            } else { //取消
              wx.showToast({
                title: '授权失败',
                icon: 'none',
                duration: 1000
              })
              wx.navigateBack({
                delta: 1
              })
            }
          }
        })
      },
      fail: function (res) {
        console.log('获取相机失败', res)
        onShow();
      }
    })
  },
  /**
   * 拍照
   */
  takePhoto: function () {
    // console.log('takePhoto')
    var that = this
    Counter++;
    that.ctx.setZoom({
      zoom: 1.0,
      success: (res) => {
        setTimeout(() => {
          that.ctx.takePhoto({
            quality: 'high', //高质量
            flash: 'off',
            success: (res) => {
              /*储存 */
              wx.setStorage({
                key: 'res.tempImagePath',
                data: res.tempImagePath,
              })
              // console.log('res.tempImagePath', res.tempImagePath)
              const base = wx.getFileSystemManager().readFileSync(res.tempImagePath, 'base64')
              // console.log('base', base)
              this.setData({
                kongfileimage: res.tempImagePath
              })
              // console.log('开始解析')
              //解码API
              wx.request({
                // url:'https://ai.china315net.com:35437/api/upload/',
                // url: 'https://ai.tj5.cc:35437/api/upload/',
                // url:'https://tj5.cc:4433/api/upload/',
                url: 'https://ai.tj5.cc:35437/api/small_upload/',
                // url:'https://tj5.cc:4433/api/small_upload/',
                method: 'POST',
                data: {
                  base,
                  'labelCodejson': this.data.labelCode
                },
                success: (res) => {
                  // console.log('base', base)
                  // console.log('res.statusCode ', res.statusCode)
                  // console.log('接口访问')
                  var dtime = util.formatTime(new Date)
                  wx.setStorage({
                    key: 'dtime',
                    data: dtime
                  })
                  // console.log('当前时间', dtime)
                  var res_data = res.data
                  // console.log('res_data', res_data)
                  var succes_data = res_data.succes
                  // console.log('succes_data', succes_data)
                  if (res_data === '码解析失败' || succes_data === 'loser' || res.statusCode !== 200) {
                    // console.log('计算res_data长度',res_data.length)
                    // console.log('网络请求值不等于200 ')
                    const datajson = '码解析失败'
                    // console.log('datajson1',datajson)
                    wx.setStorage({
                      key: 'datajson',
                      data: datajson
                    })
                  } else {
                    var img_reader = res_data.img_reader
                    // console.log('img_reader', img_reader)
                    wx.setStorage({
                      key: 'img_reader',
                      data: img_reader
                    })
                    var img_method = res_data.img_method
                    // console.log('img_method', img_method)
                    wx.setStorage({
                      key: 'img_method',
                      data: img_method
                    })
                    var points = res_data.points
                    // console.log('points', points)
                    wx.setStorage({
                      key: 'points',
                      data: points
                    })
                    var datajson = res_data.codeinfo;
                    // console.log('原图解析内容datajson', datajson)
                    wx.setStorage({
                      key: 'datajson',
                      data: datajson
                    })
                  }
                },
                fail: (res) => {
                  // console.log('调用upload接口超时', res)
                  if (res.errMsg.indexOf('timeout') !== -1) {
                    // console.log('请求超时')
                    const datajson = '码解析失败'
                    // console.log('datajson1',datajson)
                    wx.setStorage({
                      key: 'datajson',
                      data: datajson
                    })
                  }
                },
                complete: (res) => {
                  if (!res.data) {
                    // console.log('网络请求没有返回任何数据')
                    const datajson = '码解析失败'
                    // console.log('datajson1',datajson)
                    wx.setStorage({
                      key: 'datajson',
                      data: datajson
                    })
                  }
                },
                timeout: 3000
              })
              //新增请求接口
              wx.request({
                url: 'https://ai.tj5.cc:35437/classify16/',
                // url: 'https://tj5.cc:4433/classify16/',
                method: "POST",
                data: {
                  'image_type': 20,
                  'base': base,
                },
                success: (res) => {
                  let result_value = res.data.result
                  let yuan_file = res.data.image_path
                  // console.log('yuan_file', yuan_file)
                  wx.setStorage({
                    key: 'yuan_file',
                    data: yuan_file
                  })
                  if (result_value == 14) {
                    // console.log('等于14分类')
                    let hint_phone = result_value
                    this.setData({
                      hint_phone
                    })
                    wx.setStorage({
                      key: 'hint_phone',
                      data: hint_phone
                    })
                    // console.log('hint_phone', hint_phone)
                  } else {
                    // console.log('不等于14分类')
                    let hint_phone = result_value
                    wx.setStorage({
                      key: 'hint_phone',
                      data: hint_phone
                    })
                    // console.log('hint_phone', hint_phone)
                  }
                },
                fail: error => {
                  console.log('调用upload失败', error)
                }
              });
              var dtime_2 = util.formatTime(new Date)
              wx.setStorage({
                key: 'dtime_2',
                data: dtime_2
              })
            }
          })
        }, 350);
      }
    })
    let once_takephoto = 'true'
    this.setData({
      takephoto_count: Counter,
      once_takephoto: once_takephoto
    })
  },
  //源代码
  // takePhoto2: function () {
  //   var that = this
  //   that.ctx.setZoom({
  //     // flash: 'on',
  //     zoom: 4.0,
  //     success: (res) => {
  //       console.log('setZoom  成功', res)
  //       const takephoto2_state = res.errMsg
  //       this.setData({
  //         takephoto2_state
  //       })
  //       console.log('takephoto2_state', takephoto2_state)
  //       setTimeout(() => {
  //         that.ctx.takePhoto({
  //           quality: 'high', //高质量
  //           success: (res) => {
  //             console.log('到相机里面')
  //             console.log('res.data', res)
  //             console.log('res.tempfile', res.tempImagePath)
  //             /*储存 */
  //             wx.setStorage({
  //               key: 'originalImagePath',
  //               data: res.tempImagePath,
  //             })
  //             console.log('image', res.tempImagePath)
  //             this.setData({
  //               bigfileimage: res.tempImagePath
  //             })
  //             let file = res.tempImagePath
  //             const base = wx.getFileSystemManager().readFileSync(file, 'base64')
  //             console.log('file', file)
  //             console.log('base', base)
  //             wx.navigateTo({
  //               url: '../upload/upload?path=' + that.data.bigfileimage + '&char=0'
  //             })
  //             console.log('传值成功')
  //             console.log('res.tempImagePath', that.data.bigfileimage)
  //           }
  //         })
  //       },350);
  //     }
  //   })
  // },

  //新增代码
  takePhoto2: function () {
    // console.log('takePhoto2')
    const that = this;
    function isIOS() {
      let system = wx.getSystemInfoSync().system
      return system.indexOf('iOS') !== -1
    }
    if (isIOS()) {
      // console.log('当前设备是ios')
      // console.log('this.data.result_zoom', this.data.result_zoom)
      if (this.data.result_zoom === 0) {
        this.setData({
          result_zoom: 4
        })
      }
      // console.log('this.data.result_zoom', this.data.result_zoom)
      that.ctx.setZoom({
        zoom: this.data.result_zoom,
        success: res => {
          // console.log('setZoom成功', res);
          const takephoto2_state = res.errMsg;
          this.setData({
            takephoto2_state,
          });
          // console.log('takephoto2_state', takephoto2_state);
          setTimeout(() => {
            that.ctx.takePhoto({
              quality: 'high',
              flash: 'on',
              success: res => {
                // console.log('到相机里面');
                // console.log('res.data', res);
                // console.log('res.tempfile', res.tempImagePath);
                /*储存 */
                wx.setStorage({
                  key: 'originalImagePath',
                  data: res.tempImagePath,
                });
                this.setData({
                  bigfileimage: res.tempImagePath,
                });
             
                wx.navigateTo({
                  url: '../upload/upload?path=' + that.data.bigfileimage + '&char=0'
                });
              },
              fail: err => {
                console.error('拍照失败', err);
                that.takePhoto2()
                // console.log('拍照完成')
              }
            });
          })
        },
        fail: err => {
          console.error('设置缩放失败', err);
        }
      });
    } else {
      // console.log('当前设备是安卓')
      // console.log('this.data.result_zoom', this.data.result_zoom)
      if (this.data.result_zoom === 0) {
        this.setData({
          result_zoom: 6
        })
      }
      // const one_zoom = Math.floor(this.data.result_zoom * 0.85)
      const one_zoom = parseFloat((this.data.result_zoom * 0.82).toFixed(1));
      // console.log('one_zoom', one_zoom)
      const benchmarkLevel = (wx.getStorageSync('benchmarkLevel') || 0)
      const phone_model = (wx.getStorageSync('phone_model') || '')
      // wx.removeStorageSync(String(benchmarkLevel));
      // console.log('benchmarkLevel', benchmarkLevel)
      // console.log('phone_model', phone_model)
      let timeS;
      // if(){

      // }
      // console.log('手机型号',phone_model)
      let  phone_list= ['NOH-AN00','NOH-AN01','OCE-AN10','JAD-AL00','LNA-AL00','NOP-AN00','NOH-AL10','ABR-AL80','MNA-AL00','JAD-AL50','ABR-AL00','ABR-AL90','ABR-AL60','ABR-AL60','NOH-AN50']
      if(phone_list.includes(phone_model)){
        // console.log('特殊手机型号')
        timeS = 850
      }
      else if (benchmarkLevel > 40) {
        timeS = 350;
      } else if (benchmarkLevel > 30) {
        timeS = 380;
      } else if (benchmarkLevel > 20) {
        timeS = 410
      } else if (benchmarkLevel > 10) {
        timeS = 450;
      } else {
        timeS = 450;
      }
      this.takePhotoZoom(one_zoom, timeS)
    }

  },
  takePhotoZoom: function (one_zoom,timeS) {
    console.log('one_zoom',one_zoom)
    console.log('timeS',timeS)
    var that = this
    that.ctx.setZoom({
      zoom: one_zoom,
      success: (res) => {
        console.log('res.zoom  成功', res.zoom)
        setTimeout(() => {
          that.ctx.takePhoto({
            quality: 'high', //高质量
            flash: 'off',
            success: (res) => {
              console.log('放大拍照日志res', res)
              /*储存 */
              wx.setStorage({
                key: 'originalImagePath',
                data: res.tempImagePath,
              })
              wx.setStorage({
                key: 'one_zoom',
                data: one_zoom
              });
              this.setData({
                bigfileimage: res.tempImagePath,
                result_zoom: this.data.result_zoom
              })

              wx.navigateTo({
                url: '../upload/upload?path=' + that.data.bigfileimage + '&char=0'
              })
            },
            fail: (err) => {
              console.error('拍照失败2', err);
              that.takePhoto2()
            }
          })
        }, timeS);
      },
      fail: err => {
        console.error('设置缩放失败', err);
      }
    })

  },


  // getUserInfo: function () {
  //   wx.getUserInfo({
  //     desc: '获取用户信息',
  //     success: (res) => {
  //       // console.log('resresres', res.userInfo.nickName);
  //       this.setData({
  //         hasUserInfo: true,
  //         userInfo: res.userInfo.nickName
  //       })
  //       // console.log('userInfo', userInfo.nickName)
  //     }
  //   })
  // },
  Sounds: function () {
    const innerAudioContext = wx.createInnerAudioContext()
    innerAudioContext.src = 'https://ai.tj5.cc:35437/static/out(2).mp3'
    innerAudioContext.play()
    innerAudioContext.onEnded(() => {
      console.log('播放结束')
    })
  },
  Countone_Time: function () {
    console.log('1')
    var inter = setInterval(function () {
      this.setData({
        smsFlag: true,
        snsMsgWait_one: this.data.snsMsgWait_one - 1
      });
      // console.log('this.data.snsMsgWait_one', this.data.snsMsgWait_one)
      if (this.data.snsMsgWait_one == 0) {
        this.setData({
          longTimeOnce: true
        })
        clearInterval(inter)
        // console.log('this.data.all_state', this.data.all_state)
        // console.log('this.data.singe_state', this.data.singe_state)
        // console.log('longTimeOnce',this.data.longTimeOnce)
        if (this.data.singe_state === true && this.data.all_state === false && this.data.longTimeOnce === true) {
          console.log('倒计时0拍照one')
          setTimeout(() => {
            this.takePhoto2();
            this.setData({
              all_state: true
            })
            // console.log('all_state', this.data.all_state)
          }, 350);
        }
      }
    }.bind(this), 1200);
  },
  Counttwo_Time: function () {
    console.log('2')
    var inter = setInterval(function () {
      this.setData({
        smsFlag: true,
        snsMsgWait_twotime: this.data.snsMsgWait_twotime - 1
      });
      // console.log('this.data.snsMsgWait_twotime', this.data.snsMsgWait_twotime)
      if (this.data.snsMsgWait_twotime == 0) {
        clearInterval(inter)
        // console.log('this.data.all_state', this.data.all_state)
        // console.log('this.data.singe_state', this.data.singe_state)
        this.setData({
          longTimeTwo: true
        })
        // console.log('this.data.singe_state',this.data.singe_state)
        // console.log('this.data.all_state',this.data.all_state)
        // console.log('this.data.longtimeTwo',this.data.longTimeTwo)
        if (this.data.singe_state == true && this.data.all_state == false && this.data.longTimeTwo === true) {
          console.log('倒计时0拍照two')
          setTimeout(() => {
            // console.log('this.data.take_state', this.data.take_state)
            if (this.data.take_state == true) {
              // console.log('不进行拍照')
            } else {
              this.takePhoto2();
              this.setData({
                all_state: true
              })
            }
            // console.log('倒计时0拍照twoall_state', this.data.all_state)
          }, 350);
        }
      }
    }.bind(this), 1200);
  },
  Countthree_Time: function () {
    console.log('3')
    var inter = setInterval(function () {
      this.setData({
        smsFlag: true,
        snsMsgWait_three: this.data.snsMsgWait_three - 1
      });
      // console.log('this.data.snsMsgWait_three', this.data.snsMsgWait_three)
      if (this.data.snsMsgWait_three == 0) {
        clearInterval(inter)
        this.setData({
          longTimeThree: true
        })
        // console.log('this.data.singe_state',this.data.singe_state)
        // console.log('this.data.all_state',this.data.all_state)
        // console.log('this.data.longtimeThree',this.data.longTimeThree)
        if (this.data.singe_state == true && this.data.all_state == false && this.data.longTimeThree === true) {
          console.log('倒计时0拍照three')
          setTimeout(() => {
            // console.log('this.data.take_state', this.data.take_state)
            if (this.data.take_state == true) {
              console.log('不进行拍照')
            } else {
              this.takePhoto2();
              this.setData({
                all_state: true
              })
            }
            // console.log('all_state', this.data.all_state)
          }, 350);
        }
      }
    }.bind(this), 1200);
  }
})