<template>
  <Card simple class="jyh-card mt-3">
    <div class="card-title">组织预警通知列表</div>
    <div class="mb-3">
      <d-table v-if="tableData.length>0" class="jyh-table jyh-table-2" :header-bg="true" :data="tableData">
        <d-column field="updateTime" header="时间">
          <template #default="scope">
            <span>{{ formatTime(scope.row.updateTime, 'YYYY-MM-DD') }}</span>
          </template>
        </d-column>
        <d-column field="name" header="标题">
          <template #default="scope">
            <a @click="openWarningDetail(scope.row)">{{ scope.row.name }}</a>
          </template>
        </d-column>
        <d-column field="alertMsg" header="详情">
          <template #default="scope">
            <span>{{ JSON.parse(scope.row.alertMsg)?.overview || ''}}</span>
          </template>
        </d-column>
        <d-column field="level" header="级别">
          <template #default="scope">
            <d-status v-if="JSON.parse(scope.row.alertMsg)?.importance === '高'" type="error">
              {{ JSON.parse(scope.row.alertMsg)?.importance || ''}}
            </d-status>
            <d-status v-if="JSON.parse(scope.row.alertMsg)?.importance === '中'" type="warning">
              {{ JSON.parse(scope.row.alertMsg)?.importance || ''}}
            </d-status>
            <d-status v-if="JSON.parse(scope.row.alertMsg)?.importance === '低'" class="yellow-status">
              {{ JSON.parse(scope.row.alertMsg)?.importance || ''}}
            </d-status>
            <!--            <d-status v-if="scope.row.importance === 1" type="running">提示</d-status>-->
          </template>
        </d-column>
        <d-column field="status" header="状态">
          <template #default="scope, text">
            <d-tag v-if="scope.row.status === 1" type="danger" size="sm">未读</d-tag>
            <d-tag v-if="scope.row.status === 2" type="success" size="sm">已读</d-tag>
          </template>
        </d-column>
      </d-table>
      <NoData v-else :small="false"></NoData>
    </div>


    <div class="mt-20 mb-20 flex justify-end">
      <d-pagination size="md" :page-size-options="[10, 20, 50]" :total="pager.total"
                    v-model:pageSize="pager.pageSize" v-model:pageIndex="pager.pageIndex" :max-items="5"
                    :can-change-page-size="true" :can-view-total="true" total-item-text="总计" @page-index-change="changeIndex()"
                    @page-size-change="changeSize()" />
    </div>

  </Card>

  <d-modal class="warning-modal" v-model="warningModalVisable" title="">
    <EarlyWarningDetail @close="colseWarningDetail" :warningData="currentWarning" type="user"></EarlyWarningDetail>
  </d-modal>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue';
import EarlyWarningDetail from '@/views/Jyh/PersonalCenter/Detail/EarlyWarningDetail.vue';
import NoData from "@/components/NoData/NoData.vue";
import { getgroupNoticeList, getNoticeList } from '@/api/jyh';

const tableData = ref([
  // { code: '05822156', name: 'MIT License', detail: 'integer', level: 4, status: 1 },
  // { code: '05822156', name: 'MIT License', detail: 'integer', level: 3, status: 2 },
  // { code: '05822156', name: 'MIT License', detail: 'integer', level: 2, status: 1 },
  // { code: '05822156', name: 'MIT License', detail: 'integer', level: 1, status: 2 }
]);
const pager = ref({
  total: 0,
  pageIndex: 1,
  pageSize: 10
});
const warningModalVisable = ref(false);
const currentWarning = ref();
const openWarningDetail = (row) => {
  warningModalVisable.value = true;
  currentWarning.value = row;
};
const colseWarningDetail = () => {
  warningModalVisable.value = false;
};

const getList = async() => {
  const { data, error } = await getgroupNoticeList({  current: 1,size: pager.value.pageSize  });
  if (!error && data) {
    tableData.value = data.data.data.records;
    pager.value.total = data.data.data.total;
  }
};

onMounted(async() => {
  getList();
});


</script>

<style scoped lang="scss">
@import 'devui-theme/styles-var/devui-var.scss';
</style>
