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

<script>
  import {add} from "@/api/person/elderlypeople";
  import {update,getDetail} from "@/api/person/basicinfo";
  import done from "../../views/work/done";
  export default {
    name:'elderTags-form',
    props:{
      // parentId:{type:String},
      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: "medicalHistory",
              rules: [{
                required: true,
                message: "请输入既往病史",
                trigger: "blur"
              }]
            },
            {
              label: "有无子女",
              prop: "children",
              type: 'select',
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=children",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: true,
                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: true,
                message: "具有的行为能力",
                trigger: "blur"
              }]
            },
            {
              label: "功能障碍",
              prop: "dysfunction",
              type: 'select',
              multiple: true,
              dataType:'string',
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=dysfunction",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: true,
                message: "功能障碍 (可多选)",
                trigger: "blur"
              }]
            },
            {
              label: "血压",
              prop: "bloodPressure",
              rules: [{
                required: true,
                message: "请输入血压",
                trigger: "blur"
              }]
            },
            {
              label: "血氧",
              prop: "bloodOxygen",
              rules: [{
                required: true,
                message: "请输入血氧",
                trigger: "blur"
              }]
            },
            {
              label: "血糖",
              prop: "bloodSugar",
              rules: [{
                required: true,
                message: "请输入血糖",
                trigger: "blur"
              }]
            },
            {
              label: "服务需求",
              prop: "serviceDemand",
              type: 'select',
              multiple:true,
              dataType:'string',
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=service-demand",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: true,
                message: "服务需求 (可多选)",
                trigger: "blur"
              }]
            },
            {
              label: "紧急联系人",
              prop: "emergencyContactPerson",
              rules: [{
                required: true,
                message: "请输入紧急联系人",
                trigger: "blur"
              }]
            },
            {
              label: "联系人电话",
              prop: "emergencyContactPhone",
              hide: true,
              rules: [{
                required: true,
                message: "请输入紧急联系人电话",
                trigger: "blur"
              }]
            },
          ]
        },
      };
    },
    methods: {
      //提交
      addEntity(row,done){
        // console.log(this.parentId,'基本表Id');
        console.log(this.basicData.id,'对象Id');
        console.log(this.basicData,'基本信息');
        console.log(row,'row对象');
        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() {
        // getDetail(this.parentId).then(res=>{
        //   this.basicDataObject = res.data.data;
        // });
        // console.log(this.basicDataObject,'请求回的基本表信息');
        // this.basicDataObject.parentId = this.parentId;
        // let tags_temp = this.basicDataObject.tags;
        // console.log(this.basicDataObject.tags,'tags值');

        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>
