import { dateUtil } from '/nerv-lib/util/date-util';
import data from './mock.json';
import { cloneDeep } from 'lodash-es';
import { ref } from 'vue';
const columns = [
  {
    title: '能源种类',
    dataIndex: '能源种类',
  },
  {
    title: '计量单位',
    dataIndex: '计量单位',
  },
  {
    title: '速算系数',
    dataIndex: '速算系数',
  },
  {
    title: '全年',
    dataIndex: '全年',
  },
  {
    title: '1月',
    dataIndex: '1月',
  },
  {
    title: '2月',
    dataIndex: '2月',
  },
  {
    title: '3月',
    dataIndex: '3月',
  },
  {
    title: '4月',
    dataIndex: '4月',
  },
  {
    title: '5月',
    dataIndex: '5月',
  },
  {
    title: '6月',
    dataIndex: '6月',
  },
  {
    title: '7月',
    dataIndex: '7月',
  },
  {
    title: '8月',
    dataIndex: '8月',
  },
  {
    title: '9月',
    dataIndex: '9月',
  },
  {
    title: '10月',
    dataIndex: '10月',
  },
  {
    title: '11月',
    dataIndex: '11月',
  },
  {
    title: '12月',
    dataIndex: '12月',
  },
];
const formConfig = {
  schemas: [
    {
      field: 'time',
      label: '年份',
      component: 'NsDatePicker',
      componentProps: {
        picker: 'year',
        valueFormat: 'YYYY-MM-DD',
      },
    },
  ],
  params: {},
};

const mockData = ref(cloneDeep(data.dataSource));

const doWnload = (url) => {
  const a = document.createElement('a');
  document.body.appendChild(a);
  a.href = encodeURI(url);
  //设置下载的文件名
  // a.download = fileName.value;
  //触发a标签的点击事件，进行下载
  a.click();
};
export const tableConfig1 = (el, fileDownRef) => {
  return {
    title: '能耗',
    value: mockData.value,
    rowSelection: null,
    columns,
    formConfig,
    headerActions: [
      {
        label: '新增',
        name: 'groupEdit',
        type: 'primary',
        handle: (a, b) => {
          el.value.toggle();
        },
      },
      {
        label: '导入',
        name: 'groupImport',
        type: 'primary',
        extra: {
          // api: props.postImportApi, // 导入接口名
          title: '设备信息', // 弹窗title
          templateName: 'whiteListUser', // 所使用的文件名称
          indexName: '设备id', // 匹配类型字段
          message: [
            { label: '1、若必填项未填写，则不能进行导入操作' },
            { label: `2、当重复时，则更新数据。` },
            { label: '3、数据将从模版的第五行进行导入。' },
            { label: '4、文件导入勿超过5MB。' },
          ],
        },
      },
      {
        label: '导出',
        name: 'groupExports',
        type: 'primary',
        handle: () => {
          doWnload('/hx-ai-intelligent/asset/file/whiteListUser.xlsx');
        },
      },

      {
        label: '模板下载',
        name: 'groupTemDownload',
        type: 'primary',
        handle: () => {
          // http.get('/asset/file/whiteListUser.xlsx');
          doWnload('/hx-ai-intelligent/asset/file/whiteListUser.xlsx');
        },
      },
      {
        label: '上传凭证',
        name: 'groupImport',
        type: 'primary',
        extra: {
          // api: props.postImportApi, // 导入接口名
          title: '设备信息', // 弹窗title
          templateName: 'whiteListUser', // 所使用的文件名称
          indexName: '设备id', // 匹配类型字段
          message: [
            { label: '1、若必填项未填写，则不能进行导入操作' },
            { label: `2、当重复时，则更新数据。` },
            { label: '3、数据将从模版的第五行进行导入。' },
            { label: '4、文件导入勿超过5MB。' },
          ],
        },
      },
      {
        label: '凭证下载',
        name: 'groupTemDownload',
        type: 'primary',
        handle: () => {
          fileDownRef.value.toggle();
        },
      },
    ],
    columnActions: {
      title: '操作',
      actions: [
        {
          label: '编辑',
          name: 'edit',
          handle: () => {
            mockData.value.splice(0, 1);
          },
        },
        {
          label: '删除',
          name: 'FeedBackDetail',
          dynamicParams: ['uuid', 'appealType'],
          confirm: true,
          handle: () => {
            mockData.value.splice(0, 1);
          },
        },
      ],
    },
  };
};
export const tableConfig2 = {
  title: '碳排',
  value: data.dataSource,
  rowSelection: null,
  columns,
  formConfig,
  headerActions: [
    {
      label: '导出',
      name: 'groupTemDownload',
      type: 'primary',
      handle: () => {
        // http.get('/asset/file/whiteListUser.xlsx');
        doWnload('/hx-ai-intelligent/asset/file/whiteListUser.xlsx');
      },
    },
  ],
};
export const tableConfig3 = {
  title: '标煤',
  value: data.dataSource,
  rowSelection: null,
  columns,
  formConfig,
  headerActions: [
    {
      label: '导出',
      name: 'groupTemDownload',
      type: 'primary',
      handle: () => {
        // http.get('/asset/file/whiteListUser.xlsx');
        doWnload('/hx-ai-intelligent/asset/file/whiteListUser.xlsx');
      },
    },
  ],
};
