<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: "face",
              type: "upload",
              span:20,
              align:'center',
              listType: 'picture-img',
              propsHttp: {
                res: "data",
                url: "link"
              },
              action: "/api/blade-resource/oss/endpoint/put-file",
              tip: '只能生产jpg/png图片，且不超过500kb'
            },
            {
              label: "所属企业",
              prop: "enterpriseId",
              type: "select",
              width: 160,
              search: true,
              searchSpan: 6,
              overHidden: true,
              // dicUrl: `/api/enterprise/enterprise/getList`,
              props: {
                label: "enterpriseName",
                value: "id"
              },
              rules: [{
                required: true,
                message: "请输入所属企业",
                trigger: "blur"
              }]
            },
            {
              label: "所属园区",
              prop: "agencyId",
              slot: true,
              search: true,
              cascaderItem: ['residentialId'],
              type: "select",
              remote: true,
              dicUrl: "/api/cyzh-community/agency/list",
              dicFormatter:(res)=>{
                return res.data.records;//返回字典的层级结构
              },
              props: {
                label: "name",
                value: "id"
              },
              rules: [{
                required: true,
                message: "请选择所属社区",
                trigger: "blur"
              }]
            },
            {
              label: "所属区域",
              prop: "residentialId",
              slot: true,
              type: "select",
              search: true,
              cascaderItem: ['buildingId'],
              dicUrl: "/api/cyzh-community/residential/list?agencyId={{key}}",
              dicFormatter:(res)=>{
                return res.data.records;//返回字典的层级结构
              },
              // dicFlag: false,
              filterable: true,
              props: {
                label: "name",
                value: "id"
              },
              rules: [{
                required: true,
                message: "请选择所属小区",
                trigger: "blur"
              }]
            },
            {
              label: "员工编号",
              prop: "code",
              hide:true,
              rules: [{
                required: false,
                message: "请输入用户编号",
                trigger: "blur"
              }]
            },
            {
              label: "角色",
              prop: "role",
              hide:true,
              rules: [{
                required: false,
                message: "请输入角色id",
                trigger: "blur"
              }]
            },
            {
              label: "部门",
              prop: "dept",
              hide:true,
              rules: [{
                required: false,
                message: "请输入部门id",
                trigger: "blur"
              }]
            },
            {
              label: "岗位",
              prop: "post",
              hide:true,
              rules: [{
                required: false,
                message: "请输入岗位id",
                trigger: "blur"
              }]
            },
            {
              label: "来访目的",
              prop: "visitPurpose",
              hide:true,
              rules: [{
                required: false,
                message: "请输入来访目的",
                trigger: "blur"
              }]
            },
            {
              label: "备注",
              prop: "remarks",
              hide:true,
              rules: [{
                required: false,
                message: "请输入备注",
                trigger: "blur"
              }]
            },
            {
              label:"审核状态",
              prop:"examine",
              search:"true",
              searchSpan: 4,
              slot:true,
              display: false,
              type:'select',
              dicData:[
                {
                  label:'待审核',
                  value:0,
                  color:'red'
                },{
                  label:'审核通过',
                  value:1
                },{
                  label:'审核不通过',
                  value:2
                }
              ]
            },
            {
              label: "住址",
              prop: "address",
              rules: [{
                required: true,
                message: "请输入住址",
                trigger: "blur"
              }]
            },
            {
              label: "审核意见",
              prop: "opinion",
              rules: [{
                required: false,
                message: "请输入审核意见",
                trigger: "blur"
              }]
            },
            {
              label:"来源",
              prop:"createType",
              search:"true",
              searchSpan: 4,
              type:'select',
              display: false,
              dicData:[
                {
                  label:'后台',
                  value:0
                },{
                  label:'小程序',
                  value:1
                }
              ],
              rules: [{
                required: false,
                message: "请输入审核时间",
                trigger: "blur"
              }]
            },
            {
              label: "审核时间",
              prop: "auditTime",
              type:"datetime",
              display:false,
              rules: [{
                required: false,
                message: "请输入审核时间",
                trigger: "blur"
              }]
            },
            {
              label: "是否为小程序园区管理员",
              prop: "isAgencyManager",
              type:'select',
              dicData:[
                {
                  label:'是',
                  value:1
                },{
                  label:'否',
                  value:0
                }
              ],
              rules: [{
                required: true,
                message: "请选择",
                trigger: "blur"
              }]
            },
            {
              label: "园区管理员小程序登录账号",
              prop: "agencyAccount",
              rules: [{
                required: false,
                message: "请输入若为园区管理员时的小程序登录账号",
                trigger: "blur"
              }]
            },
            {
              label: "园区管理员小程序登录密码",
              prop: "agencyPassword",
              rules: [{
                required: false,
                message: "请输入若为园区管理员时的小程序登录密码",
                trigger: "blur"
              }]
            },
            {
              label: "是否为企业管理员",
              prop: "isEnterpriseManager",
              type:'select',
              dicData:[
                {
                  label:'是',
                  value:1
                },{
                  label:'否',
                  value:0
                }
              ],
              rules: [{
                required: true,
                message: "请选择",
                trigger: "blur"
              }]
            },
            {
              label: "企业管理员小程序登录账号",
              prop: "enterpriseAccount",
              rules: [{
                required: false,
                message: "请输入若为企业管理员时的小程序登录账号",
                trigger: "blur"
              }]
            },
            {
              label: "企业管理员小程序登录密码",
              prop: "enterprisePassword",
              rules: [{
                required: false,
                message: "请输入若为企业管理员时的小程序登录密码",
                trigger: "blur"
              }]
            },
          ]
        },
      };
    },
    methods: {
      //提交
      addEntity(row, done) {
        row.parentId = this.basicData.id;
        row.realname = 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>
