index.vue 6.95 KB
<script setup lang="ts">
import { reactive, ref, onMounted, getCurrentInstance } from "vue";
import { feedbackStatus, feedbackList } from "@/api/event";
import { parseTime, globalFilters } from "@/utils/tool";
import { onlineStatus } from "./../config";
import Pagination from "@/components/Pagination/index.vue";
import { ElMessageBox, ElMessage } from "element-plus";
import type { ElTable } from "element-plus";
interface Form {
  page: number;
  pageSize: number;
  handworkName: string;
  startTime: string;
  endTime: string;
}
interface Params {
  total: number;
  query: Form;
}
interface Data {
  loading: boolean;
  list: any[] | null;
  onlineStatus: any[] | null;
  params: Params;
}
let data = reactive({
  list: [],
  onlineStatus: onlineStatus,
  loading: false,
  params: {
    total: 0,
    query: {
      page: 1,
      pageSize: 10,
      handworkName: "",
      startTime: "",
      endTime: "",
    },
  },
});
const value1 = ref([]);
let multipleSelection = ref<any[]>([]);
const multipleTableRef = ref<InstanceType<typeof ElTable>>();
const {
  appContext: {
    config: { globalProperties },
  },
} = getCurrentInstance();
/**
 * 表格选中响应
 * @param {array} data 选中的一条数据
 */
const handleSelectionChange = (data: array) => {
  multipleSelection.value = data;
};
/**
 * 时间组件回调
 * @param {array} value [开始时间, 结束时间]
 */
const handleTimeChange = (value: array) => {
  data.params.query.beginTime = value ? value[0] : "";
  data.params.query.endTime = value ? value[1] : "";
  getList();
};
/**
 * 上下线状态切换
 * @param {object} obj 要操作的数据对象
 */
const handleLine = (obj: any) => {
  ElMessageBox.confirm("确认切换显示状态吗?", "警告", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(async () => {
      try {
        let res = await feedbackStatus({
          ids: obj.id,
          status: obj.status,
        });
        if (res?.data) {
          ElMessage({
            type: "success",
            message: "操作成功",
          });
          getList();
        } else {
          ElMessage({
            type: "error",
            message: "操作失败",
          });
        }
      } catch (e) {
        console.log(e);
      }
    })
    .catch(() => {
      console.log("取消");
    });
};
/**
 * 列表
 */
const getList = async () => {
  data.loading = true;
  try {
    const res = await feedbackList(data.params.query);
    data.list = res?.data?.data?.list;
    data.params.total = res?.data?.data?.total;
  } catch (e) {
    console.log(e);
  } finally {
    data.loading = false;
  }
};
onMounted(() => {
  getList();
});
</script>

<template>
  <div class="page-container">
    <!-- <h1>活动评价</h1> -->
    <el-row style="padding-bottom: 20px">
      <el-form :inline="true" label-width="70px" @submit.native.prevent>
        <el-form-item label="名称">
          <el-input
            v-model.trim="data.params.query.handworkName"
            placeholder="请填写名称"
            maxlength="15"
            @change="getList"
          />
        </el-form-item>
        <el-form-item label="时间">
          <el-date-picker
            v-model="value1"
            type="datetimerange"
            range-separator="至"
            format="YYYY-MM-DD HH:mm:ss"
            value-format="YYYY-MM-DD HH:mm:ss"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            @change="handleTimeChange"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getList">查询</el-button>
          <el-button
            type="success"
            @click="
              handleLine({
                id: multipleSelection.map((i) => i.id).join(','),
                status: 2,
              })
            "
            :disabled="!multipleSelection.length"
            >批量上线</el-button
          >
          <el-button
            type="info"
            @click="
              handleLine({
                id: multipleSelection.map((i) => i.id).join(','),
                status: 1,
              })
            "
            :disabled="!multipleSelection.length"
            >批量下线</el-button
          >
        </el-form-item>
      </el-form>
    </el-row>
    <el-table
      :data="data.list"
      style="width: 100%"
      border
      v-loading="data.loading"
      align="center"
      element-loading-text="拼命加载中"
      ref="multipleTableRef"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" align="center" />
      <el-table-column prop="id" label="ID" align="center"></el-table-column>
      <el-table-column
        prop="handworkName"
        label="活动名称"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="userName"
        label="用户名"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="comment"
        label="评价"
        align="center"
      ></el-table-column>
      <el-table-column prop="imgs" label="评价图片" align="center">
        <template #default="scope">
          <el-image
            style="width: 100px; height: 100px"
            :src="
              scope.row?.imgs[0]
                ? scope.row?.imgs[0]
                : globalProperties.$defaultImage
            "
            :preview-src-list="scope.row?.imgs ? scope.row.imgs.split(',') : []"
            :initial-index="4"
            fit="cover"
          >
          </el-image>
        </template>
      </el-table-column>
      <el-table-column prop="isAnonymity" label="匿名状态" align="center">
        <template #default="scope">
          {{ scope.row.isAnonymity ? "匿名" : "实名" }}
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" align="center">
        <template #default="scope">
          {{ scope.row.status === 2 ? "已上线" : "未上线" }}
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="评价时间" align="center">
        <template #default="scope">
          {{ parseTime(new Date(scope.row.createTime).getTime()) }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button
            type="text"
            v-if="~~scope.row.status === 1"
            @click="handleLine({ id: scope.row.id, status: 2 })"
            >上线</el-button
          >
          <el-button
            type="text"
            v-if="~~scope.row.status === 2"
            @click="handleLine({ id: scope.row.id, status: 1 })"
            >下线</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <Pagination
      :total="data.params.total"
      v-model:currentPage="data.params.query.page"
      v-model:pageSize="data.params.query.pageSize"
      @pageChange="getList"
    ></Pagination>
  </div>
</template>