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

<script>
import {add} from "@/api/person/disabler";
import {update,getDetail} from "@/api/person/basicinfo";
import {validatePhone} from "../../util/validator";

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: "livingConditions",
            type: 'select',
            multiple: true,
            dataType:'string',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=living-conditions",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: true,
              message: "请选择居住情况",
              trigger: "blur"
            }]
          },
          {
            label: "监护人",
            prop: "guardian",
            rules: [{
              required: false,
              message: "请输入监护人",
              trigger: "blur"
            }]
          },
          {
            label: "监护人电话",
            prop: "guardianPhone",
            rules: [{
              required: false,
              message: "请输入监护人电话",
            },{
              validator: validatePhone,
              trigger: "blur"
            }]
          },
          {
            label: "收入来源",
            prop: "incomeSource",
            type: 'select',
            multiple: true,
            dataType:'string',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=income-source",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: false,
              message: "请选择收入来源",
              trigger: "blur"
            }]
          },
          {
            label: "医疗保障",
            prop: "healthCare",
            type: 'select',
            multiple: true,
            dataType:'string',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=health-care",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: true,
              message: "请选择医疗保障",
              trigger: "blur"
            }]
          },
          {
            label: "康复需求",
            prop: "convalescence",
            rules: [{
              required: false,
              message: "请输入康复需求",
              trigger: "blur"
            }]
          },
          {
            label: "辅助器具",
            prop: "assistiveDevices",
            rules: [{
              required: false,
              message: "请输入辅助器具",
              trigger: "blur"
            }]
          },
          {
            label: "生活爱好",
            prop: "hobby",
            rules: [{
              required: false,
              message: "请输入生活爱好",
              trigger: "blur"
            }]
          },
          {
            label: "生活嗜好",
            prop: "addiction",
            rules: [{
              required: false,
              message: "请输入生活嗜好",
              trigger: "blur"
            }]
          },
          {
            label: "行为能力",
            prop: "ability",
            type: 'select',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=ability",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: false,
              message: "请选择行为能力",
              trigger: "blur"
            }]
          },
          {
            label: "社交能力",
            prop: "socialSkills",
            type: 'select',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=social-skills",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: false,
              message: "请选择社交能力",
              trigger: "blur"
            }]
          },
          {
            label: "就业意向",
            prop: "employmentNeeds",
            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: "visitPlan",
            type: 'textarea',
            span:12,
            rules: [{
              required: false,
              message: "请输入探访计划",
              trigger: "blur"
            }]
          },
          {
            label: "备注",
            prop: "remark",
            type: 'textarea',
            span:12,
            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>
