<!--
 * @Description: 考核填报-待填报列表页面
 * @Author: 李亚光
 * @Date: 2023-09-14
 -->
<script lang="ts" setup name="FillingTreatList">
import { reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
const { proxy } = getCurrentInstance() as any
const listQuery = reactive({
  offset: 1,
  limit: 20,
})
const columns = ref([
  {
    text: '考核结果编号',
    value: 'groupName',
    align: 'center',
  },
  {
    text: '考核方案名称',
    value: 'createUserName',
    align: 'center',
  },
  {
    text: '考核对象',
    value: 'createTime',
    align: 'center',
  },
  {
    text: '考核周期',
    value: 'remark',
    align: 'center',
  },
  {
    text: '考核时间',
    value: 'remark',
    align: 'center',
  },
  {
    text: '考核指标项目',
    value: 'remark',
    align: 'center',
  },
  {
    text: '考核指标类型',
    value: 'remark',
    align: 'center',
  },
  {
    text: '一级考核指标',
    value: 'remark',
    align: 'center',
  },
  {
    text: '考核指标得分',
    value: 'remark',
    align: 'center',
  },
  {
    text: '考核说明',
    value: 'remark',
    align: 'center',
  },
  {
    text: '提交状态',
    value: 'remark',
    align: 'center',
  },
  {
    text: '填报截至时间',
    value: 'remark',
    align: 'center',
  },
])
const list = ref([])
const total = ref(0)
const listLoading = ref(true)

// 获取数据
const fetchData = (isNowPage = true) => {
  listLoading.value = true
  if (!isNowPage) {
    // 是否显示当前页，否则跳转第一页
    listQuery.offset = 1
  }
  // getGroupList(listQuery).then((response) => {
  //   list.value = response.data.rows
  //   total.value = parseInt(response.data.total)
  listLoading.value = false
  // })
}
fetchData()
// 查询数据
const search = () => {
  fetchData(false)
}
// 重置
const reset = () => {
  listQuery.offset = 1
  listQuery.limit = 20
  search()
}
// 页数发生变化后的操作，可能是页码变化，可能是每页容量变化，此函数必写
const changePage = (val: { size: number; page: number }) => {
  if (val && val.size) {
    listQuery.limit = val.size
  }
  if (val && val.page) {
    listQuery.offset = val.page
  }
  fetchData()
}
const $router = useRouter()
// 新建编辑操作
const handler = (row: any, type: string) => {
  // $router.push({
  //   path: `/group/${type}`,
  //   query: {
  //     row: JSON.stringify(row),
  //     id: row.id,
  //   },
  // })
}
// 删除
const delHandler = (row: any) => {
  ElMessageBox.confirm(
    '确认删除此分组信息吗?',
    '确认',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    },
  ).then(() => {
    // delGroup(row.id).then((res) => {
    //   ElMessage.success('操作成功')
    //   search()
    // })
  })
}
</script>

<template>
  <app-container>
    <!-- 筛选条件 -->
    <search-area :need-clear="true" @search="search" @clear="reset">
      <search-item>
        <el-input v-model.trim="listQuery.groupName" placeholder="考核结果编号" clearable />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.groupName" placeholder="考核方案名称" clearable />
      </search-item>
      <search-item>
        <el-select v-model.trim="listQuery.groupName" placeholder="指标考核对象" clearable />
      </search-item>
      <search-item>
        <el-select v-model.trim="listQuery.groupName" placeholder="考核周期" clearable />
      </search-item>
      <search-item>
        <el-date-picker
          v-model="listQuery.endTime" type="datetime" format="YYYY-MM-DD" value-format="YYYY-MM-DD"
          placeholder="考核时间"
        />
      </search-item>
    </search-area>
    <table-container>
      <template #btns-right>
        <el-button type="primary">
          提交
        </el-button>
      </template>
      <!-- 普通表格 -->
      <normal-table
        :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="listLoading"
        :is-showmulti-select="true" @change="changePage"
      >
        <template #columns>
          <el-table-column label="操作" width="140" align="center">
            <template #default="scope">
              <el-button link type="primary" size="small">
                填报
              </el-button>
              <el-button link type="primary" size="small">
                提交
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>

