add.vue 6.41 KB
<template>
  <el-dialog :title="title" :visible.sync="open" v-if="open" width="1000px" append-to-body>
    <el-row :span="24">
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-col :span="12">
          <el-form-item label="企业名称" prop="postName">
            <el-input v-model="form.postName" placeholder="请输入企业名称" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="统一社会信用代码" prop="postCode">
            <el-input v-model="form.postCode" placeholder="请输入编码名称" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="经办人名称" prop="postSort">
            <el-input v-model="form.postCode" placeholder="请输入经办人名称" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="经办人手机号码" prop="postCode">
            <el-input v-model="form.postCode" placeholder="请输入经办人手机号码" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="经办人身份证号码" prop="postSort">
            <el-input v-model="form.postCode" placeholder="请输入经办人身份证号码" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="产品名称" prop="applyProductCode">
            <el-select v-model="form.applyProductCode" placeholder="产品名称" clearable size="small">
              <el-option v-for="(item, index) in product" :key="index" :label="item.name" :value="item.businessCode" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="风控类型" prop="status">
            <el-select v-model="form.status" placeholder="风控类型" clearable size="small">
              <el-option label="dict.label" value="dict.value" />
            </el-select>
          </el-form-item>
        </el-col>
        <div class="box">
          <el-form-item label="身份证正面照" prop="status">
            <el-upload class="avatar-uploader" action="https://jsonplaceholder.typicode.com/posts/"
              :show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
              <img v-if="imageUrl" :src="imageUrl" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
          <el-form-item label="身份证反面照" prop="status">
            <el-upload class="avatar-uploader" action="https://jsonplaceholder.typicode.com/posts/"
              :show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
              <img v-if="imageUrl" :src="imageUrl" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
          <el-form-item label="企业营业执照" prop="status">
            <el-upload class="avatar-uploader" action="https://jsonplaceholder.typicode.com/posts/"
              :show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
              <img v-if="imageUrl" :src="imageUrl" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
        </div>
      </el-form>
    </el-row>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { addPost, updatePost } from "@/api/system/post";
import { selectAll } from "@/api/postList/list";
export default {
  name: 'addMobile',
  dicts: ['sys_normal_disable'],
  data() {
    return {
      imageUrl: '',
      open: false,
      product: [],
      // 弹出层标题
      title: "",
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        postName: [
          { required: true, message: "企业名称不能为空", trigger: "blur" }
        ],
        postCode: [
          { required: true, message: "统一社会信用代码不能为空", trigger: "blur" }
        ],
        postSort: [
          { required: true, message: "经办人名称不能为空", trigger: "blur" }
        ]
      }
    }
  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.form = {}
    },
    add() {
      this.open = true;
      this.title = "添加风控申请";
      this.form = {}
      var lis = {
        pageNum: 1,
        pageSize: 10000,
      }
      selectAll(lis).then(response => {
        this.product = response.data;
      });
    },
    edit(res) {
      this.form = res
      this.open = true;
      this.title = "修改风控申请";
    },
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg';
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!');
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isJPG && isLt2M;
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.postId != undefined) {
            updatePost(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPost(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
  }
}
</script>

<style>
.box {
  display: flex;
  justify-content: space-around;
  width: 100%;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>