<template>
  <div>
    <div class="headClass" style="">
      <h3>群体成员</h3>
      <el-button type="primary"  :disabled="disabled"  @click="openDialog">选择</el-button>
    </div>
    <MyTable :tableData="pageData.tableData" :tableColumn="pageData.tableColumn" :tableHeight="pageData.tableHeight"
      :key="pageData.keyCount" :tableConfiger="pageData.tableConfiger" :controlsWidth="pageData.controlsWidth">
      <template #ryzp="{ row }">
        <el-image style="width: 100px; height: 100px" :src="`/mosty-base/minio/file/download/${row.ryzp}`"
          fit="cover" />
      </template>
      <template #zdrYjdj="{ row }">
        <DictTag :tag="false" :value="row.zdrYjdj" :options="D_GS_ZDR_YJDJ" />
      </template>
      <template #zdrZt="{ row }">
        <DictTag :tag="false" :value="row.zdrZt" :options="D_GS_ZDR_CZZT" />
      </template>
      <!-- 操作 -->
      <template #controls="{ row }">
        <el-link type="danger" @click="delDictItem(row.id)">删除</el-link>
      </template>
    </MyTable>
  </div>
  <GroupStaff v-model="showDialog" @choosed="addMarks" :roleIds="roleIds" />
</template>

<script setup>
import { ref, reactive, getCurrentInstance, watch } from "vue";
import MyTable from "@/components/aboutTable/MyTable.vue";
import GroupStaff from '../component/groupStaff.vue'
import { tbGsxtZdqtUpdate } from '@/api/qt.js'
import { ElMessageBox } from "element-plus";
const { proxy } = getCurrentInstance();
const { D_GS_ZDR_YJDJ, D_GS_ZDR_CZZT } = proxy.$dict("D_GS_ZDR_YJDJ", "D_GS_ZDR_CZZT");
const props = defineProps({
  dataList: {
    type: Object,
    default: () => { },
  }, disabled: {
    type: Boolean,
    default: false
  },
  showBut: {
    type: Boolean,
    default: false
  },
})
const pageData = reactive({
  tableData: [],
  tableColumn: [{
    prop: 'ryzp',
    label: '照片',
    showSolt: true,
  }, {
    prop: 'ryXm',
    label: '姓名',
  }, {
    prop: 'rySfzh',
    label: '身份证号',
  }, {
    prop: 'ywlb',
    label: '业务类别',
  }, {
    prop: 'zdrYjdj',
    label: '管控级别',
    showSolt: true,
  }, {
    prop: 'zdrZt',
    label: '布控情况',
    showSolt: true,
  }],
  tableHeight: '400px',
  keyCount: 0,
  tableConfiger: {
    border: true,
    stripe: true,
    showHeader: true,
    showIndex: true,
    indexLabel: '序号',
    indexWidth: 60,
    align: 'center',
    showOverflowTooltip: true,
  },
  controlsWidth: 120,

})
const listData = ref({})
const showDialog = ref(false)
const roleIds = ref([])
watch(() => props.dataList, (val) => {
  if (val) {
    listData.value = val
    pageData.tableData = val.zdryList
  }
}, { deep: true })
const openDialog = () => {
  showDialog.value = true
}
const addMarks = (val) => {
  pageData.tableData = val
  roleIds.value = val.map(item => item.id)
  if (!props.disabled && props.showBut) {
    gettbGsxtZdqtUpdate(pageData.tableData)
  }
}
// 删除
const delDictItem = (val) => {
  if (!props.disabled && props.showBut) {
    ElMessageBox.confirm(
      '是否删除性质标签',
      '提示',
      {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      }
    )
      .then(() => {
        if (!props.disabled && props.showBut) {
          gettbGsxtZdqtUpdate(pageData.tableData)
          pageData.tableData = pageData.tableData.filter(item => item.id != val)
          roleIds.value = roleIds.value.filter(item => item != val)
        }
      })
      .catch(() => {
        proxy.$message({
          message: '删除失败',
          type: 'info',
        })
      })

  } else {
    pageData.tableData = pageData.tableData.filter(item => item.id != val)
    roleIds.value = roleIds.value.filter(item => item != val)
  }
}
// 修改
const gettbGsxtZdqtUpdate = (val) => {
  const promes = {
    id: listData.value.id,
    zdryList: val
  }
  tbGsxtZdqtUpdate(promes).then((res) => {
    proxy.$message({
      message: '更新成功',
      type: 'success',
    })
  }).catch((err) => {

  });
}
const throwData = () => {
  return pageData.tableData
}
defineExpose({
  throwData
})
</script>

<style lang="scss" scoped>
@import "~@/assets/css/layout.scss";
@import "~@/assets/css/element-plus.scss";

.backinfo-container {
  padding: 10px;
}

.left_box {
  width: 200px;
  border: 1px solid #c8c8c89a;
  border-radius: 5px;
  padding: 5px;
}

.right_box {
  width: calc(100% - 230px);
  overflow-y: auto;
  padding: 5px;
}

::v-deep .el-form-item__content {
  display: block !important;
}

.headClass {
  font-size: 18px;
  font-weight: 600;
  color: #303133;
  margin: 0 0 10px 0;
  padding-bottom: 10px;
  border-bottom: 2px solid #409eff;
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.headClass::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: -2px;
  width: 60px;
  height: 2px;
  background-color: #409eff;
}

h3 {
  margin: 0;
}
</style>
