// pages/completion/completion.js
const {
  entryDetail,
  API_BASE_URL,
  install,
  getActualCapacity, 
  IMG_BASE_URL,
  installZc,
  DEV,
  getProviceCodeList,
  createQrcode,getFormSet,findTypeReferenceListNew
} = require('../../../api/api')
const utilAddWatermark = require('../../../utils/addWatermark')
const utilGetLocation = require('../../../utils/getLocation')
import Dialog from '@vant/weapp/dialog/dialog';
Page({
  data: {
    IMG_BASE_URL: IMG_BASE_URL,
    capture: ['album','camera'],
    canvasHeight: 0,
    canvasWidth: 0,
    changeAddressType: 1, //默认购售电地址一致
    DEV: DEV,
    DEVACCOUNT: wx.getStorageSync('loginName'),
    completeEnable: false, //完工按钮是否可以点击，默认false不可点击
    //安装
    photoTips: [
      // {
      //   sampleGraph: '',
      //   showKey: 'safety_warning_img2',
      //   must: '0',
      //   status: '0',
      //   key:'safetyWarningImg2',
      //   num: 15,
      //   title: '三级安全教育卡',
      //   message: ''
      // },{
      //   sampleGraph: '',
      //   showKey: 'kg_condition_files',
      //   must: '0',
      //   status: '0',
      //   key:'kgConditionFiles',
      //   num: 15,
      //   min: 1,
      //   title: '安全防护措施合照照片',
      //   message: ''
      // },
      //华融
      {
        sampleGraph: '',
        showKey: 'other_imgs5',
        must: '0',
        status: '0',
        key:'otherImgs5',
        num: 15,
        title: '水槽细节照片',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'other_imgs6',
        must: '0',
        status: '0',
        key:'otherImgs6',
        num: 15,
        title: '落水管照片',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'other_imgs7',
        must: '0',
        status: '0',
        key:'otherImgs7',
        num: 15,
        title: '假梁-斜梁方向',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'other_imgs8',
        must: '0',
        status: '0',
        key:'otherImgs8',
        num: 15,
        title: '并网箱逆变器防雨罩照片',
        message: ''
      },
      //广发
      {
        sampleGraph: '',
        showKey: 'safety_warning_img2_03',
        must: '0',
        status: '0',
        key:'safetyWarningImg2',
        num: 15,
        title: '施工安全图-三级安全教育',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'safety_warning_img3',
        must: '0',
        status: '0',
        key:'safetyWarningImg3',
        num: 15,
        title: '施工安全图-开工前站班会（施工安全用品：安全帽、安全绳、反光衣、工作鞋）',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'safety_warning_img',
        must: '0',
        status: '0',
        key:'safetyWarningImg',
        num: 15,
        title: '施工安全图-安全警示牌',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'safety_disclose_doc_img',
        must: '0',
        status: '0',
        key:'safetyDiscloseDocImg',
        num: 15,
        title: '施工安全图-安全技术交底书',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'zj_img10',
        must: '0',
        status: '0',
        key:'zjImg10',
        num: 9,
        min: 3,
        title: '基础安装-螺栓孔洞防水图',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'zj_img11',
        must: '0',
        status: '0',
        key:'zjImg11',
        num: 15,
        title: '基础安装-柱脚防水完工图',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'zj_img5_03',
        must: '0',
        status: '0',
        key:'zjImg5',
        num: 15,
        title: '支架安装图-支架安装完成VR图',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'zj_img8',
        must: '0',
        status: '0',
        key:'zjImg8',
        num: 15,
        title: '支架安装图-支架方阵（东向西完工照）',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'zj_img9',
        must: '0',
        status: '0',
        key:'zjImg9',
        num: 15,
        title: '支架安装图-支架方阵（北向南完工照）',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'zj_img4_03',
        must: '0',
        status: '0',
        key:'zjImg4',
        num: 15,
        title: '支架安装图-立柱东西间距、南北间距（带尺寸）',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'zj_img12',
        must: '0',
        status: '0',
        key:'zjImg12',
        num: 15,
        title: '支架安装图-斜梁悬挑（南）',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'zj_img13',
        must: '0',
        status: '0',
        key:'zjImg13',
        num: 15,
        title: '支架安装图-斜梁悬挑（北）',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'zj_img14',
        must: '0',
        status: '0',
        key:'zjImg14',
        num: 15,
        title: '支架安装图-檀条悬挑（东）',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'zj_img15',
        must: '0',
        status: '0',
        key:'zjImg15',
        num: 15,
        title: '支架安装图-檀条悬挑（西）',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'jd_img4_03',
        must: '0',
        status: '0',
        key:'jdImg4',
        num: 15,
        title: '支架接地图-支架接地',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'component_img3',
        must: '0',
        status: '0',
        key:'componentImg3',
        num: 15,
        title: '组件航拍俯视照片',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'component_img4',
        must: '0',
        status: '0',
        key:'componentImg4',
        num: 15,
        title: '组件安装完成VR视图',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'bk_img1',
        must: '0',
        status: '0',
        key:'bkImg1',
        num: 15,
        title: '边框接地图-边框与边框接地',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'component_img1_03',
        must: '0',
        status: '0',
        key:'componentImg1',
        num: 15,
        title: '边框接地图-组件安装倾角',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'bk_img2',
        must: '0',
        status: '0',
        key:'bkImg2',
        num: 15,
        title: '边框接地图-边框与支架接地',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'bk_img3',
        must: '0',
        status: '0',
        key:'bkImg3',
        num: 15,
        title: '边框接地图-其他图片',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'yk_img1',
        must: '0',
        status: '0',
        key:'ykImg1',
        num: 15,
        title: '压块或背压板照片',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'dc_imgs_03',
        must: '0',
        status: '0',
        key:'dcImgs',
        num: 15,
        title: '逆变器安装图-整体外观及走线及采集器（离地高度）',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'nbq_plate_img_03',
        must: '0',
        status: '0',
        key:'nbqPlateImg',
        num: 15,
        title: '逆变器安装图-铭牌',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'total_imgs_03',
        must: '0',
        status: '0',
        key:'totalImgs',
        num: 15,
        title: '逆变器安装图-接地情况',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'nbq_zlc_img',
        must: '0',
        status: '0',
        key:'nbqZlcImg',
        num: 15,
        title: '逆变器安装图-逆变器交流侧',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'open_way_voltage_imgs_03',
        must: '0',
        status: '0',
        key:'openWayVoltageImgs',
        num: 15,
        title: '逆变器安装图-组串开路电压照片',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'nbq_zb_img_03',
        must: '0',
        status: '0',
        key:'nbqZbImg',
        num: 15,
        title: '并网箱安装图-外观及走线（离地高度）',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'bw_inner_img_03',
        must: '0',
        status: '0',
        key:'bwInnerImg',
        num: 15,
        title: '并网箱安装图-并网箱内部全景',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'bw_jd_img',
        must: '0',
        status: '0',
        key:'bwJdImg',
        num: 15,
        title: '并网箱安装图-接地情况',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'fix_other_img_03',
        must: '0',
        status: '0',
        key:'fixOtherImg',
        num: 15,
        title: '线缆走向（屋顶、下墙）、线缆保护管（或桥架）敷设及固定照片',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'size_measure_imgs_03',
        must: '0',
        status: '0',
        key:'sizeMeasureImgs',
        num: 15,
        title: '电缆桥架内部电缆照片',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'jd_img8',
        must: '0',
        status: '0',
        key:'jdImg8',
        num: 15,
        title: '接地极图-并网箱、逆变器安装接地极',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'jd_img5_03',
        must: '0',
        status: '0',
        key:'jdImg5',
        num: 15,
        title: '接地极图-支架接地电阻阻值(近景)',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'jd_img11',
        must: '0',
        status: '0',
        key:'jdImg11',
        num: 15,
        title: '接地极图-支架接地电阻测量照片(远景)',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'jd_img9',
        must: '0',
        status: '0',
        key:'jdImg9',
        num: 15,
        title: '接地极图-并网箱、逆变器安装接地电阻阻值(近景)',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'jd_img12',
        must: '0',
        status: '0',
        key:'jdImg12',
        num: 15,
        title: '接地极图-并网箱、逆变器安装接地电阻测量照片 (远景)',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'jd_img10',
        must: '0',
        status: '0',
        key:'jdImg10',
        num: 15,
        title: '接地极图-接地引下线警示做法',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'fs_img1',
        must: '0',
        status: '0',
        key:'fsImg1',
        num: 15,
        title: '防水措施图-横竖向水槽',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'fs_img2',
        must: '0',
        status: '0',
        key:'fsImg2',
        num: 15,
        title: '防水措施图-落水管走向及其固定',
        message: ''
      },{
        sampleGraph: '',
        showKey: 'fs_img3',
        must: '0',
        status: '0',
        key:'fsImg3',
        num: 15,
        title: '防水措施图-其他图片',
        message: ''
      },
      //越秀
      {
          sampleGraph: '',
          showKey: 'dzjc1',
          must: '0',
          status: '0',
          key:'dzjc1',
          num: 15,
          title: '电站基础-主屋',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'dzjc2',
          must: '0',
          status: '0',
          key:'dzjc2',
          num: 15,
          title: '电站基础-副屋',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'zj_img1',
          must: '0',
          status: '0',
          key:'zjImg1',
          num: 15,
          title: '支架正面照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'zj_img2',
          must: '0',
          status: '0',
          key:'zjImg2',
          num: 15,
          title: '支架侧视图',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'zj_img3',
          must: '0',
          status: '0',
          key:'zjImg3',
          num: 15,
          title: '支架北侧照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'zj_img4',
          must: '0',
          status: '0',
          key:'zjImg4',
          num: 15,
          title: '支架型号照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'zj_img5',
          must: '0',
          status: '0',
          key:'zjImg5',
          num: 15,
          title: '航拍图照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'component_img1',
          must: '0',
          status: '0',
          key:'componentImg1',
          num: 15,
          title: '组件倾角照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'component_img2',
          must: '0',
          status: '0',
          key:'componentImg2',
          num: 15,
          title: '组件方位角照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'size_measure_imgs',
          must: '0',
          status: '0',
          key:'sizeMeasureImgs',
          num: 15,
          title: '屋顶线缆安装照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'fix_other_img',
          must: '0',
          status: '0',
          key:'fixOtherImg',
          num: 15,
          title: '线缆下墙照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'total_imgs',
          must: '0',
          status: '0',
          key:'totalImgs',
          num: 15,
          title: '逆变器组串接入照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'bw_inner_img',
          must: '0',
          status: '0',
          key:'bwInnerImg',
          num: 15,
          title: '并网箱内部照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'dc_imgs',
          must: '0',
          status: '0',
          key:'dcImgs',
          num: 15,
          title: '逆变器安装照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'nbq_zb_img',
          must: '0',
          status: '0',
          key:'nbqZbImg',
          num: 15,
          title: '并网箱逆变器整体照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'dqsb_an_img_one',
          must: '0',
          status: '0',
          key:'dqsbAnImgOne',
          num: 15,
          title: '逆变器注册截图照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'nbq_plate_img',
          must: '0',
          status: '0',
          key:'nbqPlateImg',
          num: 15,
          title: '逆变器铭牌照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'zj_plate_img',
          must: '0',
          status: '0',
          key:'zjPlateImg',
          num: 15,
          title: '组件铭牌照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'open_way_voltage_imgs',
          must: '0',
          status: '0',
          key:'openWayVoltageImgs',
          num: 15,
          title: '开路电压图',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'jd_img1',
          must: '0',
          status: '0',
          key:'jdImg1',
          num: 15,
          title: '组件与组件之间接地照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'jd_img2',
          must: '0',
          status: '0',
          key:'jdImg2',
          num: 15,
          title: '组件与支架接地照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'jd_img3',
          must: '0',
          status: '0',
          key:'jdImg3',
          num: 15,
          title: '支架与接地扁铁连接照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'jd_img4',
          must: '0',
          status: '0',
          key:'jdImg4',
          num: 15,
          title: '接地扁铁下墙照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'jd_img5',
          must: '0',
          status: '0',
          key:'jdImg5',
          num: 15,
          title: '支架接地电阻照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'jd_img6',
          must: '0',
          status: '0',
          key:'jdImg6',
          num: 15,
          title: '电气接地电阻照片',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'zj_report',
          must: '0',
          status: '0',
          key:'zjReport',
          num:1,
          title: '自检记录报告',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'other_files',
          must: '0',
          status: '0',
          key:'otherFiles',
          num:2,
          title: '其它资料',
          message: ''
        },{
          sampleGraph: '',
          showKey: 'supplement_video_url',
          must: '0',
          status: '0',
          key:'supplementVideoUrl',
          num:5,
          title: '补充视频',
          message: ''
        },
    ],   
    data: {
      name: ""
    },
    tipShow: false,
    tipTitle: '',//示例标题
    tipMsg: '',//示例内容
    sampleGraph: '', //示例图片
    // 安装
    photo: {
      contractUrl: [], //合同
      filingDocumentPhoto: [], //备案证
      otherImgs1: [], //银行印鉴留样
      otherImgs2: [], //法定代表人/负责人签字照
      otherImgs3: [], //正脸、持笔/持印、合同签署页同框
      otherImgs4: [], //签署完成照片
      //工程信息
      dzjc1: [], //电站基础-主屋照片
      dzjc2: [], //电站基础-副屋照片
      nbqPlateImg: [],//逆变器序列号照片,逆变器1铭牌照片
      txPlateImg: [],//逆变器通讯棒照片,通讯棒1铭牌照
      zjPlateImg: [],//组件铭牌照片
      zjSnImgs:[],//组件SN
      zjImg1: [],//膨胀螺栓
      zjImg2: [],//基座安装固定
      zjImg3: [],//底座防水
      zjImg4: [],//支架基础距离房檐的距离
      zjImg5: [],//支架东向西拍摄
      zjImg6: [],//支架西向东拍摄---
      zjImg7: [],//支架南向北拍摄---
      zjImg8: [],//支架北向南拍摄---
      zjImg9: [],//支架角度----
      fixOtherImg: [], //线缆下墙照片
      componentImg1: [],//支架节点（斜支撑）
      componentImg2: [],//支架距照片（南北）
      componentImg3: [],//支架距照片（东西）
      componentImg4: [],//防风加固,1-3张
      sizeMeasureImgs: [],//方管尺寸测量---，9张      
      totalImgs: [],//并网箱、逆变器外部安装照片、接地引下线,逆变器、并网箱整体安装照片,  存在字段名逆变器和并网箱接地照
      bwInnerImg: [],//并网箱内部整体照片
      dcImgs: [], //逆变器安装照片
      nbqZbImg: [],//并网箱逆变器整体照片
      dqsbAnImgOne: [],//直流线缆保护
      dqsbAnImgTwo: [],//直流线缆固定      
      zjJdImgs: [],//引下线与支架连接点、南北坡接地连接点,2张----
      groundResistanceImgs: [],//接地电阻,1-2张-----
      zujianJdImg: [],//组件边框接地     
      openWayVoltageImgs: [],//开路电压,1-6张-----     
      directionAirImg1: [],//东向西航拍----
      directionAirImg2: [],//西向东航拍----
      directionAirImg3: [],//南向北航拍----
      directionAirImg4: [],//北向南航拍----
      zjNearImg: [],//组件近景----
      zjAngleImg: [],//组件角度----
      zjItemImg: [],//檩条出组件照片----
      waterChannelImg: [],//水槽照片----
      mediumFixImg: [],//中压固定照片----
      safetyWarningImg: [],//安全警示牌----
      safetyDiscloseDocImg: [],//现场安全交底文件----
      discloseDocImg: [],//现场交底照片----
      recordDocImg: [],//记录表----
      jdImg1: [],//组件与组件之间接地照片
      jdImg2: [],//组件与支架接地照片
      jdImg3: [],//支架与接地扁铁连接照片
      jdImg4: [],//接地扁铁下墙照片
      jdImg5: [],//支架接地电阻照片
      jdImg6: [],//电气接地电阻照片
      zjReport:[],//自检记录报告
      otherFiles: [], //其他资料
      supplementVideoUrl: [], //补充视频
      kgConditionFiles: [], //安全防护措施合照照片
      //广发
      safetyWarningImg2:[],//施工安全图-三级安全教育      
      safetyWarningImg3:[],//施工安全图-开工前站班会（施工安全用品：安全帽、安全绳、反光衣、工作鞋）
      safetyWarningImg:[],//  施工安全图-安全警示牌
      safetyDiscloseDocImg:[],// 施工安全图-安全技术交底书
      zjImg10:[],//   基础安装-螺栓孔洞防水图
      zjImg11:[],//   基础安装-柱脚防水完工图     
      zjImg8:[],//  支架安装图-支架方阵（东向西完工照）
      zjImg9:[],// 支架安装图-支架方阵（北向南完工照）      
      zjImg12:[],//  支架安装图-斜梁悬挑（南）
      zjImg13:[],// 支架安装图-斜梁悬挑（北）
      zjImg14:[],//  支架安装图-檀条悬挑（东）
      zjImg15:[],// 支架安装图-檀条悬挑（西）       
      componentImg3:[],//   组件航拍俯视照片
      componentImg4:[],//   组件安装完成VR视图 
      bkImg1:[],// 边框接地图-边框与边框接地       
      bkImg2:[],// 边框接地图-边框与支架接地
      bkImg3:[],// 边框接地图-其他图片
      ykImg1:[],//  压块或背压板照片
      nbqZlcImg:[],//  逆变器安装图-逆变器交流侧 
      bwJdImg:[],//  并网箱安装图-接地情况    
      jdImg8:[],//  接地极图-并网箱、逆变器安装接地极    
      jdImg11:[],//  接地极图-支架接地电阻测量照片(远景)
      jdImg9:[],// 接地极图-并网箱、逆变器安装接地电阻阻值(近景)
      jdImg12:[],// 接地极图-并网箱、逆变器安装接地电阻测量照片 (远景)
      jdImg10:[],//  接地极图-接地引下线警示做法
      fsImg1:[],//  防水措施图-横竖向水槽
      fsImg2:[],//  防水措施图-落水管走向及其固定
      fsImg3:[],//  防水措施图-其他图片
      //华融
      otherImgs5:[], //水槽细节照片
      otherImgs6:[], //落水管照片
      otherImgs7:[], //假梁-斜梁方向
      otherImgs8:[], //并网箱逆变器防雨罩照片
    },    
    
    detail: {},
    formSetObj: {},//自定义字段
    sampleGraphArr:[],//示例图片
    filingDocumentCode: '', //项目备案代码
    completeRemark: '',//完工备注
    tabIndex: '0',
    projectListTab: [],
    remarkArr: [],
  },
  onLoad(options) {
    this.setData({
      entryId: options.projectId,
      type: options.type, //0是安装,1是并网
    })
    // wx.setNavigationBarTitle({
    //   title: options.type == 0 ? "电站安装" : "电站并网",
    // })
    this.entryDetail()    
    if (options.type == 1) {
      this.getProviceCodeList()
    }   
  },
  onReady() {
    const query = wx.createSelectorQuery()
    query.select('#Canvas')
      .fields({
        node: true,
        size: true
      })
      .exec((res) => {
        const canvas = res[0].node
        this.setData({
          canvas,
        })
      })
  },
  /** 获取自定义字段 */
  getFormSet(partner) {
    getFormSet({
      stage: '03', //01:信息登记,02：踏勘设计,03：电站安装,04：电站并网
      partner: partner,
    }).then((res) => {
      let photoTips = this.data.photoTips;
      let keyList = Object.keys(res.data.columns)
      photoTips.forEach((item)=>{
        //示例图处理
        this.data.sampleGraphArr.forEach(item2=>{
          if(item2.itemCode === item.showKey){
            item.sampleGraph = item2.list?item2.list:[]
          }
        })
        keyList.forEach((item3)=>{
          if(item.showKey === item3){
            item.status = res.data.columns[item3].status
            item.must = res.data.columns[item3].mustFillFlag           
          }
        })
      })      
      // console.log(111, photoTips)
      this.setData({
        formSetObj: res.data.columns,
        photoTips
      })      
    })
  },
  /** 获取示例图 */
  getTipImg(typeId,callback){
    findTypeReferenceListNew({      
      typeId: typeId,
    }).then((res) => {
      console.log('获取示例图', res)
      if(res.data){
        this.setData({
          sampleGraphArr: res.data,
        })
      }      
      callback()
    })
  },
  //示图图片放大
  viewPic(e){
    wx.previewImage({
        current: e.currentTarget.dataset.item, // 当前显示图片的 http 链接
        urls: [e.currentTarget.dataset.item] // 需要预览的图片 http 链接列表
      })
  },
  /** 用户信息 **/
  userFn(e){
    wx.navigateTo({
      url: '/home/pages/ownerForm/ownerForm?projectId=' + this.data.detail.entry_id + '&type=8',
    })
  },
  /** 获取电站详情 **/
  entryDetail(e) {
    wx.showLoading({
      title: '加载中',
    })
    entryDetail({
      userId: wx.getStorageSync('userId'),
      entryId: this.data.entryId,
    }).then((res) => {
      // this.getActualCapacity()
      this.setData({
        projectList: res.projectDetailList,
        detail: res,
        'data.projectId': res.project_id,        
        'data.powerStationCode': res.power_station_code,
        'data.name': res.tenant_name,
        'data.traderName': res.create_trader_name,       
        'data.phone': res.mobile,
        'data.idCard': res.id_code,
        'data.region': res.province + res.city + res.area + res.address,        
        generatorNo: res.generator_no, //发电户号
        filingDocumentCode: res.filing_document_code, //备案证        
      })
      if (res.contract_url) {//合同
        let contractUrl  = res.contract_url  ? res.contract_url .split(",") : [];
        contractUrl.forEach(itm=>{
          this.data.photo.contractUrl.push({
            name:itm,
            url:IMG_BASE_URL + itm
          });
        });
        this.setData({
          [`photo.contractUrl`]:res.contract_url ?  this.data.photo.contractUrl: [],
        })
      }       
      if (res.filing_document_photo) {//备案证
        let filingDocumentPhoto = res.filing_document_photo ? res.filing_document_photo.split(",") : [];
        filingDocumentPhoto.forEach(itm=>{
          this.data.photo.filingDocumentPhoto.push({
            name:itm,
            url:IMG_BASE_URL + itm
          });
        });
        this.setData({
          [`photo.filingDocumentPhoto`]:res.filing_document_photo ?  this.data.photo.filingDocumentPhoto: [],            
        })
      }        
      let productList = res.projectDetailList //产品集合
      // let multiPhoto = []
      let projectListTab = [];
      productList.forEach((item,index)=>{
        // multiPhoto.push(this.data.photo)
        this.setData({
          // multiPhoto,
          [`remarkArr[${index}].completeRemark`]: item.acceptingReport.completeRemark, //完工备注
          [`photo.safetyWarningImg2`]: item.acceptingReport.safetyWarningImg2 ? item.acceptingReport.safetyWarningImg2.split(",").map(itm => {return {name: itm,url: IMG_BASE_URL + itm}}) : [], //三级安全教育卡
          [`photo.kgConditionFiles`]: item.acceptingReport.kgConditionFiles ? item.acceptingReport.kgConditionFiles.split(",").map(itm => {return {name: itm,url: IMG_BASE_URL + itm}}) : [], //安全防护措施合照照片
        })
        //图片
        let photo = {};          
        if (item.acceptingReport) {          
          for(let key in this.data.photo){
            photo[key] = item.acceptingReport[key] ? item.acceptingReport[key].split(",").map(itm => { return { name: itm, url: IMG_BASE_URL + itm}}) : []
          }
        } 
        projectListTab.push({
          // photoTips: this.data.photoTips,//照片
          projectId: item.projectId,
          photo: photo,
        })
      })  
      this.setData({
        projectListTab
      })      
      //案例图片
      this.getTipImg(res.scheme_type_id,()=>{
        this.getFormSet(res.management)
      }) 
      setTimeout(res=> {
        wx.hideLoading()
        this.checkCompleteEnable()
      }, 500)      
    })
  },
  /** 获取电力公司 **/
  getProviceCodeList(e) {
    getProviceCodeList({}).then((res) => {
      if (res.code == 200) {
        var list = []
        for (let i = 0; i < res.data.length; i++) {
          const element = res.data[i];
          list.push(element.columns)
        }
        setTimeout((res) => {
          for (let j = 0; j < list.length; j++) {
            const element = list[j];
            if (element.name == this.data.province) {
              this.setData({
                powerCompanyName: element.power_company,
                powerCompanyCode: element.code
              })
            }
          }
        }, 500)
        this.setData({
          powerCompanyList: list
        })
      }
    })
  },
  /** 查询安装组件信息 **/
  getActualCapacity(e) {
    getActualCapacity({
      entryId: this.data.entryId,
    }).then((res) => {
      const data = JSON.parse(res.data)
      var list = [];
      for (let i = 0; i < data.columns.nbqTotal; i++) {
        var item = "";
        list.push(item)
      }

      var npdlist = [];
      for (let i = 0; i < data.columns.nbqTotal; i++) {
        var item = "";
        npdlist.push(item)
      }

      if (this.data.snList) {
        for (let i = 0; i < this.data.snList.length; i++) {
          for (let j = 0; j < list.length; j++) {
            if (i == j) {
              list[j] = this.data.snList[i];
            }
          }
        }
      }

      this.setData({
        nbqTotal: list
      })

      if (this.data.nbqSnList) {
        for (let i = 0; i < this.data.nbqSnList.length; i++) {
          for (let j = 0; j < npdlist.length; j++) {
            if (i == j) {
              npdlist[j] = this.data.nbqSnList[i];
            }
          }
        }
      }

      this.setData({
        nbqSnTotal: npdlist
      })


      this.setData({
        component: data.columns
      })

    })
  },
  /** 选择电力公司 **/
  bindpowerCompanyList(e) {
    this.setData({
      powerCompanyName: this.data.powerCompanyList[e.detail.value].power_company,
      powerCompanyCode: this.data.powerCompanyList[e.detail.value].code
    })
  },
  /** 判断方位角方向 **/
  getDirection:function(rotate){
    // 计算应偏移度数
    let that = this;
    var area = parseInt(rotate/90)
    var detailArea = rotate%90
    if(area==0){
      that.setData({
        areaTT:"西偏北",
        detailAreaTT: 90-detailArea
      })
    }else if(area==1){
      that.setData({
        areaTT: "西偏南",
        detailAreaTT: detailArea
      })
    } else if (area == 2) {
      that.setData({
        areaTT: "东偏南",
        detailAreaTT: 90-detailArea
      })
    }else{
      that.setData({
        areaTT: "东偏北",
        detailAreaTT: detailArea
      })
    }
    return that.data.areaTT + that.data.detailAreaTT;
  },
  /** 上传图片之前 **/
  beforeRead(e){    
    const { callback } = e.detail;
    console.log("上传前",e);   
    // callback(true);
    // return
    if (this.data.type == 0) {
      let that = this;
      wx.getSystemInfoAsync({
        success (rep) {
          if(rep.platform == 'devtools'){
            callback(true);
          }else{
            //指南针监听,手机拍摄
            wx.onCompassChange(function(res){
              console.log("指针",res);
              var rotate = 360 - res.direction.toFixed(0)
              let direction = that.getDirection(rotate) + '°';
              that.setData({
                direction: direction
              });
              setTimeout(()=>{
                wx.stopCompass();
              },100);
              callback(true);
            });
          }
        }
      });
    }else{
      callback(true);
    }
  },
   /** 上传图片 **/
   afteruploadPhotoRead(e) {
    var that = this;
    const choseType = Array.isArray(e.detail.file) ? (e.detail.file[0].choseType || undefined) : (e.detail.file.choseType || undefined); //camera相机  album相册    
    const name = e.currentTarget.dataset.name
    const pIndex = this.data.tabIndex
    console.log("上传后", this.data.direction, choseType, e);
    // 细节照片添加水印
    if ((e.currentTarget.dataset.name !=='filingDocumentPhoto' && e.currentTarget.dataset.name !=='otherImgs1' && e.currentTarget.dataset.name !=='otherImgs2' && e.currentTarget.dataset.name !=='otherImgs3' && e.currentTarget.dataset.name !=='otherImgs4') && choseType == 'camera') {     //加水印
      this.getLocation(e)
      return
    }
    
    //无水印上传
    if (Array.isArray(e.detail.file)) { //多张
      var count = 0;
      this.afteruploadPhotoReadS(e, count)
      return
    }
    const {
      file
    } = e.detail;
    wx.showLoading({
      title: '上传中',
    }) 
    wx.uploadFile({
      url: API_BASE_URL + 'common/weChat/uploadImage',
      filePath: file.url,
      name: 'file',
      complete: function (res) {
        console.log("上传图片", res)
        wx.hideLoading()
        if (res.statusCode == 200) {
          wx.showToast({
            title: '选择成功',
            icon: 'none',
          })
          var item = {
            url: "",
            name: "",
          }
          item.url = file.url;
          item.name = res.data;
          if(name != 'safetyWarningImg2' && name != 'kgConditionFiles'){
            that.data.projectListTab[pIndex].photo[name].push(item)
            that.setData({            
              [`projectListTab[${pIndex}].photo.${name}`]: that.data.projectListTab[pIndex].photo[name]
            })
          }else{
            that.data.photo[name].push(ob) 
            that.setData({
              [`photo.${name}`]: that.data.photo[name]
            }) 
          }
        } else {
          wx.showToast({
            title: '选择失败',
            icon: 'error'
          })
        }
      }
    })    
  },

  /** 上传多张图片递归 **/
  afteruploadPhotoReadS(e, count) {
    let ob = {
      name: '',
      url: '',
    }
    const name = e.currentTarget.dataset.name
    const pIndex = this.data.tabIndex
    wx.showLoading({
      title: '加载第' + (count + 1) + '张照片中',
      mask: true,
    })
    const element = e.detail.file[count];
    var that = this;
    wx.uploadFile({
      url:  API_BASE_URL + 'common/weChat/uploadImage',
      filePath: element.url,
      name: 'file',
      success(res) {
        wx.hideLoading()
        if (res.statusCode == 200) {
          count = count + 1;
          ob.name = res.data
          ob.url = element.url
          if(name != 'safetyWarningImg2' && name != 'kgConditionFiles'){
            that.data.projectListTab[pIndex].photo[name].push(ob);
            that.setData({            
              [`projectListTab[${pIndex}].photo.${name}`]: that.data.projectListTab[pIndex].photo[name]
            })
          }else{
            that.data.photo[name].push(ob) 
            that.setData({
              [`photo.${name}`]: that.data.photo[name]
            }) 
          }
          if (count == e.detail.file.length) {
            wx.showToast({
              title: '选择成功',
              icon: 'none'
            })
          } else {
            that.afteruploadPhotoReadS(e, count)
          }
        } else {
          wx.showToast({
            title: '选择失败',
            icon: 'error'
          })
        }
      }
    })
  },

  /** 删除图片 **/
  deleteImg(e) {
    let name = e.currentTarget.dataset.type
    const index = (name != 'filingDocumentPhoto' && name != 'otherFiles') ? e.detail.index : e.currentTarget.dataset.index //删除图片的下标
    const pIndex = this.data.tabIndex
    console.log("删除图片事件", this.data.projectListTab, e, index, name)   
    // this.data.photo[type].splice(index, 1);
    this.data.projectListTab[pIndex].photo[name].splice(index, 1);
    this.setData({       
      // [`photo.${type}`]: this.data.photo[type]
      [`projectListTab[${pIndex}].photo.${name}`]: this.data.projectListTab[pIndex].photo[name]
    })
    this.checkCompleteEnable()
  },
  /** 删除图片 **/
  deleteImg2(e) {
    let type = e.currentTarget.dataset.type
    const index = (type != 'filingDocumentPhoto') ? e.detail.index : e.currentTarget.dataset.index //删除图片的下标    
    console.log("删除图片事件", this.data.projectListTab, e, index)   
    this.data.photo[type].splice(index, 1);    
    this.setData({       
      [`photo.${type}`]: this.data.photo[type]      
    })
    this.checkCompleteEnable()
  },
  /** 删除文件 **/
  deleteImg2(e) {
    // console.log("删除事件2", e)
    let index= e.currentTarget.dataset.index;
    let name= e.currentTarget.dataset.name;
    this.data.photo[name].splice(index, 1);
    this.setData({
      [`photo.${name}`]: this.data.photo[name]
    })
    this.checkCompleteEnable()    
  },
  /** 提交 **/
  submitFrom(e) {
    var data;    
    if (this.data.type == 0) { //完工
      //用户类型是单位
      if(this.data.detail.tenant_type=='2'){
        if (this.data.filingDocumentCode ==null || this.data.filingDocumentCode =='') {
          wx.showToast({
            title: '请输入项目备案代码',
            icon: 'none'
          })
          return
        }
        if (!this.data.photo.filingDocumentPhoto.length > 0) {
          wx.showToast({
            title: '请上传备案证',
            icon: 'none'
          })
          return
        }else if (!this.data.photo.otherImgs1.length > 0 && this.data.formSetObj.other_imgs1.mustFillFlag =='1') {
          wx.showToast({
            title: '请上传银行印鉴留样',
            icon: 'none'
          })
          return
        }else if(!this.data.photo.otherImgs2.length > 0 && this.data.formSetObj.other_imgs2.mustFillFlag =='1') {
          wx.showToast({
            title: '请上传签约现场照片-法定代表人/负责人签字照',
            icon: 'none'
          })
          return
        }else if(!this.data.photo.otherImgs3.length > 0 && this.data.formSetObj.other_imgs3.mustFillFlag =='1') {
          wx.showToast({
            title: '请上传签约现场照片-正脸、持笔/持印、合同签署页同框',
            icon: 'none'
          })
          return
        }else if(!this.data.photo.otherImgs4.length > 0 && this.data.formSetObj.other_imgs4.mustFillFlag =='1') {
          wx.showToast({
            title: '请上传签署完成照片',
            icon: 'none'
          })
          return
        }else if(this.data.completeRemark == '' && this.data.formSetObj.complete_remark.mustFillFlag =='1') {
          // wx.showToast({
          //   title: '完工备注不能为空',
          //   icon: 'none'
          // })
          // return
        }
      }      
      //图片
      let completeList = []
      this.data.projectListTab.forEach((pItem,pindex)=>{
        for(let key in pItem.photo){
          if(Array.isArray(pItem.photo[key])){
            pItem.photo[key] = pItem.photo[key].length > 0 ? pItem.photo[key].map(itm => itm.name).join(",") : ""
          }else{
            let newKey = pItem.photo[key] ? pItem.photo[key].split(",") : [];
            pItem.photo[key] = newKey.length > 0 ? newKey.map(itm => itm).join(",") : ""
          }
          // pItem.photo[key] = pItem.photo[key].length > 0 ? pItem.photo[key].map(itm => itm.name).join(",") : ""
        }
        completeList.push({
          projectId: pItem.projectId,
          completeRemark: this.data.remarkArr[pindex].completeRemark,
          ...pItem.photo,
        });
      })
      data = {
        entryId: this.data.entryId,
        filingDocumentCode: this.data.filingDocumentCode,
        filingDocumentPhoto: this.data.photo.filingDocumentPhoto.length>0 ? this.data.photo.filingDocumentPhoto.map(itm=>itm.name).join(",") : "",
        kgConditionFiles: this.data.photo.kgConditionFiles.length>0 ? this.data.photo.kgConditionFiles.map(itm=>itm.name).join(",") : "",
        safetyWarningImg2: this.data.photo.safetyWarningImg2.length>0 ? this.data.photo.safetyWarningImg2.map(itm=>itm.name).join(",") : "",
        completeList: completeList,
      }
      // data = {
      //   entryId: this.data.entryId,
      //   filingDocumentCode: this.data.filingDocumentCode,
      //   // completeRemark: this.data.completeRemark,
      // }
      //图片
      // for(let i in this.data.photo){
      //   data[i] = this.data.photo[i].length>0 ? this.data.photo[i].map(itm=>itm.name).join(",") : "";
      // }
      console.log("提交",data);
      // return;
      wx.showLoading({
        title: "提交中"
      })
      install({
        userId: wx.getStorageSync('userId'),
        addReportReq: data
      }).then((res) => {
        wx.hideLoading()
        if (res.code == 200) {
          wx.showToast({
            title: '完工成功',
            icon: 'none',
            success: function () {
              setTimeout(function () {
                wx.navigateBack()
              }, 1500)
            }
          })
        } else {
          wx.showToast({
            title: res.errMsg || res.msg,
            icon: 'none'
          })
        }
      })
    } 
  },
  /** 暂存 **/
  cacheFrom(e) {
    wx.showLoading({
      title: '暂存中',
    })
    var data;
    //图片
    let completeList = []
    this.data.projectListTab.forEach((pItem,pindex)=>{
      for(let key in pItem.photo){
        pItem.photo[key] = pItem.photo[key].length > 0 ? pItem.photo[key].map(itm => itm.name).join(",") : ""
      }
      completeList.push({
        projectId: pItem.projectId,
        completeRemark: this.data.remarkArr[pindex].completeRemark,
        ...pItem.photo,
      });
    })   
    data = {
      entryId: this.data.entryId,
      filingDocumentCode: this.data.filingDocumentCode,
      filingDocumentPhoto: this.data.photo.filingDocumentPhoto.length>0 ? this.data.photo.filingDocumentPhoto.map(itm=>itm.name).join(",") : "",
      kgConditionFiles: this.data.photo.kgConditionFiles.length>0 ? this.data.photo.kgConditionFiles.map(itm=>itm.name).join(",") : "",
      safetyWarningImg2: this.data.photo.safetyWarningImg2.length>0 ? this.data.photo.safetyWarningImg2.map(itm=>itm.name).join(",") : "",
      completeList: completeList,
    }
   
    // console.log("暂存",data, completeList);
    // return
    installZc({
      userId: wx.getStorageSync('userId'),
      addReportReq: data
    }).then((res) => {
      wx.hideLoading()
      if (res.code == 200) {
        wx.showToast({
          title: '暂存成功',
          icon: 'none',
          success: function () {
            setTimeout(function () {
              wx.navigateBack()
            }, 1500)
          }
        })
      } else {
        wx.showToast({
          title: res.errMsg || res.msg,
          icon: 'none'
        })
      }
    })
  },  
  /** 查看注意方案 **/
  viewNote(e) {
    let title = e.currentTarget.dataset.tit;
    let message = e.currentTarget.dataset.msg;    
    Dialog.alert({
      title: title,
      message: message,
      theme: 'round-button',
    }).then(() => { });
  },
  
  
  /** 校验完工必填项是否选择或填写完毕 **/
  checkCompleteEnable(e) {
    // if (this.data.snList && this.data.snList.length > 0) {
    //   for (let i = 0; i < this.data.snList.length; i++) {
    //     const element = this.data.snList[i];
    //     if (!element) {
    //       this.setData({
    //         completeEnable: false
    //       })
    //       return
    //     }
    //   }
    // }

    // if (this.data.nbqSnList && this.data.nbqSnList.length > 0) {
    //   for (let i = 0; i < this.data.nbqSnList.length; i++) {
    //     const element = this.data.nbqSnList[i];
    //     if (!element) {
    //       this.setData({
    //         completeEnable: false
    //       })
    //       return
    //     }
    //   }
    // } 
    try{
      this.data.projectListTab.forEach(pitem=>{  
        for (let i in pitem.photo) {
          this.data.photoTips.forEach(item=>{        
            if((i == item.key) && (item.must == '1')){
              if (pitem.photo[i].length == 0 ) {
                this.setData({
                  completeEnable: false
                })
                throw Error()
              }            
            } 
          })
        }
      })
    // if(this.data.formSetObj.other_files.status=='1' && this.data.formSetObj.other_files.mustFillFlag=='1'){
    //   if(this.data.otherFiles.length == 0){
    //     this.setData({
    //       completeEnable: false
    //     })
    //     return
    //   }
    // }
    this.setData({
      completeEnable: true
    })
  }catch(e) {
    console.log(e)
  }
  },
  /** 获取用户当前地理位置后为照片添加水印 **/
  getLocation(e) {
    if (this.data.customerAddress) { //有地址直接绘制图片
      this.chooseImages(e)
      return
    }

    utilGetLocation.getLocationAddress().then((res) => {
      res.res.data = res.res.data.slice(res.res.data.lastIndexOf('省') + 1)
      this.setData({
        customerAddress: res.res.data,
        canvasLongitude: res.resLocation.longitude,
        canvasLatitude: res.resLocation.latitude,
      });
      //获取小程序二维码
      let lonLat = res.resLocation.longitude + ',' + res.resLocation.latitude;
      createQrcode({
        content:lonLat
      }).then(ret=>{
        // let codeImg ="data:image/png;base64," + ret;
        let codeImg =IMG_BASE_URL + ret;
        this.setData({
          imageCodeImg:codeImg
        });
        // console.log("codeImg",codeImg);
        this.chooseImages(e)
      });
    })
  },
  /**
   * @param {*} e  图片携带信息
   * @param {*} customerAddress 实时地理位置信息
   * @param {*} canvasLongitude 实时地理位置经度
   * @param {*} canvasLatitude 实时地理位置纬度
   */
  async chooseImages(e) {
    const photoName = e.currentTarget.dataset.type; //图片名称
    const pIndex = this.data.tabIndex;
    const tempFilePath = e.detail.file[0].url //图片路径
    const canvasWidth = wx.getSystemInfoSync().screenWidth; 
    // 获取图片信息
    await wx.getImageInfo({
      src: tempFilePath,
    }).then(async res => {
      let watermarkScale = res.width / canvasWidth;
      this.setData({
        canvasHeight: Math.round(res.height / watermarkScale),
        canvasWidth: canvasWidth,
      });
      await utilAddWatermark.addWatermark(tempFilePath, photoName, this.data).then((res) => {
        if(photoName != 'safetyWarningImg2' && photoName != 'kgConditionFiles'){
          this.data.projectListTab[pIndex].photo[photoName].push(res)
          this.setData({         
            [`projectListTab[${pIndex}].photo.${photoName}`]: this.data.projectListTab[pIndex].photo[photoName]
          })
        }else{
          this.data.photo[photoName].push(res)
          this.setData({
            [`photo.${photoName}`]: this.data.photo[photoName]
          })
        }
        this.checkCompleteEnable()
      })

    })
  },

  /** 打开省市区弹框 **/
  bindRegionChange(e) {
    this.setData({
      showRegion: true
    })
  },
  /** 选择的地址 **/
  chooseRegion(e) {
    this.setData({
      provinceName: e.detail.provinceName,
      cityName: e.detail.cityName,
      areaName: e.detail.areaName,
      address: ""
    })
  },

  /** 填充所有图片 **/
  imageAll(e) {
    var that = this
    wx.showModal({
      title: '提示',
      content: '确定选取图片后填充完工所有图片？',
      complete: (res) => {
        if (res.confirm) {
          wx.chooseMedia({
            count: 1,
            mediaType: ['image'],
            success(resImage) {
              wx.showLoading({
                title: '选择中',
              })
              wx.uploadFile({
                url: API_BASE_URL + 'common/weChat/uploadImage',
                filePath: resImage.tempFiles[0].tempFilePath,
                name: 'file',
                complete: function (res) {
                  wx.hideLoading()
                  if (res.statusCode == 200) {
                    for (let i in that.data.photo) {
                      let arr=[];                      
                      arr.push({
                        name:res.data,
                        url:IMG_BASE_URL + res.data
                      });
                      that.setData({
                        [`photo.${i}`]: arr,
                      })
                    }
                    wx.showToast({
                      title: '填充成功',
                      icon: 'none'
                    })
                    that.checkCompleteEnable()
                  } else {
                    wx.showToast({
                      title: '填充失败',
                      icon: 'none'
                    })
                  }
                }
              })
            }
          })
        }
      }
    })
  },
  /** 文件或图片上传选择-对话框 **/
  selectUplosd(e){
    var that = this;  
    let name = e.currentTarget.dataset.name;  
    let pIndex = this.data.tabIndex;
    let maxcount = e.currentTarget.dataset.maxcount;
    if(name != 'filingDocumentPhoto' && name != 'contractUrl'){
      maxcount = e.currentTarget.dataset.maxcount - that.data.projectListTab[pIndex].photo[name].length
    }else{
      maxcount = e.currentTarget.dataset.maxcount - that.data.photo[name].length
    }
    wx.showActionSheet({
      itemList: ['文件', '图片'],
      success: function (res) {
        if (!res.cancel) {
          if (res.tapIndex == 0) {//文件
            that.upload(e, name);
          } else if (res.tapIndex == 1) {//图片
            wx.chooseMedia({
              count: maxcount,
              mediaType: ['image'],
              sourceType: ['album'],
              success: function (rep) {
                if (Array.isArray(rep.tempFiles)) { //多张
                  var count = 0;
                  that.afteruploadPhotoReadFile(e, rep.tempFiles, count)
                  return
                }
                wx.showLoading({
                  title: '选择中',
                })
                wx.uploadFile({
                  url: API_BASE_URL + 'common/weChat/uploadImage',
                  filePath: rep.tempFiles[0].tempFilePath,
                  name: 'file',
                  complete: function (res) {
                    wx.hideLoading()
                    if (res.statusCode == 200) {
                      wx.showToast({
                        title: '选择成功',
                        icon: 'none',
                      })
                      if(name){
                        var item = {
                          url: "",
                          name: "",
                        }
                        item.url = rep.tempFiles[0].tempFilePath;
                        item.name = res.data;
                        if(name != 'filingDocumentPhoto'){                          
                          that.data.projectListTab[pIndex].photo[name].push(item)
                          that.setData({                           
                            [`projectListTab[${pIndex}].photo.${name}`]: that.data.projectListTab[pIndex].photo[name]
                          })
                        }else{
                          that.data.photo[name].push(item) 
                          that.setData({
                            [`photo.${name}`]: that.data.photo[name]                            
                          })
                        }
                      }
                      that.checkCompleteEnable()
                    } else {
                      wx.showToast({
                        title: '选择失败',
                        icon: 'error'
                      })
                    }
                  }
                })
              },
              fail: function(){},
            });
          }
        }
      }
    });
  },
  /** 上传pdf或图片 **/
  upload(e,name) {    
    var that = this;
    let pIndex = this.data.tabIndex;
    let maxcount = e.currentTarget.dataset.maxcount;
    if(name != 'filingDocumentPhoto' && name != 'contractUrl'){
      maxcount = e.currentTarget.dataset.maxcount - that.data.projectListTab[pIndex].photo[name].length
    }else{
      maxcount = e.currentTarget.dataset.maxcount - that.data.photo[name].length
    }
    wx.chooseMessageFile({
      // count: maxcount - this.data.projectListTab[pIndex].photo[name].length,
      count: maxcount,
      type: 'all',
      success(res) {
        if (Array.isArray(res.tempFiles)) { //多张
          var count = 0;
          that.afteruploadPhotoReadFile(e, res.tempFiles, count, 'file')
          return
        }
        //获取文件后缀
        let suffix = res.tempFiles[0].path.substring(res.tempFiles[0].path.lastIndexOf('.') + 1)
        if (suffix.search(/jpg|png|jpeg|pdf/) == -1) {
          wx.showToast({
            title: '只能上传jpg、png、jpeg、pdf文件',
            icon: 'none'
          })
          return
        } else {
          wx.showLoading({
            title: '选择中',
          })         
          wx.uploadFile({
            url: API_BASE_URL + 'common/uploadFile_Name?fileName='+res.tempFiles[0].name,
            filePath: res.tempFiles[0].path,
            name: 'file',
            complete: function (res) {              
              wx.hideLoading()
              if (res.statusCode == 200) {
                wx.showToast({
                  title: '选择成功',
                  icon: 'none'
                })
                if(name != 'filingDocumentPhoto'){                          
                  that.data.projectListTab[pIndex].photo[name].push({
                    name: JSON.parse(res.data).path,
                    url: IMG_BASE_URL + JSON.parse(res.data).path
                  });
                  that.setData({
                    [`projectListTab[${pIndex}].photo.${name}`]: that.data.projectListTab[pIndex].photo[name]
                  })
                }else{
                  that.data.photo[name].push({
                    name: JSON.parse(res.data).path,
                    url: IMG_BASE_URL + JSON.parse(res.data).path
                  });
                  that.setData({
                    [`photo.${name}`]: that.data.photo[name]
                  })
                }                
                // if(name){
                  // that.data.photo[name].push({
                  //   name: JSON.parse(res.data).path,
                  //   url: IMG_BASE_URL + JSON.parse(res.data).path
                  // });
                  // that.setData({
                  //   [`photo.${name}`]: that.data.photo[name]
                  // })
                // }else{
                  // otherFiles.push(JSON.parse(res.data).path)
                  // that.setData({
                  //   otherFiles
                  // })
                  // that.checkCompleteEnable()
                // } 
              } else {
                wx.showToast({
                  title: '选择失败',
                  icon: 'none'
                })
              }
            }
          })
        }
      }
    })
  },
  /** 文件上传多张递归 **/
  afteruploadPhotoReadFile(e, file, count, type) {
    let ob = {
      name: '',
      url: '',
    }
    const name = e.currentTarget.dataset.name
    const pIndex = this.data.tabIndex
    wx.showLoading({
      title: '加载第' + (count + 1) + '张照片中',
      mask: true,
    })
    const element = file[count];
    var that = this;
    var url = ''
    if(type =='file'){
      //获取文件后缀
      let suffix = element.path.substring(element.path.lastIndexOf('.') + 1)
      if (suffix.search(/jpg|png|jpeg|pdf/) == -1) {
        wx.showToast({
          title: '只能上传jpg、png、jpeg、pdf文件',
          icon: 'none'
        })
        return
      }
      url = API_BASE_URL + 'common/uploadFile_Name?fileName='+ element.name
    }else{
      url = API_BASE_URL + 'common/weChat/uploadImage'
    }
    wx.uploadFile({
      url: url,
      filePath: type =='file'?element.path:element.tempFilePath,
      name: 'file',
      success(res) {
        wx.hideLoading()
        if (res.statusCode == 200) {          
          count = count + 1;
          ob.name = type =='file'?JSON.parse(res.data).path: res.data,
          ob.url = type =='file'?JSON.parse(res.data).path:element.tempFilePath
          if(name != 'filingDocumentPhoto'){            
            that.data.projectListTab[pIndex].photo[name].push(ob);
            that.setData({             
              [`projectListTab[${pIndex}].photo.${name}`]: that.data.projectListTab[pIndex].photo[name]
            })
          }else{
            that.data.photo[name].push(ob);          
            that.setData({
              [`photo.${name}`]: that.data.photo[name]            
            })
          }
          if (count == file.length) {
            wx.showToast({
              title: '选择成功',
              icon: 'none'
            })
            that.checkCompleteEnable()
          } else {
            that.afteruploadPhotoReadFile(e, file, count, type)
          }
        } else {
          wx.showToast({
            title: '选择失败',
            icon: 'error'
          })
        }
      }
    })
  },
  //打开pdf文件或者大图查看图片
  openDocument(res) {
    let path = res.currentTarget.dataset.path
    if (path) {
      let suffix = path.substring(path.lastIndexOf('.') + 1) //获取文件后缀
      if (suffix == 'pdf') {
        wx.showLoading({
          title: '加载中',
        })
        wx.downloadFile({
          url: IMG_BASE_URL + path,
          complete: function (res) {
            wx.hideLoading()
            const filePath = res.tempFilePath
            wx.openDocument({
              filePath: filePath,
              showMenu: true,
              success: function (res) {}
            })
          }
        })
      } else {
        wx.previewImage({
          urls: [IMG_BASE_URL + path] // 需要预览的图片http链接列表
        })
      }
    }
  },
  //产品tab切换
  changeTab(e){
    let index = e.currentTarget.dataset.index
    this.setData({
      tabIndex: index
    })
  },
  onInput(e){
    this.setData({
      [`remarkArr[${this.data.tabIndex}].completeRemark`]: e.detail.value,
    })
  }
})