<!-- 
avatar: "https://thirdwx.qlogo.cn/mmopen/vi_32/dTbT3X0Fm7BnUA4DoQhBy14smppF5eBibqPSOib3ou5elGuJ1eYZ9sib2ZALDMs1icYupWIxiaJwWETTV8we9brCHhQ/132"
bindBrandId: null
bindBrandName: null
birthday: 631123200000
brandId: null
brandName: null
city: ""
gender: 1
id: 25
isAdmin: 0
lastLoginIp: "117.136.32.65"
lastLoginTime: 1631504271000
levelName: null
mobile: "13536501128"
nickname: "波仔"
password: "oeADe5U9uLeMYsNigq98zdu8J96A"
registerIp: "117.136.32.65"
registerTime: 1631504271000
userLevelId: null
username: "微信用户f8f4igi4j9ks"
weixinOpenid: "oeADe5U9uLeMYsNigq98zdu8J96A" 
-->
<template>
  <div class="p-4">
    <BasicTable @register="registerTable">
      <template #toolbar> </template>
      <template #avatar="{ record }">
        <Avatar :size="80" :src="record.avatar" />
      </template>

      <template #gender="{ record }">
        {{ renderGenderLabel(record.gender) }}
      </template>

      <template #birthday="{ record }">
        <Time v-if="record.birthday" :value="record.birthday" mode="datetime" />
      </template>

      <template #lastLoginTime="{ record }">
        <Time :value="record.lastLoginTime" mode="datetime" />
      </template>

      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              icon: 'mdi:information-outline',
              label: '详情',
              onClick: () => {
                go(`/order/list/detail/${record.orderNo}`);
              },
            },
            {
              icon: 'mdi:printer-outline',
              label: '打印',
              color: 'error',
              onClick: () => {
                createMessage.info(`暂未接入`);
              },
            },
          ]"
        />
      </template>
    </BasicTable>
  </div>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { BasicTable, useTable, BasicColumn, FormProps, TableAction } from '/@/components/Table';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { uploadApi } from '/@/api/sys/upload';

  import { ListApi } from '/@/api/member/list';
  import { useI18n } from '/@/hooks/web/useI18n';
  // import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
  import { useGo } from '/@/hooks/web/usePage';
  import { Avatar } from 'ant-design-vue';
  import { Time } from '/@/components/Time';

  export default defineComponent({
    components: { BasicTable, TableAction, Avatar, Time },
    setup() {
      const { createMessage } = useMessage();
      const go = useGo();
      const { t } = useI18n();
      const columns: BasicColumn[] = [
        {
          title: 'ID',
          dataIndex: 'id',
          fixed: 'left',
          width: 60,
        },
        {
          title: '会员名称',
          dataIndex: 'username',
          sorter: true,
          width: 160,
        },
        {
          title: '头像',
          dataIndex: 'avatar',
          slots: { customRender: 'avatar' },
          width: 120,
        },
        {
          title: '性别',
          dataIndex: 'gender',
          slots: { customRender: 'gender' },
          sorter: true,
          width: 120,
        },
        {
          title: '出生日期',
          dataIndex: 'birthday',
          slots: { customRender: 'birthday' },
          width: 120,
        },
        {
          title: '最后登录时间',
          dataIndex: 'lastLoginTime',
          slots: { customRender: 'lastLoginTime' },
          sorter: true,
          width: 120,
        },
        {
          title: '微信名',
          dataIndex: 'nickname',
          width: 120,
        },
        {
          title: '手机号',
          dataIndex: 'mobile',
          width: 120,
        },
      ];

      const searchForm: Partial<FormProps> = {
        labelWidth: 100,
        schemas: [
          {
            field: 'username',
            label: '会员名称',
            component: 'Input',
            colProps: {
              xl: 5,
              xxl: 5,
            },
          },
        ],
      };

      const [registerTable] = useTable({
        title: '会员列表',
        api: ListApi,
        columns: columns,
        useSearchForm: true,
        formConfig: searchForm,
        showTableSetting: true,
        tableSetting: { fullScreen: true },
        showIndexColumn: false,
        rowKey: 'id',
        pagination: { pageSize: 20 },
        bordered: true,
        fetchSetting: {
          pageField: 'page',
          sizeField: 'limit',
          listField: 'list',
          totalField: 'totalCount',
        },
      });

      function renderGenderLabel(gender: number): string {
        switch (gender) {
          case 0:
            return '未知';
          case 1:
            return '男';
          case 2:
            return '女';
          default:
            return '未知';
        }
      }

      return {
        registerTable,
        createMessage,
        t,
        go,
        renderGenderLabel,
        uploadApi: uploadApi as any,
      };
    },
  });
</script>
