<template>
  <div class="app-container">
    <div class="top-fixed">
      <div class="title-reg">
        <h3 class="title">注册信息</h3>
        <div class="top-img" @click="cancel">
          <img src='../../assets/images/cancel.png'>
        </div>
      </div>
    </div>
    <div class="content">
      <el-form ref="registerForm" :model="registerForm" :rules="registerRules" label-width="190px">
      <el-collapse v-model="activeNames">
        <template v-if="tokenVisile">
          <el-collapse-item title="账户信息" name="1">
            <el-row :gutter="40">
              <el-col :span="12">
                <el-form-item label="账户名称" prop="userName">
                  <el-input v-model="registerForm.userName" type="text" auto-complete="off" placeholder="账号">
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="密码" prop="password">
                  <el-input
                    v-model="registerForm.password"
                    type="password"
                    auto-complete="new-password"
                    placeholder="密码">
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="确认密码" prop="confirmPassword">
                  <el-input
                    v-model="registerForm.confirmPassword"
                    type="password"
                    auto-complete="new-password"
                    placeholder="确认密码">
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
          <el-collapse-item title="账户联系人信息" name="2">
            <el-row :gutter="40">
              <el-col :span="12">
                <el-form-item label="姓名" prop="nickName">
                  <el-input v-model="registerForm.nickName" type="text" auto-complete="off" placeholder="姓名">
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="手机号码" prop="phonenumber">
                  <el-input v-model="registerForm.phonenumber" type="text" auto-complete="off" placeholder="手机号码">
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="邮箱地址" prop="email">
                  <el-input v-model="registerForm.email" type="text" auto-complete="off" placeholder="邮箱地址">
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
        </template>
        <el-collapse-item title="企业信息" name="3">
          <el-row :gutter="40">
            <el-col :span="12">
              <el-form-item label="企业名称" prop="entName">
                <el-input v-model="registerForm.entName" type="text" auto-complete="off" placeholder="请输入企业名称">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="统一社会信用代码" prop="license">
                <el-input type="text" @change="validLicense"
                  v-model="registerForm.license"
                  placeholder="请输入统一社会信用代码">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="注册资金" prop="regCapital">
                <el-input type="text"
                  v-model="registerForm.regCapital"
                  placeholder="请输入注册资金">
                  <template slot="append">万元</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="工商注册时间" prop="regDate">
                <el-date-picker v-model="registerForm.regDate" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="工商注册类型" prop="regType">
                <el-select v-model="registerForm.regType" filterable>
                  <el-option v-for="item in regTypeOptions" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="主营产品(服务)所属技术领域" prop="mainProductArray">
                <el-checkbox-group v-model="registerForm.mainProductArray">
                  <el-checkbox v-for="(item, index) in mainProductsOptions" :label="item.dictLabel" :key="index">{{item.dictLabel}}</el-checkbox>
                </el-checkbox-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="通信地址" prop="address">
                <el-input v-model="registerForm.address" type="text" auto-complete="off" placeholder="请输入通信地址">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="邮政编码" prop="zipCode">
                <el-input v-model="registerForm.zipCode" type="text" auto-complete="off" placeholder="请输入邮政编码">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="企业所属行政区域" prop="provinceId">
                <el-select v-model="registerForm.provinceId" placeholder="省" @change="getCityData" style="width: 220px;" filterable>
                  <el-option v-for="(item,index) in provinceDataList" :key="index" :label="item.name" :value="item.id"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item prop="cityId" label-width="60px">
                <el-select v-model="registerForm.cityId" placeholder="市" @change="getDistrictData" style="width: 220px;" filterable>
                  <el-option v-for="(item, index) in cityDataList" :key="index" :label="item.name" :value="item.id"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label-width="0px" prop="districtId">
                <el-select v-model="registerForm.districtId" placeholder="区" style="width: 220px;" filterable>
                  <el-option v-for="(item, index) in districtDataList" :key="index" :label="item.name" :value="item.id"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="企业所得税主管税务机关" prop="taxOffice">
                <el-input v-model="registerForm.taxOffice" type="text" auto-complete="off" placeholder="请输入企业所得税主管税务机关">
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="法人信息" name="4">
          <el-row :gutter="40">
            <el-col :span="12">
              <el-form-item label="姓名" prop="legalName">
                <el-input v-model="registerForm.legalName" type="text" auto-complete="off" placeholder="请输入法人姓名">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="身份证号码" prop="legalIdCard">
                <el-input v-model="registerForm.legalIdCard" type="text" auto-complete="off" placeholder="请输入法人身份证号码">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="手机号码" prop="legalMobile">
                <el-input v-model="registerForm.legalMobile" type="text" auto-complete="off" placeholder="手机号码">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="固定电话" prop="legalPhone">
                <el-input v-model="registerForm.legalPhone" type="text" auto-complete="off" placeholder="请输入固定电话">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="传真" prop="legalFax">
                <el-input v-model="registerForm.legalFax" type="text" auto-complete="off" placeholder="请输入法人传真">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="E-mail" prop="legalEmail">
                <el-input v-model="registerForm.legalEmail" type="text" auto-complete="off" placeholder="请输入法人邮箱">
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="联系人信息" name="5">
          <el-row :gutter="40">
            <el-col :span="12">
              <el-form-item label="姓名" prop="linkName">
                <el-input v-model="registerForm.linkName" type="text" auto-complete="off" placeholder="请输入联系人姓名">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="身份证号码" prop="linkIdCard">
                <el-input v-model="registerForm.linkIdCard" type="text" auto-complete="off" placeholder="请输入联系人身份证号码">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="手机号码" prop="linkMobile">
                <el-input v-model="registerForm.linkMobile" type="text" auto-complete="off" placeholder="请填入手机号码">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="固定电话" prop="linkPhone">
                <el-input v-model="registerForm.linkPhone" type="text" auto-complete="off" placeholder="请输入联系人固定电话">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="传真" prop="linkFax">
                <el-input v-model="registerForm.linkFax" type="text" auto-complete="off" placeholder="请输入联系人传真">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="E-mail" prop="linkEmail">
                <el-input v-model="registerForm.linkEmail" type="text" auto-complete="off" placeholder="请输入联系人邮箱">
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="企业上市信息" name="6">
          <el-row :gutter="40">
            <el-col :span="12">
              <el-form-item label="企业是否上市" prop="listedFlag">
                <el-radio-group v-model="registerForm.listedFlag">
                  <el-radio v-for="(item, index) in yesOrNoOptions" :key="index" :label="item.dictValue">{{item.dictLabel}}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="registerForm.listedFlag == 1">
              <el-form-item label="企业上市代码" prop="listingCode">
                <el-input v-model="registerForm.listingCode" type="text" auto-complete="off" placeholder="请输入企业上市代码">
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="风险投资信息" name="7">
          <el-row :gutter="40">
            <el-col :span="12">
              <el-form-item label="是否引入风险投资" prop="investFlag">
                <el-radio-group v-model="registerForm.investFlag">
                  <el-radio v-for="(item, index) in yesOrNoOptions" :key="index" :label="item.dictValue">{{item.dictLabel}}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="registerForm.investFlag == 1">
              <el-form-item label="风险投资金额" prop="investCapital">
                <el-input v-model="registerForm.investCapital" type="text" auto-complete="off" placeholder="请输入风险投资金额">
                  <template slot="append">万元</template>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="高新企业" name="8">
          <el-row :gutter="40">
            <el-col :span="12">
              <el-form-item label="是否为高新企业" prop="techFlag">
                <el-radio-group v-model="registerForm.techFlag">
                  <el-radio v-for="(item, index) in yesOrNoOptions" :key="index" :label="item.dictValue">{{item.dictLabel}}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="registerForm.techFlag == 1">
              <el-form-item label="高新企业编号" prop="techCode">
                <el-input v-model="registerForm.techCode" type="text" auto-complete="off" placeholder="请输入高新企业编号">
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="上年度是否做加计扣除" name="9">
          <el-row :gutter="40">
            <el-col :span="12">
              <el-form-item label="上年度是否做加计扣除" prop="deductionFlag">
                <el-radio-group v-model="registerForm.deductionFlag">
                  <el-radio v-for="(item, index) in yesOrNoOptions" :key="index" :label="item.dictValue">{{item.dictLabel}}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="附件" name="10">
          <el-form-item label="企业营业执照" prop="licensePath" ref="licenseUpload">
            <ImageUpload @input="handleLicenseSuccess" :params="params" :limit="limit" :value="registerForm.licensePath" :fileSize="fileSize"></ImageUpload>
            <!-- <FileUpload :file="{url: registerForm.licensePath, name: registerForm.fileName}" @input="handleSuccess">上传材料</FileUpload> -->
          </el-form-item>
          <el-form-item label="其他附件" prop="attachIds">
            <FileUpload :files="registerForm.fileList" @input="handleSaleSuccess" :multiple="true" :params="params">上传材料</FileUpload>
            <el-table v-loading="loading" :data="list" border style="width: 100%;margin-top: 5px;" v-if="dataId">
              <el-table-column label="序号" type="index" width="50" align="center"></el-table-column>
              <el-table-column label="文件名称" prop="fileName" align="center"></el-table-column>
              <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                  <el-button type="text" @click="handleView(scope.row)">查看</el-button>
                  <el-button type="text" @click="handleDelete(scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <!-- <FileUpload :files="registerForm.attachIds" @input="handleSaleSuccess" :multiple="true">上传材料</FileUpload> -->
          </el-form-item>
        </el-collapse-item>
        <el-collapse-item title="文件水印" name="11">
          <el-row :gutter="40">
            <el-col :span="24">
              <el-form-item label="文件水印" prop="logo" ref="logoUpload">
                <ImageUpload @input="handleLogoSuccess" :params="params" :limit="limit" :value="registerForm.logo" :fileSize="fileSize"></ImageUpload>
                <!-- <ImageUpload @input="handleLogoSuccess"></ImageUpload> -->
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
      </el-collapse>
      <el-row :gutter="40">
        <el-col :span="24">
          <el-form-item style="width:100%;text-align: center;" label-width="0px">
            <el-button
              :loading="loading"
              size="medium"
              type="primary"
              @click.native.prevent="handleRegister" style="width: 100px;">
              <span v-if="!loading">注册</span>
              <span v-else>注 册 中...</span>
            </el-button>
            <el-button size="medium" type="primary" style="width: 100px;" @click="cancel">取消</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    </div>
    <!--  底部  -->
    <div class="el-register-footer">
      <span>Copyright © 2022 All Rights Reserved.</span>
    </div>
    <el-dialog
      :visible.sync="dialogVisible"
      title="预览"
      width="800"
      append-to-body>
      <img
        :src="dialogImageUrl"
        style="display: block; max-width: 100%; margin: 0 auto"/>
    </el-dialog>
  </div>
</template>

<script>

import { getCodeImg, registerEntApi,getEntUserById,entUserAudit,enterUserNoToken,getEnclosureApi,deleteEnclosureApi } from "@/api/login";
import {getProvinceDataApi,getRegionChildrenApi,validLicenseApi} from "@/api/common/common"
import { regTypeOptions,mainProductsOptions,yesOrNoOptions } from "@/utils/dataFormat"
import FileUpload from '@/components/FileUpload'
import ImageUpload from '@/components/ImageUpload'
import { validIDcard,validAmount} from '@/utils/validate'
import { validNumber } from '@/utils/validate'

export default {
  name: "First",
  components: {
    FileUpload,
    ImageUpload
  },
  data() {
    const equalToPassword = (rule, value, callback) => {
      if (this.registerForm.password !== value) {
        callback(new Error("两次输入的密码不一致"));
      } else {
        callback();
      }
    };
    return {
      tokenVisile: false,
      limit: 1, //长传图片数量
      fileSize: 1,
      params: {
        attachType: 'ENT',
        dataId: ''
      },
      dialogVisible: false,
      dialogImageUrl: "",
      activeNames: ['1','2','3','4','5','6','7','8','9','10', '11'],
      provinceName: '',
      attachType: 'ENT',
      dataId: '',
      list: [],
      token: '',
      cityName: '',
      districtName: '',
      codeUrl: "",
      regTypeOptions: regTypeOptions,
      mainProductsOptions: mainProductsOptions,
      yesOrNoOptions: yesOrNoOptions,
      provinceDataList: [],
      cityDataList: [],
      districtDataList: [],
      registerForm: {
        startDate: '',
        endDate: '',
        attachIds: [],
        provinceId: '',
        cityId: '',
        districtId: '',
        mainProductArray: ['电子信息'],
        mainProducts: '',
        userName: "",
        password: "",
        confirmPassword: "",
        techFlag: 1,
        listedFlag: 1,
        investFlag: 1,
        deductionFlag: 1
      },
      registerRules: {
        userName: [
          { required: true, trigger: "blur", message: "请输入您的账号" },
          { min: 2, max: 20, message: '用户账号长度必须介于 2 和 20 之间', trigger: 'blur' }
        ],
        password: [
          { required: true, trigger: "blur", message: "请输入您的密码" },
          { min: 5, max: 20, message: '用户密码长度必须介于 5 和 20 之间', trigger: 'blur' }
        ],
        confirmPassword: [
          { required: true, trigger: "blur", message: "请再次输入您的密码" },
          { required: true, validator: equalToPassword, trigger: "blur" }
        ],
        nickName: [
          { required: true, trigger: "blur", message: "请输入姓名" },
          {max: 30, message: '最多输入30个字符', trigger: 'blur' }
        ],
        phonenumber: [
          { required: true, trigger: "blur", message: "请输入手机号" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ],
        email: [
          { required: true, trigger: ["blur", "change"], message: "请输入邮箱",type: "email", },
        ],
        entName: [
          { required: true, trigger: "blur", message: "请输入企业名称" },
          {max: 30, message: '最多输入30个字符', trigger: 'blur' }
        ],
        license: [
          { required: true, trigger: "blur", message: "请输入统一社会信用代码" },
          {min: 18,max: 18, message: '请输入正确的统一社会信用代码格式', trigger: 'blur' }
        ],
        regCapital: [
          { required: true, trigger: "blur", message: "请输入注册资金" },
          { validator: validAmount, trigger: 'blur'}
        ],
        regDate: [
          { required: true, trigger: "change", message: "请选择工商注册时间" },
        ],
        regType: [
          { required: true, trigger: "change", message: "请选择工商注册类型" },
        ],
        mainProductArray: [
          { type: 'array', required: true, message: '请至少选择一个主营产品(服务)所属技术领域', trigger: 'change' }
        ],
        address: [
          { required: true, trigger: "blur", message: "请输入通信地址" },
          {max: 50, message: '最多输入50个字符', trigger: 'blur' }
        ],
        zipCode: [
          { required: true, trigger: "blur", message: "请输入邮政编码" },
          { validator: validNumber, trigger: 'blur'},
          {max: 6, message: '最多输入6位数字', trigger: 'blur' }
        ],
        provinceId: [
          { required: true, trigger: "change", message: "请选择省份" },
        ],
        cityId: [
          { required: true, trigger: "change", message: "请选择市" },
        ],
        districtId: [
          { required: true, trigger: "change", message: "请选择区" },
        ],
        taxOffice: [
          { required: true, trigger: "blur", message: "企业所得税主管税务机关" },
          {max: 30, message: '最多输入30个字符', trigger: 'blur' }
        ],
        legalName: [
          { required: true, trigger: "blur", message: "请输入姓名" },
          {max: 30, message: '最多输入30个字符', trigger: 'blur' }
        ],
        legalIdCard: [
          { required: true, trigger: "blur", message: "请输入身份证号码" },
          { validator: validIDcard, trigger: 'blur'}
        ],
        legalMobile: [
          { required: true, trigger: "blur", message: "请输入手机号码" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ],
        linkName: [
          { required: true, trigger: "blur", message: "请输入姓名" },
          {max: 30, message: '最多输入30个字符', trigger: 'blur' }
        ],
        linkIdCard: [
          { required: true, trigger: "blur", message: "请输入身份证号码" },
          { validator: validIDcard, trigger: 'blur'}
        ],
        linkMobile: [
          { required: true, trigger: "blur", message: "请输入手机号码" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ],
        listedFlag: [
          { required: true, trigger: "change", message: "请选择企业是否上市" },
        ],
        listingCode: [
          { required: true, trigger: "blur", message: "请输入企业上市代码" },
          {max: 30, message: '最多输入30个字符', trigger: 'blur' }
        ],
        investFlag: [
          { required: true, trigger: "change", message: "请选择是否引入风险投资" },
        ],
        investCapital: [
          { required: true, trigger: "blur", message: "请输入风险投资金额" },
          { validator: validAmount, trigger: 'blur'}
        ],
        techFlag: [
          { required: true, trigger: "change", message: "请选择是否为高新企业" },
        ],
        techCode: [
          { required: true, trigger: "blur", message: "请输入高新企业编号" },
          {max: 30, message: '最多输入30个字符', trigger: 'blur' }
        ],
        deductionFlag: [
          { required: true, trigger: "change", message: "请选择是否做加计扣除" },
        ],
        licensePath: [
          { required: true, trigger: "change", message: "请上传营业执照附件" },
        ],
        logo: [
          { required: true, trigger: "change", message: "请上传文件水印" },
        ]
      },
      loading: false,
      captchaOnOff: true
    };
  },
  created() {
    this.getCode();
    this.getProvinceData()
    this.token = this.$route.params.token || ''
    if(this.token) {
      this.getData()
      this.tokenVisile = false
      this.activeName = '3'
    }else {
      this.tokenVisile = true
      this.activeName = '1'
    }
  },
  methods: {
    validLicense(val) {
      validLicenseApi(val).then(res => {
        // true存在
        if(res.data) {
          this.$message.error('统一社会信用代码已经存在，不可以重复注册');
        }
      })
    },
    getEnclosureData() {
      getEnclosureApi(this.token,this.attachType, this.dataId).then(res => {
        this.list = res.data.records
      })
    },
    getData() {
      this.loading = true
      getEntUserById(this.token).then(res => {
        this.loading = false
        this.registerForm = res.data || {}
        this.dataId = res.data.id || {}
        if(this.dataId) {
          this.getEnclosureData()
        }
        let mainProductArray = this.registerForm.mainProducts.split(',') || ['电子信息'];
        this.$set(this.registerForm, 'mainProductArray', mainProductArray);
        this.registerForm.provinceId = res.data.provinceId
        if(this.registerForm.provinceId) {
          getRegionChildrenApi(this.registerForm.provinceId).then(res => {
            if(res.code == 200) {
              this.cityDataList = res.data
            }
          })
        }
        if(this.registerForm.cityId) {
          getRegionChildrenApi(this.registerForm.cityId).then(res => {
            if(res.code == 200) {
              this.districtDataList = res.data
            }
          })
        }
      })
    },
    handleSuccess(file) {
      this.registerForm.licensePath = file.url;
      this.registerForm.fileName = file.name;
    },
    // handleSaleSuccess(files) {
    //   files.forEach(item => {
    //     this.registerForm.attachIds.push(item.response.data.id)
    //   });
    // },
    handleSaleSuccess(files) {
      this.registerForm.fileList = files
      this.registerForm.attachIds = []
      files.forEach(item => {
        this.registerForm.attachIds.push(item.response.data.id)
      });
    },
    handleLogoSuccess(file) {
      this.registerForm.logo = file
    },
    handleLicenseSuccess(file) {
      this.registerForm.licensePath = file
      this.$refs.licenseUpload.clearValidate()
    },
    handleView(row) {
      // 获取文件路径
      const fileUrl = row.url
      // 获取最后一个.的位置
      const index = fileUrl.lastIndexOf(".")
      // 获取后缀
      const ext = fileUrl.substr(index+1)
      if(ext == 'jpg' || ext == 'png' || ext == 'jpeg') {
        this.dialogVisible = true
        this.dialogImageUrl = fileUrl
      }else {
         window.open(fileUrl)
      }
    },
    handleDelete(row) {
      const id = row.id;
      this.$confirm('是否确认删除该数据?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return deleteEnclosureApi(this.token,id);
        }).then(() => {
          this.getEnclosureData()
          this.$modal.msgSuccess("删除成功");
        })
    },
    //选择省份
    getCityData() {
      this.registerForm.cityId = ''
      this.registerForm.districtId = ''
      getRegionChildrenApi(this.registerForm.provinceId).then(res => {
        if(res.code == 200) {
          this.cityDataList = res.data

          let obj = this.provinceDataList.find(item => {
            return item.id == this.registerForm.provinceId
          })
          this.provinceName = obj.name
          this.registerForm.taxOffice = '国家税务总局'+this.provinceName+'税务局'
        }
      })
    },
    //选择市
    getDistrictData() {
      this.registerForm.districtId = ''
      getRegionChildrenApi(this.registerForm.cityId).then(res => {
        if(res.code == 200) {
          this.districtDataList = res.data

          let obj = this.cityDataList.find(item => {
            return item.id == this.registerForm.cityId
          })
          this.cityName = obj.name
          this.registerForm.taxOffice = '国家税务总局'+this.cityName+'税务局'
        }
      })
    },
    changeDistrict() {
      let obj = this.districtDataList.find(item => {
        return item.id == this.registerForm.districtId
      })
      this.districtName = obj.name
      this.registerForm.taxOffice = '国家税务总局'+this.districtName+'税务局'
    },
    getProvinceData() {
      getProvinceDataApi().then(res => {
        if(res.code == 200) {
          this.provinceDataList = res.data
          this.registerForm.provinceId = '1481196860266852481'
          getRegionChildrenApi(this.registerForm.provinceId).then(res => {
            if(res.code == 200) {
              this.cityDataList = res.data
              this.registerForm.cityId = '1481196860266852482'
              getRegionChildrenApi(this.registerForm.cityId).then(res => {
                if(res.code == 200) {
                  this.districtDataList = res.data
                }
              })
            }
          })
        }
      })
      this.registerForm.taxOffice = '国家税务总局长沙市税务局'
    },
    getCode() {
      getCodeImg().then(res => {
        this.captchaOnOff = res.captchaOnOff === undefined ? true : res.captchaOnOff;
        if (this.captchaOnOff) {
          this.codeUrl = "data:image/gif;base64," + res.img;
          this.registerForm.uuid = res.uuid;
        }
      });
    },
    cancel() {
      this.$router.go(-1);
    },
    handleRegister() {
      this.registerForm.mainProducts = this.registerForm.mainProductArray.join(',')
      validLicenseApi(this.registerForm.license).then(res => {
        // true存在
        if(res.data) {
          this.$message.error('统一社会信用代码已经存在，不可以重复注册');
          return
        }
      })
      this.$refs.registerForm.validate((valid,obj) => {
        if (valid) {
          this.loading = true;
          if(this.token) {
            entUserAudit(this.token, this.registerForm).then(res => {
              this.$alert("注册信息修改成功", '系统提示', {
                dangerouslyUseHTMLString: true,
                type: 'success'
              }).then(() => {
                this.$store.dispatch('LogOut').then(() => {
                  this.$router.push("/login");
                })
              }).catch(() => {});
            }).catch(() => {
              this.loading = false;
              // if (this.captchaOnOff) {
              //   this.getCode();
              // }
            })
          }else {
            registerEntApi(this.registerForm).then(res => {
              const userName = this.registerForm.userName;
              this.$alert("<font color='red'>恭喜你，您的账号 " + userName + " 注册成功！</font>", '系统提示', {
                dangerouslyUseHTMLString: true,
                type: 'success'
              }).then(() => {
                this.$router.push("/login");
              }).catch(() => {});
            }).catch(() => {
              this.loading = false;
              // if (this.captchaOnOff) {
              //   this.getCode();
              // }
            })
          }
        }else {
          const a = []
          for (let key in obj) {
            a.push(obj[key][0].message)
          }
          this.$message({
            message: a[0],
            type: "warning"
          })
          return false
        }
      });
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss">
  .title-reg {
    position: fixed;
    z-index: 999;
    top: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 45px;
    line-height: 45px;
    padding: 20px;
    background-color: #1890ff;
    img {
      left: 0;
    }
  }
  .top-fixed {
    width: 100%;
    height: 45px;
  }
  .top-img {
    float: right;
    margin-top: -64px;
  }
.register {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 900px;
  overflow-y: auto;
  scroll-behavior: auto;
  background-image: url("../../assets/images/login-background.jpg");
  background-size: cover;
}
.title {
  margin: 0px auto 30px auto;
  text-align: center;
  color: #FFFFFF;
}

.register-form {
  border-radius: 6px;
  background: #ffffff;
  width: 1200px;
  height: 800px;
  overflow-y: auto;
  padding: 25px 25px 5px 25px;
  .el-input {
    height: 38px;
    input {
      height: 38px;
    }
  }
  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 2px;
  }
}
.register-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}
.register-code {
  width: 33%;
  height: 38px;
  float: right;
  img {
    cursor: pointer;
    vertical-align: middle;
  }
}
.el-register-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}
.register-code-img {
  height: 38px;
}
/* =============自定义样式============== */
$border: #ddd;
/* 工具栏 */
.toolbar {
  margin: 0 0 15px;
  &>.title {
    position: relative;
    padding-left: 15px;
    margin-right: 15px;
    font-size: 16px;
    line-height: 28px;
    font-weight: bold;
    color: #363636;
    &:before {
      content: "";
      display: block;
      position: absolute;
      left: 0;
      top: 50%;
      transform: translate(0, -50%);
      width: 5px;
      height: 16px;
      background-color: #409EFF;
    }
  }
  &:after {
    content: "";
    clear: both;
    display: block;
  }
  &>.tip {
    display: inline-block;
    font-size: 14px;
    font-weight: normal;
    color: #666;
  }
}
</style>
