<script setup lang="ts">
import { useVbenModal } from '@vben/common-ui';
import { getUserLogAssetApi } from '#/api/core/log';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { inject, ref } from 'vue';
import { globalState } from '#/store/globalState';
import type { VxeGridProps } from '#/adapter/vxe-table';
const state = inject('globalState', globalState);
const [Modal, modalApi] = useVbenModal({
});
interface RowType {
  Uid: number;
  change_type: string;
  change_num: string;
  change_after: string;
  item_id: string;
  timestamp: string;
}
const formatType = (cellValue: string) => {
  switch (cellValue) {
    case "gain":
      return '增加';
    case "consume":
      return '减少';
    default:
      return cellValue;
  }
}
const formatItemName = (cellValue: number) => {
  // console.log(cellValue); 
  switch (cellValue) {
    case 100001:
      return '能量';
    case 100002:
      return '宠物币';
    case 100003:
      return '钻石';
    default:
      return cellValue;
  }
}
const d = ref({
  sum : 0,
  psum : 0,
  nsum : 0,
});


const gridOptions: VxeGridProps<RowType> = {
  columns: [
  { field: 'Uid', title: 'Uid' },
  { field: 'change_type', title: '变化类型', formatter:({cellValue}) => formatType(cellValue)},
  { field: 'change_num', title: '变化数值' },
  { field: 'change_after', title: '变化后数值' },
  { field: 'item_id', title: '道具id', formatter: ({ cellValue }) => formatItemName(cellValue) },
  { field: 'timestamp', title: '时间', formatter: ({ cellValue }) => new Date(cellValue*1000).toLocaleString()},
  ],
  height: '500px',
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    response: {
        total: "total",
        result: "data"
    },
    ajax: {
      query: async () => {
        const r =  await getUserLogAssetApi({
          Id: state.uid,
          Event :'',
          StartTime: modalApi.getData()?.StartTime || 0,
          EndTime: modalApi.getData()?.EndTime || 0,
          ItemId: 0,
          CurrentPage: 1,
          PageSize: 100,
        });
        d.value.sum = r.sum;
        d.value.psum = r.psum;
        d.value.nsum = r.nsum;
        return r
      },
    },
  },
  
  rowConfig: {
    isHover: true,
  },
};

const [Grid] = useVbenVxeGrid({ gridOptions});

</script>

<template>

    <Modal>
      <Grid />
    </Modal>

</template>
