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

<script>
  import {add as addDisabler} from "@/api/person/disabler";
  import {update,add} from "@/api/person/basicinfo";
  import {validatePhone} from "../../util/validator";
    export default {
      name: "basicinfo-add",
      data() {
        return {
          basicData: {},
          form: {},
          selectionList: [],
          option: {
            height:'auto',
            calcHeight: 30,
            labelWidth: 120,
            tip: false,
            searchShow: true,
            searchMenuSpan: 6,
            border: true,
            index: true,
            viewBtn: true,
            selection: true,
            dialogClickModal: false,
            menuWidth:500,
            column: [
              {
                label: "姓名",
                prop: "name",
                search:true,
                rules: [{
                  required: true,
                  message: "请输入姓名",
                  trigger: "blur"
                }]
              },
              {
                label: "照片",
                prop: "imageUri",
                type: 'upload',
                hide:true,
                listType: 'picture-img',
                propsHttp: {
                  res: "data",
                  url: "link"
                },
                action: "/api/blade-resource/oss/endpoint/put-file",
                tip: '只能生产jpg/png图片，且不超过500kb',
                rules: [{
                  required: false,
                  message: "请输入入境证明url",
                  trigger: "blur"
                }]
              },
              {
                label: "性别",
                prop: "sex",
                type: 'select',
                dataType:"number",
                dicUrl: "/api/blade-system/dict-biz/dictionary?code=sex",
                props: {
                  label: "dictValue",
                  value: "dictKey"
                },
                rules: [{
                  required: true,
                  message: "请选择性别",
                  trigger: "blur"
                }]
              },
              {
                label: "所属社区",
                prop: "agencyId",
                search: true,
                cascaderItem: ['residentialId'],
                type: "select",
                // remote: true,
                dicUrl: "/api/cyzh-community/agency/list?size=9999",
                dicFormatter:(res)=>{
                  return res.data.records;//返回字典的层级结构
                },
                props: {
                  label: "name",
                  value: "id"
                },
                rules: [{
                  required: true,
                  message: "请选择所属社区",
                  trigger: "blur"
                }]
              },
              {
                label: "所属小区",
                prop: "residentialId",
                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",
                type: "select",
                // slot:true,
                search: true,
                cascaderItem: ['unitId'],
                dicUrl: "/api/cyzh-community/building/list?residentialId={{key}}",
                dicFormatter:(res)=>{
                  return res.data.records;//返回字典的层级结构
                },
                // dicFlag: true,
                // filterable: true,
                props: {
                  label: "name",
                  value: "id"
                },
                rules: [{
                  required: true,
                  message: "请输入楼栋Id",
                  trigger: "blur"
                }]
              },
              {
                label: "所属单元",
                prop: "unitId",
                type: "select",
                // slot:true,
                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",
                type: "select",
                // slot:true,
                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",
                type: "select",
                // slot:true,
                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:'phone',
                width:120,
                rules: [{
                  required: true,
                  message: "请输入手机号码",
                  trigger: "blur"
                },{
                  validator: validatePhone,
                  trigger: "blur"
                }]
              },
              {
                label: "身份证号码",
                prop: "idCard",
                hide: true,
                rules: [{
                  required: false,
                  message: "请输入身份证号码",
                  trigger: "blur"
                }]
              },
              {
                label: "生日",
                prop: "birthday",
                type:'date',
                valueFormat:"yyyy-MM-dd",
                hide: true,
                rules: [{
                  required: false,
                  message: "请输入生日",
                  trigger: "blur"
                }]
              },
              // {
              //   label: "民族",
              //   prop: "nation",
              //   hide:true,
              //   rules: [{
              //     required: true,
              //     message: "请输入民族",
              //     trigger: "blur"
              //   }]
              // },
              {
                label: "民族",
                prop: "nation",
                type:'select',
                dicData:DIC.VALUE,
                filterable:true,
                // searchFilterable:true,
                hide:true,
                rules: [{
                  required: true,
                  message: "请输入民族",
                  trigger: "blur"
                }]
              },
              {
                label: "籍贯",
                prop: "nativePlace",
                hide:true,
                rules: [{
                  required: false,
                  message: "请输入籍贯",
                  trigger: "blur"
                }]
              },
              {
                label: "国籍",
                prop: "nationality",
                hide:true,
                type:'select',
                dataType:'number',
                dicUrl: "/api/blade-system/dict-biz/dictionary?code=nationality",
                props: {
                  label: "dictValue",
                  value: "dictKey"
                },
                rules: [{
                  required: false,
                  message: "请输入国籍",
                  trigger: "blur"
                }]
              },
              {
                label: "政治面貌",
                prop: "political",
                hide:true,
                type: 'select',
                dataType:"number",
                dicUrl: "/api/blade-system/dict-biz/dictionary?code=political",
                props: {
                  label: "dictValue",
                  value: "dictKey"
                },
                rules: [{
                  required: false,
                  message: "请输入政治面貌",
                  trigger: "blur"
                }]
              },
              {
                label: "婚姻状况",
                prop: "maritalStatus",
                type: 'select',
                dataType:"number",
                hide:true,
                dicUrl: "/api/blade-system/dict-biz/dictionary?code=marital-status",
                props: {
                  label: "dictValue",
                  value: "dictKey"
                },
                rules: [{
                  required: false,
                  message: "请选择婚姻状况",
                  trigger: "blur"
                }]
              },
              {
                label: "教育水平",
                prop: "educationalLevel",
                hide:true,
                type: 'select',
                dataType:"number",
                dicUrl: "/api/blade-system/dict-biz/dictionary?code=educational-level",
                props: {
                  label: "dictValue",
                  value: "dictKey"
                },
                rules: [{
                  required: false,
                  message: "请选择教育水平",
                  trigger: "blur"
                }]
              },
              {
                label: "工作单位",
                prop: "workplace",
                rules: [{
                  required: false,
                  message: "请输入工作单位",
                  trigger: "blur"
                }]
              },
              {
                label: "小程序openId",
                prop: "openId",
                hide: true,
                display: false,
                rules: [{
                  required: false,
                  message: "请输入小程序openId",
                  trigger: "blur"
                }]
              },
              {
                label: "邮箱",
                prop: "email",
                hide:true,
                rules: [{
                  required: false,
                  message: "请输入邮箱",
                  trigger: "blur"
                }]
              },
              {
                label:"是否会员",
                prop:'isMember',
                type:"select",
                hide:true,
                dataType:'number',
                dicData:[
                  {
                    label:'是',
                    value:1
                  },{
                    label:'否',
                    value:0
                  },{
                    label:'暂无',
                    value:-1
                  }
                ],
              },
              {
                label: "人员标签",
                prop: "tags",
                type:'select',
                width:150,
                display:false,
                multiple:true,
                slot:true,
                dataType:'string',
                dicUrl: "/api/blade-system/dict-biz/dictionary?code=person-tag",
                props: {
                  label: "dictValue",
                  value: "dictKey"
                },
                rules: [{
                  required: false,
                  message: "请输入标签",
                  trigger: "blur"
                }]
              },
              {
                label: "备注",
                prop: "remark",
                hide:true,
                rules: [{
                  required: false,
                  message: "请输入备注",
                  trigger: "blur"
                }]
              },
            ]
          },
          data: []
        };
      },
      watch:{

      },

      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);
          });
        },
      }
    }
</script>

<style scoped>

</style>
