<template>
  <div class="dialog" v-if="dialogForm">
    <div class="head_box">
      <span class="title">人力情报信息采集流转详情</span>
      <div>
        <el-button @click="close">关闭</el-button>
      </div>
    </div>
    <div class="form_cnt">
      <FormMessage disabled v-model="listQuery" :formList="formData" ref="elform" :rules="rules">
        <template #gapdive>
          <div style="width: 100%;height: 10px;" class="mb20">
            <el-divider content-position="left">基础信息</el-divider>
          </div>
        </template>
        <template #gapline>
          <div style="width: 100%;height: 10px;" class="mb20">
            <el-divider content-position="left">情报内容</el-divider>
          </div>
        </template>
        <template #scfj>
          <div style="width: 100%;padding-left: 50px;">
            <div>上传附件:<span class="f12">（可附电子表格、Word文档、图像、音视频文件）</span> </div>
            <div><MOSTY.Upload :showBtn="true" :isAll="true" :isImg="true" disabled :limit="10" v-model="fjdz" /> </div>
          </div>
        </template>
      </FormMessage>
      <el-divider content-position="left"><span class="mr20">相关人员</span> </el-divider>
      <MyTable
        :tableData="pageForm.tableData"
        :tableColumn="pageForm.tableColumn"
        :tableHeight="pageForm.tableHeight"
        :key="pageForm.keyCount"
        :tableConfiger="pageForm.tableConfiger"
        :controlsWidth="pageForm.controlsWidth"
      >
      <template #xb="{row}">
        <DictTag :value="row.xb" :tag="false" :options="props.dic.D_BZ_XB" />
      </template>
      <template #bqList="{row}">
        <div v-if="row.bqList">
          <el-tag type="success" v-for="(it,idx) in row.bqList" :key="idx">{{ it.bqMc }}</el-tag >
        </div>
      </template>
        <!-- 操作 -->
        <template #controls="{ row,index }">
          <el-link size="small" type="success" @click="addEdit('detail', row,index)">详情</el-link>
        </template>
      </MyTable>
    </div>
    <!-- 人员 -->
    <AddPeo ref="showAdd" v-if="showPerson" v-model="showPerson" :dic="props.dic" ></AddPeo>
  </div>
</template>

<script setup>
import * as MOSTY from "@/components/MyComponents/index";
import AddPeo from '@/components/addPerson/index.vue'
import MyTable from "@/components/aboutTable/MyTable.vue";
import FormMessage from "@/components/aboutTable/FormMessage.vue";
import { qcckGet } from "@/api/qcckApi.js";
import { ref, defineExpose, reactive, onMounted, defineEmits, getCurrentInstance, nextTick } from "vue";
const emit = defineEmits(["change"]);
const props = defineProps({
  dic: Object
});
const { proxy } = getCurrentInstance();
const dialogForm = ref(false); //弹窗
const rules = reactive({
  xsMc: [{ required: true, message: "请输入情报名称", trigger: "blur" }],
  xlLx: [{ required: true, message: "请选择情报类型", trigger: "change" }],
  qbLy: [{ required: true, message: "请选择情报来源", trigger: "change" }],
});
const formData = ref([
  { prop: "gapdive", type: "slot",width:'100%' },
  { label: "情报名称", prop: "xsMc", type: "input" },
  { label: "情报类型", prop: "xlLx", type: "select", options:props.dic.D_GS_XS_LX },
  { label: "情报来源", prop: "qbLy", type: "select", options:props.dic.D_GS_XS_LY},
  { label: "情报上报时间", prop: "zxkssj", type: "datetime"},
  // { label: "指向结束时间", prop: "zxjssj", type: "datetime"},
  { label: "指向地点", prop: "zxdz", type: "input"},
  { label: "所属专题", prop: "sszt", type: "select",options:props.dic.D_BZ_SSZT},
  { prop: "gapline", type: "slot",width:'100%' },
  { prop: "scfj", type: "slot",width:'100%'},
  { label: "情报内容", prop: "xsNr", type: "textarea",width:'100%'},
  { label: "群体类型", prop: "qtlx", type: "select",options:props.dic.D_GS_XS_QTLX },
  { label: "群体名称", prop: "qtmc", type: "input"},
  { label: "涉及人数", prop: "sjrs", type: "inputNumber"},
  { label: "情报报送单位", prop: "ssbmdm", type: "department"},
]);
const fjdz = ref()
const listQuery = ref({}); //表单
const loading = ref(false);
const elform = ref();
const pageForm = reactive({
  tableData: [],
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "checkBox",
    loading: false
  },
  controlsWidth: 220,
  tableColumn: [
    { label: "姓名", prop: "xm" },
    { label: "性别", prop: "xb",showSolt:true },
    { label: "身份证号", prop: "sfzh" },
    { label: "户籍地", prop: "hjdz" },
    { label: "户籍地派出所", prop: "hjdpcs" },
    { label: "标签", prop: "bqList",showSolt:true }
  ]
});
const showAdd = ref()
const showPerson = ref(false)
onMounted(()=>{
  tabHeightFn()
})


// 初始化数据
const init = (type, row) => {
  fjdz.value = []
  tabHeightFn()
  dialogForm.value = true;
  // 初始化表单数据，并根据详情页设置禁用状态
  if (row) getDataById(row.id);
};
// 根据id查询详情
const getDataById = (id) => {
  qcckGet({id}, "/mosty-gsxt/qbcj/selectByid").then((res) => {
    fjdz.value = res.ossList || [];
    listQuery.value = res;
    pageForm.tableData = res.ryList || [];
  });
};

// 打开弹窗
const addEdit = (type,row,index) =>{
  showPerson.value = true;
  nextTick(()=>{
    showAdd.value.init(type,row,index)
  })
}

// 关闭
const close = () => {
  fjdz.value = []
  listQuery.value = {};
  dialogForm.value = false;
  loading.value = false;
};

// 表格高度计算
const tabHeightFn = () => {
  pageForm.tableHeight = window.innerHeight  - 720;
  window.onresize = function () {
    tabHeightFn();
  };
};

defineExpose({ init });
</script>

<style lang="scss" scoped>
@import "~@/assets/css/layout.scss";
@import "~@/assets/css/element-plus.scss";
::v-deep .el-tabs--card > .el-tabs__header .el-tabs__item.is-active {
  color: #0072ff;
  background: rgba(0, 114, 255, 0.3);
}
.boxlist {
  width: 99%;
  height: 225px;
  margin-top: 10px;
  overflow: hidden;
}

::v-deep .avatar-uploader{
  display: flex;
  align-items: center;
}

::v-deep .el-upload-list{
  margin-left: 20px;
  display: flex;
  align-items: center;
}
::v-deep .el-upload-list__item-name .el-icon{
  top: 3px;
}
</style>
