const {
  entryDetail,
  findAllPlan,
  getElectricPlanAll,
  appletsFailed,
  appletsToExamine,
  API_BASE_URL,
  IMG_BASE_URL,
  WU_TU_PIAN_URL,
  getFormSet,
  designCustomerEntry,getAllDictionarySelect,getKcFormSet
} = require('../../../api/api')

Page({
  data: {
    IMG_BASE_URL: IMG_BASE_URL,
    WU_TU_PIAN_URL:WU_TU_PIAN_URL,
    planList: [], //方案列表

    standardSolutionsList: [{
      type: "", //方案类型
      name: "", //方案名称
      id: "", //方案ID
      code: "", //方案编号
      drawing: "", //参考图纸
    }], //标准方案初始数量

    combinedSolutionsList: [{
      type: "", //方案类型
      name: "", //方案名称
      id: "", //方案ID
      code: "", //方案编号
      pickerIndex: 0, //方案类型选择下标
      drawing: "", //参考图纸
      addType: 1, //显示新增方案按钮
    }], //组合方案初始数量

    photo: {
      fwImg1: [],
      fwImg2: [],
      fwImg3: [],
      fwImg4: [],
      fwImg5: [],
      
      flyImgs: [], //无人机航拍图
      roofPhotoOne:[],//安装区域整体照片
      roofPhotoTwo:[],//安装区域东南角照片
      roofPhotoThree:[],//安装区域西南角照片
      roofPhotoFour:[],//安装区域正南照片
      roofPhotoFive:[],//安装区域细节照片
      roofPhotoFacade:[],//房屋内部结构照片
      roofPhotoInterior:[],//房屋内部环境照片
      detailSupplementOne:[],//逆变器、配电箱预安装位置照片
      houseSupplementOne:[],//房屋其他障碍物照片
      surveyVideo:[],//踏勘补充证明视频
      houseOwnership:[],//踏勘补充证明视频
      surveyFiles:[],//踏勘记录表
      
      vrRoofOne: [], //房屋整体图
      vrRoofTwo: [], //房屋整体俯视图
      vrRoofThree: [], //房屋内部结构图
      vrRoofFour: [], //入户全景照片

      designDrawings: [], //设计图纸
      zjpbImg: [], //组件排布图
      zjzxImg: [], // 组件走线图
      zjcsImg: [], //支架侧视图
      zjhsImg: [], //电气图
    },
    photoTips:[      
      {
      showKey: 'fly_imgs',
      key:'flyImgs',
      num:9,
      minNum:3,
      title: '无人机航拍图',
    },{
      showKey: 'roof_photo_one',
      key:'roofPhotoOne',
      num:9,
      minNum:2,
      title: '安装区域整体照片',
    },{
      showKey: 'roof_photo_two',
      key:'roofPhotoTwo',
      num:9,
      minNum:1,
      title: '安装区域东南角照片',
    },{
      showKey: 'roof_photo_four',
      key:'roofPhotoFour',
      num:9,
      minNum:1,
      title: '安装区域正南照片',
    },{
      showKey: 'roof_photo_three',
      key:'roofPhotoThree',
      num:9,
      minNum:1,
      title: '安装区域西南角照片',
    },{
      showKey: 'roof_photo_five',
      key:'roofPhotoFive',
      num:9,
      minNum:1,
      title: '安装区域细节照片',
    },{
      showKey: 'roof_photo_interior',
      key:'roofPhotoInterior',
      num:9,
      minNum:2,
      title: '房屋内部环境照片',
    },{
      showKey: 'roof_photo_facade',
      key:'roofPhotoFacade',
      num:9,
      minNum:2,
      title: '房屋内部结构照片',
    },{
      showKey: 'detail_supplement_one',
      key:'detailSupplementOne',
      num:9,
      minNum:1,
      title: '逆变器、配电箱预安装位置照片',
    },{
      showKey: 'house_outline_photo',
      key: 'houseOutlinePhoto',
      num: 9,
      minNum: 1,
      title: '房屋轮廓照片',
    },{
      showKey: 'house_supplement_one',
      key:'houseSupplementOne',
      num:9,
      minNum:1,
      title: '房屋其他障碍物照片',
    },{
      showKey: 'survey_files',
      key:'surveyFiles',
      num:4,
      title: '踏勘记录表',
    },{
      showKey: 'roof_photo_one_03',
      key: 'roofPhotoOne',
      num: 9,
      minNum: 2,
      title: '房屋屋顶照片',
    },{
      showKey: 'roof_photo_two_03',
      key: 'roofPhotoTwo',
      num: 9,
      minNum: 1,
      title: '房屋屋顶东侧图片',
    },{
      showKey: 'roof_photo_three_03',
      key: 'roofPhotoThree',
      num: 9,
      minNum: 1,
      title: '房屋屋顶西侧图片',
    },{
      showKey: 'roof_photo_four_03',
      key: 'roofPhotoFour',
      num: 9,
      minNum: 1,
      title: '房屋屋顶南侧图片',
    },{
      showKey: 'fw_img3',
      key: 'fwImg3',
      num: 9,
      minNum: 1,
      title: '房屋屋顶东南侧图片',
    },{
      showKey: 'fw_img4',
      key: 'fwImg4',
      num: 9,
      minNum: 1,
      title: '房屋屋顶西南侧图片',
    },{
      showKey: 'fw_img5',
      key: 'fwImg5',
      num: 9,
      minNum: 1,
      title: '遮阴物与房屋距离、高度',
    },{
      showKey: 'survey_video',
      key: 'surveyVideo',
      num: 8,
      minNum: 1,
      title: '踏勘补充证明视频',
    },{
      showKey: 'house_ownership',
      key: 'houseOwnership',
      num: 8,
      minNum: 1,
      title: '房产证明',
    },{
      showKey: 'survey_files_03',
      key: 'surveyFiles',
      num: 9,
      minNum: 1,
      title: '户用勘察记录表（附平面草图）',
    },{
      showKey: 'fw_img1',
      key: 'fwImg1',
      num: 9,
      minNum: 1,
      title: '房屋整体图',
    },{
      showKey: 'vr_roof_one',
      key: 'vrRoofOne',
      num: 9,
      minNum: 1,
      title: '房屋整体图（VR全景）',
    },{
      showKey: 'vr_roof_two',
      key: 'vrRoofTwo',
      num: 9,
      minNum: 1,
      title: '房屋整体俯视图（无人机）',
    },{
      showKey: 'vr_roof_three',
      key: 'vrRoofThree',
      num: 9,
      minNum: 1,
      title: '房屋内部结构图（VR）',
    },{
      showKey: 'fw_img2',
      key: 'fwImg2',
      num: 9,
      minNum: 1,
      title: '房屋内部结构图',
    },{
      showKey: 'vr_roof_four',
      key: 'vrRoofFour',
      num: 9,
      minNum: 1,
      title: '入户全景照片(VR)',
    },{
      showKey: 'fly_imgs_04',
      key: 'flyImgs',
      num: 9,
      minNum: 3,
      title: '屋顶高空俯视照片',
    },{
      showKey: 'roof_photo_two_04',
      key: 'roofPhotoTwo',
      num: 9,
      minNum: 1,
      title: '屋顶东南照片',
    },{
      showKey: 'roof_photo_four_04',
      key: 'roofPhotoFour',
      num: 9,
      minNum: 1,
      title: '屋顶正南照片',
    },{
      showKey: 'roof_photo_three_04',
      key: 'roofPhotoThree',
      num: 9,
      minNum: 1,
      title: '屋顶西南照片',
    },{
      showKey: 'vr_roof_four_04',
      key: 'vrRoofFour',
      num: 9,
      minNum: 1,
      title: '入户全景照片',
    },{
      showKey: 'survey_files_04',
      key: 'surveyFiles',
      num: 4,
      title: '现场勘测表',
    }],
    formSetObj: {}, //自定义字段
    productZj:0,//产品默认的组件值
    gridType: '0'
  },
  onLoad(options) {
    this.data.entryId = options.projectId;
    this.setData({
      entryId:options.projectId,
      type:options.type
    });
    if(options.type == '3'){
      wx.setNavigationBarTitle({
        title: '设计',
      })
    }
    this.entryDetail()
    this.findAllPlan()
  },
  /*** 获取字典 */
  getDictionaryList(partner, callback) {
    getAllDictionarySelect({
      capitalId: partner,
    }).then((res) => {
      if(res.data){
        this.setData({    
          roofTypeList: res.data.roof_type.map(item=>item.columns), //屋顶类型
          angleAzimuthSel: res.data.angle_azimuth.map(item=>item.columns), //方位角
        })
      }
      if(callback) callback(res.data)
    })
  },
  /** 获取自定义字段 */
  getFormSet(partner) {
    let params = {
      stage: '02', //01:信息登记,02：踏勘设计,03：电站安装,04：电站并网
      partner: partner,
    }
    // if(this.data.type == '3'){
    //   params = {
    //     stage: '02', //01:信息登记,02：踏勘设计,03：电站安装,04：电站并网
    //     groupType: '0202',//0202：勘测设计
    //     partner: partner,
    //   }
    // }
    getFormSet(params).then((res) => {
      this.setData({
        formSetObj: res.data.columns
      })
    })
    if(partner == '03'){
      getKcFormSet().then((res) => {
        if(res.data){
          this.setData({    
            gfRoofTypeList: res.data, //广发--屋顶类型数据集合
          })
        }
      })
    }
  },
  //屋顶类型对应显示字段
  roofTypeToColumn(name){
    this.data.gfRoofTypeList.forEach(item=>{
      if(name == item.roofType){
        let selectRoofType = item.forms.map(itm=>{return itm.columns});
        let roofTypeAllColumn = {}
        selectRoofType.forEach(item2=>{
          roofTypeAllColumn[item2.column_key] = {
            status: 1,
            must_fill_flag: item2.must_fill_flag
          }
        })
        // console.log(555, roofTypeAllColumn)
        this.setData({
          roofTypeAllColumn
        })
      }
    })
  },
  /** 业主信息 **/
  userFn(e){
    wx.navigateTo({
      url: '/home/pages/ownerForm/ownerForm?projectId=' + this.data.entryId,
    })
  },
  /** 拨打业主联系电话 **/
  phoneFn(e) {
    const phone = e.currentTarget.dataset.phone;
    if (!phone) {
      wx.showToast({
        title: '暂无联系方式',
        icon: 'none'
      })
      return
    }
    wx.makePhoneCall({
      phoneNumber: phone,
    })
  },
  /** 获取方案类型和方案名称 **/
  findAllPlan(e) {
    let that = this
    findAllPlan({

    }).then((res) => {
      for (let i = 0; i < res.length; i++) {
        res[i].allPlan = JSON.parse(res[i].allPlan)
        for (let j = 0; j < res[i].allPlan.length; j++) {
          var element = res[i].allPlan[j].columns;
          res[i].allPlan[j] = element
        }
      }
      that.setData({
        planList: res,
      })
    })
  },
  /** 获取组件、逆变器、并网箱列表 **/
  getElectricPlanAll(e) {
    getElectricPlanAll({
      partnerId: wx.getStorageSync('capitalId'),//资方
    }).then((res) => {
      var AllComponentApiList = [];
      var converterApiList = [];
      var cagesApiList = [];
      var zhijApiList = [];
      for (let i = 0; i < res.zjs.length; i++) {
        const element = res.zjs[i].columns;
        AllComponentApiList.push(element)
      }
      for (let j = 0; j < res.inverters.length; j++) {
        const element = res.inverters[j].columns;
        converterApiList.push(element)
      }
      for (let k = 0; k < res.boxs.length; k++) {
        const element = res.boxs[k].columns;
        cagesApiList.push(element)
      }
      for (let k = 0; k < res.zhij.length; k++) {
        const element = res.zhij[k].columns;
        zhijApiList.push(element)
      }
      let componentApiList = AllComponentApiList.length ? AllComponentApiList.filter(itm=>Number(itm.model) >= this.data.productZj) : [];//过滤大于等于productZj的组件列表
      this.setData({
        componentApiList: componentApiList, //组件
        // [`componentList[${0}].material_model`]: componentApiList.length && (this.data.componentList[0].id == '') ? componentApiList[0].material_model : this.data.componentList[0].material_model,
        // [`componentList[${0}].model`]: componentApiList.length&&(this.data.componentList[0].id == '') ? componentApiList[0].model : this.data.componentList[0].model,
        // [`componentList[${0}].id`]: componentApiList.length&&(this.data.componentList[0].id == '') ? componentApiList[0].id : this.data.componentList[0].id,
        converterApiList: converterApiList, //逆变器
        cagesApiList: cagesApiList, //并网箱
        zhijApiList: zhijApiList, //支架
      })
    })
  },
  /** 获取电站详情 **/
  entryDetail(e) {
    let that = this
    wx.showLoading({
      title: "加载中"
    })
    entryDetail({
      userId: wx.getStorageSync('userId'),
      entryId: this.data.entryId,
    }).then((res) => {
      wx.hideLoading()
      // 组件,逆变器,并网箱,支架
      if (res.componentList.length > 0) {
        var componentList = [];
        var converterList = [];
        var cagesList = [];
        var zhijList = [];
        var componentNum = 0;
        for (let i = 0; i < res.componentList.length; i++) {
          const element = res.componentList[i];
          var OB = {
            id: "",
            num: "", //数量
            model: "", //名称
            addType: 0,
          }
          if (element.item_type == 3) {
            OB.id = element.item_id;
            OB.num = element.num;
            OB.model = element.model;
            OB.material_model = element.material_model;
            componentNum = element.num * element.model + componentNum
            componentList.push(OB)
          } else if (element.item_type == 1) {
            OB.id = element.item_id;
            OB.num = element.num;
            OB.model = element.model;
            OB.material_model = element.material_model;
            converterList.push(OB)
          } else if (element.item_type == 2) {
            OB.id = element.item_id;
            OB.num = element.num;
            OB.model = element.model;
            cagesList.push(OB)
          } else if (element.item_type == 4) {
            OB.id = element.item_id;
            OB.num = element.num;
            OB.model = element.model;
            zhijList.push(OB)
          }
        }

        //维持默认数组第一addType为1,用以显示新增按钮
        if (componentList.length > 0) {
          componentList[0].addType = 1;
          this.setData({
            componentList: componentList
          })
        } else {
          this.setData({
            componentList: [{
              id: res.modeId ? res.modeId : '',//默认产品信息中的组件规格id
              num: '', //数量
              model: res.modeId ? res.assemblySpecs : '', //名称,默认产品信息中的组件规格
              addType: 1,
            }], //组件初始数量
          })
        }
        if (converterList.length > 0) {
          converterList[0].addType = 1;
          this.setData({
            converterList: converterList
          })
        } else {
          this.setData({
            converterList: [{
              id: "",
              num: "", //数量
              model: "", //名称
              addType: 1,
            }], //逆变器初始数量
          })
        }
        if (cagesList.length > 0) {
          cagesList[0].addType = 1;
          this.setData({
            cagesList: cagesList
          })
        } else {
          this.setData({
            cagesList: [{
              id: "",
              num: "", //数量
              model: "", //名称
              addType: 1,
            }], //并网箱初始数量
          })
        }
        if (zhijList.length > 0) {
          zhijList[0].addType = 1;
          this.setData({
            zhijList: zhijList
          })
        } else {
          this.setData({
            zhijList: [{
              id: "",
              num: "", //数量
              model: "", //名称
              addType: 1,
            }], //支架初始数量
          })
        }

        this.setData({
          productZj:res.assemblySpecs ? Number(res.assemblySpecs) : 0,//产品默认的组件值
          componentNum: (componentNum/1000).toFixed(3),
        })
      }
      this.setData({
        detail: res,
        id: res.id, //修改数据的时候传此ID
        projectId: res.project_id,
        tenant_type: res.tenant_type=='1' ? '个人' : '单位',//1.个人，2单位
        capitalName: res.zfName, //资方
        filingName: res.filing_type=='1' ? '农户备案' : '项目公司备案',//备案类型
        filingType: res.filing_type, // 备案类型:1.农户备案 2.项目公司备案
        //业主信息参数
        name: res.tenant_name,
        phone: res.mobile,
        idCard: res.id_code,
        regno: res.regno,
        provinceName: res.province,
        cityName: res.city,
        areaName: res.area,
        address: res.address,
        //项目信息
        projectName: res.projectName,//产品名称
        companyName: res.project_company_name ? res.project_company_name : "",
        leaseDate: res.leaseDate ? res.leaseDate : '',//预计投放日
        repaymentMethod: res.repayment_method ? res.repayment_method : 1,//划转方式
        //如果租金划转方式是二类卡，那么二类卡的信息 显示这个
        secCardName:res.secCardName ? res.secCardName : '',//二类卡账户名    
        secCardNo:res.secCardNo ? res.secCardNo : '',//二类卡账号
        secBankNumber:res.secBankNumber ? res.secBankNumber : '',//二类卡联行号
        longitude: res.longitude, //经度
        latitude: res.latitude, //纬度
        //房屋信息
        roofType: res.roof_type,
        /********/
        sealRoof:res.seal_roof,//是否封屋顶，1是，2.否
        completionYear:res.completion_year ? res.completion_year : '',//房屋建成年份
        slopeGradient:res.slope_gradient ? res.slope_gradient : '',//屋面坡度
        purlineInterval:res.purline_interval ? res.purline_interval : '',//檀条间距
        waterproof:res.waterproof ? res.waterproof : '',//屋顶防水情况
        sourcePollution:res.source_pollution ? res.source_pollution : '',//是否有污染源
        opsCondition:res.ops_condition ? res.ops_condition : '',//是否具备运维空间
        voltageClasses:res.voltage_classes ? res.voltage_classes : '',//并网电压等级
        transformerCapacity:res.transformer_capacity ? res.transformer_capacity : '',//变压器容量
        restrictFlag:res.restrict_flag ? res.restrict_flag : '',//是否符合变压器容量限制要求
        dipAngle:res.dip_angle ? res.dip_angle : '',//组件倾角
        roofArea: res.roof_area, //屋顶面积
        deg: res.distance,//配电箱至并网点距离
        height: res.building_height,//建筑高度
        azimuth: res.azimuth ? res.azimuth : 1,//方位角
        directionDeg: res.angle,//方位角
        
        projectCode: res.projectCode,
        powerStationCode: res.power_station_code,
        createTime: res.create_time,
        shootType: res.shoot_type ? res.shoot_type : 1, 
        
        
        remark: res.remarks,
        schemeType: res.scheme_type ? res.scheme_type : 1,
        solutionRemark: res.scheme_remarks,
        'photo.designDrawings': res.design_drawings ? res.design_drawings.split(",").map(itm => {return {name: itm, url: IMG_BASE_URL + itm} }) : [], //设计图纸
        paycycle: res.pay_cycle ? res.pay_cycle : "",
        
        age: res.age ? res.age : "", //年龄
        gender: res.gender == "MALE" ? "男" : "女", //性别
        tssBankNum: res.tss_bank_num ? res.tss_bank_num : "", //卡开户行
        tssBankNumName: res.tss_bank_num_name ? res.tss_bank_num_name : "", //卡开户行名称
        bankCode: res.bank_code ? res.bank_code : "",
        bankName: res.bank_name ? res.bank_name : "", //卡账号名称
      });
      //并网方式处理
      if(res.recordBoxHistory){
        if(res.recordBoxHistory ==''){//并网方式没选择过，默认‘单户并网’          
          this.setData({
            // gridType: '0',//并网方式
            boxTotalCount: '', //总数
            boxGroupNum: '', //编号
            boxGroupName: '', //名称
          })
        }else{
          this.setData({
            gridType: res.recordBoxHistory.type,//并网方式
            gridStatus: res.recordBoxHistory.status,//状态为1不能编辑
            boxTotalCount: res.recordBoxHistory.total_count,
            boxGroupNum: res.recordBoxHistory.group_number,
            boxGroupName: res.recordBoxHistory.group_name,
            boxGroupId: res.recordBoxHistory.box_group_id,
          })                
        }
      }
      //保险购买情况
      if (res.insurance_flag == 1) {
        this.setData({
          insuranceName: "控制投放及续保"
        })
      } else if (res.insurance_flag == 2) {
        this.setData({
          insuranceName: "控制投放"
        })
      } else if (res.insurance_flag == 3) {
        this.setData({
          insuranceName: "其他"
        })
      }

      //方案信息
      if (res.scheme_type == 1) {
        for (let i = 0; i < that.data.planList.length; i++) {
          const element = that.data.planList[i];
          if (res.scheme_type_id && (res.scheme_type_id == element.id)) {
            this.setData({
              standardSolutionsListIndex: i,
            })
          }
        }
        this.setData({
          [`standardSolutionsList[0].id`]: res.scheme_id ? res.scheme_id : '',
          [`standardSolutionsList[0].type`]: res.scheme_type_name ? res.scheme_type_name : '',
          [`standardSolutionsList[0].typeId`]: res.scheme_type_id ? res.scheme_type_id : '',
          [`standardSolutionsList[0].name`]: res.scheme_name ? res.scheme_name : "",
        })
      } else if (res.scheme_type == 2) {
        if (res.composePlanList.length > 0) {
          var combinedSolutionsList = []
          for (let i = 0; i < res.composePlanList.length; i++) {
            var combinedSolutionsListOB = {}
            const element = res.composePlanList[i];

            // type: "", //方案类型
            // name: "", //方案名称
            // id: "", //方案ID
            // code: "", //方案编号
            // pickerIndex: 0, //方案类型选择下标
            // drawing: "", //参考图纸
            // addType: 1, //显示新增方案按钮
            if (i == 0) {
              combinedSolutionsListOB.addType = 1;
            }
            combinedSolutionsListOB.code = element.code;
            combinedSolutionsListOB.id = element.planId;
            combinedSolutionsListOB.name = element.name;
            combinedSolutionsListOB.type = element.planType;
            combinedSolutionsListOB.planTypeId = element.planTypeId;
            for (let i = 0; i < that.data.planList.length; i++) {
              const planTypeObj = that.data.planList[i];

              if (planTypeObj.allPlan.length > 0) {
                for (let j = 0; j < planTypeObj.allPlan.length; j++) {
                  const plan = planTypeObj.allPlan[j];
                  if (plan.id == element.planId) {
                    // console.log("=============dasddasdasdasdljjlkk", plan.id == element.planId)
                    combinedSolutionsListOB.pickerIndex = i
                  }
                }
              }
            }
            combinedSolutionsList.push(combinedSolutionsListOB)
          }
          this.setData({
            combinedSolutionsList: combinedSolutionsList
          })
        }
      }

      // 添加图片
      this.setData({
        'photo.zjpbImg': res.zjpb_img ? res.zjpb_img.split(",").map(itm => {return {name: itm,url: IMG_BASE_URL + itm}}) : [], //组件排布图
        'photo.zjzxImg': res.zjzx_img ? res.zjzx_img.split(",").map(itm => {return {name: itm,url: IMG_BASE_URL + itm}}) : [], //组件接线图
        'photo.zjcsImg': res.zjcs_img ? res.zjcs_img.split(",").map(itm => {return {name: itm,url: IMG_BASE_URL + itm}}) : [], //组件支架图
        'photo.zjhsImg': res.zjhs_img ? res.zjhs_img.split(",").map(itm => {return {name: itm,url: IMG_BASE_URL + itm}}) : [], //电气图
        // [`photo.nbqwzImg[0].url`]: res.nbqwz_img ? this.data.IMG_BASE_URL + res.nbqwz_img : WU_TU_PIAN_URL,
        // [`photo.pdxwzImg[0].url`]: res.pdxwz_img ? this.data.IMG_BASE_URL + res.pdxwz_img : WU_TU_PIAN_URL,
        
        [`photo.dzImgs`]: res.dz_imgs ? res.dz_imgs.split(",").map(itm=>{return {name:itm, url:IMG_BASE_URL + itm}}) : [{url:WU_TU_PIAN_URL}],//组合图
        //房屋信息
        [`photo.flyImgs`]:res.fly_imgs ? res.fly_imgs.split(",").map(itm=>{return {name:itm, url:IMG_BASE_URL + itm}}) : [{url:WU_TU_PIAN_URL}],//无人机航拍图
        [`photo.roofPhotoOne`]:res.roof_photo_one ? res.roof_photo_one.split(",").map(itm=>{return {name:itm, url:IMG_BASE_URL + itm}}) : [{url:WU_TU_PIAN_URL}],//安装区域整体照片
        [`photo.roofPhotoTwo`]:res.roof_photo_two ? res.roof_photo_two.split(",").map(itm=>{return {name:itm, url:IMG_BASE_URL + itm}}) : [{url:WU_TU_PIAN_URL}],//安装区域东南角照片
        [`photo.roofPhotoThree`]:res.roof_photo_three ? res.roof_photo_three.split(",").map(itm=>{return {name:itm, url:IMG_BASE_URL + itm}}) : [{url:WU_TU_PIAN_URL}],//安装区域西南角照片
        [`photo.roofPhotoFour`]:res.roof_photo_four ? res.roof_photo_four.split(",").map(itm=>{return {name:itm, url:IMG_BASE_URL + itm}}) : [{url:WU_TU_PIAN_URL}],//安装区域正南照片
        [`photo.roofPhotoFive`]:res.roof_photo_five ? res.roof_photo_five.split(",").map(itm=>{return {name:itm, url:IMG_BASE_URL + itm}}) : [{url:WU_TU_PIAN_URL}],//安装区域细节照片
        [`photo.roofPhotoInterior`]:res.roof_photo_interior ? res.roof_photo_interior.split(",").map(itm=>{return {name:itm, url:IMG_BASE_URL + itm}}) : [{url:WU_TU_PIAN_URL}],//房屋内部环境照片
        [`photo.roofPhotoFacade`]:res.roof_photo_facade ? res.roof_photo_facade.split(",").map(itm=>{return {name:itm, url:IMG_BASE_URL + itm}}) : [{url:WU_TU_PIAN_URL}],//房屋内部结构照片
        [`photo.detailSupplementOne`]:res.detail_supplement_one ? res.detail_supplement_one.split(",").map(itm=>{return {name:itm, url:IMG_BASE_URL + itm}}) : [{url:WU_TU_PIAN_URL}],//逆变器、配电箱预安装位置照片
        [`photo.houseSupplementOne`]:res.house_supplement_one ? res.house_supplement_one.split(",").map(itm=>{return {name:itm, url:IMG_BASE_URL + itm}}) : [{url:WU_TU_PIAN_URL}],//房屋其他障碍物照片
        [`photo.surveyVideo`]:res.survey_video ? res.survey_video.split(",").map(itm=>{return {name:itm, url:IMG_BASE_URL + itm}}) : [{url:WU_TU_PIAN_URL}],//踏勘补充证明视频
        [`photo.houseOwnership`]:res.house_ownership ? res.house_ownership.split(",").map(itm=>{return {name:itm, url:IMG_BASE_URL + itm}}) : [{url:WU_TU_PIAN_URL}],//房产证明
        [`photo.surveyFiles`]:res.survey_files ? res.survey_files.split(",").map(itm=>{return {name:itm, url:IMG_BASE_URL + itm}}) : [],//踏勘记录表
        [`photo.vrRoofOne`]: res.vr_roof_one ? res.vr_roof_one.split(",").map(itm => { return { name: itm, url: IMG_BASE_URL + itm}}) : [], //房屋整体图（VR全景）
        [`photo.vrRoofTwo`]: res.vr_roof_two ? res.vr_roof_two.split(",").map(itm => { return { name: itm, url: IMG_BASE_URL + itm}}) : [], //房屋整体俯视图（VR）
        [`photo.vrRoofThree`]: res.vr_roof_three ? res.vr_roof_three.split(",").map(itm => { return { name: itm, url: IMG_BASE_URL + itm}}) : [], //房屋内部结构图（VR）
        [`photo.vrRoofFour`]: res.vr_roof_four ? res.vr_roof_four.split(",").map(itm => { return { name: itm, url: IMG_BASE_URL + itm}}) : [], //入户全景照片(VR)
        [`photo.houseOutlinePhoto`]: res.house_outline_photo ? res.house_outline_photo.split(",").map(itm => { return { name: itm, url: IMG_BASE_URL + itm}}) : [], //房屋轮廓照片
        'photo.fwImg1': res.fw_img1 ? res.fw_img1.split(",").map(itm => {return {name: itm,url: IMG_BASE_URL + itm}}) : [], //房屋整体图 
        'photo.fwImg2': res.fw_img2 ? res.fw_img2.split(",").map(itm => {return {name: itm,url: IMG_BASE_URL + itm}}) : [], //房屋内部结构图  
        'photo.fwImg3': res.fw_img3 ? res.fw_img3.split(",").map(itm => {return {name: itm,url: IMG_BASE_URL + itm}}) : [], //房屋屋顶东南侧图片 
        'photo.fwImg4': res.fw_img4 ? res.fw_img4.split(",").map(itm => {return {name: itm,url: IMG_BASE_URL + itm}}) : [], //房屋屋顶西南侧图片 
        'photo.fwImg5': res.fw_img5 ? res.fw_img5.split(",").map(itm => {return {name: itm,url: IMG_BASE_URL + itm}}) : [], //遮阴物与房屋距离、高度 
      });
      // console.log("photo",this.data.photo);
      this.getFormSet(res.management)
      //下拉字典
      this.getDictionaryList(res.management, (res2)=>{
        if(res2.angle_azimuth){
          let angleList = res2.angle_azimuth.map(item=>item.columns);
          if(res.azimuth){
            let azimuthName = angleList.find(itm => itm.dict_key === res.azimuth).dict_value;
            this.setData({
              azimuthName
            })
          }   
        }
      }); 
      this.getElectricPlanAll();
      setTimeout(()=>{
        if(res.management == '03' && res.roof_type !=''){
          this.roofTypeToColumn(res.roof_type)
        }
      },500)
    })
  },
  /** 打开文件 **/
  openDocument(res) {
    console.log('openDocument', res)
    let path = res.currentTarget.dataset.path
    if (path) {
      //获取文件后缀
      let suffix = path.substring(path.lastIndexOf('.') + 1) //获取文件后缀
      if (suffix.search(/jpg|png|jpeg/) == -1) {
        wx.downloadFile({
          // 示例 url，并非真实存在
          url: IMG_BASE_URL + path,
          success: function (res) {
            const filePath = res.tempFilePath
            wx.openDocument({
              filePath: filePath,
              showMenu: true,
              success: function (res) {
                console.log('打开文档成功')
              }
            })
          }
        })
      } else {
        wx.previewImage({
          urls: [IMG_BASE_URL + path] // 需要预览的图片http链接列表
        })
      }
    }
  },
  /** 上传pdf或图片 **/
  upload(e) {
    var that = this;
    let name = e.currentTarget.dataset.name;
    let maxcount = e.currentTarget.dataset.maxcount;
    wx.chooseMessageFile({
      count: maxcount - this.data.photo[name].length,
      type: 'all',
      success(res) {
        if (Array.isArray(res.tempFiles)) { //多张
          var count = 0;
          that.afteruploadPhotoReadFile(e, res.tempFiles, count, 'file')
          return
        }
        //获取文件后缀/jpg|png|jpeg|pdf|dwg
        let suffix = res.tempFiles[0].path.substring(res.tempFiles[0].path.lastIndexOf('.') + 1)
        if (suffix.search(/pdf|dwg/) == -1&&name=='designDrawings') {
          wx.showToast({
            title: '文件格式不正确',
            icon: 'none'
          })
          return
        }
        wx.showLoading({
          title: '选择中',
        })
        console.log("执行",res);
        wx.uploadFile({
          // url: that.data.API_BASE_URL + 'common/weChat/uploadImage',
          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'
              })
              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 {
              wx.showToast({
                title: '选择失败',
                icon: 'none'
              })
            }
          }
        })
      }
    })
  },
  /** 删除图片 **/
  deleteImg(e) {
    const name = e.currentTarget.dataset.name
    const index = (name != 'surveyFiles' && name != 'designDrawings') ? e.detail.index : e.currentTarget.dataset.index //删除图片的下标
    this.data.photo[name].splice(index, 1);
    this.setData({
      [`photo.${name}`]: this.data.photo[name]
    })
  },
  /**
   * 选择设计方案
   * @param {*} e 1:标准方案 2:组合方案
   */
  radioChangeSolution(e) {
    this.setData({
      schemeType: e.detail.value == 1 ? 1 : 2,
    })
  },
  /** 选择标准方案类型 **/
  bindPlanChange(e) {
    const index = e.detail.value; //选择第几个
    this.data.standardSolutionsList[0].type = this.data.planList[index].name; //方案类型
    this.data.standardSolutionsList[0].typeId = this.data.planList[index].id; //方案类型id
    this.data.standardSolutionsList[0].name = ""; //方案名称
    this.data.standardSolutionsList[0].code = ""; //方案编号
    this.data.standardSolutionsList[0].nameId = ""; //方案名称Id
    this.data.standardSolutionsList[0].id = "";
    this.setData({
      standardSolutionsList: this.data.standardSolutionsList,
      standardSolutionsListIndex: index, //选择方案类型的下标用以渲染方案名称picker选择器
    })
  },
  /** 选择标准方案名称 **/
  bindPlanNameChange(e) {
    if (!this.data.standardSolutionsListIndex) {
      wx.showToast({
        title: '请先选择标准方案类型',
        icon: 'none'
      })
      return
    }
    const index = e.detail.value; //选择第几个
    this.data.standardSolutionsList[0].name = this.data.planList[this.data.standardSolutionsListIndex].allPlan[index].name; //方案名称
    this.data.standardSolutionsList[0].id = this.data.planList[this.data.standardSolutionsListIndex].allPlan[index].id; //方案名称Id

    this.setData({
      standardSolutionsList: this.data.standardSolutionsList,
    })

  },
  /** 选择组合方案类型 **/
  bindCombinationPlanChange(e) {
    const pickerIndex = e.detail.value; //选择器选择第几个
    const index = e.currentTarget.dataset.index; //选择第几个

    this.setData({
      [`combinedSolutionsList[${index}].type`]: this.data.planList[pickerIndex].name,
      [`combinedSolutionsList[${index}].planTypeId`]: this.data.planList[pickerIndex].id,
      [`combinedSolutionsList[${index}].pickerIndex`]: pickerIndex, //选择方案类型的下标用以渲染方案名称picker选择器
      [`combinedSolutionsList[${index}].name`]: "",
      [`combinedSolutionsList[${index}].code`]: "",
      [`combinedSolutionsList[${index}].id`]: "",
    })
  },
  /** 选择组合方案名称 **/
  bindCombinationPlanNameChange(e) {
    const pickerIndex = e.detail.value; //选择器选择第几个
    const cindex = e.currentTarget.dataset.cindex; //选择第几个
    const index = e.currentTarget.dataset.index; //选择第几个
    for (let i = 0; i < this.data.combinedSolutionsList.length; i++) {
      const element = this.data.combinedSolutionsList[i];
      if (index == i && !element.type) {
        wx.showToast({
          title: '请先选择当前组合方案类型',
          icon: 'none'
        })
        return
      }
    }
    this.setData({
      [`combinedSolutionsList[${index}].id`]: this.data.planList[cindex].allPlan[pickerIndex].id,
      [`combinedSolutionsList[${index}].name`]: this.data.planList[cindex].allPlan[pickerIndex].name,
      [`combinedSolutionsList[${index}].code`]: this.data.planList[cindex].allPlan[pickerIndex].code,
    })
  },
  /** 选择组件 **/
  bindComponentChange(e) {
    const pickerIndex = e.detail.value; //选择器选择第几个
    const index = e.currentTarget.dataset.index; //选择第几个
    this.setData({
      [`componentList[${index}].material_model`]: this.data.componentApiList[pickerIndex].material_model,
      [`componentList[${index}].model`]: this.data.componentApiList[pickerIndex].model,
      [`componentList[${index}].id`]: this.data.componentApiList[pickerIndex].id,
    })
  },
  /** 选择逆变器 **/
  bindConverterChange(e) {
    const pickerIndex = e.detail.value; //选择器选择第几个
    const index = e.currentTarget.dataset.index; //选择第几个
    this.setData({
      [`converterList[${index}].material_model`]: this.data.converterApiList[pickerIndex].material_model,
      [`converterList[${index}].model`]: this.data.converterApiList[pickerIndex].model,
      [`converterList[${index}].id`]: this.data.converterApiList[pickerIndex].id,
    })
  },
  /** 选择并网箱 **/
  bindCagesChange(e) {
    const pickerIndex = e.detail.value; //选择器选择第几个
    const index = e.currentTarget.dataset.index; //选择第几个
    this.setData({
      [`cagesList[${index}].model`]: this.data.cagesApiList[pickerIndex].model,
      [`cagesList[${index}].id`]: this.data.cagesApiList[pickerIndex].id,
    })
  },
  /** 选择支架 **/
  bindZhijChange(e) {
    const pickerIndex = e.detail.value; //选择器选择第几个
    const index = e.currentTarget.dataset.index; //选择第几个
    this.setData({
      [`zhijList[${index}].model`]: this.data.zhijApiList[pickerIndex].model,
      [`zhijList[${index}].id`]: this.data.zhijApiList[pickerIndex].id,
    })
  },
  /**
   * 输入组件,逆变器,并网箱的数量
   * @param {*} e  1:组件 2:逆变器 3:并网箱
   */
  inputNum(e) {
    switch (e.currentTarget.dataset.type) {
      case "1":
        this.setData({
          [`componentList[${e.currentTarget.dataset.index}].num`]: e.detail.value,
        })
        var componentNum = 0
        for (let i = 0; i < this.data.componentList.length; i++) {
          const element = this.data.componentList[i];
          componentNum = element.num * element.model
        }
        this.setData({
          componentNum: (componentNum/1000).toFixed(3)
        })
        break;
      case "2":
        this.setData({
          [`converterList[${e.currentTarget.dataset.index}].num`]: e.detail.value,
        })
        break;
      case "3":
        this.setData({
          [`cagesList[${e.currentTarget.dataset.index}].num`]: e.detail.value,
        })
        break;
      case "4":
        this.setData({
          [`zhijList[${e.currentTarget.dataset.index}].num`]: e.detail.value,
        })
        break;
    }
  },
  /** 新增方案 **/
  addSolution(e) {
    const list = [{
      type: "", //方案类型
      name: "", //方案名称
      id: "", //方案ID
      code: "", //方案编号
      pickerIndex: 0, //方案类型选择下标
      drawing: "", //参考图纸
    }]
    var demo = this.data.combinedSolutionsList.concat(list)
    this.setData({
      [`combinedSolutionsList[${demo.length-1}]`]: demo[demo.length - 1]
    })
  },
  /** 删除方案 **/
  deleteSolution(e) {
    wx.showModal({
      title: '提示',
      content: '确定删除当前方案？',
      complete: (res) => {
        if (res.confirm) {
          this.data.combinedSolutionsList.splice(e.currentTarget.dataset.index, 1)
          this.setData({
            combinedSolutionsList: this.data.combinedSolutionsList
          })
        }
      }
    })
  },
  /**
   * 新增型号
   * @param {*} e 1:组件 2:逆变器 3:并网箱
   */
  add(e) {
    const list = {
      id: "",
      num: "",
      name: "",
    }
    switch (e.currentTarget.dataset.type) {
      case "1":
        this.setData({
          componentList: this.data.componentList.concat(list)
        })
        break;
      case "2":
        this.setData({
          converterList: this.data.converterList.concat(list)
        })
        break;
      case "3":
        this.setData({
          cagesList: this.data.cagesList.concat(list)
        })
        break;
      case "4":
        this.setData({
          zhijList: this.data.zhijList.concat(list)
        })
        break;
    }
  },
  /**
   * 删除型号
   * @param {*} e 1:组件 2:逆变器 3:并网箱
   */
  delete(e) {
    wx.showModal({
      title: '提示',
      content: '确定删除？',
      complete: (res) => {
        if (res.confirm) {
          switch (e.currentTarget.dataset.type) {
            case "1":
              this.data.componentList.splice(e.currentTarget.dataset.index, 1)
              this.setData({
                componentList: this.data.componentList
              })
              break;
            case "2":
              this.data.converterList.splice(e.currentTarget.dataset.index, 1)
              this.setData({
                converterList: this.data.converterList,
              })
              break;
            case "3":
              this.data.cagesList.splice(e.currentTarget.dataset.index, 1)
              this.setData({
                cagesList: this.data.cagesList,
              })
              break;
            case "4":
              this.data.zhijList.splice(e.currentTarget.dataset.index, 1)
              this.setData({
                zhijList: this.data.zhijList,
              })
              break;
          }
        }
      }
    })
  },
  /** 上传设计图纸,多张图片递归 **/
  afteruploadPhotoReadS(e, count) {
    let ob = {
      name: '',
      url: '',
    }
    wx.showLoading({
      title: '加载第' + (count + 1) + '张照片中',
      mask: true,
    })
    const element = e.detail.file[count];
    var that = this;
    wx.uploadFile({
      url: that.data.API_BASE_URL + 'common/weChat/uploadImage',
      filePath: element.url,
      name: 'file',
      success(res) {
        wx.hideLoading()
        console.log("res", res)
        if (res.statusCode == 200) {
          count = count + 1;
          ob.name = res.data
          ob.url = element.url
          that.data.photo.designDrawings.push(ob)
          console.log("designDrawings", that.data.photo.designDrawings)
          that.setData({
            'photo.designDrawings': that.data.photo.designDrawings
          })
          if (count == e.detail.file.length) {
            wx.showToast({
              title: '选择成功',
              icon: 'error'
            })
          } else {
            that.afteruploadPhotoReadS(e, count)
          }
        } else {
          wx.showToast({
            title: '选择失败',
            icon: 'error'
          })
        }
      }
    })
  },
  /** 文件上传多张递归 **/
  afteruploadPhotoReadFile(e, file, count, type) {
    let ob = {
      name: '',
      url: '',
    }
    const name = e.currentTarget.dataset.name
    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)
      // console.log(989898, name,suffix)
      if (suffix.search(/pdf|dwg/) == -1&&name=='designDrawings') {
        wx.showToast({
          title: '文件格式不正确',
          icon: 'none'
        })
        return
      }
      else if (suffix.search(/jpg|png|jpeg|pdf/) == -1 && name!='designDrawings') {
        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
          that.data.photo[name].push(ob);
          that.setData({
            [`photo.${name}`]: that.data.photo[name]
          })
          if (count == file.length) {
            wx.showToast({
              title: '选择成功',
              icon: 'none'
            })
          } else {
            that.afteruploadPhotoReadFile(e, file, count, type)
          }
        } else {
          wx.showToast({
            title: '选择失败',
            icon: 'error'
          })
        }
      }
    })
  },
  /** 不通过 **/
  noPass(e) {
    if (!this.data.auditOpinion) {
      wx.showToast({
        title: '请输入不通过审核意见',
        icon: 'none'
      })
      return
    }
    wx.showLoading({
      title: "提交中"
    })
    appletsFailed({
      id: this.data.entryId,
      remarks: this.data.auditOpinion ? this.data.auditOpinion : "",
      userId: wx.getStorageSync('userId')
    }).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.msg || res.errMsg,
          icon: res.code
        })
      }
    })
  },
  /** 通过 **/
  pass(ee) {
    // if (this.data.schemeType == 1 && !this.data.standardSolutionsList[0].id) {
    //   wx.showToast({
    //     title: "请完整选择标准方案",
    //     icon: 'none'
    //   })
    //   return
    // } else if (this.data.schemeType == 2) {
    //   for (let i = 0; i < this.data.combinedSolutionsList.length; i++) {
    //     const element = this.data.combinedSolutionsList[i];
    //     if (!element.code) {
    //       wx.showToast({
    //         title: "请完整选择组合方案",
    //         icon: 'none'
    //       })
    //       return;
    //     }
    //   }
    // }

    // var composePlanList = []; // 标准方案或组合方案
    // if (this.data.schemeType == 2) { //组合
    //   this.data.combinedSolutionsList.forEach(element => {
    //     var composePlanListOB = {}
    //     composePlanListOB.code = element.code;
    //     composePlanListOB.name = element.name;
    //     composePlanListOB.planType = element.type;
    //     composePlanListOB.planId = element.id;
    //     composePlanListOB.planTypeId = element.planTypeId;
    //     composePlanList.push(composePlanListOB)
    //   });
    // }

    // var itemList = []; //组件 逆变器 并网箱  1:组件 2:逆变器 3:并网箱
    // this.data.componentList.forEach(element => { //组件
    //   var component = {}
    //   if (element.id && element.num) {
    //     component.itemType = 3;
    //     component.itemId = element.id;
    //     component.num = element.num
    //     itemList.push(component)
    //   }
    // });

    // this.data.converterList.forEach(element => { //逆变器
    //   var component = {}
    //   if (element.id && element.num) {
    //     component.itemType = 1;
    //     component.itemId = element.id;
    //     component.num = element.num;
    //     itemList.push(component)
    //   }
    // });

    // this.data.cagesList.forEach(element => { //并网箱
    //   var component = {}
    //   if (element.id && element.num) {
    //     component.itemType = 2;
    //     component.itemId = element.id;
    //     component.num = element.num;
    //     itemList.push(component)
    //   }
    // });
    // this.data.zhijList.forEach(element => { //支架
    //   var component = {}
    //   if (element.id && element.num) {
    //     component.itemType = 4;
    //     component.itemId = element.id;
    //     component.num = element.num;
    //     itemList.push(component)
    //   }
    // });

    var CustomerEntry = {
      id: this.data.id ? this.data.id : "",
      // composePlanLists: composePlanList.length > 0 ? composePlanList : [],
      // itemList: itemList,
      // schemeTypeId: this.data.schemeType == 1 ? this.data.standardSolutionsList[0].typeId ? this.data.standardSolutionsList[0].typeId : "" : "", //当设计方案为标准方案时,传参
      // schemeTypeName: this.data.schemeType == 1 ? this.data.standardSolutionsList[0].type ? this.data.standardSolutionsList[0].type : "" : "",
      // schemeId: this.data.schemeType == 1 ? this.data.standardSolutionsList[0].id ? this.data.standardSolutionsList[0].id : "" : "",
      // schemeName: this.data.schemeType == 1 ? this.data.standardSolutionsList[0].name ? this.data.standardSolutionsList[0].name : "" : "",
      // designDrawings: this.data.photo.designDrawings.length > 0 ? this.data.photo.designDrawings.map(itm => itm.name).join(",") : "", //设计图纸,
      // schemeType: this.data.schemeType, //设计方案
      // schemeRemarks: this.data.solutionRemark ? this.data.solutionRemark : "", //方案备注
      examineRemarks: this.data.auditOpinion ? this.data.auditOpinion : "", //审核意见
    }
    console.log("CustomerEntry", CustomerEntry)
    // return
    var data = {
      userId: wx.getStorageSync('userId'),
      CustomerEntry: CustomerEntry,
    }

    wx.showLoading({
      title: "提交中"
    })

    appletsToExamine(
      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.msg || res.errMsg,
          icon: 'none'
        })
      }
    })
  },
  /** 取消 **/
  cancel(e) {
    wx.showModal({
      title: '提示',
      content: '确定取消？',
      complete: (res) => {
        if (res.cancel) {}
        if (res.confirm) {
          wx.navigateBack()
        }

      }
    })
  },
  /** 勘测设计暂存或提交 **/
  submitFrom(e) {
    var type = e.currentTarget.dataset.type
    if (this.data.schemeType == 1 && !this.data.standardSolutionsList[0].id) {
      wx.showToast({
        title: "请完整选择标准方案",
        icon: 'none'
      })
      return
    } else if (this.data.schemeType == 2) {
      for (let i = 0; i < this.data.combinedSolutionsList.length; i++) {
        const element = this.data.combinedSolutionsList[i];
        if (!element.code) {
          wx.showToast({
            title: "请完整选择组合方案",
            icon: 'none'
          })
          return;
        }
      }
    }

    var composePlanList = []; // 标准方案或组合方案
    if (this.data.schemeType == 2) { //组合
      this.data.combinedSolutionsList.forEach(element => {
        var composePlanListOB = {}
        composePlanListOB.code = element.code;
        composePlanListOB.name = element.name;
        composePlanListOB.planType = element.type;
        composePlanListOB.planId = element.id;
        composePlanListOB.planTypeId = element.planTypeId;
        composePlanList.push(composePlanListOB)
      });
    }

    var itemList = []; //组件 逆变器 并网箱  1:组件 2:逆变器 3:并网箱
    this.data.componentList.forEach(element => { //组件
      var component = {}
      if (element.id && element.num) {
        component.itemType = 3;
        component.itemId = element.id;
        component.num = element.num
        itemList.push(component)
      }
    });

    this.data.converterList.forEach(element => { //逆变器
      var component = {}
      if (element.id && element.num) {
        component.itemType = 1;
        component.itemId = element.id;
        component.num = element.num;
        itemList.push(component)
      }
    });

    this.data.cagesList.forEach(element => { //并网箱
      var component = {}
      if (element.id && element.num) {
        component.itemType = 2;
        component.itemId = element.id;
        component.num = element.num;
        itemList.push(component)
      }
    });
    this.data.zhijList.forEach(element => { //支架
      var component = {}
      if (element.id && element.num) {
        component.itemType = 4;
        component.itemId = element.id;
        component.num = element.num;
        itemList.push(component)
      }
    });

    var CustomerEntry = {
      type: type, //0:暂存 1:提交
      id: this.data.id ? this.data.id : "",
      composePlanLists: composePlanList.length > 0 ? composePlanList : [],
      itemList: itemList,


      schemeTypeId: this.data.schemeType == 1 ? this.data.standardSolutionsList[0].typeId ? this.data.standardSolutionsList[0].typeId : "" : "", //当设计方案为标准方案时,传参
      schemeTypeName: this.data.schemeType == 1 ? this.data.standardSolutionsList[0].type ? this.data.standardSolutionsList[0].type : "" : "",
      schemeId: this.data.schemeType == 1 ? this.data.standardSolutionsList[0].id ? this.data.standardSolutionsList[0].id : "" : "",
      schemeName: this.data.schemeType == 1 ? this.data.standardSolutionsList[0].name ? this.data.standardSolutionsList[0].name : "" : "",

      designDrawings: this.data.photo.designDrawings.length > 0 ? this.data.photo.designDrawings.map(itm => itm.name).join(",") : "", //设计图纸,
      zjpbImg: this.data.photo.zjpbImg.length > 0 ? this.data.photo.zjpbImg.map(itm => itm.name).join(",") : "", //组件排布图,
      zjzxImg: this.data.photo.zjzxImg.length > 0 ? this.data.photo.zjzxImg.map(itm => itm.name).join(",") : "", //组件支架图,
      zjcsImg: this.data.photo.zjcsImg.length > 0 ? this.data.photo.zjcsImg.map(itm => itm.name).join(",") : "", //组件接线图, 
      zjhsImg: this.data.photo.zjhsImg.length > 0 ? this.data.photo.zjhsImg.map(itm => itm.name).join(",") : "", //电气图, 

      schemeType: this.data.schemeType, //设计方案
      schemeRemarks: this.data.solutionRemark ? this.data.solutionRemark : "", //方案备注
      examineRemarks: this.data.auditOpinion ? this.data.auditOpinion : "", //审核意见
    }
    console.log("CustomerEntry", CustomerEntry)
    console.log("zhijList", this.data.zhijList)
    // return
    var data = {
      userId: wx.getStorageSync('userId'),
      CustomerEntry: CustomerEntry,
    }

    wx.showLoading({
      title: "提交中"
    })

    designCustomerEntry(
      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.msg || res.errMsg,
          icon: 'none'
        })
      }
    })
  },
  /** 文件或图片上传选择-对话框 **/
  selectUplosd(e){
    var that = this;
    let name = e.currentTarget.dataset.name;
    let maxcount = e.currentTarget.dataset.maxcount;
    wx.showActionSheet({
      itemList: ['文件', '图片'],
      success: function (res) {
        if (!res.cancel) {
          if (res.tapIndex == 0) {//文件         
            that.upload(e);
          } else if (res.tapIndex == 1) {//图片           
            wx.chooseMedia({
              count: maxcount - that.data.photo[name].length,
              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',
                      })
                      var item = {
                        url: "",
                        name: "",
                      }
                      item.url = rep.tempFiles[0].tempFilePath;
                      item.name = res.data;
                      that.data.photo[name].push(item)
                      that.setData({
                        [`photo.${name}`]: that.data.photo[name]
                      })
                    } else {
                      wx.showToast({
                        title: '选择失败',
                        icon: 'error'
                      })
                    }
                  }
                })
              },
              fail: function(){},
            });
          }
        }
      }
    });
  },
})