<template>
  <a-tabs v-model:activeKey="searchInfo.activeKey">
    <a-tab-pane key="1" tab="权益订单">
      <BasicTable @register="registerTimeTable">
        <template #action="{ record }">
          <TableAction
            :actions="[
              {
                label: '编辑',
                icon: 'ep:edit',
                onClick: handleEdit.bind(null, record),
              },
              {
                label: '删除',
                icon: 'ic:outline-delete-outline',
                popConfirm: {
                  title: '是否确认删除',
                  confirm: handleDelete.bind(null, record),
                },
              },
            ]"
          />
        </template>
      </BasicTable>
    </a-tab-pane>
    <a-tab-pane key="2" tab="下载订单">
      <BasicTable @register="registerDown"></BasicTable>
    </a-tab-pane>
    <a-tab-pane key="3" tab="消费订单">
      <BasicTable @register="registerCamera"></BasicTable>
    </a-tab-pane>
  </a-tabs>
</template>
<script lang="ts">
import { defineComponent, reactive, computed } from 'vue';
import { BasicTable, useTable, FormProps, TableAction } from '/@/components/Table';
import { PageWrapper } from '/@/components/Page';
import { Divider, Card, Empty, Descriptions, Steps, Tabs } from 'ant-design-vue';
import { DelAndUpload } from '/@/api/product';
import { IncrementList } from '/@/api/order'
import { DownList,CameraList } from '/@/api/order'
import { useModal } from '/@/components/Modal';
import { useI18n } from '/@/hooks/web/useI18n';
import { useMessage } from '/@/hooks/web/useMessage';
import { cameraColumns, dowmColumns, equityColumns,equitySearchForm } from './data'
import { otherInfoStore } from '/@/store/modules/other'
export default defineComponent({
  components: {
    BasicTable,
    TableAction,
    PageWrapper,
    [Divider.name]: Divider,
    [Card.name]: Card,
    Empty,
    [Descriptions.name]: Descriptions,
    [Descriptions.Item.name]: Descriptions.Item,
    [Steps.name]: Steps,
    [Steps.Step.name]: Steps.Step,
    [Tabs.name]: Tabs,
    [Tabs.TabPane.name]: Tabs.TabPane,
  },
  setup() {
    const { t } = useI18n();
    const otherInfo = otherInfoStore();
    const OverviewInfo = computed(() => otherInfo.getOverviewInfo);
    const { userName } = OverviewInfo.value
    const searchInfo = reactive<Recordable>({
      activeKey: '1',
      userName,
    });
    console.log('OverviewInfo',searchInfo,OverviewInfo,userName)
    const [registerAddModal, { openModal: openAddModal }] = useModal();
    const [registerEditModal, { openModal: openEditModal }] = useModal();
    const { createMessage } = useMessage();

    const searchForm: Partial<FormProps> = {
      labelWidth: 100,
      schemas: [
        {
          field: 'version',
          label: '版本号',
          component: 'Input',
          componentProps: {
            maxLength: 100,
          },
          colProps: {
            xl: 6,
            xxl: 6,
          },
        },
      ],
    };
    
    const [registerDown, { reload:Downreload }] = useTable({
      api: DownList,
      title: '下载列表',
      columns: dowmColumns,
      useSearchForm: true,
      formConfig: searchForm,
      showTableSetting: true,
      showIndexColumn: false,
      rowKey: 'id',
      searchInfo,
      fetchSetting: {
        pageField: 'pageNum',
        sizeField: 'pageSize',
        listField: 'list',
        totalField: 'total',
      },
      // actionColumn: {
      //   width: 180,
      //   title: '操作',
      //   dataIndex: 'action',
      //   slots: { customRender: 'action' },
      // },
      canResize: false,
    });
    
    const [registerCamera, { reload:Camerareload }] = useTable({
      api: CameraList,
      title: '相机列表',
      columns: cameraColumns,
      useSearchForm: true,
      formConfig: searchForm,
      showIndexColumn: false,
      showTableSetting: true,
      searchInfo,
      rowKey: 'id',
      fetchSetting: {
        pageField: 'pageNum',
        sizeField: 'pageSize',
        listField: 'list',
        totalField: 'total',
      },
      canResize: false,
    });
    const [registerTimeTable, { reload }] = useTable({
      api: IncrementList,
      title: '权益列表',
      columns: equityColumns,
      useSearchForm: true,
      formConfig: equitySearchForm,
      showIndexColumn: false,
      showTableSetting: true,
      searchInfo,
      rowKey: 'id',
      fetchSetting: {
        pageField: 'pageNum',
        sizeField: 'pageSize',
        listField: 'list',
        totalField: 'total',
      },
      // searchInfo: searchInfo,
      // actionColumn: {
      //   width: 180,
      //   title: '操作',
      //   dataIndex: 'action',
      //   slots: { customRender: 'action' },
      // },
      canResize: false,
    });
    function tabChange(val: string) {
      console.log('tabChange', val);
      reload();
    }
    async function handleDelete(record: Recordable) {
      console.log('点击了删除', record);
      await DelAndUpload({ id: record.id });
      createMessage.success(t('common.optSuccess'));
      reload();
    }
    function handleOpen(record: Recordable) {
      console.log('点击了启用', record);
    }
    function handleEdit(record: Recordable) {
      console.log('record', record);
      openEditModal(true, {
        ...record,
      });
    }
    return {
      registerTimeTable,
      registerCamera,
      registerDown,
      handleDelete,
      handleOpen,
      tabChange,
      reload,
      Downreload,
      Camerareload,
      registerAddModal,
      registerEditModal,
      openAddModal,
      handleEdit,
      t,
      searchInfo,
    };
  },
});
</script>
<style lang="less" scoped>
.desc-wrap-BasicTable {
  background-color: #f0f2f5;
  .vben-basic-table-form-container {
    padding: 0;
  }
}
</style>
