// 获取全局应用程序实例对象
var util = require('../../utils/util')
var Count = 0
var fail_Count = 0
// 创建页面实例对象
Page({
  // 页面的初始数据
  data: {
    notice: '',
    tempFilePath: '',
    width: 0,
    height: 0,
    score: '',
    hasTakePhoto: false,
    data: '',
    datemill: '',
    dtime: '',
    dtime1: '',
    dtime2: '',
    bg: 'white',
    isLoading: true,
    recognizeLabelCode: '',
    labelCode: '',
    labelInfo: null,
    openid: '',
    aiState: 0,
    sameCodeState: 0,
    Labeldiff: 0,
    filePath: '',
    datajson: '',
    labelCodejson: '',
    labelCodejson_len: '',
    imagefile: '',
    image_file: '',
    phone_score: '',
    max_score: '',
    if_fileimage: '',
    cha_zhi: '',
    img_method: '',
    img_reader: '',
    points: '',
    image_file_myapi: '',
    userid: '',
    userimage: '',
    userinfo_name: '',
    img_method_chuan: '',
    img_reader_chuan: '',
    points_chuan: '',
    isShowads: 'None',
    snsMsgWait: 3,
    snsMsgWait_1: 2,
    windowWidth: '',
    windowHeight: '',
    people_zhi: false,
    ammeterInfo: '',
    people_reply: 0,
    state_2: '',
    people_isloading: false,
    peo_state: 0,
    result_state: '',
    true_state: false,
    fail_state: false,
    people_time: '',
    people_replytime: '',
    people_wait: 7,
    zidong_fuzhi: false,
    hint_phone: '',
    yuan_file: '',
    max_score_value: '',
    Score_list_value: '',
    upload_state: '',
    jupload_state: '',
    phone_model: '',
    timeout_indexOf: 0,
    latitude: '',
    longitude: '',
    res_data: '',
    exit: false,
    cpid: '',
    address: '',
    province: '',
    city: '',
    county: '',
    labelInfoUrl: '',
    reason: '',
    extraData: '',
    all_info: '',
    zoom_number: ''
  },
  onLoad: function (options) {
    this.onHide()
    const openid = wx.getStorageSync('openid')
    const extraData = JSON.parse(wx.getStorageSync('extraData'))
    const param = wx.getStorageSync('fenggu')
    console.log(78787878, param)
    let labelInfo = extraData
    console.log('labelInfo', labelInfo)
    var userid = labelInfo.uid
    // console.log('userid', userid)
    var cpid = labelInfo.cpid
    // console.log('cpid', cpid)
    this.setData({
      userid,
      cpid,
      param
    })
    if (labelInfo === '') {
      console.log('id为空')
      this.setData({
        userid: false,
        cpid: false
      })
    } else {
      this.setData({
        userid: userid,
        cpid: cpid
      })
    }
    if (labelInfo.os === 'davis') {
      console.log('云平台')
      wx.request({
        url:
          'https://davis.china315net.com/wx/ajax/consumer/info?consumer_id=' +
          userid,
        method: 'GET',
        success: (res) => {
          if (res.data.e !== '') {
            console.log('获取用户失败eeeee')
            this.setData({
              userimage: '获取失败',
              userinfo_name: '获取失败'
            })
          } else {
            var userinfo = res.data
            var userimage = userinfo.headimg
            var userinfo_name = userinfo.nickname
            this.setData({
              userimage,
              userinfo_name
            })
          }
        },
        fail: (error) => {
          console.log('获取用户失败', error)
        }
      })
    } else {
      console.log('不走云平台')
      wx.request({
        url:
          'https://tjfnew.china315net.com/api/MiniProgram/requestUserData.ashx?uid=' +
          userid,
        method: 'POST',
        success: (res) => {
          if (res.statusCode !== 200) {
            console.log('获取用户失败!=200')
            this.setData({
              userimage: '获取失败',
              userinfo_name: '获取失败'
            })
          } else {
            var userinfo = res.data
            var userimage = userinfo.headimg
            var userinfo_name = userinfo.nickname
            this.setData({
              userimage,
              userinfo_name
            })
          }
        },
        fail: (error) => {
          console.log('获取用户失败', error)
        }
      })
      //获取地理位置信息
      wx.request({
        url: `https://tjfnew.china315net.com/api/MiniProgram/getAddressByCpid.ashx?cpid=${cpid}&uid=${userid}`,
        method: 'GET',
        success: (res) => {
          console.log('获取地理位置信息')
          console.log('res.statusCode', res.statusCode)
          if (res.statusCode !== 200) {
            console.log('获取地理位置失败!=200')
            this.setData({
              address: '获取失败',
              province: '获取失败',
              city: '获取失败',
              county: '获取失败'
            })
          } else {
            var locationinfo = res.data
            var address = locationinfo.address
            // console.log('address', address);
            var province = locationinfo.province
            // console.log('province', province)
            var city = locationinfo.city
            // console.log('city', city)
            var county = locationinfo.county
            // console.log('county', county)
            this.setData({
              address,
              province,
              city,
              county
            })
          }
        },
        fail: (error) => {
          console.log('获取地理位置失败', error)
        }
      })
    }
    // if (cpid.length === 16) {
    //   console.log('种子')
    //   wx.request({
    //     url: 'http://315ys.cn/zq/web/getOutCodeInfo.do?c=' + cpid,
    //     method: 'POST',
    //     success: (res) => {
    //       // console.log('获取用户信息', res.data)
    //       // console.log('res.statusCode ', res.statusCode)
    //       if (res.data.e !== '') {
    //         console.log('获取用户失败eeeee')
    //         this.setData({
    //           userlat: '获取失败',
    //           userlon: '获取失败',
    //           address: '获取失败',
    //           MSG:'获取失败',
    //           CUSTOMERNAME:'获取失败',
    //           BILLDATEL:'获取失败'
    //         })
    //       } else {
    //         var userinfo = res.data
    //         var userlat = userinfo.qryAddr.LAT
    //         var userlon = userinfo.qryAddr.LNG
    //         var address = userinfo.qryAddr.ADDR
    //         var MSG = userinfo.outList.MSG //出库内容
    //         var CUSTOMERNAME = userinfo.outList.CUSTOMERNAME  //经销商
    //         var BILLDATE = userinfo.outList.BILLDATE //出库时间
    //         this.setData({
    //           userlat,
    //           userlon,
    //           address,
    //           MSG,
    //           CUSTOMERNAME,
    //           BILLDATE
    //         })
    //       }
    //     },
    //     fail: (error) => {
    //       console.log('获取接口信息失败', error)
    //     }
    //   })
    // }
    let SCREEN_WIDTH = 750
    let RATE =
      wx.getSystemInfoSync().screenHeight / wx.getSystemInfoSync().screenWidth

    let { windowWidth = SCREEN_WIDTH, windowHeight = SCREEN_WIDTH * RATE } =
      wx.getSystemInfoSync()
    this.setData({
      windowWidth,
      windowHeight
    })
    const datajson = wx.getStorageSync('datajson')
    wx.removeStorageSync('datajson')
    // console.log('datajson原图解析内容', datajson)
    const img_reader_chuan = wx.getStorageSync('img_reader')
    const img_method_chuan = wx.getStorageSync('img_method')
    const points_chuan = wx.getStorageSync('points')
    const hint_phone = wx.getStorageSync('hint_phone')
    wx.removeStorageSync('hint_phone')
    console.log('hint_phone', hint_phone)
    const yuan_file = wx.getStorageSync('yuan_file')
    wx.removeStorageSync('yuan_file')
    // console.log('yuan_file', yuan_file)

    const phone_model = wx.getStorageSync('phone_model') || []
    wx.removeStorageSync(phone_model)
    // console.log('phone_model', phone_model)
    const latitude = wx.getStorageSync('latitude') || '获取失败'
    wx.removeStorageSync('latitude')
    // console.log('latitude',latitude)
    const longitude = wx.getStorageSync('longitude') || '获取失败'
    wx.removeStorageSync('longitude')
    // console.log('longitude',longitude)
    var timesc = new Date().getTime()
    let all_info = wx.getStorageSync('all_info') || '获取失败'
    // console.log('all_info',all_info)
    let zoom_number = wx.getStorageSync('one_zoom') || '获取失败'
    // console.log('zoom_number',zoom_number)
    this.setData({
      img_reader_chuan,
      img_method_chuan,
      points_chuan,
      hint_phone,
      yuan_file,
      phone_model,
      timesc,
      latitude,
      longitude,
      all_info,
      zoom_number
    })

    if (labelInfo) {
      console.log('获取标签号labelInfo', labelInfo)
      const labelCode = labelInfo.cpid_jm || labelInfo.cpid
      this.setData({
        labelCode,
        labelInfo,
        openid,
        filePath: options.path,
        datajson
      })
    } else {
      console.log('标签号为空')
      this.setData({
        filePath: options.path
      })
    }
    this.uploadImg()
  },
  uploadImg() {
    console.log('this.data.filePath', this.data.filePath)
    const base = wx
      .getFileSystemManager()
      .readFileSync(this.data.filePath, 'base64')

    //增加不需要进行码判断
    // this.checkAiResult(base);
    // console.log('base', base)
    if (this.data.labelCode) {
      // console.log('开始检查标签相似')
      this.checkIsSameCode(base, (state) => {
        this.setData({
          sameCodeState: state
        })
        if (state === 1) {
          this.checkAiResult(base)
        } else {
          this.setData({
            isLoading: false
          })
        }
      })
      console.log('sameCodeState', this.data.sameCodeState)
    } else {
      console.log('进入不需要检查标签相似')
      this.setData({
        sameCodeState: 1,
        userimage: false,
        userinfo_name: false
      })
      this.checkAiResult(base)
    }
  },
  //检查标签是否相同
  checkIsSameCode(base, cb) {
    // console.log('this.data.labelCode', this.data.labelCode)
    // console.log('this.data.labelCode.length', this.data.labelCode.length)
    const requestData = {
      base: base,
      labelCodejson: this.data.labelCode
    }
    wx.request({
      // url: 'https://tj5.cc:4433/api/upload/',
      // url: 'https://ai.china315net.com:35437/api/upload/',
      // url:'https://www.7856.work:4433/api/upload/',
      url: 'https://ai.tj5.cc:35437/api/upload/',
      method: 'POST',
      data: requestData,
      success: (res) => {
        const res_data = res.data
        // console.log("res_data", res_data);
        const recognize_LabelCode = res_data.codeinfo
        // console.log('recognizeLabelCode放大解析内容', recognize_LabelCode)
        const recognize_labelimage = res_data.image_file
        const succes_data = res_data.succes
        const img_method = res_data.img_method
        const img_reader = res_data.img_reader
        const points = res_data.points
        var image_file_myapi = res_data.image_file
        this.setData({
          image_file_myapi,
          img_reader,
          img_method,
          points,
          recognize_labelimage,
          recognize_LabelCode
        })
        const labelCode = this.data.labelCode
        const labelCodejson = labelCode.substring(-12)
        let recognizeLabelCode = ''
        let datajson = ''
        if (
          res_data === '码解析失败' ||
          succes_data === 'loser' ||
          res.statusCode !== 200
        ) {
          // console.log('网络请求值不等于200')
          recognizeLabelCode = '码解析失败'
        } else {
          recognizeLabelCode = recognize_LabelCode
        }
        if (!this.data.datajson || this.data.value === 'false') {
          datajson = '码解析失败'
        } else {
          datajson = this.data.datajson
        }
        this.setData({
          recognizeLabelCode,
          datajson,
          labelCodejson,
          labelCodejson_len: labelCodejson.length
        })
        console.log(
          'this.data.recognizeLabelCode放大解析内容',
          this.data.recognizeLabelCode
        )
        console.log('this.data.datajson1111原图解析内容', this.data.datajson)
        console.log('labelcodejson111标签号', labelCodejson)
        //判断放大解析与原图解析内容是否与标签号一致
        if (
          this.data.recognizeLabelCode === labelCodejson ||
          this.data.datajson === labelCodejson
        ) {
          console.log('一致')
          cb(1)
        } else if (
          this.data.recognizeLabelCode === '码解析失败' &&
          this.data.datajson === '码解析失败'
        ) {
          console.log('解析失败')
          cb(2)
          // this.setData({
          //   aiState: 3
          // })
          const dtime1 = util.formatTime(new Date())
          wx.request({
            url: 'https://ai.tj5.cc:35437/api/all/',
            // url: 'https://ai.china315net.com:35437/api/all/',
            // url: 'https://tj5.cc:4433/api/all/',
            // url:'https://www.7856.work:4433/api/all/',
            method: 'POST',
            data: {
              result: '码解析失败',
              score: '0',
              imagefile: recognize_labelimage,
              classs: this.data.hint_phone,
              usetime: '0',
              datetime: dtime1,
              openid: this.data.openid,
              userip: '',
              userlat: this.data.latitude,
              userlon: this.data.longitude,
              recognizelabelcode: this.data.recognizeLabelCode,
              artwork: this.data.datajson,
              labelcode: this.data.labelCode,
              scorelist: '',
              img_method: '',
              img_reader: '',
              points: '',
              userid: this.data.userid || '',
              userimage: this.data.userimage,
              userinfo_name: this.data.userinfo_name,
              yuan_file: this.data.yuan_file,
              phone_model: this.data.phone_model,
              cpid: this.data.cpid || '',
              address: this.data.address || '',
              province: this.data.province || '',
              city: this.data.city || '',
              county: this.data.county || '',
              all_info: this.data.all_info || '',
              zoom_number: this.data.zoom_number || ''
            },
            success: (res) => {
              console.log('all入库成功', res)
              wx.reLaunch({
                url: `/pages/result/result?aiState=${0}`
              })
            },
            fail: (error) => {
              console.log('入库失败', error)
            }
          })
        } else {
          console.log('码不同')
          const Labeldiff = 1
          cb(0)
          // console.log('码不同', this.data.sameCodeState)
          const dtime2 = util.formatTime(new Date())
          wx.request({
            url: 'https://ai.tj5.cc:35437/api/all/',
            // url: 'https://tj5.cc:4433/api/all/',
            // url:'https://www.7856.work:4433/api/all/',
            // url: 'https://ai.china315net.com:35437/api/all/',
            method: 'POST',
            data: {
              result: '码不同',
              score: '0',
              imagefile: recognize_labelimage,
              classs: '',
              usetime: '0',
              datetime: dtime2 || '',
              openid: this.data.openid,
              userip: '',
              userlat: this.data.latitude,
              userlon: this.data.longitude,
              recognizelabelcode: this.data.recognizeLabelCode,
              artwork: this.data.datajson,
              labelcode: this.data.labelCode,
              scorelist: '',
              img_method: '',
              img_reader: '',
              points: '',
              userid: this.data.userid || '',
              userimage: this.data.userimage || '',
              userinfo_name: this.data.userinfo_name || '',
              yuan_file: this.data.yuan_file || '',
              phone_model: this.data.phone_model || '',
              cpid: this.data.cpid || '',
              address: this.data.address || '',
              province: this.data.province || '',
              city: this.data.city || '',
              county: this.data.county || '',
              all_info: this.data.all_info || '',
              zoom_number: this.data.zoom_number || ''
            },
            success: (res) => {
              console.log('all入库成功', res)
              wx.reLaunch({
                url: `/pages/result/result?Labeldiff=${Labeldiff}`
              })
              return
            },
            fail: (error) => {
              console.log('入库失败', error)
            }
          })
        }
      },
      fail: (error) => {
        console.log('调用upload接口超时', error)
        cb(2)
        console.log('222222222222')
        wx.request({
          url: 'https://ai.tj5.cc:35437/api/all/',
          // url: 'https://tj5.cc:4433/api/all/',
          // url:'https://www.7856.work:4433/api/all/',
          method: 'POST',
          data: {
            result: '调用upload接口超时',
            score: '0',
            imagefile: '',
            classs: this.data.hint_phone,
            usetime: '0',
            datetime:'',
            openid: this.data.openid,
            userip: '',
            userlat: this.data.latitude,
            userlon: this.data.longitude,
            recognizelabelcode: '码解析失败',
            artwork: this.data.datajson,
            labelcode: this.data.labelCode,
            scorelist: '',
            img_method: '',
            img_reader: '',
            points: '',
            userid: this.data.userid || '',
            userimage: this.data.userimage,
            userinfo_name: this.data.userinfo_name,
            yuan_file: this.data.yuan_file,
            phone_model: this.data.phone_model,
            cpid: this.data.cpid || '',
            address: this.data.address || '',
            province: this.data.province || '',
            city: this.data.city || '',
            county: this.data.county || '',
            all_info: this.data.all_info || '',
            zoom_number: this.data.zoom_number || ''
          },
          success: (res) => {
            console.log('success,调用upload接口超时', res)
            wx.reLaunch({
              url: `/pages/result/result?aiState=${0}`
            })
          },
          fail: (error) => {
            console.log('fail,调用upload接口超时', error)
          }
        })
        //判断手机型号 开始注释
        // let timeoutIndex = -1;
        // if (wx.getSystemInfoSync().platform === 'ios') {
        //   timeoutIndex = res.errMsg.indexOf('timeout');
        //   // console.log('timeoutIndex', timeoutIndex)
        // } else if (wx.getSystemInfoSync().platform === 'android') {
        //   timeoutIndex = res.errMsg.indexOf('time out');
        //   // console.log('timeoutIndex', timeoutIndex)
        // }
        // if (timeoutIndex !== -1) {
        //   console.log('请求超时1')
        //   // console.log('this.data.datajson', this.data.datajson)
        //   if (this.data.datajson === this.data.labelCode) {
        //     console.log('到这里')
        //     cb(1);
        //   } else if ((this.data.datajson !== '' && this.data.datajson !== '码解析失败') && (this.data.datajson !== this.data.labelCode)) {
        //     cb(0);
        //     const dtime2 = util.formatTime(new Date());
        //     // console.log('dtime2', dtime2)
        //     // console.log('this.data.recognizeLabelCode',this.data.recognizeLabelCode)
        //     wx.request({
        //       url: 'https://ai.tj5.cc:35437/api/all/',
        //       // url: 'https://tj5.cc:4433/api/all/',
        //       // url:'https://www.7856.work:4433/api/all/',
        //       // url: 'https://ai.china315net.com:35437/api/all/',
        //       method: "POST",
        //       data: {
        //         'result': '码不同',
        //         'score': '0',
        //         'imagefile': '',
        //         'classs': '',
        //         'usetime': '0',
        //         'datetime': dtime2,
        //         'openid': this.data.openid,
        //         'userip': '',
        //         'userlat': this.data.latitude,
        //         'userlon': this.data.longitude,
        //         'recognizelabelcode': '',
        //         'artwork': this.data.datajson,
        //         'labelcode': this.data.labelCode,
        //         'scorelist': '',
        //         'img_method': '',
        //         'img_reader': '',
        //         'points': '',
        //         'userid': this.data.userid || '',
        //         'userimage': this.data.userimage,
        //         'userinfo_name': this.data.userinfo_name,
        //         'yuan_file': this.data.yuan_file,
        //         'phone_model': this.data.phone_model,
        //         'cpid': this.data.cpid || '',
        //         'address': this.data.address || '',
        //         'province': this.data.province || '',
        //         'city': this.data.city || '',
        //         'county': this.data.county || '',
        //       },
        //       success: (res) => {
        //         console.log('success,码不同', res);
        //       },
        //       fail: (error) => {
        //         console.log('fail,码不同', error)
        //       }
        //     });
        //   } else {
        //     console.log('res.data', !res.data)
        //     if (!res.data) {
        //       // console.log('网络请求没有返回任何数据')
        //       console.log('请求超时2');

        //       const dtime2 = util.formatTime(new Date());
        //       // console.log('dtime2_2', dtime2)
        //       cb(2);
        //       wx.request({
        //         url: 'https://ai.tj5.cc:35437/api/all/',
        //         // url: 'https://tj5.cc:4433/api/all/',
        //         // url:'https://www.7856.work:4433/api/all/',
        //         method: "POST",
        //         data: {
        //           'result': '接口超时',
        //           'score': '0',
        //           'imagefile': '',
        //           'classs': this.data.hint_phone,
        //           'usetime': '0',
        //           'datetime': dtime2,
        //           'openid': this.data.openid,
        //           'userip': '',
        //           'userlat': this.data.latitude,
        //           'userlon': this.data.longitude,
        //           'recognizelabelcode': '解析超时',
        //           'artwork': this.data.datajson,
        //           'labelcode': this.data.labelCode,
        //           'scorelist': '',
        //           'img_method': '',
        //           'img_reader': '',
        //           'points': '',
        //           'userid': this.data.userid || '',
        //           'userimage': this.data.userimage,
        //           'userinfo_name': this.data.userinfo_name,
        //           'yuan_file': this.data.yuan_file,
        //           'phone_model': this.data.phone_model,
        //           'cpid': this.data.cpid || '',
        //           'address': this.data.address || '',
        //           'province': this.data.province || '',
        //           'city': this.data.city || '',
        //           'county': this.data.county || '',
        //         },
        //         success: (res) => {
        //           console.log('success,调用接口超时成功', res);
        //         },
        //         fail: (error) => {
        //           console.log('fail,调用接口超时失败', error)
        //         }
        //       });
        //     }
        //   }
        // } else {
        //   console.log('网络请求发生错误')
        //   const dtime2 = util.formatTime(new Date());
        //   // console.log('dtime2_2', dtime2)
        //   cb(2);
        //   wx.request({
        //     url: 'https://ai.tj5.cc:35437/api/all/',
        //     // url: 'https://tj5.cc:4433/api/all/',
        //     // url:'https://www.7856.work:4433/api/all/',
        //     method: "POST",
        //     data: {
        //       'result': '网络请求发生错误',
        //       'score': '0',
        //       'imagefile': '',
        //       'classs': this.data.hint_phone,
        //       'usetime': '0',
        //       'datetime': dtime2,
        //       'openid': this.data.openid,
        //       'userip': '',
        //       'userlat': this.data.latitude,
        //       'userlon': this.data.longitude,
        //       'recognizelabelcode': '码解析失败',
        //       'artwork': this.data.datajson,
        //       'labelcode': this.data.labelCode,
        //       'scorelist': '',
        //       'img_method': '',
        //       'img_reader': '',
        //       'points': '',
        //       'userid': this.data.userid || '',
        //       'userimage': this.data.userimage,
        //       'userinfo_name': this.data.userinfo_name,
        //       'yuan_file': this.data.yuan_file,
        //       'phone_model': this.data.phone_model,
        //       'cpid': this.data.cpid || '',
        //       'address': this.data.address || '',
        //       'province': this.data.province || '',
        //       'city': this.data.city || '',
        //       'county': this.data.county || '',
        //     },
        //     success: (res) => {
        //       console.log('success,网络请求发生错误', res)
        //     },
        //     fail: (error) => {
        //       console.log('fail,网络请求发生错误', error);
        //     }
        //   });
        // }
        //一直注释到这里
      },
      timeout: 7000
    })
  },
  //检查ai识别结果
  checkAiResult(base) {
    wx.request({
      //线上服务器
      // url: 'https://ai.china315net.com:35437/classify/',
      // url: 'https://ai.tj5.cc:35437/classify16/',
      url: 'https://ai.tj5.cc:35437/classify16/',
      // url: 'https://ai.china315net.com:35437/classify16/',
      // 测试服务器
      // url: 'https://tj5.cc:4433/objectclass/',
      // url: 'https://tj5.cc:4433/classify16/',
      // url:'https://www.7856.work:4433/api/classify16/',
      method: 'POST',
      data: {
        image_type: 50,
        base: base
      },
      success: (res) => {
        console.log('打印分类接口返回数据res.data', res.data)
        let imagefile = res.data.image_path
        const classScore = res.data.result
        const max_score = Math.max.apply(null, res.data.confidence)
        const max_score_value = max_score.toFixed(3)
        const Score_list = res.data.confidence
        // console.log('Score_list', Score_list)
        for (var i = 0; i < Score_list.length; i++) {
          Score_list[i] = Score_list[i].toFixed(3)
        }
        var floatList = [] // 存放转换后的浮点型数据
        for (var i = 0; i < Score_list.length; i++) {
          var num = parseFloat(Score_list[i])
          if (!isNaN(num)) {
            // 如果转换结果不是NaN，则表示转换成功
            floatList.push(num) // 将转换结果添加到列表中
          }
        }
        const phone_score = res.data.confidence[4]

        function mysort(a) {
          var n = a.length
          var newa = []
          var temp
          for (var i = 0; i < n; i++) {
            for (var j = i; j < n; j++) {
              if (a[i] > a[j]) {
                temp = a[i]
                a[i] = a[j]
                a[j] = temp
              }
            }
            newa.push(a[i])
          }
          return newa
        }
        const class_score_sor = mysort(Score_list)
        // console.log('class_score_sor', class_score_sor)
        const second_score = class_score_sor[14]
        // console.log('second_score', second_score)
        const cha_zhi = max_score - second_score
        // console.log('cha_zhi', cha_zhi)

        let notice = ''
        // let score = res.data.confidence
        let succ = ''
        // ai通过状态

        let aiState = 0
        this.setData({
          isLoading: true,
          imagefile: imagefile,
          phone_score: phone_score
        })
        // console.log('classScore_11111', classScore)
        if (this.data.hint_phone == 14) {
          notice = '手机边框'
          // notice = '请拍摄结构三维码'
        } else if (max_score < 0.85 || cha_zhi < 0.3) {
          notice = '算法不确定具体分类'
        } else if (classScore == 0) {
          // console.log(1)
          notice = '结构三维码'
          succ = 'lightgreen'
          aiState = 1
        } else if (classScore == 1) {
          notice = '拍摄模糊，请重新拍照'
          succ = 'rgb(245, 12, 12)'
          aiState = 2
        } else if (classScore == 2) {
          // notice = '太小'
          // console.log(2)
          notice = '请拍摄结构三维码'
          succ = 'rgb(245, 12, 12)'
        } else if (classScore == 3) {
          // notice = '复印'
          // console.log(3)
          notice = '请拍摄结构三维码'
          succ = 'rgb(245, 12, 12)'
        } else if (classScore == 4) {
          // console.log(4)
          notice = '请拍摄结构三维码'
          succ = 'rgb(245, 12, 12)'
        } else if (classScore == 5) {
          // notice = '没有识别到结构三维码'
          // console.log(5)
          notice = '请拍摄结构三维码'
          succ = 'rgb(245, 12, 12)'
          // } else if (classScore == 6 && this.data.attention_chuan === 0 ) {
        } else if (classScore == 6) {
          // console.log(6)
          notice = '多层纸结构三维码'
          succ = 'lightgreen'
          aiState = 1
          // } else if (classScore == 7 && this.data.attention_chuan === 0){
        } else if (classScore == 7) {
          // console.log(7)
          notice = '烫金三维码'
          succ = 'lightgreen'
          aiState = 1
        } else if (res.data.result == 8) {
          // console.log(8)
          // notice = '屏幕(烫金三维码)'
          notice = '请拍摄结构三维码'
        } else if (res.data.result == 9) {
          // console.log(9)
          // notice = '复印(烫金三维码)'
          notice = '请拍摄结构三维码'
        } else if (res.data.result == 10) {
          // console.log(10)
          // notice ='模糊(烫金三维码)'
          notice = '请拍摄结构三维码'
        } else if (res.data.result == 11) {
          // console.log(11)
          // notice= '屏幕(反光)'
          notice = '请拍摄结构三维码'
        } else if (res.data.result == 12) {
          // console.log(12)
          // notice = '屏幕(干涉条纹)'
          notice = '请拍摄结构三维码'
        } else if (res.data.result == 13) {
          // console.log(13)
          // notice = '屏幕(像素点)'
          notice = '请拍摄结构三维码'
        } else if (res.data.result == 14) {
          // console.log(14)
          // notice ='屏幕(手机边框，太小)'
          notice = '请拍摄结构三维码'
        } else if (res.data.result == 15) {
          // console.log(15)
          // notice = '立体三维码'
          notice = '请拍摄结构三维码'
        } else if (res.data.result == 16) {
          // console.log('铆钉三维码')
          notice = '铆钉三维码'
          aiState = 1
        } else if (res.data.result == 17) {
          // console.log('高分子三维码')
          notice = '高分子三维码'
          aiState = 1
        } else if (res.data.result == 18) {
          // console.log('护照烫金三维码')
          notice = '护照烫金三维码'
          aiState = 1
        } else if (res.data.result == 19) {
          // console.log('烫金三维码（小尺寸）')
          notice = '烫金三维码（小尺寸）'
        } else if (res.data.result == 20) {
          // console.log('立方体三维码')
          notice = '立方体三维码'
        } else if (res.data.result == 21) {
          // console.log('墙上三维码')
          notice = '墙上三维码'
        } else if (res.data.result == 22) {
          // console.log('车牌三维码')
          notice = '车牌三维码'
        } else if (res.data.result == 23) {
          // console.log('中国结三维码')
          notice = '中国结三维码'
        } else {
          notice = '算法不确定具体分类'
        }
        // if(wx.getStorageSync('fenggu') ==='fenggu'){
        //   if (aiState === 1 ) {
        //     wx.redirectTo({
        //       url:`/pages/fenggu/success/success?time1${this.data.dtime || this.data.people_time}&time2=${this.data.people_replytime/1000 || this.data.datemill/1000}`
        //     })
        //   } else {
        //     wx.navigateTo({
        //       url:`/pages/fenggu/AICheck/AICheck?sameCodeState=${this.data.sameCodeState}`
        //     })
        //   }
        //   return
        // }

        //更新数据
        this.setData({
          isLoading: false,
          imagefile: imagefile,
          phone_score: phone_score,
          succ: succ,
          notice: notice,
          aiState: aiState
        })

        wx.setStorage({
          key: 'notice',
          data: notice
        })
        console.log('notice结果展示', notice)
        if (notice != '手机边框') {
          if (aiState !== 1) {
            Count++
          } else {
            Count = 0
          }
          if (Count >= 3) {
            // console.log('Count', Count)
            console.log('三次未通过调用人工')
            var people_time = util.formatTime(new Date())
            var timessc = new Date().getTime()
            this.setData({
              isLoading: true,
              people_time
            })
            Count = 0
            console.log('三次请拍摄结构三维码调用人工')
            wx.request({
              header: {
                'Content-Type':
                  'application/x-www-form-urlencoded;charset=utf-8'
              },
              // url: 'https://tj5.cc:4433/bg/swmrecognizeproject/apis/miniprogram/uploadimg.ashx',
              url: 'https://www.7856.work:4433/bg/swmrecognizeproject/apis/miniprogram/uploadimg.ashx',
              // url: 'https://192.168.8.8:4433/bg/swmrecognizeproject/apis/miniprogram/uploadimg.ashx',
              // url: 'https://tj5.cc:4433/bg/swmrecognizeproject/apis/miniprogram/uploadimg',
              method: 'POST',
              data: {
                base: base,
                image_file: this.data.yuan_file
              },
              success: (res) => {
                console.log('三次拍照未通过人工回复倒计时')
                // console.log('获取返回信息', res.data)
                let upload_state = res.data.length
                // console.log('upload_state', upload_state)
                if (upload_state > 500) {
                  console.log('人工调用接口失败')
                  this.setData({
                    fail_state: true,
                    isLoading: false,
                    sameCodeState: 1
                  })
                  // console.log('this.data.sameCodeState', this.data.sameCodeState)
                } else {
                  var inter = setInterval(
                    function () {
                      this.setData({
                        smsFlag: true,
                        sendTime: this.data.people_wait,
                        people_wait: this.data.people_wait - 1
                      })
                      // console.log('this.data.people_wait', this.data.people_wait)
                      if (this.data.people_wait < 0) {
                        this.setData({
                          zidong_fuzhi: true
                        })
                        // console.log('this.data.zidong_fuzhi', this.data.zidong_fuzhi)
                        clearInterval(inter)
                      }
                    }.bind(this),
                    1000
                  )
                  // let people_statu = res.data.success
                  let people_id = res.data.id
                  let people_image = res.data.image
                  if (people_id != '') {
                    this.data.setInter = setInterval(() => {
                      console.log('每隔1s执行一次')
                      wx.request({
                        // url: 'https://tj5.cc:4433/api/getstate/',
                        url: 'https://www.7856.work:4433/api/getstate/',
                        // url: 'https://192.168.8.8:4433/api/getstate/',
                        method: 'POST',
                        data: {
                          people_image: people_image
                        },
                        success: (res) => {
                          // console.log('res.data', res.data)
                          let peo_state = res.data.state[0]
                          // console.log('peo_state', peo_state)
                          if (peo_state !== '') {
                            console.log('状态值不为空')
                            this.setData({
                              sameCodeState: 3
                            })
                            // console.log('this.data.sameCodeState3', this.data.sameCodeState)
                            if (peo_state == 1) {
                              console.log('人工回复真品')
                              this.setData({
                                peo_state: peo_state,
                                true_state: true,
                                isLoading: false,
                                aiState: 1
                              })
                              // console.log('this.data.peo_state', this.data.peo_state)
                              // console.log('this.data.aiState', this.data.aiState)
                              clearInterval(this.data.setInter)
                              var timeec = new Date().getTime()
                              var people_replytime = timeec - timessc
                              // console.log('本次认证时间people_replytime', people_replytime / 1000)
                              this.setData({
                                people_replytime
                              })
                              // console.log('people_replytime', people_replytime)
                            }
                            if (
                              (peo_state !== 0 && peo_state !== 1) ||
                              this.data.zidong_fuzhi
                            ) {
                              console.log('人工回复不是真品')
                              this.setData({
                                peo_state: peo_state,
                                fail_state: true,
                                isLoading: false,
                                sameCodeState: 1
                              })
                              // console.log('this.data.peo_state', this.data.peo_state)1
                              // console.log('this.data.fail_state', this.data.fail_state)
                              // console.log('this.data.sameCodeState', this.data.sameCodeState)
                              clearInterval(this.data.setInter)
                              var timeec = new Date().getTime()
                              var people_replytime = timeec - timessc
                              this.setData({
                                people_replytime
                              })
                              // console.log('people_replytime', people_replytime)
                            } else {
                              console.log('没有进行回复')
                              var timeec = new Date().getTime()
                              var people_replytime = timeec - timessc
                              this.setData({
                                people_replytime
                              })
                              // console.log('people_replytime', people_replytime)
                            }
                          }
                        }
                      })
                    }, 2500)
                  }
                }
              },
              fail: (err) => {
                console.log('err', err)
              },
              complete: (res) => {
                if (!res.data) {
                  console.log('调用人工回复接口失败')
                  this.setData({
                    fail_state: true,
                    isLoading: false,
                    sameCodeState: 1
                  })
                }
              },
              timeout: 5000
            })
          }
          this.setData({
            Count
          })
        }
        var timeec = new Date().getTime()
        var datemill = timeec - this.data.timesc
        // console.log('本次认证时间', datemill / 1000)
        var dtime = util.formatTime(new Date())

        this.setData({
          notice,
          datemill,
          dtime,
          succ,
          aiState
        })
        if (this.data.recognizeLabelCode === '码解析失败') {
          console.log('判断条件成功，使用原图的')
          const img_method = this.data.img_method_chuan
          const img_reader = this.data.img_reader_chuan
          const points = this.data.points_chuan
          this.setData({
            img_method,
            img_reader,
            points
          })
        } else {
          console.log('使用放大的')
          const img_method = this.data.img_method
          const img_reader = this.data.img_reader
          const points = this.data.points
          this.setData({
            img_reader,
            img_method,
            points
          })
        }

        let state = 0
        if (
          notice === '结构三维码' ||
          notice === '烫金三维码' ||
          notice === '多层纸结构三维码' ||
          notice === '高分子三维码' ||
          notice === '铆钉三维码' ||
          notice === '护照烫金三维码'
        ) {
          state = 1
          this.setData({
            sameCodeState: 3
          })
          console.log('走这里')
          // this.popup()
        } else {
          this.setData({
            sameCodeState: 2
          })
        }
        // console.log('this.data.sameCodeState', this.data.sameCodeState)
        if (state == 1) {
          console.log('倒计时')
          var inter = setInterval(
            function () {
              this.setData({
                smsFlag: true,
                sendTime: this.data.snsMsgWait_1,
                snsMsgWait_1: this.data.snsMsgWait_1 - 1
              })
              // console.log('this.data.snsMsgWait_1', this.data.snsMsgWait_1)
              if (this.data.snsMsgWait_1 === -1) {
                this.popup()
              }
              if (this.data.snsMsgWait_1 < 0) {
                clearInterval(inter)
                this.setData({
                  snsMsgWait_1: 2,
                  smsFlag: false
                })
              }
            }.bind(this),
            1000
          )
        }

        this.callBackAIStatus(state)
        const postdata = {
          result: notice,
          score: max_score_value,
          imagefile: this.data.image_file_myapi || imagefile,
          classs: classScore,
          usetime: datemill / 1000,
          datetime: dtime,
          openid: this.data.openid,
          userip: '',
          userlat: this.data.latitude,
          userlon: this.data.longitude,
          recognizelabelcode: this.data.recognizeLabelCode,
          artwork: this.data.datajson,
          labelcode: this.data.labelCode || '',
          scorelist: floatList,
          img_method: this.data.img_method,
          img_reader: this.data.img_reader,
          points: this.data.points,
          userid: this.data.userid || '',
          userimage: this.data.userimage,
          userinfo_name: this.data.userinfo_name,
          yuan_file: this.data.yuan_file,
          phone_model: this.data.phone_model,
          cpid: this.data.cpid || '',
          address: this.data.address || '',
          province: this.data.province || '',
          city: this.data.city || '',
          county: this.data.county || '',
          all_info: this.data.all_info || '',
          zoom_number: this.data.zoom_number || ''
        }
        console.log('this.data.image_file_myapi')
        console.log('aistate', aiState)

        wx.request({
          // url: 'https://ai.china315net.com:35437/api/all/',
          url: 'https://ai.tj5.cc:35437/api/all/',
          // url: 'https://tj5.cc:4433/api/all/',
          // url:'https://www.7856.work:4433/api/all/',
          method: 'POST',
          data: {
            ...postdata
          },
          success: (res1) => {
            this.setData({
              success: res1.data.log
            })
          },
          complete: () => {}
        })
        wx.removeStorage({
          artwork: this.data.datajson,
          succes(res) {
            console.log('resresres', res)
          }
        })
        try {
          wx.removeStorageSync('artwork')
        } catch (e) {
          console.log('eee', e)
        }

        // 跳转到结果页面
        wx.reLaunch({
          url: `/pages/result/result?time1=${
            util.formatTime(new Date()) || this.data.people_time
          }&time2=${new Date().getTime()}&aiState=${aiState}`
        })
        return
      },
      fail: (res) => {
        console.log('分类接口报错', res)
      }
    })
  },
  back() {
    wx.reLaunch({
      url: '/pages/index/index'
    })
  },
  // old() {
  //   wx.getSystemInfo({
  //     success: function (res) {
  //       var width = res.windowWidth
  //       var height = res.windowHeight
  //       var gap = 20
  //       that.setData({
  //           width: width,
  //           height: height,
  //           gpa: gap
  //         }),
  //         wx.getImageInfo({
  //           src: that.path,
  //           success: function (res) {
  //             console.log('src', that.path)
  //             that.canvas = wx.createCanvasContext('image_id', that)
  //             console.log('that.canvas', that.canvas)
  //             that.canvas.drawImage(that.path, 0, 0, width, height)
  //             // wx.showLoading({
  //             //   title: '数据处理中',
  //             //   mask: true
  //             // })
  //             that.canvas.draw()
  //             setTimeout(function () {
  //               wx.canvasToTempFilePath({
  //                 canvasId: 'image_id',
  //                 x: 75,
  //                 y: 0,
  //                 width: 450,
  //                 height: 450,
  //                 destWidth: 659,
  //                 destHeight: 1280,
  //                 fileType: 'jpg',
  //                 canvasId: 'image_id',
  //                 quality: 1,
  //                 success: (res) => {
  //                   // console.log('destwidth',304*wx.getSystemInfoSync().pixelRatio)
  //                   // console.log('destwidth',304*wx.getSystemInfoSync().pixelRatio)
  //                   let openid = openid
  //                   console.log('openid', openid)
  //                   let image = res.tempFilePath
  //                   console.log('image11111', image)
  //                   that.filePath = res.tempFilePath
  //                   console.log('file', that.filepath)
  //                   const base = wx.getFileSystemManager().readFileSync(that.filePath, 'base64')
  //                   console.log('base', base)
  //                   var timesc = new Date().getTime();
  //                   wx.request({
  //                     //线上服务器
  //                     url: 'https://ai.china315net.com:35437/classify/',
  //                     // 测试服务器
  //                     // url: 'http://236.123nat.com:5050/',
  //                     method: 'POST',
  //                     data: {
  //                       base
  //                     },
  //                     success: (res) => {
  //                       console.log(res)
  //                       console.log('data', res.data.result)
  //                       let notice = ''
  //                       let score = ''
  //                       that.setData({
  //                         isLoading: false
  //                       })
  //                       if (res.data.result == 0) {
  //                         notice = '结构三维码'
  //                         score = res.data.confidence
  //                         that.setData({
  //                           succ: 'lightgreen'
  //                         })
  //                       } else if (res.data.result == 1) {
  //                         notice = '拍摄模糊，请重新拍照'
  //                         score = res.data.confidence
  //                         that.setData({
  //                           succ: 'rgb(245, 12, 12)'
  //                         })
  //                       } else if (res.data.result == 2) {
  //                         notice = '请拍摄结构三维码'
  //                         score = res.data.confidence
  //                         that.setData({
  //                           succ: 'rgb(245, 12, 12)'
  //                         })
  //                       } else if (res.data.result == 3) {
  //                         notice = '请拍摄结构三维码'
  //                         score = res.data.confidence
  //                         that.setData({
  //                           succ: 'rgb(245, 12, 12)'
  //                         })
  //                       } else if (res.data.result == 4) {
  //                         notice = '请拍摄结构三维码'
  //                         score = res.data.confidence
  //                         that.setData({
  //                           succ: 'rgb(245, 12, 12)'
  //                         })
  //                       } else if (res.data.result == 5) {
  //                         notice = '请拍摄结构三维码'
  //                         score = res.data.confidence
  //                         that.setData({
  //                           succ: 'rgb(245, 12, 12)'
  //                         })
  //                       } else if (res.data.result == 6) {
  //                         notice = '结构三维码'
  //                         score = res.data.confidence
  //                         that.setData({
  //                           succ: 'lightgreen'
  //                         })
  //                       } else if (res.data.result == 7) {
  //                         notice = '烫金三维码'
  //                         score = res.data.confidence
  //                         that.setData({
  //                           succ: 'lightgreen'
  //                         })
  //                       }
  //                       var timeec = new Date().getTime();
  //                       var datemill = timeec - timesc
  //                       var dtime = util.formatTime(new Date)
  //                       console.log('当前时间', dtime)
  //                       console.log('datemi', datemill)
  //                       that.setData({
  //                         notice,
  //                         score,
  //                         datemill,
  //                         dtime
  //                       })
  //                       console.log('data', this.data, 'score', score)
  //                     }
  //                   })
  //                 }
  //               });
  //             }, 1000);
  //           },
  //           next_calculator: function () {
  //             wx.reLaunch({
  //               url: '../index/index',
  //             })
  //           },
  //           next_calculatorin: function () {
  //             wx.reLaunch({
  //               url: '../index/index',
  //             })
  //           },
  //           back() {
  //             wx.reLaunch({
  //               url: '/pages/index/index',
  //             })
  //           }
  //         })
  //     }
  //   })
  // },
  // 回调AI结果
  callBackAIStatus(state) {
    const labelInfo = this.data.labelInfo
    console.log('labelInfo', labelInfo)
    if (!labelInfo) {
      return
    }
    labelInfo.state = state
    //调用云平台接口
    if (labelInfo.os === 'davis') {
      wx.request({
        url: 'https://davis.china315net.com/wx/ajax/get_ai_status/',
        method: 'GET',
        data: {
          label_code: labelInfo.cpid,
          consumer_id: labelInfo.uid,
          uuid: labelInfo.uuid,
          state: labelInfo.state
        },
        success: (res) => {
          console.log('回调成功davis')
        }
      })
    } else {
      console.log('没有davis')
      // console.log('labelInfo', labelInfo)
      wx.request({
        url: 'https://tjfnew.china315net.com/ajax/requestMiniprogramAIStatus.ashx',
        method: 'GET',
        data: {
          ...labelInfo
        },
        success: (res) => {
          console.log('回调成功')
        }
      })
    }
  },

  //点击按钮显示
  popup: function (e) {
    this.setData({
      showModal: true
    })
    // console.log('popup_showModal', this.data.showModal);
    //实现倒计时
    var inter = setInterval(
      function () {
        this.setData({
          smsFlag: true,
          sendTime: this.data.snsMsgWait,
          snsMsgWait: this.data.snsMsgWait - 1
        })
        // console.log('this.data.snsMsgWait', this.data.snsMsgWait)
        if (this.data.snsMsgWait === -1) {
          this.hidepopup()
        }
        if (this.data.snsMsgWait < 0) {
          clearInterval(inter)
          this.setData({
            snsMsgWait: 3,
            smsFlag: false
          })
        }
      }.bind(this),
      1000
    )
  },
  //点击隐藏图标
  hidepopup: function () {
    this.setData({
      showModal: false
    })
    //在需要退出小程序的地方调用添加下面代码即可(js文件中)
    // wx.exitMiniProgram({success: (res) => {}})
  },
  Exit: function () {
    wx.exitMiniProgram({
      success: (res) => {
        console.log('用户点击退出小城序')
      }
    })
  },
  CleanData: function () {
    //修改 清除缓存
  },
  onHide: function () {
    const innerAudioContext = wx.createInnerAudioContext()
    innerAudioContext.stop()
    innerAudioContext.destroy()
  }
})
