<template>
  <basic-container>
    <avue-form :option="option"
               v-model="form"
               @submit="addEntity">
    </avue-form>
  </basic-container>
</template>

<script>
  import {add} from "@/api/person/enterprisestaff";
  import {update, getDetail} from "@/api/person/basicinfo";
  export default {
    name:'enterpriseStaffTags-form',
    props:{
      closeFn:{type:Function},
      basicData:{type:Object}
    },
    data() {
      return {
        form: {},
        option: {
          height:'auto',
          calcHeight: 30,
          labelWidth: 120,
          tip: false,
          submitText:"提交",
          emptyBtn:false,
          column: [
            {
              label: "昵称",
              prop: "name",
              rules: [{
                required: true,
                message: "请输入昵称",
                trigger: "blur"
              }]
            },
            {
              label: "真名",
              prop: "realName",
              rules: [{
                required: true,
                message: "请输入真名",
                trigger: "blur"
              }]
            },
            {
              label: "所属企业",
              prop: "enterpriseId",
              rules: [{
                required: true,
                message: "请输入所属企业",
                trigger: "blur"
              }]
            },
            {
              label: "企业名称",
              prop: "enterpriseName",
              rules: [{
                required: true,
                message: "请输入企业名称",
                trigger: "blur"
              }]
            },
            {
              label: "用户编号",
              prop: "code",
              rules: [{
                required: true,
                message: "请输入用户编号",
                trigger: "blur"
              }]
            },
            {
              label: "头像",
              prop: "avatar",
              rules: [{
                required: true,
                message: "请输入头像",
                trigger: "blur"
              }]
            },
            {
              label: "邮箱",
              prop: "email",
              rules: [{
                required: true,
                message: "请输入邮箱",
                trigger: "blur"
              }]
            },
            {
              label: "手机号码",
              prop: "phone",
              rules: [{
                required: true,
                message: "请输入手机号码",
                trigger: "blur"
              }]
            },
            {
              label: "生日",
              prop: "birthday",
              rules: [{
                required: true,
                message: "请输入生日",
                trigger: "blur"
              }]
            },
            {
              label: "性别",
              prop: "sex",
              rules: [{
                required: true,
                message: "请输入性别",
                trigger: "blur"
              }]
            },
            {
              label: "角色id",
              prop: "roleId",
              rules: [{
                required: true,
                message: "请输入角色id",
                trigger: "blur"
              }]
            },
            {
              label: "部门id",
              prop: "deptId",
              rules: [{
                required: true,
                message: "请输入部门id",
                trigger: "blur"
              }]
            },
            {
              label: "岗位id",
              prop: "postId",
              rules: [{
                required: true,
                message: "请输入岗位id",
                trigger: "blur"
              }]
            },
            {
              label: "来访目的",
              prop: "visitPurpose",
              rules: [{
                required: true,
                message: "请输入来访目的",
                trigger: "blur"
              }]
            },
            {
              label: "备注",
              prop: "remarks",
              rules: [{
                required: true,
                message: "请输入备注",
                trigger: "blur"
              }]
            },
            {
              label: "小程序openId",
              prop: "openId",
              rules: [{
                required: true,
                message: "请输入小程序openId",
                trigger: "blur"
              }]
            },
            {
              label: "是否审核通过（0待审核，1审核通过，2审核不通过）",
              prop: "examine",
              rules: [{
                required: true,
                message: "请输入是否审核通过（0待审核，1审核通过，2审核不通过）",
                trigger: "blur"
              }]
            },
            {
              label: "住址",
              prop: "address",
              rules: [{
                required: true,
                message: "请输入住址",
                trigger: "blur"
              }]
            },
            {
              label: "身份证号码",
              prop: "idcard",
              rules: [{
                required: true,
                message: "请输入身份证号码",
                trigger: "blur"
              }]
            },
            {
              label: "人脸信息",
              prop: "face",
              rules: [{
                required: true,
                message: "请输入人脸信息",
                trigger: "blur"
              }]
            },
            {
              label: "园区id",
              prop: "agencyId",
              rules: [{
                required: true,
                message: "请输入园区id",
                trigger: "blur"
              }]
            },
            {
              label: "区域id",
              prop: "residentialId",
              rules: [{
                required: true,
                message: "请输入区域id",
                trigger: "blur"
              }]
            },
            {
              label: "审核时间",
              prop: "auditTime",
              rules: [{
                required: true,
                message: "请输入审核时间",
                trigger: "blur"
              }]
            },
            {
              label: "审核意见",
              prop: "opinion",
              rules: [{
                required: true,
                message: "请输入审核意见",
                trigger: "blur"
              }]
            },
            {
              label: "创建方式（来源）{0：后台，1：小程序}",
              prop: "createType",
              rules: [{
                required: true,
                message: "请输入创建方式（来源）{0：后台，1：小程序}",
                trigger: "blur"
              }]
            },
            {
              label: "机构路径",
              prop: "orgPosition",
              rules: [{
                required: true,
                message: "请输入机构路径",
                trigger: "blur"
              }]
            },
            {
              label: "是否为小程序园区管理员：0-否 1-是",
              prop: "isAgencyManager",
              rules: [{
                required: true,
                message: "请输入是否为小程序园区管理员：0-否 1-是",
                trigger: "blur"
              }]
            },
            {
              label: "若为园区管理员时的小程序登录账号",
              prop: "agencyAccount",
              rules: [{
                required: true,
                message: "请输入若为园区管理员时的小程序登录账号",
                trigger: "blur"
              }]
            },
            {
              label: "若为园区管理员时的小程序登录密码",
              prop: "agencyPassword",
              rules: [{
                required: true,
                message: "请输入若为园区管理员时的小程序登录密码",
                trigger: "blur"
              }]
            },
            {
              label: "是否为企业管理员：0-否 1-是",
              prop: "isEnterpriseManager",
              rules: [{
                required: true,
                message: "请输入是否为企业管理员：0-否 1-是",
                trigger: "blur"
              }]
            },
            {
              label: "若为企业管理员时的小程序登录账号",
              prop: "enterpriseAccount",
              rules: [{
                required: true,
                message: "请输入若为企业管理员时的小程序登录账号",
                trigger: "blur"
              }]
            },
            {
              label: "若为企业管理员时的小程序登录密码",
              prop: "enterprisePassword",
              rules: [{
                required: true,
                message: "请输入若为企业管理员时的小程序登录密码",
                trigger: "blur"
              }]
            },
          ]
        },
      };
    },
    methods: {
      //提交
      addEntity(row, done) {
        row.parentId = this.basicData.id;
        row.name = this.basicData.name;
        add(row).then(() => {
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
          this.LoadAndUpdate();
          this.closeFn();
        }, error => {
          this.$message({
            type:"fail",
            message:"操作失败!"
          });
          window.console.log(error);
        });
      },
      LoadAndUpdate() {
        let tags_temp = this.basicData.tags;
        if (tags_temp) {
          tags_temp += "，企业员工";
        } else {
          tags_temp = "企业员工";
        }
        this.basicData.tags = tags_temp;
        update(this.basicData).then(()=>{
          this.closeFn();
        }, error => {
          console.log(error);
        })
      }
    }
  };
</script>

<style>
</style>
