<template>
  <basic-container>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="基础信息" name="first"></el-tab-pane>
      <el-tab-pane label="吸毒人员信息" name="second"></el-tab-pane>
    </el-tabs>
    <avue-form v-show="activeName=='first'" :option="optionBasic" v-model="formBasic"></avue-form>
    <avue-form v-show="activeName=='second'" :option="optionDrug" v-model="formDrug" @submit="addEntity"></avue-form>
  </basic-container>
</template>

<script>
  import {DIC} from "@/api/util/nation"
  import {add,update,getDetail,getList} from "@/api/person/basicinfo";
  import {update as drugUpdate,addDrug} from "@/api/person/drug";
  export default {
    name: "drug-form",
    props:{
      closeFn:{type:Function},
      tag:{type:Number},
      formBasic:{type:Object},
      formDrug:{type:Object},
    },
    data(){
      return{
        activeName:'first',
        formBasic:{},
        formDrug:{},
        loading:false,
        query: {},
        optionBasic:{
          tip: false,
          submitBtn:false,
          emptyBtn:false,
          column:[
            {
              label: "身份证号",
              prop: "idCard",
              search:true,
              hide: true,
              rules: [{
                required: false,
                message: "请输入身份证号码",
                trigger: "blur"
              }]
            },
            {
              label: "姓名",
              prop: "name",
              search:true,
              rules: [{
                required: true,
                message: "请输入姓名",
                trigger: "blur"
              }]
            },
            {
              label: "性别",
              prop: "sex",
              type: 'select',
              dataType:"number",
              search:true,
              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: "请选择楼栋",
                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: "请选择单元",
                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: "请选择楼层d",
                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: "请选择房间",
                trigger: "blur"
              }]
            },
            {
              label:'手机号码',
              prop:'phone',
              width:120,
              rules: [{
                required: true,
                message: "请输入手机号码",
                trigger: "blur"
              }]
            },
            {
              label: "邮箱",
              prop: "email",
              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",
              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",
              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: "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: "remark",
              type:'textarea',
              hide:true,
              rules: [{
                required: false,
                message: "请输入备注",
                trigger: "blur"
              }]
            },
          ]
        },
        optionDrug:{
          emptyBtn:false,
          submitText:"提交",
          column: [
            {
              label: "基本表ID",
              prop: "parentId",
              hide:true,
              display:false,
              rules: [{
                required: true,
                message: "请输入基本表ID",
                trigger: "blur"
              }]
            },
            {
              label: "姓名",
              prop: "name",
              search:true,
              rules: [{
                required: true,
                message: "请输入姓名",
                trigger: "blur"
              }]
            },
            {
              label: "吸毒原因",
              prop: "reason",
              type: "select",
              dataType:'string',
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=drug_reason",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: false,
                message: "请输入吸毒原因",
                trigger: "blur"
              }]
            },
            {
              label: "毒品来源",
              prop: "source",
              hide:true,
              rules: [{
                required: false,
                message: "请输入毒品来源",
                trigger: "blur"
              }]
            },
            {
              label: "戒毒情况",
              prop: "detoxification",
              hide:true,
              type: "select",
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=detoxification",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: false,
                message: "请输入戒毒情况",
                trigger: "blur"
              }]
            },
            {
              label: "关注程度",
              prop: "attention",
              hide:true,
              type: "select",
              dataType: 'number',
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=drug_attention",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: false,
                message: "请输入关注程度",
                trigger: "blur"
              }]
            },
            {
              label: "吸毒状态",
              prop: "drugStatus",
              type: "select",
              datatype:'number',
              dicData:[
                {
                  label:'在吸',
                  value:0
                },{
                  label:'停吸',
                  value: 1
                }
              ],
              rules: [{
                required: true,
                message: "请输入吸毒状态",
                trigger: "blur"
              }]
            },
            {
              label: "吸毒人员类型",
              prop: "type",
              hide:true,
              type: "select",
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=drug_type",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: false,
                message: "请输入吸毒人员类型",
                trigger: "blur"
              }]
            },
            {
              label: "吸毒后果",
              prop: "consequence",
              type: "select",
              hide:true,
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=drug_consequence",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: true,
                message: "请输入吸毒后果",
                trigger: "blur"
              }]
            },
            {
              label: "滥用毒品种类",
              prop: "species",
              type: "select",
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=drug_species",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: true,
                message: "请输入滥用毒品种类",
                trigger: "blur"
              }]
            },
            {
              label: "管控情况",
              prop: "controlSituation",
              type: "select",
              hide:true,
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=drug_controlSituation",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: false,
                message: "请输入管控情况",
                trigger: "blur"
              }]
            },
            {
              label: "管控人姓名",
              prop: "controllerName",
              hide:true,
              rules: [{
                required: false,
                message: "请输入管控人姓名",
                trigger: "blur"
              }]
            },
            {
              label: "管控人联系方式",
              prop: "controllerPhone",
              hide:true,
              rules: [{
                required: false,
                message: "请输入管控人联系方式",
                trigger: "blur"
              }]
            },
            {
              label: "帮扶情况",
              prop: "helpSituation",
              hide:true,
              rules: [{
                required: false,
                message: "请输入帮扶情况",
                trigger: "blur"
              }]
            },
            {
              label: "帮扶人姓名",
              prop: "helperName",
              hide:true,
              rules: [{
                required: false,
                message: "请输入帮夫人姓名",
                trigger: "blur"
              }]
            },
            {
              label: "帮扶人联系方式",
              prop: "helperPhone",
              hide:true,
              rules: [{
                required: false,
                message: "请输入帮扶人联系方式",
                trigger: "blur"
              }]
            },
            {
              label: "是否服用美沙酮戒毒",
              prop: "methadone",
              type: "select",
              hide:true,
              dataType:'number',
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=yes_no",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: true,
                message: "请输入是否服用美沙酮戒毒",
                trigger: "blur"
              }]
            },
            {
              label: "查获日期",
              prop: "date",
              type:'date',
              valueFormat:"yyyy-MM-dd",
              hide:true,
              rules: [{
                required: false,
                message: "请输入查获日期",
                trigger: "blur"
              }]
            },
            {
              label: "初次发现日期",
              prop: "findDate",
              type:'date',
              valueFormat:"yyyy-MM-dd",
              hide:true,
              rules: [{
                required: false,
                message: "请输入初次发现日期",
                trigger: "blur"
              }]
            },
            {
              label: "是否有犯罪史",
              prop: "criminalHistory",
              type: "select",
              dataType:'number',
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=yes_no",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: true,
                message: "请输入是否有犯罪史",
                trigger: "blur"
              }]
            },
            {
              label: "犯罪情况",
              prop: "crime",
              hide:true,
              rules: [{
                required: false,
                message: "请输入犯罪情况",
                trigger: "blur"
              }]
            },
            {
              label: "行动趋向",
              prop: "action",
              hide:true,
              type:'textarea',
              rules: [{
                required: false,
                message: "请输入行动趋向",
                trigger: "blur"
              }]
            },
            {
              label: "生活状况",
              prop: "living",
              rules: [{
                required: false,
                message: "请输入生活状况",
                trigger: "blur"
              }]
            },
            {
              label: "社会关系",
              prop: "relationship",
              hide:true,
              rules: [{
                required: false,
                message: "请输入社会关系",
                trigger: "blur"
              }]
            },
            {
              label: "现实表现",
              prop: "performance",
              type:'textarea',
              hide:true,
              rules: [{
                required: false,
                message: "请输入现实表现",
                trigger: "blur"
              }]
            },
          ]
        },
      }
    },
    methods:{
      addEntity(){
        //新增
        if (this.tag==1){
          var ObjectList = new Array();
          ObjectList.push(this.formDrug);
          ObjectList.push(this.formBasic);
          addDrug(ObjectList).then(()=>{
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$emit('refreshChange');
            this.closeFn();
          }, error => {
            // loading();
            window.console.log(error);
          });
        }else {
          //修改基本信息
          update(this.formBasic).then(() => {}, error => {
            window.console.log(error);
          });
          //修改吸毒人员信息
          drugUpdate(this.formDrug).then(() => {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$emit('refreshChange');
            this.closeFn();
          }, error => {
            window.console.log(error);
          });
        }
      },
      handleClick(tab, event){
        console.log(tab,event)
      },
    }
  }
</script>

<style scoped>

</style>
