<!-- 文章评论 -->
<template>
    <div class="table-box">
        <div style="padding-bottom: 16px">
            <el-button type="primary" @click="getArticleRemarkExport"> 导出 </el-button>
        </div>
        <ProTable
            ref="proTableRef"
            :formData="dataStore.formData"
            :columns="dataStore.columns"
            :request-api="getArticleRemarkListApi"
            :init-param="dataStore.initParam"
        >
            <!-- <template #image="scope">
                <el-image :src="scope.row.image ? h + scope.row.image : ''" style="width: 60px; height: 60px" />
            </template> -->
            <template #is_audited="scope">
                <el-tag :type="scope.row.is_audited ? 'success' : 'danger'" effect="dark">{{
                    scope.row.is_audited ? "已审核" : "待审核"
                }}</el-tag>
            </template>
            <template #operation="scope">
                <el-button size="small" type="primary" @click="getArticleRemarkExamine(scope.row.id)">{{
                    scope.row.is_audited ? "取消审核" : "审核通过"
                }}</el-button>
                <el-button size="small" type="danger" @click="getArticleRemarkDel(scope.row.id)">删除</el-button>
            </template>
        </ProTable>
    </div>
</template>

<script setup lang="ts" name="articleRemarkListIndex">
import ProTable from "@/components/ProTable/index.vue";
import { messageBox } from "@/utils/messageBox";
import { useMsg } from "@/hooks/useMsg";
import { useExport } from "@/hooks/useExport";
// import { h } from "@/utils/url";
//列表接口

import {
    getArticleRemarkListApi,
    getArticleRemarkDelApi,
    getArticleRemarkExamineApi,
    getArticleRemarkExportApi
} from "@/api/modules/articleRemark";
//深拷贝方法
import { cloneDeep } from "lodash-es";
//表格和搜索條件
import { RULE_FORM, FORM_DATA, COLUMNS, RULES } from "./constant/index";
// 获取 ProTable 元素，调用其获取刷新数据方法（还能获取到当前查询参数，方便导出携带参数）
const proTableRef = ref<any>(null);

// 数据源
const dataStore = reactive<any>({
    columns: COLUMNS, //列表配置项
    rules: cloneDeep(RULES), //抽屉表单验证
    initParam: cloneDeep(RULE_FORM), // 初始化搜索条件|重置搜索条件
    ruleForm: cloneDeep(RULE_FORM), // 搜索參數
    formData: FORM_DATA, //搜索配置项
    selectRow: {} //当前选择的row
});
//导出
const getArticleRemarkExport = async () => {
    const result = await getArticleRemarkExportApi({
        ...proTableRef?.value?.searchParam,
        ...proTableRef?.value?.pageable
    });
    await useExport(result);
};

//删除
const getArticleRemarkDel = async (id: any) => {
    messageBox("你确定要删除?", async () => {
        const result = await getArticleRemarkDelApi(id);
        if (result?.code === 0) {
            const { msg } = result;
            useMsg("success", msg);
            proTableRef?.value?.getTableList();
        }
    });
};
//审核
const getArticleRemarkExamine = async (id: any) => {
    const result = await getArticleRemarkExamineApi(id);
    if (result?.code === 0) {
        const { msg } = result;
        useMsg("success", msg);
        proTableRef?.value?.getTableList();
    }
};
</script>

<style scoped></style>
