| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import assert from 'node:assert/strict'
- import test from 'node:test'
- import type { Plan } from '../src/api/pl'
- import { toCalendarTrips, filterVehicleScope } from '../src/views/pl/dispatch-calendar/model'
- import { calendarCopyTitle, calendarCopyText } from '../src/views/pl/dispatch-calendar/copy'
- test('复制标题按点击当天计算,支持跨月、跨年及过去日期', () => {
- const today = new Date(2026, 9, 25, 23, 59)
- assert.equal(calendarCopyTitle('2026-10-26', today), '明日计划 10.26')
- assert.equal(calendarCopyTitle('2026-10-27', today), '后日计划 10.27')
- assert.equal(calendarCopyTitle('2026-10-28', today), '运输计划 10.28')
- assert.equal(calendarCopyTitle('2026-10-25', today), '运输计划 10.25')
- assert.equal(calendarCopyTitle('2026-10-24', today), '运输计划 10.24')
- assert.equal(calendarCopyTitle('2027-01-01', new Date(2026, 11, 31)), '明日计划 01.01')
- assert.equal(calendarCopyTitle('2024-03-01', new Date(2024, 1, 28)), '后日计划 03.01')
- })
- const plan = (id: string, override: Partial<Plan> = {}): Plan =>
- ({
- id,
- planNo: id,
- followStatus: 'pending',
- planDate: '2026-10-26',
- licensePlate: '皖HA3690',
- vehicleId: 'own',
- calendarVehicleType: 'self',
- load: { customerName: '安庆山峡' },
- deliveries: [
- { customerName: '安徽云栋', products: [{ productId: 'acid', productName: 'cp酸' }] }
- ],
- ...override
- }) as Plan
- test('复制一车一行,合并任务保留数量,使用简称并带真实备注', () => {
- const plans = [
- plan('p1', { remark: ' 下午待定\n请联系 ' }),
- plan('p2'),
- plan('p3', {
- licensePlate: '皖H10291',
- vehicleId: 'carrier',
- calendarVehicleType: 'carrier'
- })
- ]
- const trips = toCalendarTrips(plans, '2026-10')
- assert.equal(
- calendarCopyText('2026-10-26', filterVehicleScope(trips), plans, new Date(2026, 9, 25)),
- '明日计划 10.26\n• 皖HA3690 / cp酸 山峡 - 云栋(2车次) / 下午待定 请联系'
- )
- assert.match(calendarCopyText('2026-10-26', trips, plans), /\n• 皖H10291 \/ cp酸 山峡 - 云栋/)
- assert.equal(calendarCopyText('2026-10-27', trips, plans), '')
- })
- test('同一车辆多个送货段分别显示,不串联收货方,重复段保留段次数', () => {
- const plans = [
- plan('p1', {
- deliveries: [
- { customerName: '甲', products: [{ productId: 'acid', productName: '98酸' }] },
- { customerName: '甲', products: [{ productId: 'acid', productName: '98酸' }] },
- { customerName: '乙', products: [{ productId: 'base', productName: '液碱' }] }
- ]
- })
- ]
- assert.equal(
- calendarCopyText('2026-10-26', toCalendarTrips(plans, '2026-10'), plans, new Date(2026, 9, 25)),
- '明日计划 10.26\n• 皖HA3690 / 98酸 山峡 - 甲(1车次 / 2段次) / 液碱 山峡 - 乙'
- )
- })
|