const {
  projectList,
  API_BASE_URL,
  IMG_BASE_URL,
  getElectricPlanAll,
  findAllPlan,
  editCustomerEntryBy,
  entryDetail,
  getAddressByLonLat,
  getAddressLonLat,getFormSet
} = require('../../../api/api')
const utilAddWatermark = require('../../../utils/addWatermark')
const utilAddWatermark2 = require('../../../utils/addWatermark2')
const utilGetLocation = require('../../../utils/getLocation')
const utils = require('../../../utils/util')

Page({
  /**
   * 页面的初始数据
   */
  data: {
    isEdit: false,
    API_BASE_URL: API_BASE_URL,
    IMG_BASE_URL: IMG_BASE_URL,
    capture: ['camera'], //拍摄模式
    data: {
      name: ""
    },
    photo: {
      regnoUrl:[],//营业执照
      idCardFrontFileList: [], //身份证正面
      idCardBackFileList: [], //身份证反面

      bankCard: [], //银行卡照片
      // residenceBooklet: [], //户口本复印件
      bpCardFront: [], // 共签人身份证正面
      bpCardBack: [], //  共签人身份证反面
      bpFile: [], //   共签人子女证明材料      
      //踏勘记录表
      surveyPhoneOne: [], //踏勘记录表1
      surveyPhoneTwo: [], //踏勘记录表2
      filingPhone: [], //备案文件
      //外观照片
      outwardHousePhone: [], //房屋外观照片
      inwardHousePhone: [], //房屋内部照片
      roofHousePhone: [], //楼顶厚度照片
      designPaper: "", //设计图纸
      zjpbImg: [], //组件排布图
      zjzxImg: [], // 组件走线图
      zjcsImg: [], //支架侧视图
      zjhsImg: [], //支架后视图
      nbqwzImg: [], //逆变器位置
      pdxwzImg: [], //配电箱位置
    },

    roofType: "平屋顶", //默认为平屋顶
    schemeType: 1, //默认为标准方案
    shootType: 1, //默认为无人机拍摄
    azimuth: 1, //方位角默认为正南
    gender: 1, //默认为男
    repaymentMethod: 1, //划转方式默认为二类卡
    projectId: '',
    insuranceList: ["控制投放及续保", "控制投放", "其他"],
    filingList: ['农户备案', '项目公司备案'],
    isComplement: false, //默认不需要填写共签人信息
  },

  onLoad(e) {
    const projectId = e.projectId; //有projectId说明从列表进去,可能是修改或者是暂存过
    if (projectId) {
      this.setData({
        projectId,
      })
    }
    this.entryDetail();
  },
  onReady() {
  },
  /** 获取电站详情 **/
  entryDetail(e) {
    let that = this
    wx.showLoading({
      title: "加载中"
    })
    entryDetail({
      userId: wx.getStorageSync('userId'),
      entryId: this.data.projectId
    }).then((res) => {
      wx.hideLoading()
      this.setData({
        tenantName: res.tenant_name,
        regno:res.regno,
        [`photo.regnoUrl`]:res.regnoUrl ? [{url:IMG_BASE_URL+res.regnoUrl}] : [],
        mobile: res.mobile,
        region:res.province + res.city + res.area + res.address,
        // [`photo.idCardBackFileList[0].name`]: res.id_card_back,
        // [`photo.idCardBackFileList[0].url`]: this.data.IMG_BASE_URL + res.id_card_back,
        // [`photo.idCardFrontFileList[0].name`]: res.id_card_front,
        // [`photo.idCardFrontFileList[0].url`]: this.data.IMG_BASE_URL + res.id_card_front,
        [`photo.idCardBackFileList`]:res.id_card_back ? [{url:IMG_BASE_URL+res.id_card_back}] : [],
        [`photo.idCardFrontFileList`]:res.id_card_front ? [{url:IMG_BASE_URL+res.id_card_front}] : [],
        corp:res.corp,
        idCard: res.id_code,
        tenant_type: res.tenant_type,
        gender: res.gender == "MALE" ? "1" : "2",
        age: res.age,
      })
      this.getFormSet(res.management);
    });
  },

  /** 获取自定义字段 **/
  getFormSet(partner) {
    getFormSet({
      stage: '01',
      partner: partner,
    }).then((res) => {
      this.setData({
        formSetObj: res.data.columns
      })
    })
  },
  /** 返回 **/
  cancel(e) {
    wx.navigateBack();
  },
})