<template>
  <el-card class="hl-card">
    <template #header>
      <span>待办关注配置</span>
    </template>
    <ContentWrap class="borderxx">
      <!-- 搜索工作栏 -->
      <el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true" label-width="88px">
        <!-- <el-form-item label="序号" prop="serialnumber">
        <el-input v-model="queryParams.serialnumber" placeholder="请输入序号" clearable @keyup.enter="handleQuery"
          class="!w-240px" />
      </el-form-item> -->
        <el-form-item label="事项" prop="event">
          <el-input v-model="queryParams.event" placeholder="请输入事项" clearable @keyup.enter="handleQuery"
            class="!w-200px" />
        </el-form-item>
        <el-form-item label="事项说明" prop="eventdescription" class="!w-240px">
          <el-input v-model="queryParams.eventdescription" placeholder="请输入事项说明" clearable @keyup.enter="handleQuery"
            class="!w-280px" />
        </el-form-item>

        <!-- <el-form-item label="类型" prop="type">
        <el-input v-model="queryParams.type" placeholder="请输入类型" clearable @keyup.enter="handleQuery"
          class="!w-240px" />
      </el-form-item>
      <el-form-item label="级别" prop="level">
        <el-select v-model="queryParams.level" placeholder="请选择级别" clearable class="!w-240px">
          <el-option v-for="dict in getStrDictOptions(DICT_TYPE.DB_LEVEL)" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="提醒周期（天）" prop="remindtime">
        <el-input v-model="queryParams.remindtime" placeholder="请输入提醒周期（天）" clearable @keyup.enter="handleQuery"
          class="!w-240px" />
      </el-form-item>
      <el-form-item label="提醒人" prop="remindman">
        <el-input v-model="queryParams.remindman" placeholder="请输入提醒人" clearable @keyup.enter="handleQuery"
          class="!w-240px" />
      </el-form-item>
      <el-form-item label="添加人" prop="addid">
        <el-input v-model="queryParams.addid" placeholder="请输入添加人" clearable @keyup.enter="handleQuery"
          class="!w-240px" />
      </el-form-item>
      <el-form-item label="添加时间" prop="addtime">
        <el-date-picker v-model="queryParams.addtime" value-format="YYYY-MM-DD HH:mm:ss" type="daterange"
          start-placeholder="开始日期" end-placeholder="结束日期"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" class="!w-240px" />
      </el-form-item>
      <el-form-item label="修改人" prop="reviseman">
        <el-input v-model="queryParams.reviseman" placeholder="请输入修改人" clearable @keyup.enter="handleQuery"
          class="!w-240px" />
      </el-form-item>
      <el-form-item label="修改时间" prop="revisetime">
        <el-date-picker v-model="queryParams.revisetime" value-format="YYYY-MM-DD HH:mm:ss" type="daterange"
          start-placeholder="开始日期" end-placeholder="结束日期"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" class="!w-240px" />
      </el-form-item>
      <el-form-item label="备用1" prop="attr1">
        <el-input v-model="queryParams.attr1" placeholder="请输入备用1" clearable @keyup.enter="handleQuery"
          class="!w-240px" />
      </el-form-item>
      <el-form-item label="备用2" prop="attr2">
        <el-input v-model="queryParams.attr2" placeholder="请输入备用2" clearable @keyup.enter="handleQuery"
          class="!w-240px" />
      </el-form-item>
      <el-form-item label="备用3" prop="attr3">
        <el-input v-model="queryParams.attr3" placeholder="请输入备用3" clearable @keyup.enter="handleQuery"
          class="!w-240px" />
      </el-form-item>
      <el-form-item label="备用4" prop="attr4">
        <el-input v-model="queryParams.attr4" placeholder="请输入备用4" clearable @keyup.enter="handleQuery"
          class="!w-240px" />
      </el-form-item>
      <el-form-item label="备用5" prop="attr5">
        <el-input v-model="queryParams.attr5" placeholder="请输入备用5" clearable @keyup.enter="handleQuery"
          class="!w-240px" />
      </el-form-item>
      <el-form-item label="备用6" prop="attr6">
        <el-input v-model="queryParams.attr6" placeholder="请输入备用6" clearable @keyup.enter="handleQuery"
          class="!w-240px" />
      </el-form-item>
      <el-form-item label="备用7" prop="attr7">
        <el-input v-model="queryParams.attr7" placeholder="请输入备用7" clearable @keyup.enter="handleQuery"
          class="!w-240px" />
      </el-form-item>
      <el-form-item label="备用8" prop="attr8">
        <el-date-picker v-model="queryParams.attr8" value-format="YYYY-MM-DD" type="date" placeholder="选择备用8" clearable
          class="!w-240px" />
      </el-form-item>
      <el-form-item label="备用9" prop="attr9">
        <el-date-picker v-model="queryParams.attr9" value-format="YYYY-MM-DD" type="date" placeholder="选择备用9" clearable
          class="!w-240px" />
      </el-form-item>
      <el-form-item label="备用10" prop="attr10">
        <el-date-picker v-model="queryParams.attr10" value-format="YYYY-MM-DD" type="date" placeholder="选择备用10"
          clearable class="!w-240px" />
      </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="handleQuery">
            <Icon icon="ep:search" class="mr-5px" /> 搜索
          </el-button>
          <el-button @click="resetQuery">
            <Icon icon="ep:refresh" class="mr-5px" /> 重置
          </el-button>
          <!-- <el-button type="primary" plain @click="openForm('create')" v-hasPermi="['heli:attentiontodo:create']">
            <Icon icon="ep:plus" class="mr-5px" /> 新增
          </el-button> -->
          <!-- <el-button type="success" plain @click="handleExport" :loading="exportLoading"
          v-hasPermi="['heli:attentiontodo:export']">
          <Icon icon="ep:download" class="mr-5px" /> 导出
        </el-button> -->
        </el-form-item>
      </el-form>
    </ContentWrap>

    <!-- 列表 -->
    <ContentWrap>
      <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
        <!-- <el-table-column label="id" align="center" prop="id" /> -->
        <!-- <el-table-column label="序号" align="center" prop="serialnumber" /> -->
        <el-table-column fixed type="index" width="100" label="序号" align="center" />
        <el-table-column label="事项" align="center" prop="event" />
        <el-table-column label="事项说明" min-width="150" align="center" prop="eventdescription" />
        <el-table-column label="类型" align="center" prop="type">
          <template #default="scope">
            <dict-tag v-for="item in scope.row.type"
			:key="item"
			:type="DICT_TYPE.DB_TYPE"
			 :value="item" />
          </template>
        </el-table-column>
        <el-table-column label="级别" align="center" prop="level">
          <template #default="scope">
            <dict-tag :type="DICT_TYPE.DB_LEVEL" :value="scope.row.level" />
          </template>
        </el-table-column>
        <el-table-column label="提醒周期（天）" min-width="160" align="center" prop="remindtime" />
        <el-table-column label="提醒人" align="center" prop="remindman" />



        <!-- <el-table-column label="添加人" align="center" prop="addid" /> -->
        <!-- <el-table-column label="添加时间" align="center" prop="addtime" :formatter="dateFormatter" width="180px" /> -->
        <!-- <el-table-column label="修改人" align="center" prop="reviseman" /> -->
        <!-- <el-table-column label="修改时间" align="center" prop="revisetime" :formatter="dateFormatter" width="180px" /> -->
        <!-- <el-table-column label="备用1" align="center" prop="attr1" /> -->
        <!-- <el-table-column label="备用2" align="center" prop="attr2" /> -->
        <!-- <el-table-column label="备用3" align="center" prop="attr3" /> -->
        <!-- <el-table-column label="备用4" align="center" prop="attr4" /> -->
        <!-- <el-table-column label="备用5" align="center" prop="attr5" /> -->
        <!-- <el-table-column label="备用6" align="center" prop="attr6" /> -->
        <!-- <el-table-column label="备用7" align="center" prop="attr7" /> -->
        <!-- <el-table-column label="备用8" align="center" prop="attr8" :formatter="dateFormatter" width="180px" /> -->
        <!-- <el-table-column label="备用9" align="center" prop="attr9" :formatter="dateFormatter" width="180px" /> -->
        <!-- <el-table-column label="备用10" align="center" prop="attr10" :formatter="dateFormatter" width="180px" /> -->
        <el-table-column label="操作" fixed="right" align="center">
          <template #default="scope">
            <el-button link type="primary" @click="openForm('update', scope.row.id)"
              v-hasPermi="['heli:attentiontodo:update']">
              编辑
            </el-button>
            <!-- <el-button link type="danger" @click="handleDelete(scope.row.id)"
              v-hasPermi="['heli:attentiontodo:delete']">
              删除
            </el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <Pagination :total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize"
        @pagination="getList" />
    </ContentWrap>
  </el-card>
  <!-- 表单弹窗：添加/修改 -->
  <AttentiontodoForm ref="formRef" @success="getList" />
</template>

<script setup lang="ts">
import { getStrDictOptions, DICT_TYPE } from '@/utils/dict'
// import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import * as AttentiontodoApi from '@/api/heli/attentiontodo'
import AttentiontodoForm from './AttentiontodoForm.vue'

defineOptions({ name: 'AttentiontodoForm' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const list = ref([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  serialnumber: undefined,
  event: undefined,
  eventdescription: undefined,
  type: undefined,
  level: undefined,
  remindtime: undefined,
  remindman: undefined,
  addid: undefined,
  addtime: [],
  reviseman: undefined,
  revisetime: [],
  attr1: undefined,
  attr2: undefined,
  attr3: undefined,
  attr4: undefined,
  attr5: undefined,
  attr6: undefined,
  attr7: undefined,
  attr8: undefined,
  attr8: [],
  attr9: undefined,
  attr9: [],
  attr10: undefined,
  attr10: [],
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await AttentiontodoApi.getAttentiontodoPage(queryParams)
    list.value = data.list
	 list.value.forEach(item => {
		 if(item.type){
			 if (item.type.includes(',')) {
			         item.type = item.type.split(',');
			       }
		 }

	    });
    total.value = data.total


  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
  formRef.value.open(type, id)
}

/** 删除按钮操作 */
const handleDelete = async (id: number) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await AttentiontodoApi.deleteAttentiontodo(id)
    message.success(t('common.delSuccess'))
    // 刷新列表
    await getList()
  } catch { }
}

/** 导出按钮操作 */
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await AttentiontodoApi.exportAttentiontodo(queryParams)
    download.excel(data, '待办关注.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
