
<template>
  <div class="jeepay-m-center" style="margin-top: 5px; margin-left: 20px;">
    <a-steps v-show="(vdata.showStyle == showStyleEnum.step) && !isMobile" :current="vdata.currentStep - 1" type="navigation">
      <a-step title="主体信息" />
      <a-step title="经营信息" />
      <a-step title="结算账户" />
    </a-steps>
    <a-divider v-show="!isMobile" />
    <a-divider v-show="isMobile" class="jeepay-m-divider" orientation="left" style="color: #1A66FF;"><span style="color: #2980FD;">{{ vdata.currentStep }}</span>/{{ vdata.steps.length }} {{ vdata.steps[vdata.currentStep - 1] }}</a-divider>
    <!-- 1. 主体信息  -->
    <a-form
      v-show="vdata.showStyle == showStyleEnum.block || vdata.currentStep == 1"
      ref="stepForm1Ref"
      style="margin-top: 20px;"
      :model="applymentDetailInfo"
      :label-col="{ span: 4 }"
      :wrapper-col="{ span: 8 }"
      :rules="vdata.step1Rules"
    >
      <a-divider class="jeepay-m-divider" orientation="left" style="color: #1A66FF;">基础项</a-divider>
      <!-- 商户信息：merInfo  start -->
      <a-form-item label="商户类型" name="merchantType">
        <a-radio-group v-model:value="applymentDetailInfo.merchantType">
          <a-radio :value="1">小微商户</a-radio>
          <a-radio :value="2">个体工商户</a-radio>
          <a-radio :value="3">企业</a-radio>
        </a-radio-group>
      </a-form-item>
      

      <!-- 商户信息：merInfo  end -->

      <!-- 附加信息：plusInfo 该字段为商户的法人身份证等信息 start -->
      <a-divider class="jeepay-m-divider" orientation="left" style="color: #1A66FF;">法定代表人证件</a-divider>
      
      <a-form-item label="法人身份证人像面照片" name="idcard1Img">
        <JeepayUpload v-model:src="applymentDetailInfo.idcard1Img" :imgSize="1" bizType="applyment" ocrType="idCard" @ocrScan="ocrScanByAccountFunc" />
        <span class="jeepay-tip-text">(上传图片自动识别 身份证名称 身份证号)</span>
      </a-form-item>

      <a-form-item label="法人身份证国徽面照片" name="idcard2Img">
        <JeepayUpload v-model:src="applymentDetailInfo.idcard2Img" :imgSize="1" bizType="applyment" ocrType="idCard" @ocrScan="ocrScanByAccountFunc" />
        <span class="jeepay-tip-text">(上传图片自动识别 有效期)</span>
      </a-form-item>
      
      <a-form-item label="法人姓名" name="idcardName">
        <a-input v-model:value.trim="applymentDetailInfo.idcardName" />
      </a-form-item>

      <a-form-item label="法人身份证号" name="idcardNo">
        <a-input v-model:value.trim="applymentDetailInfo.idcardNo" />
      </a-form-item>

      <a-form-item label="法人手机号" name="legalPhone">
        <a-input v-model:value.trim="applymentDetailInfo.legalPhone" />
      </a-form-item>

      <a-form-item label="法人身份证有效期开始日期" name="idcardEffectBegin">
        <a-input v-model:value.trim="applymentDetailInfo.idcardEffectBegin" />
      </a-form-item>
        
      <a-form-item class="jeepay-valid" label="法人身份证有效期结束日期" name="idcardEffectEnd">
        <a-input v-model:value.trim="applymentDetailInfo.idcardEffectEnd" :disabled="applymentDetailInfo.idcardEffectEnd == '长期'" style="width: 150px;margin-right: 10px;" />
        <a-checkbox :checked="applymentDetailInfo.idcardEffectEnd == '长期' " @change="(e) => applymentDetailInfo.idcardEffectEnd = e.target.checked ? '长期' : '' ">长期</a-checkbox>
      </a-form-item>

      <a-divider class="jeepay-m-divider" orientation="left" style="color: #1A66FF;">商户联系人信息</a-divider>
      <a-button shape="round" style="margin-left: 40%; margin-bottom:10px " type="primary" @click="isLegal('contact')">
        <arrow-right-outlined />
        点此使用法人信息
      </a-button>
      
      <a-form-item label="商户联系人姓名" name="contactName">
        <a-input v-model:value.trim="applymentDetailInfo.contactName" />
      </a-form-item>

      <a-form-item label="联系人身份证号码" name="contactIdcardNo">
        <a-input v-model:value.trim="applymentDetailInfo.contactIdcardNo" />
      </a-form-item>

      <a-form-item label="联系人电话" name="contactPhone">
        <a-input v-model:value.trim="applymentDetailInfo.contactPhone" />
      </a-form-item>

      <a-form-item label="联系人身份证有效期开始日期" name="contactIdcardEffectBegin">
        <a-input v-model:value.trim="applymentDetailInfo.contactIdcardEffectBegin" />
      </a-form-item>
        
      <a-form-item class="jeepay-valid" label="联系人身份证有效期结束日期" name="contactIdcardEffectEnd">
        <a-input v-model:value.trim="applymentDetailInfo.contactIdcardEffectEnd" :disabled="applymentDetailInfo.contactIdcardEffectEnd == '长期'" style="width: 150px;margin-right: 10px;" />
        <a-checkbox :checked="applymentDetailInfo.contactIdcardEffectEnd == '长期' " @change="(e) => applymentDetailInfo.contactIdcardEffectEnd = e.target.checked ? '长期' : '' ">长期</a-checkbox>
      </a-form-item>
      <!-- 附加信息：plusInfo 该字段为商户的法人身份证等信息 end -->
      

      <!-- 法人信息 -->
    </a-form>

    <!-- 2. 经营信息  -->
    <a-form
      v-show="vdata.showStyle == showStyleEnum.block || vdata.currentStep == 2"
      ref="stepForm2Ref"
      :model="applymentDetailInfo"
      :label-col="{ span: 4 }"
      :wrapper-col="{ span: 8 }"
      :rules="vdata.step2Rules"
    >
      <!-- 营业执照信息：licInfo start -->
      <div v-if="applymentDetailInfo.merchantType == 2 || applymentDetailInfo.merchantType == 3">
        <a-divider class="jeepay-m-divider" orientation="left" style="color: #1A66FF;">营业执照信息</a-divider>
        <a-form-item label="营业执照照片" name="licenseImg">
          <JeepayUpload v-model:src="applymentDetailInfo.licenseImg" :imgSize="1" bizType="applyment" ocrType="license" @ocrScan="ocrScanFunc" />
          <span class="jeepay-tip-text">(上传图片自动识别：营业执照编号、注册名称、经营详细地址、有效期、部分主营信息（前160个字），识别出来的具体内容商户可自行修改)</span>
        </a-form-item>
        
        <a-form-item label="营业执照编号" name="licenseNo">
          <a-input v-model:value.trim="applymentDetailInfo.licenseNo" />
        </a-form-item>
        
        <a-form-item label="注册名称" name="mchFullName">
          <a-input v-model:value.trim="applymentDetailInfo.mchFullName" />
        </a-form-item>

        <a-form-item label="营业执照有效期开始日期" name="licenseEffectBegin">
          <a-input v-model:value.trim="applymentDetailInfo.licenseEffectBegin" />
        </a-form-item>
        
        <a-form-item class="jeepay-valid" label="营业执照有效期结束日期" name="licenseEffectEnd">
          <a-input v-model:value.trim="applymentDetailInfo.licenseEffectEnd" :disabled="applymentDetailInfo.licenseEffectEnd == '长期'" style="width: 150px;margin-right: 10px;" />
          <a-checkbox :checked="applymentDetailInfo.licenseEffectEnd == '长期' " @change="(e) => applymentDetailInfo.licenseEffectEnd = e.target.checked ? '长期' : '' ">长期</a-checkbox>
        </a-form-item>
      
        <a-form-item class="jeepay-valid" label="注册资本（万元）" name="capital">
          <a-input v-model:value.trim="applymentDetailInfo.capital" :disabled="applymentDetailInfo.capital == '无'" style="width: 150px;margin-right: 10px;" />
          <a-checkbox :checked="applymentDetailInfo.capital == '无' " @change="(e) => applymentDetailInfo.capital = e.target.checked ? '无' : '' ">无</a-checkbox>
          <br>
          <span class="jeepay-tip-text">(如果有注册资本，请填写阿拉伯数字，比如：100)</span>
        </a-form-item>

        <a-form-item label="营业执照注册地址" name="licenseAddress">
          <a-input v-model:value.trim="applymentDetailInfo.licenseAddress" />
        </a-form-item>

        <a-divider class="jeepay-m-divider" orientation="left" style="color: #1A66FF;">受益人信息</a-divider>
        <a-button shape="round" style="margin-left: 40%; margin-bottom:10px " type="primary" @click="isLegal('controler')">
          <arrow-right-outlined />
          点此使用法人作为受益人
        </a-button>
        <a-form-item label="受益人姓名" name="controlerName">
          <a-input v-model:value.trim="applymentDetailInfo.controlerName" />
          <span class="jeepay-tip-text">(控股股东或实际控制人姓名或名称)</span>
        </a-form-item>

        <a-form-item label="受益人身份证号" name="controlerLegalCode">
          <a-input v-model:value.trim="applymentDetailInfo.controlerLegalCode" />
          <span class="jeepay-tip-text">(控股股东或实际控制人证件号码)</span>
        </a-form-item>

        <a-form-item label="收益人身份证有效期开始日期" name="controlerLegalValidityBegin">
          <a-input v-model:value.trim="applymentDetailInfo.controlerLegalValidityBegin" />
        </a-form-item>
        
        <a-form-item class="jeepay-valid" label="收益人身份证有效期结束日期" name="controlerLegalValidityEnd">
          <a-input v-model:value.trim="applymentDetailInfo.controlerLegalValidityEnd" :disabled="applymentDetailInfo.controlerLegalValidityEnd == '长期'" style="width: 150px;margin-right: 10px;" />
          <a-checkbox :checked="applymentDetailInfo.controlerLegalValidityEnd == '长期' " @change="(e) => applymentDetailInfo.controlerLegalValidityEnd = e.target.checked ? '长期' : '' ">长期</a-checkbox>
        </a-form-item>
      </div>
      <!-- 营业执照信息：licInfo end -->

      <a-divider class="jeepay-m-divider" orientation="left" style="color: #1A66FF;">经营信息</a-divider>
      
      <a-form-item label="经营名称 (店名)" name="mchShortName">
        <a-input v-model:value.trim="applymentDetailInfo.mchShortName" />
      </a-form-item>

      <a-form-item label="主营业务" name="businessScope">
        <a-textarea v-model:value.trim="applymentDetailInfo.businessScope" show-count :maxlength="160" />
      </a-form-item>
      
      <a-form-item label="商户类型（MCC）" name="mccCode">
        <JeepayEasypayMccSelect v-model:value="applymentDetailInfo.mccCode" />
      </a-form-item>

      <a-form-item label="商户（经营）区域" name="areaCode">
        <JeepayAreaSelectYsf v-model:value="applymentDetailInfo.areaCode" @change="searchAreaFunc" />
      </a-form-item>

      <a-form-item label="注册（经营）地址" name="address">
        <a-input v-model:value.trim="applymentDetailInfo.address" />
      </a-form-item>
      
      <a-divider class="jeepay-m-divider" orientation="left" style="color: #1A66FF;">门店图片信息</a-divider>
      <!-- photo start -->
      <a-form-item label="收银台照片" name="storeCashierImg">
        <JeepayUpload v-model:src="applymentDetailInfo.storeCashierImg" :imgSize="1" bizType="applyment" />
        <span class="jeepay-tip-text">(小微商户需要法人手持身份证照片站在收银台前面拍照并上传，其他类型的商户仅拍照收银台即可)</span>
      </a-form-item>

      <a-form-item label="内部环境照" name="storeInnerImg">
        <JeepayUpload v-model:src="applymentDetailInfo.storeInnerImg" :imgSize="1" bizType="applyment" />
      </a-form-item>

      <a-form-item label="营业场所门头照" name="storeOuterImg">
        <JeepayUpload v-model:src="applymentDetailInfo.storeOuterImg" :imgSize="1" bizType="applyment" />
      </a-form-item>

      <a-form-item label="门牌号照" name="houseNumImg">
        <JeepayUpload v-model:src="applymentDetailInfo.houseNumImg" :imgSize="1" bizType="applyment" />
        <span class="jeepay-tip-text">(如果无门牌号，比如摊位，就把摊位拍照上传)</span>
      </a-form-item>

      <a-form-item label="定位照" name="locationImg">
        <JeepayUpload v-model:src="applymentDetailInfo.locationImg" :imgSize="1" bizType="applyment" />
        <span class="jeepay-tip-text">(小微：必须上传【租赁合同】证明合规性；<br>
          个体和企业：地图可以直接搜到公司名称的话，直接截图上传就行，没在地图注册的话，去经营现场打开地图，浮现光标的地址，进行截图上传)</span>
      </a-form-item>
      <!-- photo end -->
    </a-form>
    

    <!-- 3. 结算账户  -->
    <a-form
      v-show="vdata.showStyle == showStyleEnum.block || vdata.currentStep == 3"
      ref="stepForm3Ref"
      :model="applymentDetailInfo"
      :label-col="{ span: 4 }"
      :wrapper-col="{ span: 8 }"
      :rules="vdata.step3Rules"
    >
      <!-- 结算账户信息：accInfo start -->
      <a-divider class="jeepay-m-divider" orientation="left" style="color: #1A66FF;">结算账户信息</a-divider>
      <a-form-item label="结算方式" name="settleWay">
        <a-radio-group v-model:value="applymentDetailInfo.settleWay" defaultValue="01" @change="() => emit('itemRender')">
          <a-radio value="01">T1</a-radio>
          <a-radio value="02">D1</a-radio>
          <a-radio value="03">D0</a-radio>
        </a-radio-group>
      </a-form-item>
      
      <div v-if="applymentDetailInfo.merchantType != 1">
        <a-form-item label="账户类型" name="settAccountType">
          <a-radio-group v-model:value="applymentDetailInfo.settAccountType">
            <a-radio value="B">对公</a-radio>
            <a-radio value="C">个人（对私）</a-radio>
          </a-radio-group>
        </a-form-item>

        <a-form-item v-if="applymentDetailInfo.settAccountType == 'C'" label="是否结算到法人" name="ifSettToLegal">
          <a-radio-group v-model:value="applymentDetailInfo.ifSettToLegal" @change="isLegal('settle')">
            <a-radio :value="1">是</a-radio>
            <a-radio :value="0">否</a-radio>
          </a-radio-group>
        </a-form-item>
      </div>

      <a-form-item v-if="applymentDetailInfo.settAccountType == 'C' || applymentDetailInfo.merchantType == 1" label="银行卡正面照" name="settAccountLicenseImg">
        <JeepayUpload v-model:src="applymentDetailInfo.settAccountLicenseImg" :imgSize="1" bizType="applyment" ocrType="bankCard" @ocrScan="ocrScanBySettAccountBankCardFunc" />
        <span class="jeepay-tip-text">(上传图片自动识别 银行卡号)</span>
      </a-form-item>

      <a-form-item v-if="applymentDetailInfo.settAccountType == 'C' && applymentDetailInfo.merchantType != 1 && applymentDetailInfo.ifSettToLegal == 0" label="持卡人手持银行卡照片" name="settAccountByHandImg">
        <JeepayUpload v-model:src="applymentDetailInfo.settAccountByHandImg" :imgSize="1" bizType="applyment" />
        <span class="jeepay-tip-text">(此处对应易生的清算授权书内容，使用本平台需要上传持卡人手持银行卡)</span>
      </a-form-item>

      <a-form-item label="开户支行名称" name="settAccountBankBranchName">
        <a-input v-model:value.trim="applymentDetailInfo.settAccountBankBranchName" placeholder="开户支行名称" />
        <span><a href="https://www.icvio.cn/" target="_blank">开户支行名称及联行号查询</a></span>
      </a-form-item>

      <a-form-item label="联行号" name="bankCode">
        <a-input v-model:value.trim="applymentDetailInfo.bankCode" placeholder="联行号" />
      </a-form-item>

      <a-form-item label="结算账户号" name="settAccountNo">
        <a-input v-model:value.trim="applymentDetailInfo.settAccountNo" />
      </a-form-item>

      <a-form-item label="账户名称" name="settAccountName">
        <a-input v-model:value.trim="applymentDetailInfo.settAccountName" />
      </a-form-item> 

      <div v-if="applymentDetailInfo.settAccountType == 'C'">
        <a-form-item label="结算人身份证号" name="settAccountIdcardNo">
          <a-input v-model:value.trim="applymentDetailInfo.settAccountIdcardNo" />
        </a-form-item> 
        <a-form-item label="结算人手机号" name="settAccountPhone">
          <a-input v-model:value.trim="applymentDetailInfo.settAccountPhone" />
        </a-form-item>
      </div>

      <div v-if="applymentDetailInfo.merchantType == 3 && applymentDetailInfo.settAccountType == 'C'">
        <a-divider class="jeepay-m-divider" orientation="left" style="color: #1A66FF;">对公账户信息</a-divider>
      </div>

      <a-form-item v-if="applymentDetailInfo.merchantType != 1" label="开户许可证照片" name="companyAccountLicenseImg">
        <JeepayUpload v-model:src="applymentDetailInfo.companyAccountLicenseImg" :imgSize="1" bizType="applyment" />
        <span class="jeepay-tip-text">(以下场景下必传：1.对私结算；2.经营名称等包含“有限”两字)</span>
      </a-form-item>
      
      <!-- 结算账户信息：accInfo end -->

      <!-- 结算账户信息2：accInfoBak 企业且对私时，上传企业的对公账户信息 start -->
      <div v-if="applymentDetailInfo.merchantType == 3 && applymentDetailInfo.settAccountType == 'C'">
        <a-form-item label="开户支行名称" name="companyAccountBankBranchName">
          <a-input v-model:value.trim="applymentDetailInfo.companyAccountBankBranchName" placeholder="开户支行名称" />
          <span><a href="https://www.icvio.cn/" target="_blank">联行号及开户支行名称查询</a></span>
        </a-form-item>

        <a-form-item label="联行号" name="companyBankCode">
          <a-input v-model:value.trim="applymentDetailInfo.companyBankCode" placeholder="联行号" />
        </a-form-item>

        <a-form-item label="结算账户号" name="companyAccountNo">
          <a-input v-model:value.trim="applymentDetailInfo.companyAccountNo" />
        </a-form-item>

        <a-form-item label="账户名称" name="companyAccountName">
          <a-input v-model:value.trim="applymentDetailInfo.companyAccountName" />
        </a-form-item> 
      </div>
      <!-- 结算账户信息2：accInfoBak 企业且对私时，上传企业的对公账户信息 end -->
      
      
      <!-- 产品费率 -->
      <a-divider class="jeepay-m-divider" orientation="left" style="color: #1A66FF;">产品费率</a-divider>

      <div label="配置费率" name="fee" style="width:100%;">
        <JeepayPaywayRatePanel 
          ref="jeepayPaywayRatePanelRef"
          :configMode="configMode"
          :infoId=" (mchApplymentData.applyId || '') + '_' + mchApplymentData.mchNo" 
          :selectIfCode="mchApplymentData.ifCode"
          onlyRate="true"
        />
      </div>
    </a-form>
    <a-divider />

    <div class="jeepay-btn-box jeepay-m-btn-box" style="margin-top: 50px; margin-bottom: 50px;text-align: center;">
      <a-button v-show="vdata.showStyle == showStyleEnum.step && vdata.currentStep > 1" class="jeepay-m-btn" data-type="inline" type="primary" @click="toPrevStep"><left-circle-outlined /> 上一步 </a-button>
      <a-button v-show="vdata.showStyle == showStyleEnum.step && vdata.currentStep < 3" class="jeepay-m-btn" data-type="inline" type="primary" @click="toNextStep">下一步 <right-circle-outlined /> </a-button>
    </div>
  </div>
</template>

<script setup lang="ts">

import {reactive, getCurrentInstance, defineEmits, inject, ref} from 'vue'
import ruleGenerator from '@/utils/ruleGenerator'

const jeepayPaywayRatePanelRef = ref()

// 获取当前实例的代理对象
const { proxy } : any = getCurrentInstance()

const { $infoBox } = getCurrentInstance()!.appContext.config.globalProperties


// 显示类型枚举值
const showStyleEnum = {
  step: 'step',
  block: 'block'
}

// emit： 向父组件进行通讯。 
const emit = defineEmits(['itemRender'])

// 参数注入： 是否手机端
let isMobile : any = inject('isMobile')

// 响应式数据
const vdata : any = reactive({
  showStyle: 'step', // 显示类型： step-分步,  block-整页显示 
  steps: ['主体信息', '经营信息', '结算账户'],
  isTempData: false, // 是否保存草稿
  isvDefaultPaywayFee: {} as any, // 服务商默认费率
  currentStep: 1,
  receiverTableData: [] as any,
  branchBankList:[] as any, // 支行列表
  step1Rules: {
                merchantType: [ ruleGenerator.requiredSelect('商户类型', 'number') ],
                idcard1Img: [ ruleGenerator.requiredUpload('法人身份证人像面照片') ],
                idcard2Img: [ ruleGenerator.requiredUpload('法人身份证国徽面照片') ],
                idcardName: [ ruleGenerator.requiredInput('法人姓名') ],
                idcardNo: [ ruleGenerator.requiredInput('法人身份证号') ],
                legalPhone: [ ruleGenerator.requiredInput('法人手机号') ],
                idcardEffectBegin: [ ruleGenerator.requiredInput('法人身份证有效期开始日期') ],
                idcardEffectEnd: [ ruleGenerator.requiredInput('法人身份证有效期结束日期') ],
                contactName: [ ruleGenerator.requiredInput('商户联系人姓名') ],
                contactIdcardNo: [ ruleGenerator.requiredInput('联系人身份证号码') ],
                contactPhone: [ ruleGenerator.requiredInput('联系人电话') ],
                contactIdcardEffectBegin: [ ruleGenerator.requiredInput('联系人身份证有效期开始日期') ],
                contactIdcardEffectEnd: [ ruleGenerator.requiredInput('联系人身份证有效期结束日期') ]
              },
  step2Rules: {
      licenseImg: [ ruleGenerator.requiredUpload('营业执照照片') ],
      licenseNo: [ ruleGenerator.requiredInput('营业执照编号') ],
      mchFullName: [ ruleGenerator.requiredInput('注册名称') ],
      licenseEffectBegin: [ ruleGenerator.requiredInput('营业执照有效期开始日期') ],
      licenseEffectEnd: [ ruleGenerator.requiredInput('营业执照有效期结束日期') ],
      capital: [ ruleGenerator.requiredInput('注册资本') ],
      licenseAddress: [ ruleGenerator.requiredInput('营业执照注册地址') ],
      controlerName: [ ruleGenerator.requiredInput('受益人姓名') ],
      controlerLegalCode: [ ruleGenerator.requiredInput('受益人身份证号') ],
      controlerLegalValidityBegin: [ ruleGenerator.requiredInput('收益人身份证有效期开始日期') ],
      controlerLegalValidityEnd: [ ruleGenerator.requiredInput('收益人身份证有效期结束日期') ],
      mchShortName: [ ruleGenerator.requiredInput('经营名称 (店名)') ],
      businessScope: [ ruleGenerator.requiredInput('主营业务') ],
      mccCode: [ ruleGenerator.requiredSelect('商户类型') ],
      areaCode: [ ruleGenerator.requiredSelect('经营区域', 'array') ],
      address: [ ruleGenerator.requiredInput('经营地址') ],
      storeCashierImg: [ ruleGenerator.requiredUpload('收银台照片') ],
      storeInnerImg: [ ruleGenerator.requiredUpload('内部环境照') ],
      storeOuterImg: [ ruleGenerator.requiredUpload('营业场所门头照') ],
      houseNumImg: [ ruleGenerator.requiredUpload('门牌号照') ],
      locationImg: [ ruleGenerator.requiredUpload('定位照') ],
  },
  step3Rules: {
      settleWay: [ ruleGenerator.requiredSelect('结算方式', 'string') ],
      settAccountType: [ ruleGenerator.requiredSelect('结算类型', 'string') ],
      ifSettToLegal: [ ruleGenerator.requiredSelect('是否为法人', 'number') ],
      settAccountLicenseImg: [ ruleGenerator.requiredUpload('银行卡正面照') ],
      settAccountByHandImg: [ ruleGenerator.requiredUpload('持卡人手持银行卡照片') ],
      settAccountBankBranchName: [ ruleGenerator.requiredInput('开户支行名称') ],
      bankCode: [ ruleGenerator.requiredInput('联行号') ],
      settAccountNo: [ ruleGenerator.requiredInput('结算账户号') ],
      settAccountName: [ ruleGenerator.requiredInput('账户名称') ],
      settAccountIdcardNo: [ ruleGenerator.requiredInput('结算人身份证号码') ],
      settAccountPhone: [ ruleGenerator.requiredInput('结算人手机号') ],
      // companyAccountLicenseImg: [ ruleGenerator.requiredUpload('开户许可证照片') ],
      stlAuthImg: [ ruleGenerator.requiredUpload('对私清算授权书照片') ],
      // 对公账户
      companyAccountBankBranchName: [ ruleGenerator.requiredInput('开户支行名称') ],
      companyBankCode: [ ruleGenerator.requiredInput('联行号') ],
      companyAccountNo: [ ruleGenerator.requiredInput('结算账户号') ],
      companyAccountName: [ ruleGenerator.requiredInput('账户名称') ]
  }
})

// 接收进件参数(包含 用户号， ifCode )
let mchApplymentDataRef : any = inject('mchApplymentData')
let mchApplymentData : any = mchApplymentDataRef.value

// 接收父组件的进件详细参数
let applymentDetailInfoInject : any = inject('applymentDetailInfo')
let applymentDetailInfo : any = applymentDetailInfoInject.value

// 参数注入： 配置方式
let configMode : any = inject('configMode')


// 下一步
function toNextStep() {
  // 验证是否通过
  proxy.$refs['stepForm'+vdata.currentStep+'Ref'].validate().then( () => {
      vdata.currentStep ++
  })
  if (!applymentDetailInfo.settleWay) {
    applymentDetailInfo.settleWay = '01'
  }
}

// 上一步
function toPrevStep(){
  vdata.currentStep --
}

function validateAllForm(step: number){
  return proxy.$refs['stepForm'+step+'Ref'].validate().then( () => {
     if(step >= 3){
      return Promise.resolve()
     }
     return validateAllForm(++step)
     
  })
}

if(applymentDetailInfo.feeData) {
  vdata.receiverTableData = applymentDetailInfo.feeData
}

// 图片识别的回调函数  营业执照
function ocrScanFunc(orcObject){
  if(orcObject){
    if(orcObject.licenseNo){
      applymentDetailInfo.licenseNo = orcObject.licenseNo
    }
    if(orcObject.mchFullName){
      applymentDetailInfo.mchFullName = orcObject.mchFullName
    }
    if(orcObject.licenseAddress){
      applymentDetailInfo.licenseAddress = orcObject.licenseAddress
    }
    if(orcObject.licenseEffectBegin){
      applymentDetailInfo.licenseEffectBegin = orcObject.licenseEffectBegin
    }
    if(orcObject.licenseEffectEnd){
      applymentDetailInfo.licenseEffectEnd = orcObject.licenseEffectEnd
    }
    if(orcObject.licenseBusiness){
      applymentDetailInfo.businessScope = orcObject.licenseBusiness.substring(0,160)
    }
  }
}

// 识别银行卡信息 
function ocrScanBySettAccountBankCardFunc(orcObject){
  if(orcObject){
     if(orcObject.settAccountNo){
      applymentDetailInfo.settAccountNo = orcObject.settAccountNo
    }
  }
}

// 图片识别的回调函数  法人身份证
function ocrScanByAccountFunc(orcObject){
  if(orcObject){
    if(orcObject.idcardName){
      applymentDetailInfo.idcardName = orcObject.idcardName
    }
    if(orcObject.idcardNo){
      applymentDetailInfo.idcardNo = orcObject.idcardNo
    }
    if(orcObject.idcardEffectBegin){
      applymentDetailInfo.idcardEffectBegin = orcObject.idcardEffectBegin
    }
    if(orcObject.idcardEffectEnd){
      applymentDetailInfo.idcardEffectEnd = orcObject.idcardEffectEnd
    }
  }
}

// 点击【保存】的前置事件, 需要返回Promise对象
function saveDataPreCallback(isTemp){

  if (applymentDetailInfo.merchantType == 1) {
    applymentDetailInfo.mchFullName = applymentDetailInfo.mchShortName + '[商户_' + applymentDetailInfo.idcardName + ']'
  }

  // 放置费率配置项
  let paywayFeeList = jeepayPaywayRatePanelRef.value.getReqMchRatePaywayFeeList()
  if(typeof(paywayFeeList) != 'object'){
      return Promise.reject()
  }

  // 赋值到对象中
  applymentDetailInfo.paywayFeeList = paywayFeeList


  // 站点信息
  applymentDetailInfo.feeData = vdata.receiverTableData

  // 保存草稿只校验当前步骤数据
  if (isTemp) {
    return Promise.resolve()
  }

  // 验证所有表单
  return validateAllForm(1).then(() => {
    return Promise.resolve()
  }).catch((params: any) => {
    $infoBox.message.error('数据填写不完整， 请检查后提交')
    return Promise.reject()
  })
}


// 商户经营地省市县 回调
function searchAreaFunc(value) {
  if (applymentDetailInfo.address) {
    applymentDetailInfo.address = ''
  }
  if (value.length) {
    if (value.length == 2) {
      applymentDetailInfo.address = value[0].label + '' + value[1].label + ''
    } else if (value.length == 3) {
      applymentDetailInfo.address = value[0].label + '' + value[1].label + '' + value[2].label + ''
    }
  }
}

// 将法人信息填入到指定地方
function isLegal(type){
  if (type) {
    if (type == 'contact') {
      // 将法人信息填入到商户联系人中
      applymentDetailInfo.contactName = applymentDetailInfo.idcardName
      applymentDetailInfo.contactIdcardNo = applymentDetailInfo.idcardNo
      applymentDetailInfo.contactPhone = applymentDetailInfo.legalPhone
      applymentDetailInfo.contactIdcardEffectBegin = applymentDetailInfo.idcardEffectBegin
      applymentDetailInfo.contactIdcardEffectEnd = applymentDetailInfo.idcardEffectEnd
    } else if (type == 'settle') {
      // 是否结算到法人
      if (applymentDetailInfo.ifSettToLegal == 1) {
        applymentDetailInfo.settAccountName = applymentDetailInfo.idcardName
        applymentDetailInfo.settAccountIdcardNo = applymentDetailInfo.idcardNo
        applymentDetailInfo.settAccountPhone = applymentDetailInfo.legalPhone
      } else {
        applymentDetailInfo.settAccountName = ''
        applymentDetailInfo.settAccountIdcardNo = ''
        applymentDetailInfo.settAccountPhone = ''
      }
    } else if (type == 'controler') {
      // 将法人作为受益人
      applymentDetailInfo.controlerName = applymentDetailInfo.idcardName
      applymentDetailInfo.controlerLegalCode = applymentDetailInfo.idcardNo
      applymentDetailInfo.controlerLegalValidityBegin = applymentDetailInfo.idcardEffectBegin
      applymentDetailInfo.controlerLegalValidityEnd = applymentDetailInfo.idcardEffectEnd
    }
  }
}

defineExpose({ saveDataPreCallback })

</script>

<style lang="less" scoped>
.jeepay-tip-text{
  font-size: 10px; color: rebeccapurple
}
.option-left {
  width: 50%;
  word-wrap: break-word; 
  white-space: normal;
  word-break: break-all;
}
.option-right {
  color: rgb(153, 153, 153);
}
.option-bottom {
  word-wrap: break-word; 
  white-space: normal;
  word-break: break-all;
  color: rgb(153, 153, 153);
}
.jeepay-btn-box {
  margin: 15px -12px !important;
}
.jeepay-btn-box .ant-btn {
  margin: 0 10px;
}
</style>