const app = getApp()
import { debounce, getDetectFileType } from '../../utils/util/util'
import FileUploader from '../../utils/upload/upload_file_chunk'

Page({
  data: {
    // 是否显示信息
    showSystemInfo: false,
    //系统信息
    systemInfo: null,
    //系统信息字符串展示
    systemInfoStr: null,
    //是否是K8容器中运行的小程序
    isKEightDevice: false,

    /**
     * 初始化刷脸服务
     */
    //入参打印
    initObj: null,
    //结果
    initResult: null,
    //初始化入参
    initParams: {},

    /**
     * 调用1：N刷脸
     */
    //入参打印
    oneVNObj: null,
    //结果
    oneVNResult: null,
    //调用服务入参
    oneVNParams: {},
    //服务编码
    oneVNServiceCode: "",

    /**
     * 调用订阅授权服务
     */
    //入参打印
    authObj: null,
    //结果
    authResult: null,
    //调用服务入参
    authParams: {},
    //服务编码
    authServiceCode: "",

    downloadFileChunkItem: {
      status: '',
      errorTips: '',
      chunkIndex: 0,
      totalChunks: 0,
      url: '',
      fileType: '',
      fileName: '测试',
      originalUrl: 'https://tx.hz-hanghui.com:8088/yx-fyzd/file/img/localPreviewPageUrl.jpg',
      // originalUrl: 'https://vipmp4i.vodfile.m1905.com/202411161120/d92631080d326316a8d249a67161916d/video/moss/2024/11/15/v202411152H376OYBGLJZWLWT/v202411152H376OYBGLJZWLWT.mp4',
      // 'https://vipmp4i.vodfile.m1905.com/202411161120/d92631080d326316a8d249a67161916d/video/moss/2024/11/15/v202411152H376OYBGLJZWLWT/v202411152H376OYBGLJZWLWT.mp4'
    },
    videoChunkItem: {
      chunkIndex: 0,
      totalChunks: 0,
      url: '',
      width: 0,
      height: 0,
    },

    activeTab: 0,
    menuList: [
      /*{
        name: 'web-view',
        id: -1,
        ampe_params: []
      },*/
      {
        name: '系统信息',
        id: 0,
        ampe_params: []
      },
      {
        name: '刷脸指令',
        id: 1,
        ampe_params: [
          {
            name: "刷脸初始化请求",
            number: "A1",
            aromeCode: "",
            initParams: {
              "action": "initFace",
              "event": "open",
              "taskId": "A1",
              "params": {
                "serviceId": "",
                "query": "",
                "scope": ""
              }
            }
          },
          {
            name: "唤起刷脸请求1:N",
            number: "A2",
            aromeCode: "",
            initParams: {
              "action": "getFaceInfo",
              "event": "open",
              "taskId": "A2"
            }
          },
          {
            name: "唤起刷脸请求1:1",
            number: "A3",
            aromeCode: "",
            initParams: {
              "action": "getFaceInfoPersonCard",
              "event": "open",
              "taskId": "A3",
              "params": {
                "certName": "",
                "certNo": "",
                "certPhotoBase64Str": ""
              }
            }
          },
          {
            name: '刷脸入库',
            tips: '调用刷脸（老年食堂）',
            aromeCode: "",
            number: "A4",
            initParams: {
              "action": "doStorageFaceInfo",
              "event": "open",
              "taskId": "A4",
              "params": {
                "appid": "2021003181682188",
                "orgOutId": "hanghuijingquTest3",
                "componentOutId": "day_label_sign_online",
                "isvPid": "2088721034139660"
              }
              // "params": {
              //   "appId":"2021004147600083",
              //   "orgOutId":"huanggangzhangzheshitang",
              //   "componentOutId":"day_label_sign_online",
              //   "isvPid":"2088741779695636"
              // }
            }
          },
          {
            name: '刷证/输证⼊库',
            tips: '调用刷证/输证入库（老年食堂）',
            aromeCode: "",
            number: "A5",
            initParams: {
              "action": "doStorageFaceInfo",
              "event": "open",
              "taskId": "A5",
              "params": {
                "uniqueId": "2021003181682188",
                "name": "XXXXXX",
                "certNo": "XXXXXX",
                "phone": "XXXXXX"
              }
            }
          },
        ]
      },
      {
        name: '刷身份证',
        id: 2,
        ampe_params: [
          {
            name: "开启刷身份证（单次）",
            number: "B1",
            aromeCode: '',
            initParams: {
              "action": "getIDCardInfo",
              "event": "open",
              "taskId": "B1",
              "params": {
                "infoType": "base,photo,other"
              }
            }
          },
          {
            name: "关闭刷身份证（单次）",
            number: "B2",
            aromeCode: '',
            initParams: {
              "action": "closeIDCardInfo",
              "event": "open",
              "taskId": "B2",
              "params": {
                "infoType": "base,photo,other"
              }
            }
          },
          {
            name: "身份证持续监听",
            aromeCode: "initIDCardListener",
            number: "B3",
            initParams: {}
          },
        ]
      },
      {
        name: '二维码',
        id: 3,
        ampe_params: [
          {
            name: "开启刷⼆维码（单次）",
            number: "C1",
            aromeCode: "",
            initParams: {
              "action": "getQRCode",
              "event": "open",
              "taskId": "C1"
            }
          },
          {
            name: "二维码持续监听",
            aromeCode: "initQRListener",
            number: "C2",
            initParams: {}
          },
        ]
      },
      {
        name: '麦克风',
        id: 4,
        ampe_params: [
          {
            name: "开启⻨克⻛（持续）",
            tips: 'app持续发录⾳数据给小程序',
            number: "D1",
            aromeCode: "",
            initParams: {
              "action": "startMicrophoneListener",
              "event": "open",
              "taskId": "D1",
              "params": {
                "intervalTime": 1000,//2.9.0版本及之后版本已废弃该字段
                "isMicrophoneSourceData": false //2.9.8版本添加
              }
            }
          },
          {
            name: "停⽌⻨克⻛监听",
            number: "D3",
            aromeCode: "",
            initParams: {
              "action": "stopMicrophoneListener",
              "event": "open",
              "taskId": "D3",
            }
          },
          {
            name: "⻨克⻛持续监听",
            aromeCode: "initMicrophoneListener",
            number: "D2",
            isCumulative: false,
            initParams: {}
          },
        ]
      },
      {
        name: '设备信息',
        id: 5,
        ampe_params: [
          {
            name: "开启设备信息请求",
            number: "E1",
            aromeCode: "",
            initParams: {
              "action": "getDeviceInfo",
              "event": "open",
              "taskId": "E1",
            }
          },
        ]
      },
      {
        name: '语音播报请求',
        id: 6,
        ampe_params: [
          {
            name: "语⾳播报请求",
            aromeCode: "",
            number: "F1",
            initParams: {
              "action": "speech",
              "event": "open",
              "taskId": "F1",
              "params": {
                "text": "要播报的⽂字内容",
                "pitch": 1.0,
                "rate": 1.0
              }
            }
          },
          {
            name: "语音停止请求",
            aromeCode: "",
            number: "F2",
            initParams: {
              "action": "speechStop",
              "event": "open",
              "taskId": "F2",
            }
          },
        ]
      },
      {
        name: '手输身份证号',
        id: 7,
        ampe_params: [
          {
            name: "手输身份证号",
            aromeCode: "",
            number: "G1",
            initParams: {
              "action": "enterIDNumber",
              "event": "open",
              "taskId": "G1"
            }
          },
        ]
      },
      {
        name: '小票打印机小程序',
        id: 8,
        ampe_params: [
          {
            name: "小票打印机小程序",
            number: "H1",
            aromeCode: "",
            initParams: {
              "action": "receiptPrinting",
              "event": "open",
              "taskId": "H1",
              "params": {
                "printList": [{
                  "text": "测试⽂字打印",
                  "textSize": 26,
                  "bold": false,
                  "algin": "left"
                }, {
                  "imageBase64": "测试图⽚打印，实际传⼊base64图⽚值/9j/4AAQSkZJRgABAgAAAQABABntRS5Sj//",
                  "width": 376,
                  "height": 376
                }]
              }
            }
          },
        ]
      },
      {
        name: '小程序超时',
        id: 9,
        ampe_params: [
          {
            name: "超时监听",
            aromeCode: "ampeOperationTimeout",
            number: "I1",
            initParams: {}
          },
        ]
      },
      {
        name: '红外感应',
        id: 10,
        ampe_params: [
          {
            name: "开启红外感应监听",
            aromeCode: "",
            number: "J1",
            initParams: {
              "action": "startInfraredInductionListener",
              "event": "open",
              "taskId": "J1",
              "params": {
                "intervalTime": 3000
              }
            }
          },
          {
            name: "停⽌红外感应监听",
            aromeCode: "",
            number: "J3",
            initParams: {
              "action": "stopInfraredInductionListener",
              "event": "open",
              "taskId": "J3",
            }
          },
          {
            name: "红外感应持续监听",
            aromeCode: "initInfraredInductionListener",
            number: "J2",
            initParams: {}
          },
        ]
      },
      {
        name: '双屏异显',
        id: 11,
        ampe_params: [
          {
            name: "副屏显示不同⻚⾯",
            aromeCode: "",
            number: "K1",
            initParams: {
              "action": "openSecondaryScreen",
              "event": "open",
              "taskId": "K1",
              "params": {
                "secondaryScreenBase64": "https://tx.hz-hanghui.com:8088/yx-fyzd/file/upload/imagesnew/20241107/570733822954438656.png"
              }
            }
          },
          {
            name: "关闭副屏显示",
            aromeCode: "",
            number: "K2",
            initParams: {
              "action": "closeSecondaryScreen",
              "event": "close",
              "taskId": "K2",
            }
          },
          {
            name: "获取副屏显示/关闭的状态",
            aromeCode: "",
            number: "K3",
            initParams: {
              "action": "getSecondaryScreenState",
              "event": "open",
              "taskId": "K3",
            }
          },
        ]
      },
      {
        name: '社保卡',
        id: 12,
        ampe_params: [
          {
            name: '读取社保卡信息（单次）',
            aromeCode: "",
            number: "L1",
            initParams: {
              "action": "getSocialSecurityCardInfo",
              "event": "open",
              "taskId": "K3",
            }
          },

          {
            name: '获取社保卡配置信息（单次）',
            aromeCode: "",
            number: "L2",
            initParams: {
              "action": "socialSecurityCardConfig",
              "event": "open",
              "taskId": "K3",
            }
          },
          {
            name: '开启社保卡读取监听（持续）',
            aromeCode: "socialSecurityCardListener",
            number: "L3",
            initParams: {}
          },
        ]
      },
      {
        name: 'NFC',
        id: 13,
        ampe_params: [
          {
            name: '启动NFC轮询A',
            aromeCode: "",
            number: "M1-1",
            initParams: {
              "action": "startCPUCardLoopRead",
              "event": "open",
              "taskId": "M1-1",
              "params": {
                "intervalTime": "5000",
              }
            }
          },
          {
            name: '启动NFC轮询B',
            aromeCode: "",
            number: "M1-2",
            initParams: {
              "action": "startCPUCardLoopRead",
              "event": "open",
              "taskId": "M1-2",
              "params": {
                "intervalTime": "5000",
                "isComeBackFailed": true //2.9.8版本添加
              }
            }
          },
          {
            name: '停止NFC轮询',
            aromeCode: "",
            number: "M3",
            initParams: {
              "action": "stopCPUCardLoopRead",
            }
          },
          {
            name: 'NFC监听',
            aromeCode: "CPUCardListener",
            number: "M2",
            initParams: {}
          },
          {
            name: '单次读取NFC',
            aromeCode: "",
            number: "M4",
            initParams: {
              "action": "readOnceCPUCardInfo",
            }
          },
          {
            name: '发送NFC-APDU命令',
            aromeCode: "",
            number: "M5",
            initParams: {
              "action": "sendCPUCardCommand",
              "event": "open",
              "taskId": "M5",
              "params": {
                "commandApdu": "0084000008",
                "type": "1",
                "slot": "1"
              }
            }
          },
          {
            name: '发送NFC-APDU命令集',
            aromeCode: "",
            number: "M6",
            initParams: {
              "action": "sendCPUCardApduCommands",
              "event": "open",
              "taskId": "M6",
              "params": {
                "commandApdus": ["0084000008", "0084000008", "0084000008"],
                "type": "1",
                "slot": "1"
              }
            }
          },
          {
            name: '冷复位',
            aromeCode: "",
            number: "M7",
            initParams: {
              "action": "psamCardColdReset",
              "event": "open",
              "taskId": "M7",
              "params": {
                "slot": "1"
              }
            }
          },
          {
            name: '启动蜂鸣器',
            aromeCode: "",
            number: "M8",
            initParams: {
              "action": "startBuzzer",
              "event": "open",
              "taskId": "M8",
              "params": {
                "beep": "50",
              }
            }
          },
        ]
      },
      {
        name: 'M1卡',
        id: 14,
        ampe_params: [
          {
            name: '关闭循环读取M1卡',
            aromeCode: "",
            number: "N3",
            initParams: {
              "action": "doM1Listener",
              "event": "stop",
              "taskId": "N3",
            }
          },
          {
            name: '开始循环读取M1卡',
            aromeCode: "",
            number: "N2",
            initParams: {
              "action": "doM1Listener",
              "event": "start",
              "taskId": "N2",
              "params": {
                //读取的扇区
                "sector": 15,
                //读取的块:支持指定多个块区,返回的数据会将0,1,2,3块区的内容按顺序拼接返回
                "block": "0,1,2,3",
                //读取密钥
                "secretKey": "FFFFFFFFFFFF"
              }
            }
          },
          {
            name: 'M1卡读取监听',
            aromeCode: "initM1Listener",
            number: "N1",
            initParams: {}
          },
          {
            name: '单次M1卡写入',
            aromeCode: "",
            number: "N4",
            initParams: {
              "action": "doM1Write",
              "event": "",
              "taskId": "N4",
              "params": {
                //写入的扇区
                "sector": 15,
                //写入的块: 只能指定一个块区,如需要写入多个块,可以调用多次
                "block": 0,
                //写入密钥
                "secretKey": "FFFFFFFFFFFF",
                //写入内容
                "content": "字符串utf-8"
              }
            }
          },
          {
            name: '擦除M1卡内容',
            aromeCode: "",
            number: "N5",
            initParams: {
              "action": "doM1Clear",
              "event": "",
              "taskId": "N5",
              "params": {
                //清空的扇区
                "sector": 15,
                //清空的块: 只能指定一个块区,如需要清空多个块,可以调用多次
                "block": 0,
                //写入密钥
                "secretKey": "FFFFFFFFFFFF",
                //填入的初始值-Number
                "value": 0
              }
            }
          },
        ]
      },
      {
        name: 'ASR(数科版)',
        id: 20,
        ampe_params: [
          {
            name: '初始化语音识别配置',
            aromeCode: "",
            number: "S1",
            initParams: {
              "action": "doASR",
              "event": "init",
              "taskId": "3",
              "params": {
                //租户ID,咨询服务商提供
                "tenantCode": "hanghui",
                //识别语种,非必填,默认中文-cn;英⽂-en,⻄班⽛⽂-es,菲律宾文-phl,印尼⽂-id
                "lang": "cn"
              }
            }
          },
          {
            name: '声明语音识别监听回调函数',
            aromeCode: "initASR",
            number: "S2",
            initParams: {}
          },
          {
            name: '开始语音识别',
            aromeCode: "",
            number: "S3",
            initParams: {
              "action": "doASR",
              "event": "start",
              "taskId": "S3",
              "params": {}
            }
          },
          {
            name: '停止语音识别',
            aromeCode: "",
            number: "S4",
            initParams: {
              "action": "doASR",
              "event": "stop",
              "taskId": "S4",
              "params": {}
            }
          },
        ]
      },
      {
        name: '关闭小程序',
        id: 15,
        ampe_params: [
          {
            name: '关闭小程序',
            aromeCode: "",
            number: "O1",
            initParams: {
              "action": "deviceConfig",
              "event": "open",
              "taskId": "O1",
              "params": {
                "deviceConfig": {
                  "exitApplet": 1
                }
              }
            }
          },
        ]
      },
      {
        name: '显示/隐藏导航栏',
        id: 16,
        ampe_params: [
          {
            name: '开启导航栏（仅本次运⾏有效）',
            aromeCode: "",
            number: "P1",
            initParams: {
              "action": "deviceConfig",
              "event": "open",
              "taskId": "P1",
              "params": {
                "deviceConfig": {
                  "hideNavigationBar": 2
                }
              }
            }
          },
          {
            name: '隐藏导航栏（仅本次运⾏有效）',
            aromeCode: "",
            number: "P2",
            initParams: {
              "action": "deviceConfig",
              "event": "open",
              "taskId": "P2",
              "params": {
                "deviceConfig": {
                  "hideNavigationBar": 1
                }
              }
            }
          },
        ]
      },
      {
        name: '显示/隐藏通知栏',
        id: 17,
        ampe_params: [
          {
            name: '开启通知栏（仅本次运⾏有效）',
            aromeCode: "",
            number: "Q1",
            initParams: {
              "action": "deviceConfig",
              "event": "open",
              "taskId": "Q1",
              "params": {
                "deviceConfig": {
                  "hideNotificationBar": 2
                }
              }
            }
          },
          {
            name: '隐藏通知栏（仅本次运⾏有效）',
            aromeCode: "",
            number: "Q2",
            initParams: {
              "action": "deviceConfig",
              "event": "open",
              "taskId": "Q2",
              "params": {
                "deviceConfig": {
                  "hideNotificationBar": 1
                }
              }
            }
          },
        ]
      },
      {
        name: '右上角悬浮关闭小程序按钮',
        id: 18,
        ampe_params: [
          {
            name: '右上角悬浮关闭小程序按钮（根据指定AppId）',
            aromeCode: "",
            number: "R1",
            initParams: {
              "action": "floatingExitButton",
              "event": "open",
              "taskId": "R1",
              "params": {
                "isOpen": true,
                "appId": "123456"
              }
            }
          },
        ]
      },
      {
        name: '扬声器',
        id: 20,
        ampe_params: [
          {
            name: '获取扬声器音量',
            aromeCode: "",
            number: "R1",
            initParams: {
              "action": "loudspeaker",
              "event": "get",
              "taskId": "R1",
              "params": {

              }
            }
          }, {
            name: '设置扬声器音量',
            aromeCode: "",
            number: "R1",
            initParams: {
              "action": "loudspeaker",
              "event": "set",
              "taskId": "R1",
              "params": {
                "volume": "0.95"
              }
            }
          }, {
            name: '获取缓存文件列表',
            aromeCode: "",
            number: "z1",
            initParams: {
              "action": "storage",
              "event": "get",
              "taskId": "z1",
              "params": {}
            }
          }, {
            name: '缓存文件',
            aromeCode: "",
            number: "z2",
            initParams: {
              "action": "storage",
              "event": "set",
              "taskId": "z2",
              "params": {
                fileName: "夏伟浩.mp4",
                fileUrl: "https://wallpaper-static.cheetahfun.com/wallpaper/sites/dynamics/vm5.mp4"
              }
            }
          }, {
            name: '移除缓存文件',
            aromeCode: "",
            number: "z3",
            initParams: {
              "action": "storage",
              "event": "remove",
              "taskId": "z3",
              "params": {
                fileName: "夏伟浩",
                fileType: ".mp4",
                path: "/storage/emulated/0/Download/夏伟浩.mp4"
              }
            }
          },
        ]
      },
      // {
      //   name: '附件上传',
      //   id: 19,
      //   ampe_params: []
      // },
    ],

  },
  onLoad(query) {
    this.setData({
      activeTab: 0,
    })
    my.pageScrollTo({
      selector: `.menu-box-0`,
      // offsetTop: -12,//偏移的位置
      duration: 300,
    });
  },
  // 切换 Menu
  onMenuChange(e) {
    console.log(e)
    let currentItem = e.currentTarget.dataset.item;
    this.setData({
      activeTab: currentItem.id,
    })
    my.pageScrollTo({
      selector: `.menu-box-${currentItem.id}`,
      // offsetTop: -12,//偏移的位置
      duration: 300,
    });
  },
  //切换系统信息的显示
  changeMsg() {
    let { showSystemInfo } = this.data;
    this.setData({
      showSystemInfo: !showSystemInfo
    })
  },
  //初始化接口
  doInit() {
    let that = this
    let params = JSON.parse(JSON.stringify(that.data.initParams))

    this.setData({
      initObj: JSON.stringify(params)
    })
    my.call("aromeInitBpaasService", params, (res) => {
      that.setData({
        initResult: JSON.stringify(res)
      })
    })
  },
  //调用刷脸
  doOneVN() {
    let that = this
    let params = JSON.parse(JSON.stringify(that.data.oneVNParams))

    that.setData({
      oneVNObj: JSON.stringify(params) + "----服务编码: " + that.data.oneVNServiceCode
    })
    console.log(JSON.stringify(params) + "----服务编码: " + that.data.oneVNServiceCode)
    my.call('aromeStartBpaasService', {
      serviceCode: that.data.oneVNServiceCode,
      params: params,
      taskId: parseInt(Math.random() * 1000000 + 1)
    }, (res) => {
      that.setData({
        oneVNResult: JSON.stringify(res)
      })
      app.data.authParams.user_id = res.alipayUid || ""
      app.data.authParams.ftoken = res.ftoken || ""
    })
  },
  //调用授权服务
  doAuth() {
    let that = this
    let params = JSON.parse(JSON.stringify(that.data.authParams))

    that.setData({
      authObj: JSON.stringify(params) + "----服务编码: " + that.data.authServiceCode
    })
    my.call('aromeStartBpaasService', {
      serviceCode: that.data.authServiceCode,
      params: params,
      taskId: parseInt(Math.random() * 1000000 + 1)
    }, (res) => {
      that.setData({
        authResult: JSON.stringify(res)
      })
    })
  },
  //关闭结果
  close(e) {
    let type = e.currentTarget.dataset.type
    switch (type) {
      case "init":
        this.setData({
          initResult: null,
          initObj: null
        })
        break;
      case "oneVN":
        this.setData({
          oneVNResult: null,
          oneVNObj: null
        })
        break;
      case "auth":
        this.setData({
          authObj: null,
          authResult: null
        })
        break;
      case "imgUpload":
        this.setData({
          'downloadFileChunkItem.status': '',
          'downloadFileChunkItem.errorTips': '',
          'downloadFileChunkItem.chunkIndex': 0,
          'downloadFileChunkItem.totalChunks': 0,
          'downloadFileChunkItem.url': '',
          'downloadFileChunkItem.fileType': '',
          'downloadFileChunkItem.fileName': '测试',
          'downloadFileChunkItem.originalUrl': 'https://tx.hz-hanghui.com:8088/yx-fyzd/file/img/localPreviewPageUrl.jpg',
          // 'downloadFileChunkItem.originalUrl': 'https://vipmp4i.vodfile.m1905.com/202411161120/d92631080d326316a8d249a67161916d/video/moss/2024/11/15/v202411152H376OYBGLJZWLWT/v202411152H376OYBGLJZWLWT.mp4',
        })
        break;
      case "videoUpload":
        this.setData({
          'videoChunkItem.chunkIndex': 0,
          'videoChunkItem.totalChunks': 0,
          'videoChunkItem.url': '',
          'videoChunkItem.width': 0,
          'videoChunkItem.height': 0,
        })
        break;

      default:
        break;
    }
  },
  //进入设置页
  doSetting(e) {
    let route = {
      init: "/pages/setInit/setInit",
      oneVN: "/pages/setOneVN/setOneVN",
      auth: "/pages/setAuth/setAuth"
    }
    let type = e.currentTarget.dataset.type
    my.navigateTo({
      url: route[type]
    })
  },
  //更新配置信息
  updateConfig() {
    this.data.initParams = app.data.initParams;

    this.data.oneVNParams = app.data.oneVNParams;
    this.data.oneVNServiceCode = app.data.oneVNServiceCode;

    this.data.authParams = app.data.authParams;
    this.data.authServiceCode = app.data.authServiceCode;
  },
  handleChange(e) {
    let field = e.currentTarget.dataset.field;
    let json = e.detail.value
    console.log(json)
    this.setData({
      [`downloadFileChunkItem.${field}`]: json
    })
  },
  async handleUpload(e) {
    let type = e.currentTarget.dataset.type;
    let _this = this
    // my.downloadFile({
    //   url: 'http://img.alicdn.com/tfs/TB1x669SXXXXXbdaFXXXXXXXXXX-520-280.jpg',
    //   success(res) {
    //     console.log('downloadFile success：',res.apFilePath,res.tempFilePath); // apFilePath 与 tempFilePath 等价
    //   },
    //   fail(res) {
    //     console.log('downloadFile fail：',res);
    //   },
    // });
    // 数据重置
    this.setData({
      'downloadFileChunkItem.status': 'padding',
      'downloadFileChunkItem.chunkIndex': 0,
      'downloadFileChunkItem.totalChunks': 0,
      'downloadFileChunkItem.url': '',
      'downloadFileChunkItem.fileType': '',
    })
    const uploader = new FileUploader({
      url: _this.data.downloadFileChunkItem.originalUrl,  // 文件路径
      chunkSize: 512 * 1024, // 每片大小为 512KB
      fileName: _this.data.downloadFileChunkItem.fileName,  // 文件名
      retryLimit: 3 // 每片的最大重试次数
    });
    // 开始上传
    await uploader.startUpload((status, res) => {
      console.log('callback', res)
      _this.setData({
        'downloadFileChunkItem.status': status,
      })
      if (status == 'success') {
        let params = res.params
        _this.setData({
          'downloadFileChunkItem.chunkIndex': params.currentIndex + 1,
          'downloadFileChunkItem.totalChunks': params.totalChunks,
        })
      } else {
        _this.setData({
          'downloadFileChunkItem.errorTips': res,
        })
      }
    })
    _this.setData({
      'downloadFileChunkItem.url': uploader.filePath,
      'downloadFileChunkItem.fileType': (uploader.fileType || '').match(/^[^\/]+/)[0],
    })
    console.log(uploader.filePath)
    /*    if (type == 'img') {
          my.chooseImage({
            // 可以根据您的业务按需选择使用 ['album'] 或 ['camera'] 或 ['album', 'camera']
            sourceType: ['album'],
            success: function (res) {
              console.log(res);
              let tempFilePath = res.tempFilePaths[0]
              let arr = []
              const uploader = new FileUploader({
                filePath: 'https://tx.hz-hanghui.com:8088/yx-fyzd/file/img/localPreviewPageUrl.jpg',  // 文件路径
                chunkSize: 512 * 1024, // 每片大小为 512KB
                fileName: '测试图片',  // 文件名
                // retryLimit: 3 // 每片的最大重试次数
              });

              // 开始上传
              uploader.startUpload((e) => {
                console.log('callback', e)
                _this.setData({
                  'imgChunkItem.chunkIndex': e.chunkIndex + 1,
                  'imgChunkItem.totalChunks': e.totalChunks,
                })
              })
              _this.setData({
                'imgChunkItem.url': tempFilePath,
              })
              // const fs = my.getFileSystemManager();
              // fs.readFile({
              //   // readFile 不传入 encodding 参数，则以 ArrayBuffer 方式读取
              //   filePath: `${res.tempFilePaths[0]}`,
              //   success: ({ data }) => {
              //     console.log(data)
              //     const arrayBuffer = data; // 文件的 ArrayBuffer 数据
              //     const base64 = my.arrayBufferToBase64(arrayBuffer);
              //     _this.setData({
              //       fileUrl: `data:image/png;base64,${base64}`
              //     })
              //     console.log("base64", `data:image/png;base64,${base64}`);
              //   },
              // });
            },
            fail: function (err) {
              console.log(err);
            },
          });
        } else if (type == 'video') {
          my.chooseVideo({
            // 可以根据您的业务按需选择使用 [‘camera'] 或者 ['album', 'camera']
            sourceType: ['album'],
            success: async function (res) {
              console.log(res);
              const tempFilePath = res.tempFilePath;
              const uploader = new FileUploader({
                filePath: tempFilePath,  // 文件路径
                chunkSize: 512 * 1024, // 每片大小为 512KB
                fileName: '测试视频',  // 文件名
                retryLimit: 3 // 每片的最大重试次数
              });

              // 开始上传
              uploader.startUpload((e) => {
                console.log('callback', e)
                _this.setData({
                  'videoChunkItem.chunkIndex': e.chunkIndex + 1,
                  'videoChunkItem.totalChunks': e.totalChunks,
                })
              })
              _this.setData({
                'videoChunkItem.url': tempFilePath,
                'videoChunkItem.width': res.width,
                'videoChunkItem.height': res.height,
              })
              // // 2. 读取文件内容为 ArrayBuffer
              // const fileManager = my.getFileSystemManager();
              // fileManager.readFile({
              //   filePath: tempFilePath,
              //   success: ({ data }) => {
              //     const arrayBuffer = data; // 文件的 ArrayBuffer 数据
              //     console.log(arrayBuffer)
              //   },
              //   fail: (err) => {
              //     console.error('文件读取失败', err);
              //   }
              // });
            },
            fail: function (err) {
              console.log(err);
            },
          });
        }*/
  },
  goToWebView() {
    // my.getLocation({
    //   type: 1, // 获取经纬度和省市区县数据
    //   success: (res) => {
    //     console.log(res);
    //     my.showModal({
    //       title: '提示',
    //       content: res && JSON.stringify(res),
    //       success: function(res) {
    //         console.log(res);
    //       },
    //       fail: function(err) {
    //         console.log(err);
    //       }
    //     });
    //   },
    //   fail: (error) => {
    //     console.error('定位失败: ', JSON.stringify(error));
    //   },
    //   complete: (res) => {
    //     console.log(res);
    //   },
    // });
    my.navigateTo({
      url: '/pages/digitalHumans/digitalHumans'
    })
  },
  onReady() {
    // 页面加载完成
  },
  onShow() {
    this.setData({
      systemInfo: app.data.systemInfo,
      systemInfoStr: JSON.stringify(app.data.systemInfo),
      isKEightDevice: app.data.isKEightDevice,
      initObj: null,
      initResult: null,
      oneVNObj: null,
      oneVNResult: null,
      authObj: null,
      authResult: null
    });
    this.updateConfig();
  },
  onHide() {
    // 页面隐藏
  },
  onUnload() {
    // 页面被关闭
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
  },
  onReachBottom() {
    // 页面被拉到底部
  },
  onShareAppMessage() {
    // 返回自定义分享信息
  },
  // 页面的 onPageScroll 事件处理函数
  onPageScroll: debounce(function (e) {
    // 创建选择器对象
    const query = my.createSelectorQuery();
    console.log(e)
    query.selectAll('.scroll-item')
      .boundingClientRect()
      .exec((res) => {
        // console.log('ssssssssssssssssssssss===', res[0]);
        let obj = (res[0] || []).filter(fv => fv.bottom > 0)[0] || {}
        console.log(obj, obj.dataset.id)
        this.setData({
          activeTab: obj.dataset.id
        })
        // bottom height
      });
  }, 100),
});
