<script setup lang="tsx">
// import dayjs from 'dayjs';
// import { fetchGetStoreList } from '@/service/api/xsb-manage/store-info';
import { computed } from 'vue';
import { fetchList } from '@/service/api/delivery/ponits-details';
import { commonExport } from '@/utils/common';
import { useTable } from '@/components/zt/Table/hooks/useTable';

const columns: NaiveUI.TableColumn<Api.goods.ShopSku>[] = [
  {
    key: 'orderNumber',
    align: 'center',
    title: '流水号'
  },
  {
    key: 'realName',
    title: '姓名',
    align: 'center'
  },
  {
    key: 'mobile',
    title: '用户手机号',
    align: 'center'
  },
  {
    key: 'businessType',
    title: '业务场景',
    align: 'center'
  },
  {
    key: 'variablePoints',
    title: '变动积分',
    align: 'center'
  },
  {
    key: 'currentlyAvailablePoints',
    title: '变动后积分',
    align: 'center'
  },
  // {
  //   key: 'receiveTime',
  //   title: '变动前积分',
  //   align: 'center',
  //   width: 120,
  //   ellipsis: {
  //     tooltip: true
  //   }
  // },
  {
    key: 'creationDate',
    title: '更新时间',
    align: 'center'
  }
];

const [registerTable, { getTableData, getSeachForm, setTableLoading }] = useTable({
  searchFormConfig: {
    schemas: [
      {
        label: '手机号',
        component: 'NInput',
        field: 'mobile'
      },
      {
        label: '业务场景',
        component: 'NSelect',
        field: 'businessType',
        componentProps: {
          options: [
            {
              label: '充值',
              value: 'CZ'
            },
            {
              label: '过期',
              value: 'GQ'
            },
            {
              label: '退款过期',
              value: 'TKGQ'
            },
            {
              label: '退款',
              value: 'TK'
            },
            {
              label: '星闪豹',
              value: 'XSB'
            },
            {
              label: '充电',
              value: 'CD'
            },

            {
              label: '电影',
              value: 'DYY'
            },
            {
              label: '虚拟商品',
              value: 'XNSP'
            },
            {
              label: '大健康',
              value: 'DJK'
            }
          ]
        }
      },

      {
        label: '更新时间',
        component: 'NDatePicker',
        field: 'createTime',
        componentProps: {
          type: 'datetimerange',
          defaultTime: ['00:00:00', '23:59:59']
        }
      }
    ],
    inline: false,
    size: 'small',
    labelPlacement: 'left',
    isFull: false
  },
  tableConfig: {
    keyField: 'skuId',
    title: '积分明细',
    showAddButton: false,
    fieldMapToTime: [['createTime', ['startTime', 'endTime']]]
  }
});

const tableData = computed(() => {
  return getTableData();
});

async function handleExport() {
  setTableLoading(true);
  try {
    await commonExport('/platform/pointsRecord/backendPointsRecordListExport', getSeachForm(), '积分明细.xlsx');
  } finally {
    setTableLoading(false);
  }
}
</script>

<template>
  <LayoutTable>
    <ZTable :columns="columns" :show-table-action="false" :api="fetchList" @register="registerTable">
      <template #prefix="{ loading }">
        <NSpace>
          <NButton size="small" :disabled="tableData.length == 0" :loading="loading" @click="handleExport">
            导出全部
          </NButton>
        </NSpace>
      </template>
    </ZTable>
  </LayoutTable>
</template>

<style scoped></style>
