<template>
  <ele-page flex-table>
    <page-search @search="reload"></page-search>
    <common-table
      ref="pageRef"
      :pageConfig="pageConfig"
      :columns="columns"
      :tools="false"
      show-summary
      :flex-table="false"
    >
      <template #toolbar="{ row }">
        <div>
          <el-radio-group @change="handleStatusChange" v-model="useStatus">
            <el-radio-button label="订单审核实时统计" value="1" />
            <el-radio-button label="订单审核历史统计" value="2" />
          </el-radio-group>
          <el-button
            style="margin-left: 40px"
            type="success"
            plain
            v-permission="'statistic:recycleOrder:export'"
            @click="handleExportExcel(row)"
          >
            导出EXCEL
          </el-button>
        </div>
      </template>
    </common-table>
  </ele-page>
</template>

<script setup>
  import { ref, reactive } from 'vue';
  import CommonTable from '@/components/CommonPage/CommonTable.vue';
  import pageSearch from './components/page-search.vue';
  import { useDictData } from '@/utils/use-dict-data';

  defineOptions({ name: 'auditOrder' });

  const useStatus = ref('1');
  function handleStatusChange(val) {
    useStatus.value = val;
    pageRef.value?.reload();
  }

  /** 表格列配置 */
  const columns = ref([
    { type: 'index', label: '#', align: 'center', width: 80 },
    { label: '审核员', prop: 'godownName', align: 'center' },
    { label: '审核订单量', prop: 'orderNum', align: 'center' },
    { label: '审核书籍数量', prop: 'bookNum', align: 'center' },
    { label: '实际回收数量', prop: 'price', align: 'center' },
    { label: '不良率', prop: 'auditNum', align: 'center' },
    { label: '统计日期', prop: 'createTime', align: 'center' }
  ]);

  /** 页面组件实例 */
  const pageRef = ref(null);

  const pageConfig = reactive({
    pageUrl: '/baseinfo/godown/pagelist',
    exportUrl: '/baseinfo/godown/export',
    fileName: '审核统计',
    cacheKey: 'auditOrderTable'
  });

  //刷新表格
  function reload(where) {
    pageRef.value?.reload(where);
  }

  //导出excel
  function handleExportExcel() {
    pageRef.value?.exportData('审核统计');
  }
</script>
