<!--
 * @Author: wj 1454560336@qq.com
 * @Date: 2023-09-18 10:57:47
 * @LastEditors: wenjie 1454560336@qq.com
 * @LastEditTime: 2024-05-16 09:38:09
 * @FilePath: \admin-manage\src\views\operationManage\shopManage\shopAdd2.vue
 * @Description: 
 * 
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved. 
-->
<!--
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2023-05-26 16:37:34
 * @LastEditors: wj 1454560336@qq.com
 * @LastEditTime: 2023-11-20 15:04:50
 * @FilePath: \admin-manage\src\views\operationManage\shopManage\shopAdd1.vue
 * @Description: 
 * 
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved. 
-->
<template>
  <div class="shopAdd app-container">
    <div class="step-box">
      <el-steps :space="200" :active="step" simple finish-status="success">
        <el-step title="商户信息"></el-step>
        <el-step title="身份信息"></el-step>
        <el-step title="结算信息"></el-step>
        <el-step title="股东信息"></el-step>
        <el-step title="图片信息"></el-step>
      </el-steps>
    </div>

    <el-form
      :model="setQuery"
      ref="setQuery"
      :rules="rules"
      label-width="180px"
      v-loading="loading"
      :disabled="mode == 'detail'"
    >
      <template v-if="step == 1">
        <el-form-item label="营业名称：" prop="shop_name">
          <el-input
            v-model="setQuery.shop_name"
            class="item-width-300"
            placeholder="请输入营业名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="营业地区-详细地址：" prop="shop_addr_ext">
          <el-input
            v-model="setQuery.shop_addr_ext"
            class="item-width-600"
            disabled
            placeholder="请选择营业地址"
          ></el-input>
          <i class="el-icon-location position red ml10" @click="chooseAddress"></i>
        </el-form-item>
        <!-- <el-form-item label="商户类型：" prop="mchntType">
          <el-select
            v-model="setQuery.mchntType"
            class="item-width-300"
            placeholder="请选择商户类型"
          >
            <el-option
              v-for="item in typeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="所属行业：" prop="mccCode">
          <el-select
            v-model="setQuery.mccCode"
            class="item-width-300"
            filterable
            placeholder="请选择所属行业"
          >
            <el-option
              v-for="item in mccOptions"
              :key="item.mcccode"
              :label="item.mccname"
              :value="item.mcccode"
            >
            </el-option>
          </el-select>
        </el-form-item>
         <el-form-item label="是否连锁：" prop="isChain">
          <el-radio-group v-model="setQuery.isChain">
          <el-radio label="0">是</el-radio>
          <el-radio label="1">否</el-radio>
        </el-radio-group>
        </el-form-item>
        <el-form-item label="营业执照号码：" prop="shop_lic">
          <el-input
            v-model="setQuery.shop_lic"
            class="item-width-300"
            placeholder="请输入营业执照号码："
          ></el-input>
        </el-form-item>
        <el-form-item label="营业执照：" prop="businessImg">
          <Upload
            type="C0002"
            id="C0002"
            width="250px"
            height="150px"
            :disabled="mode == 'detail'"
            uploadType="YIN_LIAN_AUTH"
            :imgUrl="setQuery.businessImg"
            @uploadEnd="uploadEnd"
          ></Upload>
          <div class="notice">
            (图片支持jpg, png, bmp格式，建议上传100kb~500kb大小文件)
          </div>
        </el-form-item>
         <el-form-item label="绑定主商户" prop="remark">
          <el-checkbox-group v-model="setQuery.remark">
            <el-checkbox label="89852017372911Y中数">慧研学惠生活</el-checkbox>
            <el-checkbox label="89852017372912Y贵大" >印象贵大</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
      </template>

      <template v-if="step == 2">
        <el-form-item label="姓名：" prop="legal_name">
          <el-input
            v-model="setQuery.legal_name"
            size="small"
            class="item-width-300"
            placeholder="请输入身份证姓名"
          ></el-input>
        </el-form-item>
        <el-form-item label="身份证号码：" prop="legal_idcard_no">
          <el-input
            v-model="setQuery.legal_idcard_no"
            size="small"
            :maxlength="18"
            class="item-width-300"
            placeholder="请输入身份证号码"
          ></el-input>
        </el-form-item>
        <el-form-item label="身份证有效期：" prop="legal_card_start">
          <el-date-picker
            v-model="date"
            :disabled="checked"
            size="small"
            type="daterange"
            range-separator="至"
            value-format="yyyy-MM-dd"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
          <el-checkbox v-model="checked" :disabled="!setQuery.legal_card_start">长期</el-checkbox>
        </el-form-item>
        <el-form-item label="职业：" prop="legal_occupation">
          <el-select
            v-model="setQuery.legal_occupation"
            size="small"
            class="item-width-300"
            placeholder="请选择职业类型"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="身份证正面：" prop="idCardImg">
          <Upload
            type="A0001"
            id="A0001"
            width="250px"
            height="150px"
            :disabled="mode == 'detail'"
            uploadType="YIN_LIAN_AUTH"
            :imgUrl="setQuery.idCardImg"
            @uploadEnd="uploadEnd"
          ></Upload>
          <div class="notice">
            (图片支持jpg, png, bmp格式，建议上传100kb~500kb大小文件)
          </div>
        </el-form-item>
        <el-form-item label="身份证反面：" prop="idCardBackImg">
          <Upload
            type="A0011"
            id="A0011"
            width="250px"
            height="150px"
            :disabled="mode == 'detail'"
            uploadType="YIN_LIAN_AUTH"
            :imgUrl="setQuery.idCardBackImg"
            @uploadEnd="uploadEnd"
          ></Upload>
          <div class="notice">
            (图片支持jpg, png, bmp格式，建议上传100kb~500kb大小文件)
          </div>
        </el-form-item>
        <el-form-item label="手持身份证：" prop="handIdCardImg">
          <Upload
            type="A0007"
            id="A0007"
            width="250px"
            height="150px"
            :disabled="mode == 'detail'"
            uploadType="YIN_LIAN_AUTH"
            :imgUrl="setQuery.handIdCardImg"
            @uploadEnd="uploadEnd"
          ></Upload>
          <div class="notice">
            (图片支持jpg, png, bmp格式，建议上传100kb~500kb大小文件)
          </div>
        </el-form-item>
      </template>

      <template v-if="step == 3">
        <el-form-item label="账户类型：">
          <el-radio v-model="setQuery.bank_acct_type" label="0"
            >个人账户</el-radio
          >
          <el-radio v-model="setQuery.bank_acct_type" label="1"
            >公司账户</el-radio
          >
        </el-form-item>
        <el-form-item label="账户名称：" prop="bank_acct_name">
          <el-input
            v-model="setQuery.bank_acct_name"
            size="small"
            class="item-width-300"
            placeholder="请输入账户名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="银行账号：" prop="bank_acct_no">
          <el-input
            v-model="setQuery.bank_acct_no"
            size="small"
            class="item-width-300"
            placeholder="请输入银行账号"
          ></el-input>
        </el-form-item>
        <el-form-item label="银行预留手机号：" prop="legal_mobile">
          <el-input
            v-model="setQuery.legal_mobile"
            :maxlength="11"
            size="small"
            class="item-width-300"
            placeholder="请输入银行预留手机号"
          ></el-input>
        </el-form-item>
        <el-form-item label="开户所在地：" prop="bank_city_id">
          <el-select
            v-model="setQuery.bank_province_id"
            class="item-width-150"
            size="small"
            placeholder="请选择省"
            :loading="selectLoading"
          >
            <el-option
              v-for="item in provinceList"
              :key="item.name"
              :label="item.name"
              :value="item.code"
            >
            </el-option>
          </el-select>
          <el-select
            v-model="setQuery.bank_city_id"
            class="item-width-150 ml10"
            size="small"
            placeholder="请选择市"
            :loading="selectLoading"
          >
            <el-option
              v-for="item in cityList"
              :key="item.name"
              :label="item.name"
              :value="item.code"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属支行：" prop="bank_no">
          <el-select
            v-model="setQuery.bank_no"
            class="item-width-300"
            size="small"
            filterable
            remote
            placeholder="请选择所属支行"
            :remote-method="branchBankList"
          >
            <el-option
              v-for="item in bankList"
              :key="item.bankBranchName"
              :label="item.bankBranchName"
              :value="item.code"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-if="setQuery.bank_acct_type == 0" label="银行卡正面照片：" prop="cardImg">
          <Upload
            type="B0025"
            id="B0025"
            width="250px"
            height="150px"
            uploadType="YIN_LIAN_AUTH"
            :imgUrl="setQuery.cardImg"
            @uploadEnd="uploadEnd"
          ></Upload>
          <div class="notice">照片需高清、完整、不能有遮挡</div>
          <div class="notice">
            (图片支持jpg, png, bmp格式，建议上传100kb~500kb大小文件)
          </div>
        </el-form-item>
        <el-form-item v-else label="对公结算证明：" prop="settleImg">
          <Upload
            type="B0006"
            id="B0006"
            width="250px"
            height="150px"
            uploadType="YIN_LIAN_AUTH"
            :imgUrl="setQuery.settleImg"
            @uploadEnd="uploadEnd"
          ></Upload>
          <div class="notice">照片需高清、完整、不能有遮挡</div>
          <div class="notice">
            (图片支持jpg, png, bmp格式，建议上传100kb~500kb大小文件)
          </div>
        </el-form-item>
      </template>

      <template v-if="step == 4">
        <div class="title">股东信息</div>
        <el-form-item label="控股股东：" prop="shareholderName">
          <el-input
            v-model="setQuery.shareholderName"
            size="small"
            class="item-width-300"
            placeholder="请输入身份证姓名"
          ></el-input>
          <el-button type="text" class="ml10" @click="handleCopy(1)"
            >同步法人信息</el-button
          >
        </el-form-item>
         <el-form-item label="证件类型：" prop="shareholderCertType">
          <el-select
            v-model="setQuery.shareholderCertType"
            size="small"
            class="item-width-300"
            placeholder="请选择证件类型"
          >
            <el-option
              v-for="item in cardOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="证件号码：" prop="shareholderCertno">
          <el-input
            v-model="setQuery.shareholderCertno"
            size="small"
            :maxlength="18"
            class="item-width-300"
            placeholder="请输入证件号码"
          ></el-input>
        </el-form-item>
        <el-form-item label="身份证有效期：" prop="shareholderCertBeginDate">
          <el-date-picker
            v-model="date1"
            :disabled="checked1"
            size="small"
            type="daterange"
            range-separator="至"
            value-format="yyyy-MM-dd"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
          <el-checkbox :disabled="!setQuery.shareholderCertBeginDate" v-model="checked1">长期</el-checkbox>
        </el-form-item>
        <el-form-item label="家庭地址：" prop="shareholderHomeAddr">
          <el-input
            v-model="setQuery.shareholderHomeAddr"
            size="small"
            class="item-width-500"
            placeholder="请输入家庭地址"
          ></el-input>
        </el-form-item>

        <div class="line"></div>

        <div v-for="(item,index) in setQuery.bnfList" :key="index">
          <div class="title">受益人{{index+1}}</div>
          <el-form-item label="受益人：" :prop="'bnfList.'+index+'.bnfName'" :rules="{ required: true, message: '请输入受益人', trigger: 'blur' }">
            <el-input
              v-model="item.bnfName"
              size="small"
              class="item-width-300"
              placeholder="请输入受益人姓名"
            ></el-input>
            <el-button type="text" class="ml10" v-if="index == 0" @click="handleCopy(2)"
              >同步股东信息</el-button
            >
          </el-form-item>
          <el-form-item label="证件类型：" :prop="'bnfList.'+index+'.bnfCertType'" :rules="{ required: true, message: '请选择证件类型', trigger: 'change' }">
            <el-select
              v-model="item.bnfCertType"
              size="small"
              class="item-width-300"
              placeholder="请选择证件类型"
            >
              <el-option
                v-for="item in cardOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="证件号码：" :prop="'bnfList.'+index+'.bnfCertno'" :rules="{ required: true, message: '请输入身份证号', trigger: 'blur' }">
            <el-input
              v-model="item.bnfCertno"
              size="small"
              :maxlength="18"
              class="item-width-300"
              placeholder="请输入受益人证件号码"
            ></el-input>
          </el-form-item>
          <el-form-item label="身份证有效期：" :prop="'bnfList.'+index+'.bnfCertBeginDate'" :rules="{ required: true, message: '请选择身份证有效期', trigger: 'change' }">
            <el-date-picker
              v-model="perSonObj['date'+(index+1)]"
              :disabled="perSonObj['checked'+(index+1)]"
              size="small"
              type="daterange"
              @change="changeTime($event,index)"
              range-separator="至"
              value-format="yyyy-MM-dd"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
            <el-checkbox v-model="perSonObj['checked'+(index+1)]" @change="checkChange($event,index)" :disabled="!setQuery.bnfList[index].bnfCertBeginDate">  长期</el-checkbox>
          </el-form-item>
          <el-form-item label="家庭地址：" :prop="'bnfList.'+index+'.bnfHomeAddr'" :rules="{ required: true, message: '请输入家庭地址', trigger: 'blur' }">
            <el-input
              v-model="item.bnfHomeAddr"
              size="small"
              class="item-width-300"
              placeholder="请输入受益人家庭地址"
            ></el-input>
           <el-button size="small" class="ml10" type="danger" v-if="setQuery.bnfList.length>1" @click="delPerson(index)">删除受益人</el-button> 
          </el-form-item>
        </div>
        <el-form-item>
           <el-button size="small" @click="addPerson">添加受益人</el-button> 
        </el-form-item>
      </template>

      <template v-if="step == 5">
        <template v-if="setQuery.mchntType == 0 || setQuery.mchntType == 2">

        <el-form-item label="店铺门面照：" prop="doorImg">
          <div class="notice">
            需拍全，包含完整的牌匾、门框（建议正对门店 2 米处拍摄 ）
          </div>
          <div class="notice">
            查看示例图(图片支持jpg, png, bmp格式，建议上传100kb~500kb大小文件)
          </div>
          <Upload
            type="C0005"
            id="C0005"
            width="250px"
            height="150px"
            uploadType="YIN_LIAN_AUTH"
            :imgUrl="setQuery.doorImg"
            @uploadEnd="uploadEnd"
          ></Upload>
        </el-form-item>
        <el-form-item label="店铺室内照：" prop="insideImg">
          <div class="notice">需真实展示店内环境情况 查看示例图</div>
          <div class="notice">
            (图片支持jpg, png, bmp格式，建议上传100kb~500kb大小文件)
          </div>
          <Upload
            type="C0015"
            id="C0015"
            width="250px"
            height="150px"
            uploadType="YIN_LIAN_AUTH"
            :imgUrl="setQuery.insideImg"
            @uploadEnd="uploadEnd"
          ></Upload>
        </el-form-item>
        </template>
        <el-form-item v-if="setQuery.mchntType == 1 || setQuery.mchntType == 2" label="网站截图：" prop="websiteScreenshot">
          <div class="notice">需真实展示网站或app截图 查看示例图</div>
          <div class="notice">
            (图片支持jpg, png, bmp格式，建议上传100kb~500kb大小文件)
          </div>
          <Upload
            type="C0034"
            id="C0034"
            width="250px"
            height="150px"
            uploadType="YIN_LIAN_AUTH"
            :imgUrl="setQuery.websiteScreenshot"
            @uploadEnd="uploadEnd"
          ></Upload>
        </el-form-item>
        <!-- <el-form-item label="租赁协议照：" prop="agreement">
          <div class="notice">需真实展示网站或app截图 查看示例图</div>
          <div class="notice">
            (图片支持jpg, png, bmp格式，建议上传100kb~500kb大小文件)
          </div>
          <Upload
            type="C00084"
            id="C00084"
            width="250px"
            height="150px"
            uploadType="YIN_LIAN_AUTH"
            :imgUrl="setQuery.agreement"
            @uploadEnd="uploadEnd"
          ></Upload>
        </el-form-item>

        <el-form-item label="经营商品照片：" prop="goodsImg">
          <div class="notice">需真实展示店内商品照片 查看示例图</div>
          <div class="notice">
            (图片支持jpg, png, bmp格式，建议上传100kb~500kb大小文件)
          </div>
          <Upload
            type="C0021"
            id="C0021"
            width="250px"
            height="150px"
            uploadType="YIN_LIAN_AUTH"
            :imgUrl="setQuery.goodsImg"
            @uploadEnd="uploadEnd"
          ></Upload>
        </el-form-item> -->
        <!-- <el-form-item label="辅助证明材料：" prop="otherImg">
          <div class="notice">
            辅助证明材料:
            包括但不限于营业场所租赁协议或者产权证明、集中经营场所管理方出具的证明文件等能够反映商户真实、合法从事商品或服务交易活动的材料。
            (图片支持jpg, png,
            bmp格式，建议上传100kb~500kb大小文件，最多上传20张)
          </div>
          <div class="img" v-for="item in imgList" :key="item"></div>
          <Upload v-if="imgList.length !== 8" v-model="setQuery.img"></Upload>
        </el-form-item> -->
      </template>
    </el-form>

    <div class="btn-group">
      <el-button @click="pre" v-if="step != 1">上一步</el-button>
      <el-button type="primary" v-if="step < 5" @click="next">下一步</el-button>
      <el-button
        type="primary"
        v-else-if="step == 5 && mode != 'detail'"
        @click="save"
        >提 交</el-button
      >
      <el-button type="primary" v-if="mode == 'detail'" @click="edit"
        >编辑</el-button
      >
    </div>

    <el-dialog
      title="选择地址"
      close="chose-model"
      :close-on-press-escape="false"
      :show-close="false"
      :close-on-click-modal="false"
      width="60vw"
      :visible.sync="showMap"
    >
      <div id="container"></div>
      <div class="address-input-box">
        <el-input
          v-model="setQuery.shop_addr_ext"
          size="small"
          class="address-input"
          placeholder="店铺详细地址"
        ></el-input>
        <el-button
          type="primary"
          size="small"
          class="address-btn"
          @click="saveAddress"
          >提 交</el-button
        >
      </div>
    </el-dialog>

    <el-dialog
      title="提示"
      :visible.sync="showSign"
      :close-on-press-escape="false"
      :show-close="false"
      :close-on-click-modal="false"
      width="600px"
      center
    >
      <div class="sign-box">
        <div class="notice">
          如果没有打开银联签约页面，请
          <a :href="yinlianUrl" target="_blank" rel="noopener noreferrer"
            >点击此处</a
          >跳转到银联页面完成签约，签约完成后点击我已签约按钮
        </div>
        <el-button
          class="sign-btn"
          type="primary"
          :loading="signLoading"
          @click="handleSign"
          >我已签约</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import Upload from "@/components/Upload";
import {
  complexIng,
  startComplex,
  shopInfo,
  legal,
  getRegion,
  branchBankList,
  picUpload,
  bankInfo,
  shareholderInfo,
  complexUpload,
  agreementSign,
  applyQry,
  getMcc,
  requestAccountVerify,
  companyAccountVerify,
  nmrsQryEntpAccountDetail,
} from "@/api/payment";
import { debounce } from "@/utils/index";

export default {
  components: {
    Upload,
  },
  data() {
    return {
      yinlianUrl: "",
      mode: "add",
      map: null, //百度地图
      province: "",
      city: "",
      district: "", //区
      marker: "", //标记点
      step: 1,
      active: 1,
      showMap: false, //地图显示
      checked: false,
      checked1: false,
      perSonObj:{
        checked1: false,
        date1: [],
      },
      showSign: false, //控制签约按钮页面
      signLoading: false,
      loading: false,
      imgList: [],
      date: [],
      date1: [],
      accesseId:'',
      setQuery: {
        isChain:'0',
        accesser_user_id: "",
        bank_acct_name: "",
        bank_acct_no: "",
        bank_acct_type: "0",
        bank_no: "",
        bank_province_id: "", //开户省
        bank_city_id: "", //开户市
        bnfList: [
          {
            bnfCertBeginDate: "",
            bnfCertExpire: "",
            bnfCertType: "1",
            bnfCertno: "",
            bnfName: "",
            bnfHomeAddr: "",
          },
        ],
        detailDistrict: "",
        developingDept: "",
        developingPersonID: "",
        externalName: "",
        fax: "",
        lastClientManager: "",
        lastTerminalManager: "",
        legal_card_start: "",
        legal_card_deadline: "",
        legal_email: "",
        legal_idcard_no: "",
        legal_mobile: "",
        legal_name: "",
        legal_occupation: "",
        legal_sex: "1",
        legalmanCareerDesc: "",
        legalmanHomeAddr: "",
        mccCode: "",
        mchntType: "1",
        pic_list: [
          {
            epId: "",
            fileUrl: "",
            picType: "A0001",
          },
        ],
        product: "",
        reg_mer_type: "01",
        remark: [],
        serviceDistrict: "",
        shareholderCertBeginDate:'',
        shareholderCertExpire: "",
        shareholderCertType: "1",
        shareholderCertno: "",
        shareholderHomeAddr: "",
        shareholderName: "",
        shop_addr_ext: "",
        shop_city_id: "",
        shop_country_id: "",
        shop_lic: "",
        shop_name: "",
        shop_province_id: "",
        ums_qrcode_list: "",
        idCardImg: "", //身份证正面
        idCardBackImg: "", //身份证反面面
        handIdCardImg: "", //身份证反面面
        cardImg: "", //银行卡照片
        doorImg: "", //门头照
        insideImg: "", //室内照
        goodsImg: "", //商品照片
        otherImg: "", //辅助证明材料
        websiteScreenshot: "", //网站截图
        agreement: "", //租聘协议
        businessImg: "", //营业执照
        settleImg:'',//对公结算图
      },
      selectLoading: false,
      rules: {
        shop_addr_ext: [
          { required: true, message: "请输入地址", trigger: "blur" },
        ],
        shop_name: [
          { required: true, message: "请输入商铺名称", trigger: "blur" },
        ],
        shop_lic: [
          { required: true, message: "请输入营业执照编号", trigger: "blur" },
        ],
        legal_mobile: [
          { required: true, message: "请输入商铺手机号", trigger: "blur" },
        ],
        mchntType: [
          { required: true, message: "请选择商户类型", trigger: "change" },
        ],
        mccCode: [
          { required: true, message: "请选择所属行业", trigger: "change" },
        ],
        remark: [
          { type: 'array', required: true, message: '请至少绑定一个主商户', trigger: 'change' }
        ],
        legal_name: [
          { required: true, message: "请输入身份证姓名", trigger: "blur" },
        ],
        legal_idcard_no: [
          { required: true, message: "请输入身份证号码", trigger: "blur" },
        ],
        legal_card_start: [
          { required: true, message: "请选择身份证有效期", trigger: "change" },
        ],
        legal_occupation: [
          { required: true, message: "请选择职业类型", trigger: "change" },
        ],
        bank_acct_name: [
          { required: true, message: "请输入账户名称", trigger: "blur" },
        ],
        bank_acct_no: [
          { required: true, message: "请输入银行账号", trigger: "blur" },
        ],
        bank_city_id: [
          { required: true, message: "请选择开户市", trigger: "change" },
        ],
        bank_no: [
          {
            required: true,
            message: "请手动输入选择所属支行",
            trigger: "change",
          },
        ],
        businessImg: [
          { required: true, message: "请上传营业执照", trigger: "change" },
        ],
        idCardImg: [
          { required: true, message: "请上传身份证正面", trigger: "change" },
        ],
        idCardBackImg: [
          { required: true, message: "请上传身份证反面", trigger: "change" },
        ],
        handIdCardImg: [
          {
            required: true,
            message: "请上传手持身份证正面照",
            trigger: "change",
          },
        ],
        settleImg: [
          { required: true, message: "请上传对公结算证明", trigger: "change" },
        ],
        cardImg: [
          { required: true, message: "请上传银行卡照片", trigger: "change" },
        ],
        doorImg: [
          { required: true, message: "请上传门头照", trigger: "change" },
        ],
        insideImg: [
          { required: true, message: "请上传室内照", trigger: "change" },
        ],
        goodsImg: [
          { required: true, message: "请上传商品照片", trigger: "change" },
        ],
        insideImg: [
          { required: true, message: "请上传室内照", trigger: "change" },
        ],
        otherImg: [
          { required: true, message: "请上传辅助证明材料", trigger: "change" },
        ],
        websiteScreenshot: [
          { required: true, message: "请上传网站截图", trigger: "change" },
        ],
        agreement: [
          { required: true, message: "请上传租聘协议", trigger: "change" },
        ],
        shareholderHomeAddr: [
          { required: true, message: "请输入家庭地址", trigger: "blur" },
        ],
        shareholderCertno: [
          { required: true, message: "请输入身份证号", trigger: "blur" },
        ],
        shareholderCertType: [
          { required: true, message: "请选择证件类型", trigger: "change" },
        ],
        shareholderName: [
          { required: true, message: "请输入股东姓名", trigger: "blur" },
        ],
         shareholderCertBeginDate: [
          { required: true, message: "请选择身份证有效期", trigger: "change" },
        ],
        isChain: [
          { required: true, message: "请选择是否连锁", trigger: "change" },
        ],
        
      },
      cardOptions:[
        {
          value: "1",
          label: "身份证",
        },
        {
          value: "2",
          label: "护照",
        },
        {
          value: "3",
          label: "军官证",
        },
        {
          value: "4",
          label: "警官证",
        },
        {
          value: "5",
          label: "士兵证",
        },
        {
          value: "6",
          label: "台湾居民来往大陆通行证",
        },
        {
          value: "7",
          label: "回乡证",
        },
        {
          value: "8",
          label: "港澳居民来往内地通行证",
        },
        {
          value: "10",
          label: "港澳台居民居住证",
        },
        {
          value: "11",
          label: "营业执照",
        },
        {
          value: "12",
          label: "组织机构代码证",
        },
        {
          value: "13",
          label: "税务登记证",
        },
        {
          value: "14",
          label: "商业登记证",
        },
        {
          value: "15",
          label: "民办非企业登记证书",
        },
        {
          value: "16",
          label: "批文证明",
        },
      ],
      typeOptions: [
        {
          value: "0",
          label: "实体商户",
        },
        {
          value: "1",
          label: "网络商户",
        },
        {
          value: "2",
          label: "实体兼线上",
        },
      ],
      options: [
        {
          value: "0",
          label: "各类专业、技术人员",
        },
        {
          value: "1",
          label: "国家机关、党群组织、企事业单位的负责人",
        },
        {
          value: "2",
          label: "办事人员和有关人员",
        },
        {
          value: "3",
          label: "商业工作人员",
        },
        {
          value: "4",
          label: "服务性工作人员",
        },
        {
          value: "5",
          label: "农林牧渔劳动者",
        },
        {
          value: "6",
          label: "生产工作、运输工作和部分体力劳动者",
        },
        {
          value: "7",
          label: "不便分类的其他劳动者",
        },
      ],
      mccOptions: [],
      provinceList: [],
      cityList: [],
      bankList: [],
      picObj: {
        A0001: "idCardImg",
        A0007: "handIdCardImg",
        A0011: "idCardBackImg",
        B0025: "cardImg",
        B0006: "settleImg",
        B0026: "银行卡背面照",
        C0002: "businessImg",
        C0003: "商户税务登记证",
        C0004: "组织机构代码证",
        C0005: "doorImg",
        C0008: "辅助证明材料",
        C00081: "辅助证明材料",
        C00082: "辅助证明材料",
        C00083: "辅助证明材料",
        C00084: "agreement",
        C00085: "辅助证明材料",
        C00086: "辅助证明材料",
        C00087: "辅助证明材料",
        C00088: "辅助证明材料",
        C0013: "辅助证明材料1",
        C0014: "辅助证明材料2",
        C0015: "insideImg",
        C0021: "goodsImg",
        C0032: "其他材料",
        C0034: "websiteScreenshot",
        C0099: "网站或APP截图",
      },

      // options1: [
      //   {
      //     value: "1",
      //     label: "加油充电",
      //   },
      //   {
      //     value: "2",
      //     label: "酒店民宿",
      //   },
      //   {
      //     value: "3",
      //     label: "餐饮美食",
      //   },
      //   {
      //     value: "4",
      //     label: "慧研学",
      //   },
      //   {
      //     value: "5",
      //     label: "超市购物",
      //   },
      //   {
      //     value: "6",
      //     label: "健身运动",
      //   },
      //   {
      //     value: "7",
      //     label: "医疗健康",
      //   },
      //   {
      //     value: "8",
      //     label: "家政服务",
      //   },
      // ],
    };
  },
  watch: {
    checked(val) {
      if (val) {
        this.setQuery.legal_card_deadline = "9999-12-31";
        // this.setQuery.legal_card_start = "9999-12-31";
        // this.date = ["9999-12-31", "9999-12-31"];
          this.date = [this.setQuery.legal_card_start, "9999-12-31"];

      } else {
        this.date = [];
      }
    },
    date(val) {
      if (val == null) {
        this.setQuery.legal_card_start = "";
        this.setQuery.legal_card_deadline = "";
      } else {
        this.setQuery.legal_card_start = val[0];
        this.setQuery.legal_card_deadline = val[1];
      }
    },
    date1(val) {
      if (val == null) {
          this.setQuery.shareholderCertBeginDate = ''
          this.setQuery.shareholderCertExpire = ''

      } else {
          this.setQuery.shareholderCertBeginDate = val[0]
          this.setQuery.shareholderCertExpire = val[1]
      }
    },
    checked1(val) {
      if (val) {
        // this.setQuery.shareholderCertBeginDate = "9999-12-31";
        this.setQuery.shareholderCertExpire = "9999-12-31";
          this.date1 = [this.setQuery.shareholderCertBeginDate, "9999-12-31"];
        
      } else {
           this.date1 = [];

      }
    },
    // date2(val) {
    //   if (val == null) {
    //     this.setQuery.bnfList[0].bnfCertBeginDate = ''
    //      this.setQuery.bnfList[0].bnfCertExpire = ''
    //   } else {
    //      this.setQuery.bnfList[0].bnfCertBeginDate = val[0]
    //      this.setQuery.bnfList[0].bnfCertExpire = val[1]
    //   }
    // },
    // checked2(val) {
    //   if (val) {
    //     this.setQuery.bnfList[0].bnfCertBeginDate = "9999-12-31"
    //     this.setQuery.bnfList[0].bnfCertExpire = "9999-12-31"
    //       this.date2 = ["9999-12-31", "9999-12-31"];

    //   } else {
    //        this.date2 = [];
        
    //   }
    // },

    "setQuery.bank_province_id": function (val, old) {
      if (val) {
        this.getRegion("city");
      }
      if (old !== "") {
        this.setQuery.bank_city_id = "";
      }
    },

    "setQuery.shop_addr_ext": debounce(function (val) {
      if (this.map) {
        let that = this;
        //创建地址解析器实例
        var myGeo = new BMapGL.Geocoder();
        that.marker ? that.map.removeOverlay(that.marker) : "";

        // 将地址解析结果显示在地图上，并调整地图视野
        myGeo.getPoint(
          val,
          function (point) {
            console.log(point);
            if (point) {
              that.marker = new BMapGL.Marker(point, { title: val });
              if (that.map) {
                that.map.centerAndZoom(point, 16);
                that.map.addOverlay(that.marker);
                // 根据坐标得到地址描述    
                myGeo.getLocation(new BMapGL.Point(point.lng, point.lat), function(result){      
                    if (result){      
                      console.log(result);
                       // 选择营业地址时保存省市区
                      that.province = result.addressComponents.province;
                      that.city = result.addressComponents.city;
                      that.district = result.addressComponents.district;
                    }      
                });
              }
            }
          },
          that.city
        );
      }
    }),
  },
  methods: {
    changeTime(val,index){
      console.log(val,index);
      if (val == null) {
        this.setQuery.bnfList[index].bnfCertBeginDate = ''
         this.setQuery.bnfList[index].bnfCertExpire = ''
      } else {
         this.setQuery.bnfList[index].bnfCertBeginDate = val[0]
         this.setQuery.bnfList[index].bnfCertExpire = val[1]
      }
    },
    // 受益人身份证是否长期
    checkChange(val,index){
      console.log(111111111111,val,index);
      if (val) {
        this.$set(this.perSonObj,['date'+(index+1)],[this.setQuery.bnfList[index].bnfCertBeginDate, "9999-12-31"])
        this.$set(this.setQuery.bnfList[index],'bnfCertExpire',"9999-12-31")

      } else {
           this.perSonObj['date'+(index+1)]= [];
            this.setQuery.bnfList[index].bnfCertBeginDate = ''
            this.setQuery.bnfList[index].bnfCertExpire = ''
      }
    },
    // 添加受益人
    addPerson(){
      this.setQuery.bnfList.push(
        {
            bnfCertBeginDate: "",
            bnfCertExpire: "",
            bnfCertType: "1",
            bnfCertno: "",
            bnfName: "",
            bnfHomeAddr: "",
          }
      )
     

    },
    delPerson(index){
      this.setQuery.bnfList.splice(index,1)
    },
    // 同步信息
    handleCopy(type) {
      if (type == 1) {
        if (this.setQuery.legal_card_deadline == "9999-12-31") {
          this.checked1 = true;

        } else {
          // this.setQuery.shareholderCertExpire =this.setQuery.legal_card_deadline;
        }
          this.date1 = this.date
          this.setQuery.shareholderCertType = '1'
        this.setQuery.shareholderCertno = this.setQuery.legal_idcard_no;
        // this.setQuery.shareholderHomeAddr = this.setQuery.legalmanHomeAddr;
        this.setQuery.shareholderName = this.setQuery.legal_name;
      } else {
        if (this.setQuery.shareholderCertExpire == "9999-12-31") {
          this.perSonObj.checked1 = true;
        } else {
          // this.setQuery.bnfList[0].bnfCertExpire =
          //   this.setQuery.legal_card_deadline;
        }
          this.perSonObj.date1 = this.date1
        this.setQuery.bnfList[0].bnfCertType =this.setQuery.shareholderCertType;
        this.setQuery.bnfList[0].bnfCertBeginDate =this.setQuery.shareholderCertBeginDate;
        this.setQuery.bnfList[0].bnfCertExpire =this.setQuery.shareholderCertExpire;
        this.setQuery.bnfList[0].bnfCertno = this.setQuery.shareholderCertno;
        this.setQuery.bnfList[0].bnfHomeAddr = this.setQuery.shareholderHomeAddr;
        this.setQuery.bnfList[0].bnfName = this.setQuery.shareholderName;

      }
    },
    
    // 点击我已签约
    handleSign() {
      this.signLoading = true;
      this.applyQry(this.setQuery.ums_reg_id).then(() => {
        this.showSign = false;
        this.$router.push("/merchantManage/index");

      });
    },
    handleTab(val) {
      this.active = val;
    },
    pre() {
      this.step--;
    },
    next() {
      if (this.mode == "detail") {
        this.step++;
      } else {
        this.$refs.setQuery.validate((v) => {
          if (v) {
            this.step++;
          }
        });
      }
    },
    // 详情切换到编辑模式
    edit() {
      this.mode = "edit";
    },
    // 统一提交
    save() {
      if (this.loading) return;
      this.loading = true;
      try {
        // this.provinceList.map((item) => {
        //   if (this.province && item.name.indexOf(this.province) != -1) {
        //     //找到省id
        //     this.setQuery.shop_province_id = item.code;
        //   }
        // });
        // this.cityList.map((item) => {
        //   if (this.city && item.name.indexOf(this.city) != -1) {
        //     //找到市id
        //     this.setQuery.shop_city_id = item.code;
        //   }
        // });
        new Promise((resolve,reject)=>{
            if(this.setQuery.shop_province_id){
              resolve(this.setQuery.shop_province_id)
            }else{
            getRegion({
              code: '',
              type: "province",
            }).then((res) => {
              if (res.state == "Success") {
                res.content.map((item) => {
                  if (this.province && item.name.indexOf(this.province) != -1) {
                    //找到省id
                    this.setQuery.shop_province_id = item.code;
                    resolve(item.code)
                  }
                });
              }
            })
          }
        }).then(id=>{
          return new Promise((resolve,reject)=>{
            if(this.setQuery.shop_city_id){
              resolve(this.setQuery.shop_city_id)
            }else{
              getRegion({
                code: id,
                type: "city",
              }).then((res) => {
                if (res.state == "Success") {
                  res.content.map((item) => {
                    if (this.city && item.name.indexOf(this.city) != -1) {
                      //找到省id
                      this.setQuery.shop_city_id = item.code;
                      resolve(item.code)
                    }
                  });
                }
              })
            }
          })
        }).then(id=>{
            return new Promise((resolve,reject)=>{
                if(this.setQuery.shop_country_id){
                  resolve(this.setQuery.shop_country_id)
                }else{
                  getRegion({
                    code: id,
                    name: "",
                    type: "county",
                  }).then((res) => {
                    if (res.state == "Success") {
                      res.content.map((item) => {
                        if (this.district && item.name.indexOf(this.district) != -1) {
                          //找到区id
                          this.setQuery.shop_country_id = item.code;
                            resolve(item.code)
                        }
                      });
                    }
                  });
                }
            })
        }).then(r=>{

          this.shopInfo().then((res) => {
                    return this.legal();
                  })
                  .then((r) => {
                    return this.bankInfo();
                  })
                  .then(()=>{
                    return this.shareholderInfo();

                  })
                  .then((res) => {
                      return this.complexUpload();
                  })
                  .then((id) => {
                    return this.requestAccountVerify(id);
                  })
                  .then((id) => {
                    return this.agreementSign(id);
                  })
                  .then((url) => {
                    // 跳转银联后
                    this.showSign = true;
                    this.yinlianUrl = url;
                    this.loading = false;
                  });
        })

            
      } catch (error) {
        this.loading = false;
      }
    },
    startComplex() {
      return new Promise((resolve, reject) => {
      startComplex({
        accesseId:'',
        epId: this.$route.query.id,
        reg_mer_type: "01", //00：企业商户01：个人工商户02：小微商户03：机关事业单位或社会团体
      }).then((res) => {
        this.accesseId =  res.content.accesser_user_id
        resolve(res)
      });
      })
    },
    // 获取签约流程
    complexIng() {
      this.loading = true;
      return new Promise((resolve, reject) => {
        complexIng({ accesseId:this.$route.query.accesseId||this.accesseId,epId: this.$route.query.id }).then((res) => {
          this.loading = false;
          if (res.state == "Success") {
            if (res.content && res.content.shop_name && res.content.shop_addr_ext) {
              if(res.content.apply_status != '00'&&res.content.apply_status!=null){
                this.$message({
                  message: res.content.apply_status_msg,
                  type: res.content.apply_status == '01' || res.content.apply_status == '02'|| res.content.apply_status == '03' ?"success":'error',
                  duration: 0,
                });
              }
              //有数据时 回填数据
              this.setQuery = res.content;
              if(this.setQuery.remark){
                this.setQuery.remark = this.setQuery.remark.split(',')
              }else{
                this.setQuery.remark = []
              }
              if (this.setQuery.legal_card_deadline == "9999-12-31") {
                this.checked = true;
              } else if (this.setQuery.legal_card_deadline) {
                this.date = [
                  this.setQuery.legal_card_start,
                  this.setQuery.legal_card_deadline,
                ];
              }

              if (this.setQuery.shareholderCertExpire == "9999-12-31") {
                this.checked1 = true;
              } else if (this.setQuery.shareholderCertExpire) {
                this.date1 = [
                  this.setQuery.shareholderCertBeginDate,
                  this.setQuery.shareholderCertExpire,
                ];
              }

              if (!this.setQuery.bnfList) {
                this.setQuery.bnfList = [
                  {
                    bnfCertBeginDate: "",
                    bnfCertExpire: "",
                    bnfCertType: "1",
                    bnfCertno: "",
                    bnfName: "",
                    bnfHomeAddr: "",
                  },
                ];
              }else{
                this.setQuery.bnfList.map((item,index)=>{
                  if (item.bnfCertExpire == "9999-12-31") {
                   this.perSonObj['checked'+(index+1)] = true;
                 
                 } else if (item.bnfCertExpire) {
                   this.perSonObj['checked'+(index+1)] = false;
                 }
                 this.$set( this.perSonObj,'date'+(index+1),[
                     item.bnfCertBeginDate,
                     item.bnfCertExpire
                   ])
                })
              }

              // if (this.setQuery.bnfList[0].bnfCertExpire == "9999-12-31") {
              //   this.checked2 = true;
              // }

              // 提取图片
              this.setQuery.pic_list.map((item) => {
                for (const key in this.picObj) {
                  if (this.picObj.hasOwnProperty.call(this.picObj, key)) {
                    if (item.picType == key) {
                      // 把图片从数组中提取出来
                      this.setQuery[this.picObj[key]] = item.fileUrl ;
                      break;
                    }
                  }
                }
              });
            }
            resolve(res);
          }
        });
      });
    },
    // 获取地区
    getRegion(type) {
      return new Promise((resolve, reject) => {
        getRegion({
          code: type == "city" ? this.setQuery.bank_province_id : "",
          type,
        }).then((res) => {
          if (res.state == "Success") {
            this[type + "List"] = res.content;
            resolve();
            // res.content.map(item=>{
            //   if(type == 'province'&& this.setQuery.shop_province_id == item.code){
            //     this.province
            //   }
            // })
          }
        });
      });
    },
    // 商户信息
    shopInfo() {
      let obj = {
        accesseId:this.$route.query.accesseId||this.accesseId,
        developingPersonID: "",
        fax: "",
        isChain: this.setQuery.isChain,
        mchntType: this.setQuery.mchntType,
        epId: this.$route.query.id,
        externalName: this.setQuery.shop_name,
        mccCode: this.setQuery.mccCode,
        product: [
          {
            product_id: "8",
          },
        ],
        shop_addr_ext: this.setQuery.shop_addr_ext,
        shop_city_id: this.setQuery.shop_city_id,
        shop_country_id: this.setQuery.shop_country_id,
        shop_lic: this.setQuery.shop_lic,
        shop_name: this.setQuery.shop_name,
        shop_province_id: this.setQuery.shop_province_id,
      };
      return new Promise((resolve, reject) => {
        shopInfo(obj).then((res) => {
          if (res.state == "Success") {
            resolve();
          } else {
            this.$message.closeAll();
            this.$message({
              message: res.exception.message,
              type: "error",
              duration: 5000,
            });
            this.loading = false;
          }
        });
      });
    },
    // 法人信息
    legal() {
      let obj = {
        accesseId:this.$route.query.accesseId||this.accesseId,
        epId: this.$route.query.id,
        legal_card_deadline: this.setQuery.legal_card_deadline,
        legal_card_start: this.setQuery.legal_card_start,
        legal_email: "",
        legal_idcard_no: this.setQuery.legal_idcard_no,
        legal_name: this.setQuery.legal_name,
        legal_occupation: this.setQuery.legal_occupation,
        legal_sex: (this.setQuery.legal_idcard_no + "")[16] % 2 == 0 ? 2 : 1,
        legalmanCareerDesc: this.setQuery.legalmanCareerDesc,
        legalmanHomeAddr: this.setQuery.legalmanHomeAddr,
      };
      return new Promise((resolve, reject) => {
        legal(obj).then((res) => {
          if (res.state == "Success") {
            resolve();
          } else {
            this.$message.closeAll();
            this.$message({
              message: res.exception.message,
              type: "error",
              duration: 5000,
            });
            this.loading = false;
          }
        });
      }).catch(() => {
        this.loading = false;
      });
    },
    // 图片统一上传
    uploadEnd(val) {
      console.log(val);
      // this.setQuery[this.picObj[val.type]] = val.url
      this.$set(this.setQuery, this.picObj[val.type], val.url);
      // this.setQuery.idCardImg = val.url
      let obj = {
        accesseId:this.$route.query.accesseId||this.accesseId,
        epId: this.$route.query.id,
        fileUrl: val.url,
        picType: val.type,
      };
      picUpload(obj).then((res) => {});
    },
    // 股东信息
    shareholderInfo() {
      let obj = {
        accesseId:this.$route.query.accesseId||this.accesseId,
        bnfList: this.setQuery.bnfList,
        epId: this.$route.query.id,
        shareholderCertBeginDate: this.setQuery.shareholderCertBeginDate,
        shareholderCertExpire: this.setQuery.shareholderCertExpire,
        shareholderCertType: this.setQuery.shareholderCertType,
        shareholderCertno: this.setQuery.shareholderCertno,
        shareholderHomeAddr: this.setQuery.shareholderHomeAddr,
        shareholderName: this.setQuery.shareholderName,
      };
      return new Promise((resolve, reject) => {
        shareholderInfo(obj).then((res) => {
          if (res.state == "Success") {
            resolve();
          } else {
            this.$message.closeAll();
            this.$message({
              message: res.exception.message,
              type: "error",
              duration: 5000,
            });
            this.loading = false;
          }
        });
      });
    },
    // 结算信息
    bankInfo() {
      let obj = {
        accesseId:this.$route.query.accesseId||this.accesseId,
        bank_acct_name: this.setQuery.bank_acct_name,
        bank_acct_no: this.setQuery.bank_acct_no,
        bank_acct_type: this.setQuery.bank_acct_type,
        legal_mobile: this.setQuery.legal_mobile,
        bank_no: this.setQuery.bank_no,
        epId: this.$route.query.id,
        remark: this.setQuery.remark.join(),
        bank_province_id: this.setQuery.bank_province_id,
        bank_city_id: this.setQuery.bank_city_id,
      };
      return new Promise((resolve, reject) => {
        bankInfo(obj)
          .then((res) => {
            if (res.state == "Success") {
              resolve();
            } else {
              this.$message.closeAll();
              this.$message({
                message: res.exception.message,
                type: "error",
                duration: 5000,
              });
              this.loading = false;
            }
          })
          .catch(() => {
            this.loading = false;
          });
      });
    },
    // 档案提交
    complexUpload() {
      return new Promise((resolve, reject) => {
        complexUpload({ accesseId:this.$route.query.accesseId||this.accesseId,epId: this.$route.query.id, })
          .then((res) => {
            if (res.state == "Success") {
              resolve(res.content.ums_reg_id);
            } else {
              this.$message.closeAll();
              this.$message({
                message: res.exception.message,
                type: "error",
                duration: 5000,
              });
            }
              this.loading = false;
          })
          .catch(() => {
            this.loading = false;
          });
      });
    },
    companyAccountVerify(ums_reg_id){
      return new Promise((resolve,reject)=>{
        this.$prompt(
            "银联已打款到你的结算账户，请输入银联打款金额进行验证",
            "提示",
            {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              inputPattern: /^[0-9]+(\.[0-9]+)?$/,
              inputErrorMessage: "请输入正确的打款金额",
            }
          ).then(({ value }) => {
            // 验证打款金额
            companyAccountVerify({
              trans_amt: value,
              accesseId:this.$route.query.accesseId||this.accesseId,
              epId:this.$route.query.id
              // company_account: this.setQuery.bank_acct_no,
              // ums_reg_id,
            }).then((data) => {
              if (data.state == "Success") {
                resolve(ums_reg_id);
              } else {//验证失败
                this.companyAccountVerify(ums_reg_id)
                this.loading = false;
                this.$message.closeAll();
                  this.$message({
                  message: data.exception.message,
                  type: "error",
                  duration: 5000,
                });
              }
            });
          });
      })
    },
    // 发起对公打款申请
    requestAccountVerify(ums_reg_id) {
      return new Promise((resolve, reject) => {
        // 公司账户
        if (this.setQuery.bank_acct_type == 1) {
          this.$confirm(
            `你还未完成对公账户验证，请先完成对公账户验证再完成认证`,
            "提示",
            {
              confirmButtonText: "开始认证",
              type: "warning",
            }
          ).then(() => {
            // 发起打款请求
            requestAccountVerify({
              // company_account: this.setQuery.bank_acct_no,
              // ums_reg_id,
              accesseId:this.$route.query.accesseId||this.accesseId,
              epId:this.$route.query.id
            })
              .then((res) => {
                if (res.state == "Success") {
                  // 成功后让用户填写打款金额
                  this.companyAccountVerify(ums_reg_id).then(id=>{
                    resolve(id)
                  })
                } else {
                  this.$message.closeAll();
                  this.$message({
                    message: res.exception.message,
                    type: "error",
                    duration: 5000,
                  });
                  this.loading = false;
                  reject();
                }
              })
              .catch(() => {
                this.$message.closeAll();
                this.$message({
                  message: res.exception.message,
                  type: "error",
                  duration: 5000,
                });
                this.loading = false;
              });
          });
        } else {
           resolve(ums_reg_id);
        }
      });
    },
    // 前端签约
    agreementSign(ums_reg_id) {
      return new Promise((resolve, reject) => {
        agreementSign({ ums_reg_id, pcOrH5: "PC" }).then((res) => {
          if (res.state == "Success") {
            window.open(res.content);
            this.setQuery.ums_reg_id = ums_reg_id;
            resolve(res.content);
          } else {
            this.$message.closeAll();
            this.$message({
              message: res.exception.message,
              type: "error",
              duration: 5000,
            });
            this.loading = false;
          }
        });
      });
    },
    // 入网状态查询
    applyQry(ums_reg_id) {
      return new Promise((resolve, reject) => {
        applyQry({ accesseId:this.$route.query.accesseId||this.accesseId,epId: this.$route.query.id, ums_reg_id })
          .then((res) => {
            if (res.state == "Success") {
              this.$message({
                message: res.content.apply_status_msg,
                type: "success",
                duration: 0,
              });
              resolve();
            } else {
              this.$message.closeAll();
              this.$message({
                message: res.exception.message,
                type: "error",
                duration: 5000,
              });
              this.signLoading = false;
            }
          })
          .catch(() => {
            this.signLoading = false;
          });
      });
    },

    // 银行列表
    branchBankList(query) {
      if (query !== "") {
        branchBankList({
          areaCode: this.setQuery.bank_city_id,
          key: query,
        }).then((res) => {
          if (res.state == "Success") {
            this.bankList = res.content.branchBankList;
          }
        });
      }
    },
    getMcc() {
      getMcc({
        bigmccname: "",
        mcccode: "",
        mccname: "",
      }).then((res) => {
        if (res.state == "Success") {
          this.mccOptions = res.content;
        }
      });
    },
    // 选择经营地址
    chooseAddress() {
      this.showMap = true;
      let that = this;
      this.$nextTick(() => {
        this.map = new BMapGL.Map("container");
        var geoc = new BMapGL.Geocoder();
        that.map.enableScrollWheelZoom(); // 启用滚轮放大缩小
        var myCity = new BMapGL.LocalCity();
        myCity.get((result) => {
          that.city = result.name;
          var cityName = result.name;
          that.map.setCenter(cityName);
          var point = new BMapGL.Point(result.center.lat, result.center.lng);
          that.map.centerAndZoom(point, 15);
          let cache = this.setQuery.shop_addr_ext;
          this.setQuery.shop_addr_ext = "切换地址触发标记点";
          setTimeout(() => {
            this.setQuery.shop_addr_ext = cache;
          }, 100);
        });

        that.map.addEventListener("click", function (e) {
          var pt = e.latlng;
          that.map.removeOverlay(that.marker); //移除点标记
          geoc.getLocation(pt, function (rs) {
            var addComp = rs.addressComponents;
            let point1 = new BMapGL.Point(rs.point.lng, rs.point.lat);
            that.marker = new BMapGL.Marker(point1); // 创建标注
            that.map.addOverlay(that.marker); // 将标注添加到地图中
            that.setQuery.shop_addr_ext = rs.address + rs.content.poi_desc;
            // 选择营业地址时保存省市区
            that.province = addComp.province;
            that.city = addComp.city;
            that.district = addComp.district;
          });
        });
      });
    },
    // 保存地址
    saveAddress() {
      this.$confirm("请确认地址信息准确无误，并精确到门牌号?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.showMap = false;
      });
    },
  },
  beforeDestroy() {
    this.$message.closeAll();
  },
  mounted() {},
  created() {
    this.mode = this.$route.query.mode || "add";
    if(this.mode == 'add'){
      this.startComplex().then((res) => {
       if (
            res.content.ums_reg_id &&
            res.content.apply_status === "00"
          ) {
            //资料提交  没有银联签约
            if (this.setQuery.bank_acct_type == 1 && !res.content.verification) {
              // 查询对公验证
              this.requestAccountVerify(res.content.ums_reg_id).then((id) => {
                this.agreementSign(id).then((url) => {
                  // 跳转银联后
                  this.showSign = true;
                  this.yinlianUrl = url;
                  this.loading = false;
                })
              });
            }else{
              this.agreementSign(res.content.ums_reg_id).then((url) => {
                  // 跳转银联后
                  this.showSign = true;
                  this.yinlianUrl = url;
                  this.loading = false;
                })
            }
          }
          return this.getRegion("province");
        })
    }else{

      this.complexIng().then((res) => {
          // 没有开始填写
          if (!res.content) {
            this.startComplex();
          } else if (
            res.content.ums_reg_id &&
            res.content.apply_status === "00"
          ) {
            //资料提交  没有银联签约
            if (this.setQuery.bank_acct_type == 1 && !res.content.verification) {
              // 查询对公验证
              this.requestAccountVerify(res.content.ums_reg_id).then((id) => {
                this.agreementSign(id).then((url) => {
                  // 跳转银联后
                  this.showSign = true;
                  this.yinlianUrl = url;
                  this.loading = false;
                })
              });
            }else{
              this.agreementSign(res.content.ums_reg_id).then((url) => {
                  // 跳转银联后
                  this.showSign = true;
                  this.yinlianUrl = url;
                  this.loading = false;
                })
            }
          }
          return this.getRegion("province");
        })
    }
      
    this.getMcc();
  },
};
</script>

<style lang="scss">
@import "@/styles/element-variables";
.el-step__title.is-success,
.el-step__head.is-success {
  color: $--color-primary !important;
}
.el-step__head.is-success {
  border-color: $--color-primary !important;
}
.disabled {
  pointer-events: none;
  cursor: not-allowed;
}
.chose-model .el-dialog__body {
  padding: 0 !important;
}
.sign-box {
  .notice {
    font-size: 14px;
    color: #666;
    padding: 20px 0;
    a {
      color: #535efe;
    }
  }
  .sign-btn {
    margin: 30px auto 0;
    display: block;
  }
}
.address-input-box {
  display: flex;
  .address-input {
    flex: 1;
  }
}
.shopAdd {
  padding-bottom: 40px;

  .position{
    cursor: pointer;
    font-size: 20px;
  }

  .line {
    width: 100%;
    height: 1px;
    background: #f5f5f5;
  }
  .title {
    font-weight: bold;
    color: #181818;
    margin: 20px 0;
  }
  .step-box {
    display: flex;
    justify-content: center;
    margin: 50px 0;
    .el-steps {
      width: 90%;
      // margin-left: 200px;
    }
  }

  .tabs {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    .tab {
      padding: 2px 10px;
      border: 1px solid #ccc;
      border-radius: 4px;
      margin-right: 8px;
    }
    .active {
      border: 1px solid $--color-primary;
      color: $--color-primary;
    }
  }

  .img {
    width: 150px;
    height: 100px;
    border-radius: 4px;
    background: #f1f1f1;
  }

  .el-checkbox {
    margin-left: 10px;
  }

  .notice {
    font-size: 12px;
    color: #ccc;
  }

  .btn-group {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #container {
    width: 100%;
    height: 600px;
  }
}
</style>