<template>
  <div class="desc-wrap-BasicTable">
    <BasicTable @register="registerTable"> </BasicTable>
  </div>
</template>
<script lang="ts">
import { defineComponent, onMounted } from 'vue';
import {
  BasicTable,
  useTable,
  TableAction,
  BasicColumn,
  TableImg,
  FormProps,
} from '/@/components/Table';
import { useI18n } from '/@/hooks/web/useI18n';
import { usePermissionStore } from '/@/store/modules/permission';
import { dincrementList, cameraIncrementLog } from '/@/api/equity';
export default defineComponent({
  components: {
    BasicTable,
    TableAction,
    TableImg,
  },
  setup() {
    const { t } = useI18n();
    const permissionStore = usePermissionStore();
    const { getCheckPerm } = permissionStore;
    onMounted(() => {
      // console.log(router.currentRoute.value.params.id);
    });
    const columns: BasicColumn[] = [
      {
        title: t('routes.equity.operationType'),
        dataIndex: 'operationType',
        width: 80,
        customRender: ({ record }) => {
          return t(`routes.equity.operation.${record.operationType || 0}`);
        },
      },{
        title: t('routes.device.snCode'),
        dataIndex: 'snCode',
        width: 100,
      },
      {
        title: t('routes.equity.operationUserName'),
        dataIndex: 'operationUserName',
        ellipsis: false,
        width: 120,
        customRender: ({ record }) => {
          return record.operationUserName || t('routes.equity.platform');
        },
      },
      {
        title: t('routes.equity.operationTime'),
        dataIndex: 'createTime',
        width: 180,
      },
      {
        title: t('routes.equity.Type'),
        dataIndex: 'validTimeType',
        width: 180,
        customRender({ record }) {
          if(record.validTimeType==2 || record.validTimeType==3){
            return '-'
          }
          return record.validTimeType==0 ?t('routes.equity.equityType.0'):record.validTimeType==1? t('routes.equity.equityType.3') : '-';
        },
      },
      {
        title: t('routes.equity.incrementId'),
        dataIndex: 'incrementId',
        width: 180,
        customRender({ record }) {
          if(record.validTimeType==2 || record.validTimeType==3){
            return '-'
          }
          return record.incrementId ? record.incrementId : '-';
        },
      },
    ];
    const searchForm: Partial<FormProps> = {
      labelWidth: 120,
      autoAdvancedLine: 1,
      actionColOptions: {
        span: 24,
      },
      schemas: [
        {
          field: 'operationType',
          component: 'Select',
          label: t('routes.equity.operationType'),
          colProps: {
            xl: 7,
            xxl: 7,
          },
          componentProps: {
            options: [
              {
                  label: t('routes.equity.operation.0'),
                  value: 0,
                  key: '0',
                },{
                label: t('routes.equity.operation.1'),
                value: 1,
                key: '1',
              },{
                label: t('routes.equity.operation.2'),
                value: 2,
                key: '2',
              },{
                label: t('routes.equity.operation.3'),
                value: 3,
                key: '3',
              }
            ],
          },
        },{
          field: 'snCode',
          component: 'Input',
          label: t('routes.device.snCode'),
          colProps: {
            xl: 7,
            xxl: 7,
          },
        },
        {
          field: 'incrementTypeId',
          component: 'ApiSelect',
          label: t('routes.equity.Type'),
          componentProps: {
            maxLength: 50,
            api: async function () {
              const list = await dincrementList();
              return list.map((ele) => {
                return { name: t(`routes.finance.equityType.${ele.validTimeType}`), value: ele.id };
              });
            },
            numberToString: true,
            labelField: 'name',
            valueField: 'value',
            immediate: true,
          },
          colProps: {
            xl: 7,
            xxl: 7,
          },
        },
        {
          field: 'operationUserName',
          component: 'Input',
          label: t('routes.equity.operationUserName'),
          colProps: {
            xl: 7,
            xxl: 7,
          },
        },
        {
          field: 'timeList',
          label: t('routes.equity.operationTime'),
          component: 'RangePicker',
          componentProps: {
            maxLength: 100,
            format: 'YYYY-MM-DD',
            valueFormat: 'YYYY-MM-DD',
            showTime: true,
          },
          colProps: {
            xl: 7,
            xxl: 7,
          },
        },
      ],
    };
    const [registerTable, { reload }] = useTable({
      api: cameraIncrementLog,
      columns: columns,
      useSearchForm: true,
      formConfig: searchForm,
      showTableSetting: true,
      showIndexColumn: false,
      rowKey: 'id',
      beforeFetch: (T) => {
        if (T.ctivated) {
          T.activatedStartTime = T.ctivated[0];
          T.activatedEndTime = T.ctivated[1];
        }
        return T;
      },
      fetchSetting: {
        pageField: 'pageNum',
        sizeField: 'pageSize',
        listField: 'list',
        totalField: 'total',
      },
      canResize: false,
    });
    return {
      registerTable,
      reload,
      getCheckPerm,
    };
  },
});
</script>
<style lang="less" scoped>
.desc-wrap-BasicTable {
  background-color: #f0f2f5;
  .vben-basic-table-form-container {
    padding: 0;
  }
}
</style>
