<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      v-show="showSearch"
      :inline="true"
    >
      <el-form-item
        :label="t('admin.form.name', { type: t('admin.common.activity') })"
        prop="title"
      >
        <el-input
          v-model="queryParams.title"
          :placeholder="
            t('admin.form.placeholder', { type: t('activity.activityName') })
          "
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="t('activity.activityStatus')" prop="status">
        <el-select
          v-model="queryParams.status"
          :placeholder="t('admin.form.pleaseSelect')"
          size="small"
        >
          <el-option :label="t('common.show')" value="1"></el-option>
          <el-option :label="t('common.hide')" value="2"></el-option>
          <!-- <el-option label="已结束" value="3"></el-option> -->
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          size="small"
          type="primary"
          icon="Search"
          @click="handleQuery"
        >
          {{ t("admin.common.search") }}
        </el-button>
        <el-button size="small" icon="Refresh" @click="resetQuery">
          {{ t("admin.common.reset") }}
        </el-button>
      </el-form-item>
    </el-form>

    <!-- 表格数据 -->
    <el-table v-loading="loading" :data="dataList">
      <el-table-column :label="t('admin.common.dataNumber')" prop="id" />
      <el-table-column
        :label="t('admin.form.name', { type: t('admin.common.activity') })"
        prop="title"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        :label="t('activity.signUpDeadline')"
        align="center"
        prop="joinDeadline"
      >
        <template #default="{ row }">
          <span>{{ parseTime(row.joinDeadline) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        :label="t('activity.activityStartTime')"
        align="center"
        prop="beginTime"
      >
        <template #default="{ row }">
          <span>{{ parseTime(row.beginTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        :label="t('activity.activityEndTime')"
        align="center"
        prop="finishTime"
      >
        <template #default="{ row }">
          <span>{{ parseTime(row.finishTime) }}</span>
        </template>
      </el-table-column>

      <el-table-column
        :label="t('activity.activitySignUpTime')"
        align="center"
        prop="createTime"
      >
        <template #default="{ row }">
          <span>{{ parseTime(row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="t('common.status')" align="center" prop="status">
        <template #default="{ row }">
          <el-tag type="success" v-if="row.status == 1">{{
            t("common.show")
          }}</el-tag>
          <el-tag type="danger" v-else-if="row.status == 2">{{
            t("common.hide")
          }}</el-tag>
          <el-tag type="info" v-else>{{ t("common.unknown") }}</el-tag>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup>
import { activitysList } from "@/api/admin/expert";
import { useI18n } from "vue-i18n";
import { reactive, ref, toRefs } from "vue";
import { parseTime } from "@/utils/ruoyi";

const { t } = useI18n();
const dataList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const queryRef = ref();
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    notifyCrowd: "2",
    title: undefined,
    status: undefined,
  },
});

const { queryParams } = toRefs(data);

/** 查询数据列表 */
const getList = async () => {
  loading.value = true;
  const resp = await activitysList(queryParams.value);
  dataList.value = resp.rows;
  total.value = resp.total;
  loading.value = false;
};

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  if (queryRef.value) {
    queryRef.value.resetFields();
    handleQuery();
  }
}

getList();
</script>
