gaoluyang
11 小时以前 a2d9fcb259621829bf4ec9680b5dbeac95ab5805
src/views/crm/salesTarget/analysis/data.ts
@@ -4,6 +4,25 @@
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { SALES_TARGET_PERIOD_TYPE } from '../data';
/**
 * 按周期类型算当前周期值:年度 2026 / 季度 2026-Q4 / 月度 2026-10。
 * 达成分析打开时默认落在「当前季度」,与销售目标的演示数据周期一致。
 */
function currentPeriodValue(periodType?: number): string {
  const now = new Date();
  const year = now.getFullYear();
  const month = now.getMonth() + 1;
  if (periodType === SALES_TARGET_PERIOD_TYPE.YEAR) {
    return `${year}`;
  }
  if (periodType === SALES_TARGET_PERIOD_TYPE.MONTH) {
    return `${year}-${String(month).padStart(2, '0')}`;
  }
  return `${year}-Q${Math.ceil(month / 3)}`;
}
/** 达成分析的查询表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
@@ -12,11 +31,18 @@
      label: '周期类型',
      component: 'Select',
      rules: 'required',
      componentProps: {
        options: getDictOptions(DICT_TYPE.CRM_SALES_TARGET_PERIOD_TYPE, 'number'),
      componentProps: (_values, form) => ({
        options: getDictOptions(
          DICT_TYPE.CRM_SALES_TARGET_PERIOD_TYPE,
          'number',
        ),
        placeholder: '请选择周期类型',
      },
      defaultValue: 1,
        // 周期类型一变就把周期值换成当前对应周期,避免留在上一个类型的值上查不到数据
        onChange: (value: number) => {
          form.setFieldValue('periodValue', currentPeriodValue(value));
        },
      }),
      defaultValue: SALES_TARGET_PERIOD_TYPE.QUARTER,
    },
    {
      fieldName: 'periodValue',
@@ -26,7 +52,7 @@
      componentProps: {
        placeholder: '如 2026 / 2026-Q1 / 2026-07',
      },
      defaultValue: new Date().getFullYear().toString(),
      defaultValue: currentPeriodValue(SALES_TARGET_PERIOD_TYPE.QUARTER),
    },
    {
      fieldName: 'targetDimension',