<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 record.operationType?t('routes.equity.operation.1'):t('routes.equity.operation.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 }) {
          return record.validTimeType==0 ?t('routes.equity.equityType.0'):record.validTimeType==1? t('routes.equity.equityType.3') : t('routes.device.NoBind');
        },
      },
      {
        title: t('routes.equity.incrementId'),
        dataIndex: 'incrementId',
        width: 180,
        // customRender({ record }) {
        //   return record.userName ? record.userName : '-';
        // },
      },
    ];
    const searchForm: Partial<FormProps> = {
      labelWidth: 120,
      autoAdvancedLine: 1,
      actionColOptions: {
        span: 24,
      },
      schemas: [
        {
          field: 'snCode',
          component: 'Input',
          label: t('routes.device.snCode'),
          colProps: {
            xl: 7,
            xxl: 7,
          },
        },
        {
          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',
              }
            ],
          },
        },
        {
          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>
