data.tsx 10.1 KB
import { InputNumber, Tag } from 'ant-design-vue';
import { BasicColumn } from '@/components/Table';
import { func } from 'vue-types';
import { h, ref } from 'vue';
import { FilePptOutlined } from '@ant-design/icons-vue';
import axios from 'axios';
import { queryNoOptions } from '/@/api/project/order';
import { useOrderStoreWithOut } from '/@/store/modules/order';
import { useOrderInfo } from '/@/hooks/component/order';
import { useUserStoreWithOut } from '/@/store/modules/user';

const userStore = useUserStoreWithOut();
// export const COLUMNS = [
//   {
//     title: '客户编码',
//     dataIndex: 'settingValue',
//     width: 150,
//   },
//   {
//     title: '利润率',
//     dataIndex: 'relationValue',
//     width: 150,
//     editComponent: 'InputNumber',
//     editRow: true,
//     scopedSlots: { customRender: 'name' }
//   },
// ];
const innerNoOptions = ref([]);
const projectNoOptions = ref([]);
const orderStore = useOrderStoreWithOut();
const {
  customerCode,
  productionDepartment,
} = useOrderInfo(orderStore);
export const searchFormSchema = [
  {
    field: 'customerCode',
    label: '客户编码',
    component: 'Select',
    colProps: { span: 8 },

    componentProps: {
      options: customerCode,
      showSearch: true,
      mode: 'multiple',
    },
  },
  {
    field: 'projectNo',
    label: '项目号',
    component: 'Select',
    colProps: { span: 8 },

    componentProps: {
      options: projectNoOptions,
      showSearch: true,
      mode: 'multiple',
      onSearch: async (value: any) => {
        projectNoOptions.value = await queryNoOptions('projectNo', value);
      },
      // onSearch: async (value: any) => {
      //   projectNoOptions.value = await queryNoOptions('projectNo', value);
      // },
    },
  },
  // {
  //   field: 'productionDepartment',
  //   label: '生产科',
  //   component: 'Select',
  //   colProps: { span: 8 },

  //   componentProps: {
  //     mode: 'multiple',

  //     options: productionDepartment,
  //     showSearch: true,
  //   },
  // },
  // {
  //   field: 'innerNo',
  //   label: '内部编号',
  //   component: 'Select',
  //   colProps: { span: 8 },

  //   componentProps: {
  //     options: innerNoOptions,
  //     showSearch: true,
  //     mode: 'multiple',
  //     onSearch: async (value: any) => {
  //       innerNoOptions.value = await queryNoOptions('innerNo', value);
  //     },
  //   },
  // },
]
export const COLUMNS = [
  {
    title: '客户编码',
    dataIndex: 'customerCode',
    width: 150,
  },
  {
    title: '项目号',
    dataIndex: 'projectNoPrefix',
    width: 100,
  },
  {
    title: '订单总数量',
    dataIndex: 'orderCount',
    width: 120,
    customRender: (column) => {
      return column.record?.orderCount;
    },
  },
  {
    title: '客户总金额¥',
    width: 150,
    dataIndex: 'customerTotalPrice',
    customRender: (column) => {
      return column.record?.customerRmbTotalPrice?.toFixed(2);
    },
  },
  {
    title: '客户总金额$',
    width: 150,
    dataIndex: 'customerTotalPrice',
    customRender: (column) => {
      return column.record?.customerTotalPrice?.toFixed(2);
    },
  },
  {
    title: '生产科总价合计价¥',
    dataIndex: 'productionDepartmentTotalPrice',
    width: 160,
    customRender: (column) => {
      return column.record?.productionDepartmentTotalPrice?.toFixed(2);
    },
  },
  {
    title: '包装费用合计¥',
    dataIndex: 'packetTotalPrice',
    width: 150,
    customRender: (column) => {
      return column.record?.packetRmbTotalPrice?.toFixed(2);
    },
  },
  {
    title: '包装费用合计$',
    dataIndex: 'packetTotalPrice',
    width: 150,
    customRender: (column) => {
      return column.record?.packetTotalPrice?.toFixed(2);
    },
  },
  {
    title: '研发复制费合计¥',
    dataIndex: 'developmentCopyRmbTotalPrice',
    width: 160,
    customRender: (column) => {
      return column.record?.developmentCopyRmbTotalPrice?.toFixed(2);
    },
  },
  {
    title: '固定成本¥',
    dataIndex: 'fixedCost',
    width: 120,
    customRender: (column) => {
      return column.record?.fixedCost?.toFixed(2);
    },
  },
  {
    title: '西班牙提成¥',
    dataIndex: 'spainRmbCommission',
    width: 150,
    customRender: (column) => {
      return column.record?.spainRmbCommission?.toFixed(2);
    },
  },
  {
    title: '已发提成¥',
    dataIndex: 'spainPaidRmbCommission',
    width: 120,
    customRender: (column) => {
      return column.record?.spainPaidRmbCommission?.toFixed(2);
    },
  },
  {
    title: '未发提成¥',
    dataIndex: 'spainUnpaidRmbCommission',
    width: 120,
    customRender: (column) => {
      return column.record?.spainUnpaidRmbCommission?.toFixed(2);
    },
  },
  {
    title: '中国团队提成¥',
    dataIndex: 'rmbCommission',
    width: 150,
    customRender: (column) => {
      return column.record?.rmbCommission?.toFixed(2);
    },
  },
  {
    title: '已发提成¥',
    dataIndex: 'paidRmbCommission',
    width: 120,
    customRender: (column) => {
      return column.record?.paidRmbCommission?.toFixed(2);
    },
  },
  {
    title: '未发提成¥',
    dataIndex: 'unpaidRmbCommission',
    width: 120,
    customRender: (column) => {
      return column.record?.unpaidRmbCommission?.toFixed(2);
    },
  },
  {
    title: '支出合计¥',
    dataIndex: 'rmbTotalExpense',
    width: 120,
    customRender: (column) => {
      return column.record?.rmbTotalExpense?.toFixed(2);
    },
  },
  {
    title: '毛利润¥',
    dataIndex: 'profit',
    width: 120,
    customRender: (column) => {
      return column.record?.profit?.toFixed(2);
    },
  },
  {
    title: '毛利率',
    dataIndex: 'profitRate',
    width: 120,
    customRender: (column) => {
      if (column.record?.profitRate) {
        return (column.record?.profitRate * 100).toFixed(2) + '%';
      }
      return column.record?.profitRate?.toFixed(2);
    },
  },
  {
    title: '研发贸易净利润¥',
    dataIndex: 'developmentProfit',
    width: 160,
    customRender: (column) => {
      return column.record?.developmentProfit?.toFixed(2);
    },
  },
  {
    title: '净利润率',
    dataIndex: 'developmentProfitRate',
    width: 120,
    customRender: (column) => {
      if (column.record?.developmentProfitRate) {
        return (column.record?.developmentProfitRate * 100).toFixed(2) + '%';
      }
      return column.record?.developmentProfitRate?.toFixed(2);
    },
  },
  {
    title: '包装费用合计¥',
    dataIndex: 'packetRmbTotalPrice',
    width: 150,
    customRender: (column) => {
      return column.record?.packetRmbTotalPrice?.toFixed(2);
    },
  },
  {
    title: '包装费用实际金额¥',
    dataIndex: 'packetActualRmbTotalPrice',
    width: 160,
    customRender: (column) => {
      return column.record?.packetActualRmbTotalPrice?.toFixed(2);
    },
  },
  {
    title: '实际跟单单价¥',
    dataIndex: 'actualOrderRmbPrice',
    width: 160,
    customRender: (column) => {
      return column.record?.actualOrderRmbPrice?.toFixed(2);
    },
  },
  {
    title: '实际跟单单价折算美金¥',
    dataIndex: 'actualOrderPrice',
    width: 190,
    customRender: (column) => {
      return column.record?.actualOrderPrice?.toFixed(2);
    },
  },
  {
    title: '包装费用收益¥',
    dataIndex: 'packetProfitRmbPrice',
    width: 150,
    customRender: (column) => {
      return column.record?.packetProfitRmbPrice?.toFixed(2);
    },
  },
  {
    title: '综合收益¥',
    dataIndex: 'comprehensiveProfit',
    width: 120,
    customRender: (column) => {
      return column.record?.comprehensiveProfit?.toFixed(2);
    },
  },
  {
    title: '文件',
    dataIndex: 'fileUrl',
    width: 120,
    customRender: (column) => {
      // 构造符合 API 要求的参数
      // await exportAnalysis({ ids: ids });
      const handleClick = () => {
        const token = userStore.getToken;
        axios
          .post(
            '/basic-api/project/businessProfit/export',
            {},  // 请求体为空
            {
              params: {
                projectNoPrefix: column.record.projectNoPrefix,  // 将参数放到查询字符串中
              },
              headers: {
                Authorization: `${token}`,  // 去掉引号
              },
              responseType: 'blob',  // 设置响应类型为 'blob'
            }
          )
          .then((response) => {
            // 创建一个 Blob 对象来保存二进制数据
            const blob = new Blob([response.data], { type: 'application/zip' });
            const getFormattedDate = (): string => {
              const date = new Date();

              const year = date.getFullYear();
              const month = String(date.getMonth() + 1).padStart(2, '0');
              const day = String(date.getDate()).padStart(2, '0');

              const hours = String(date.getHours()).padStart(2, '0');
              const minutes = String(date.getMinutes()).padStart(2, '0');
              const seconds = String(date.getSeconds()).padStart(2, '0');

              return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
            };
            const date = getFormattedDate();
            // 创建一个链接元素用于下载
            const link = document.createElement('a');
            link.href = window.URL.createObjectURL(blob);
            link.download = `${date}.xlsx`; // 你可以为文件命名
            document.body.appendChild(link);
            link.click(); // 自动点击链接,触发下载
            document.body.removeChild(link); // 下载完成后移除链接
          })
          .catch((error) => {
            console.error(error);
          });
      };
      return <FilePptOutlined style="font-size:25px" onClick={() => handleClick()} />;
    },
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 120,
    customRender: (column) => {
      if (column.record?.developmentStatus === null || column.record?.developmentStatus === -1) {
        return '未完成';
      } else if (column.record?.developmentStatus === 0) {
        return '待审核';
      } else if (column.record?.developmentStatus === 1) {
        return '已审核';
      }
    },
  },
];