<template>
  <div class="p-4">
    <BasicTable @register="registerTable">
      <template #toolbar> </template>
      <template #feedType="{ record }">
        {{ renderFeedbackType(record.feedType) }}
      </template>

      <template #addTime="{ record }">
        <Time :value="record.addTime" 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 { Switch } from 'ant-design-vue';
  // import { h } from 'vue';
  import { ListApi } from '/@/api/feedback/list';
  import { useI18n } from '/@/hooks/web/useI18n';
  // import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
  import { useGo } from '/@/hooks/web/usePage';
  import { Time } from '/@/components/Time';

  export default defineComponent({
    components: { BasicTable, TableAction, Time },
    setup() {
      const { createMessage } = useMessage();
      const go = useGo();
      const { t } = useI18n();
      const columns: BasicColumn[] = [
        // {
        //   title: 'ID',
        //   dataIndex: 'userId',
        //   fixed: 'left',
        //   width: 60,
        // },
        {
          title: '会员名称',
          dataIndex: 'userName',
          width: 160,
        },
        {
          title: '会员昵称',
          dataIndex: 'nickName',
          width: 80,
        },
        {
          title: '手机',
          dataIndex: 'mobile',
          width: 80,
        },
        {
          title: '反馈类型',
          dataIndex: 'feedType',
          slots: { customRender: 'feedType' },
          sorter: true,
          width: 80,
        },
        {
          title: '详细内容',
          dataIndex: 'content',
          width: 250,
        },
        {
          title: '反馈时间',
          dataIndex: 'addTime',
          slots: { customRender: 'addTime' },
          width: 130,
        },
        // {
        //   title: '操作',
        //   dataIndex: '',
        //   slots: { customRender: 'action' },
        //   fixed: 'right',
        //   width: 140,
        // },
      ];

      const searchForm: Partial<FormProps> = {
        labelWidth: 100,
        schemas: [
          {
            field: 'name',
            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: 'userId',
        pagination: { pageSize: 20 },
        bordered: true,
        fetchSetting: {
          pageField: 'page',
          sizeField: 'limit',
          listField: 'list',
          totalField: 'totalCount',
        },
      });

      function renderFeedbackType(type: number): string {
        switch (type) {
          case 0:
            return '商口相关';
          case 1:
            return '物流状况';
          case 2:
            return '客户服务';
          case 3:
            return '产品建议';
          case 4:
            return '其他';
          default:
            return '';
        }
      }

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