baseInfo.vue 8.33 KB
<template>
  <div class="base_info_wrap">
    <el-image class="top_bg" :src="getImage('info-bg.png', '/home')"></el-image>
    <div class="info_wrap">
      <div class="template_btn" @click="getTemplateAuth">获取授权书模板</div>
      <div class="business_licence">
        <el-row :gutter="20">
          <el-col :span="12" class="upload_col">
            <el-upload
                action="/api/web/businessLicense/checkBusinessLicense"
                :show-file-list="false"
                :on-success="(response, uploadFile)=>handleAvatarSuccess(response, uploadFile, 'isUploadBusinessLicense', 'businessLicence')"
                :before-upload="(rawFile)=>beforeAvatarUpload(rawFile, 'isUploadBusinessLicense')"
            >
              <div class="upload_wrap" v-loading="state.isUploadBusinessLicense">
                <div class="bg_wrap">
                  <el-image class="upload_bg" :src="getImage('yyzz.png', '/home')"></el-image>
                  <img v-if="ruleForm.businessLicence" :src="ruleForm.businessLicence" class="licence"/>
                </div>
                <div class="upload_btn">点击上传营业执照</div>
              </div>
            </el-upload>
          </el-col>
          <el-col :span="12" class="upload_col">
            <el-upload
                action="/api/web/oss/uploadFile"
                :show-file-list="false"
                :on-success="(response, uploadFile)=>handleAvatarSuccess(response, uploadFile, 'isUploadAuth', 'authorizeFile')"
                :before-upload="(rawFile)=>beforeAvatarUpload(rawFile, 'isUploadAuth')"
                :headers="{
                                  authorization: state.token,
                                }"
            >
              <div class="upload_wrap" v-loading="state.isUploadAuth">
                <div class="bg_wrap">
                  <el-image class="upload_bg" :src="getImage('auth.png', '/home')"></el-image>
                  <img v-if="ruleForm.authorizeFile" :src="ruleForm.authorizeFile" class="licence"/>
                </div>
                <div class="upload_btn">点击上传授权书</div>
              </div>
            </el-upload>
          </el-col>
        </el-row>
      </div>

      <div class="info_form">
        <el-form ref="ruleFormRef" :model="ruleForm" :rules="rules" label-width="140px" label-position="left">
          <el-form-item label="企业名称" prop="enterpriseName" class="info_form_item">
            <el-input v-model="ruleForm.enterpriseName" placeholder="请输入企业名称"></el-input>
          </el-form-item>
          <el-form-item label="统一社会信用代码" prop="uscCode" class="info_form_item">
            <el-input v-model="ruleForm.uscCode" placeholder="请输入统一社会信用代码"></el-input>
          </el-form-item>
          <el-form-item label="企业办公地址" prop="serviceAddress" class="info_form_item">
            <el-input v-model="ruleForm.serviceAddress" placeholder="请输入企业办公地址"></el-input>
          </el-form-item>
          <el-form-item label="所属核心企业" prop="coreEnterprise" class="info_form_item">
            <template v-for="item in ruleForm.coreEnterprise">
              <span>{{ item.companyName }}</span><br/>
            </template>
            <!--<el-select v-model="ruleForm.coreCompanyId" placeholder="请选择所属核心企业">
                <el-option
                        v-for="item in coreCompanyList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                />
            </el-select>-->
          </el-form-item>
        </el-form>
      </div>

      <div class="info_btn_wrap">
        <div class="info_btn">
          <el-button type="primary" round :loading="loading" @click="linkTo" class="primary-btn" style="width: 100%">
            下一步
          </el-button>
        </div>
      </div>
    </div>

    <el-dialog v-model="state.dialogVisible" calss="template_dialog" width="80%" title="获取授权书模板" destroy-on-close
               :close-on-click-modal="false">

      <el-form ref="templateFormRef" :model="templateForm" :rules="templateRules" label-position="top"
               label-width="auto">
        <el-form-item prop="email" label="请输入用于接收授权书模板文件的电子邮箱:">
          <el-input v-model="templateForm.email"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
              <span class="dialog-footer">
                <el-button type="primary" @click="sendEmial">确定</el-button>
              </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import {CirclePlusFilled} from '@element-plus/icons-vue'
import type {UploadProps} from 'element-plus'
import router from "../../router/index";
import './../../assets/css/baseInfo.scss'
import getImage from './../../assets/getImage'
import * as api from "./../../interface/api"
import {formValidationForm} from "./../../utils/vaildation"

import {loginMain} from './../../store/index'
import {storeToRefs} from 'pinia';

let loginAct = loginMain()
let {getStoreToken} = storeToRefs(loginAct)

const arrowPath = ref("/product")
defineExpose({arrowPath})

let ruleForm = reactive({
  enterpriseName: undefined,
  uscCode: undefined,
  serviceAddress: undefined,
  businessLicence: undefined,
  authorizeFile: undefined,
  coreEnterprise: [],
})
let templateForm = reactive({
  email: undefined
})
let loading = ref(false)
let rules = reactive<FormRules>({
  enterpriseName: [
    {required: true, message: "请输入企业名称", trigger: ["blur", "change"]}
  ],
  uscCode: [
    {required: true, message: "请输入统一社会信用代码", trigger: ["blur", "change"]}
  ],
  serviceAddress: [
    {required: true, message: "请输入企业办公地址", trigger: ["blur", "change"]}
  ]
})
let templateRules = reactive<FormRules>({
  email: [
    {required: true, message: "请输入企业邮箱", trigger: ["blur", "change"]},
    {validator: formValidationForm.Form().checkEmail_N, trigger: ["blur"]}
  ],
})
const ruleFormRef = ref<FormInstance>()
const templateFormRef = ref<FormInstance>()

let state = reactive({
  dialogVisible: false,
  isUploadBusinessLicense: false,
  isUploadAuth: false,
  token: getStoreToken.value,
})

const handleAvatarSuccess: UploadProps['onSuccess'] = (response, uploadFile, isUpload, url) => {
  state[isUpload] = false
  if (response.code == 2000) {
    ElMessage.success('上传成功')
    // state[url] = URL.createObjectURL(uploadFile.raw!)
    if (isUpload == 'isUploadBusinessLicense') {
      ruleForm[url] = response.data.businessLicenseUrl
      ruleForm.enterpriseName = response.data.enterpriseName
      ruleForm.uscCode = response.data.uniscid
      ruleForm.serviceAddress = response.data.enterpriseAddress
      ruleForm.coreEnterprise = response.data.coreEnterprise
    }
    if (isUpload == 'isUploadAuth') {
      ruleForm[url] = response.data.path
    }
  } else {
    ElMessage.error(response.msg)
  }
}

const beforeAvatarUpload: UploadProps['beforeUpload'] = (rawFile, isUpload) => {
  if (rawFile.type !== 'image/jpeg') {
    ElMessage.error('文件的格式必须是JPG!')
    return false
  } else if (rawFile.size / 1024 / 1024 > 5) {
    ElMessage.error('文件大小不能超过5M!')
    return false
  }
  state[isUpload] = true
  return true
}

let coreCompanyList = ref([
  {
    label: '北京大禹创联商贸有限公司',
    value: 1
  },
  {
    label: '青岛中和盛杰食品有限公司',
    value: 2
  }
])

let linkTo = () => {
  ruleFormRef.value.validate((vaild, fileds) => {
    if (vaild) {
      if (ruleForm.businessLicence == undefined) {
        ElMessage.error("请上传营业执照")
        return
      }
      if (ruleForm.authorizeFile == undefined) {
        ElMessage.error("请上传授权书")
        return
      }
      api.realNameAuth(ruleForm).then(res => {
        ElMessage.success('提交成功')
        router.push("/authResult")
      })
    }
  })
}

let getTemplateAuth = () => {
  state.dialogVisible = true
}

let sendEmial = () => {
  templateFormRef.value.validate((vaild, fileds) => {
    if (vaild) {
      api.sendAuthLetterEmail(templateForm).then(res => {
        ElMessage.success("发送成功")
        state.dialogVisible = false
        templateFormRef.value.resetFields()
      })
    }
  })
}

</script>

<style scoped>
</style>