<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: false,
              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: "buildingId",
          //   slot: true,
          //   type: "select",
          //   search: true,
          //   cascaderItem: ['unitId'],
          //   dicUrl: `/api/cyzh-community/building/list?residentialId={{key}}`,
          //   dicFormatter:(res)=>{
          //     return res.data.records;//返回字典的层级结构
          //   },
          //   // dicFlag: false,
          //   filterable: true,
          //   props: {
          //     label: "name",
          //     value: "id"
          //   },
          //   rules: [{
          //     required: true,
          //     message: "请输入楼栋Id",
          //     trigger: "blur"
          //   }]
          // },
          // {
          //   label: "所属单元",
          //   prop: "unitId",
          //   slot: true,
          //   type: "select",
          //   search: true,
          //   cascaderItem: ['floorId'],
          //   dicUrl: "/api/cyzh-community/unit/list?buildingId={{key}}",
          //   dicFormatter:(res)=>{
          //     return res.data.records;//返回字典的层级结构
          //   },
          //   // dicFlag: false,
          //   filterable: true,
          //   props: {
          //     label: "name",
          //     value: "id"
          //   },
          //   rules: [{
          //     required: true,
          //     message: "请输入单元Id",
          //     trigger: "blur"
          //   }]
          // },
          // {
          //   label: "所属楼层",
          //   prop: "floorId",
          //   slot: true,
          //   type: "select",
          //   search: true,
          //   cascaderItem: ['roomId'],
          //   dicUrl: "/api/cyzh-community/floor/list?unitId={{key}}",
          //   dicFormatter:(res)=>{
          //     return res.data.records;//返回字典的层级结构
          //   },
          //   // dicFlag: false,
          //   filterable: true,
          //   props: {
          //     label: "name",
          //     value: "id"
          //   },
          //   rules: [{
          //     required: true,
          //     message: "请输入楼层Id",
          //     trigger: "blur"
          //   }]
          // },
          // {
          //   label: "所属房间",
          //   prop: "roomId",
          //   slot: true,
          //   type: "select",
          //   search: true,
          //   dicUrl: "/api/cyzh-community/room/list?floorId={{key}}",
          //   dicFormatter:(res)=>{
          //     return res.data.records;//返回字典的层级结构
          //   },
          //   // dicFlag: false,
          //   filterable: true,
          //   props: {
          //     label: "name",
          //     value: "id"
          //   },
          //   rules: [{
          //     required: true,
          //     message: "请输入房间Id",
          //     trigger: "blur"
          //   }]
          // },
          {
            label: "备注",
            prop: "remark",
            type: 'textarea',
            span:18,
            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>
