<!--
 * @Author: chris
 * @Date: 2026-01-16 14:47:23
 * @LastEditors: chris
 * @LastEditTime: 2026-01-20 15:46:24
-->
<script setup>
import SearchModule from './components/SearchModule.vue';
import FeedBackTable from './components/FeedBackTable.vue';
import { defaultQueryParams, columnsConfig } from './config.js'
import { listFeedBack, updateFeedBack } from '@/api/feedback/index.js'

const feedBackList = ref([]);
const loading = ref(false);
const total = ref(0);
const queryParams = ref ({
  ...defaultQueryParams
})

getFeedBackList()

function getFeedBackList() {
  loading.value = true;
  return listFeedBack(queryParams.value).then((res) => {
    feedBackList.value = res.rows;
    total.value = res.total;
  }).finally(() => {
    loading.value = false;
  })  
}

function handleQuery(query) {
  queryParams.value = Object.assign(queryParams.value, query);
  getFeedBackList();
}

function handleReset(formRef) {
  queryParams.value = {
    ...defaultQueryParams
  }
  formRef.resetFields();
  getFeedBackList();
}

function handleRead(row) {
  updateFeedBack({
    id: row.id,
    deptId: row.deptId,
    content: row.content,
    status: 1
  }).then(() => {
    getFeedBackList();
  })
}
</script>

<template>
  <div class="app-container">
    <SearchModule @query="handleQuery" @reset="handleReset" />

    <FeedBackTable :tableData="feedBackList" :loading="loading" :columns="columnsConfig" @handleRead="handleRead" />
    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getFeedBackList" />
  </div>
</template>

<style lang="scss" scoped>

</style>
