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

<script>
import {add} from "@/api/person/keypeople";
import {update, getDetail} from "@/api/person/basicinfo";
import done from "../../views/work/done";
export default {
  name:'disablerTags-form',
  props:{
    closeFn:{type:Function},
    basicData:{type:Object}
  },
  data() {
    return {
      form: {},
      basicDataObject:{},
      option: {
        height:'auto',
        calcHeight: 30,
        labelWidth: 120,
        tip: false,
        submitText:"提交",
        emptyBtn:false,
        column: [
          {
            label: "基本表Id",
            prop: "parentId",
            display: false,
            rules: [{
              required: true,
              message: "请输入基本表Id",
              trigger: "blur"
            }]
          },
          {
            label: "重点人员类型",
            prop: "type",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=key-type",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            type: "select",
            multiple: true,
            dataType:'string',
            rules: [{
              required: true,
              message: "请选择重点人员类型",
              trigger: "blur"
            }]
          },
          {
            label: "是否需要援助",
            prop: "assistance",
            type: 'select',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=assistance",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: false,
              message: "是否需要援助",
              trigger: "blur"
            }]
          },
          {
            label: "是否需要走访",
            prop: "visit",
            type: 'select',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=visit",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: false,
              message: "是否需要走访",
              trigger: "blur"
            }]
          },
          {
            label: "访问人员",
            prop: "visitPerson",
            rules: [{
              required: true,
              message: "请输入访问人员",
              trigger: "blur"
            }]
          },
          {
            label: "备注",
            prop: "remark",
            type: 'textarea',
            rules: [{
              required: false,
              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>
