372 lines
13 KiB
Vue
372 lines
13 KiB
Vue
<template>
|
||
<div class="page-container manual-calendar-page">
|
||
<section class="panel manual-calendar-panel">
|
||
<div class="panel-top"
|
||
><h2 class="title-bar-heading">{{ title }}</h2
|
||
><span class="manual-subtitle">每日手工安排 · 每条计划计 1 车次</span></div
|
||
>
|
||
<div class="manual-controls">
|
||
<el-button :disabled="month === '1900-01'" @click="month = shiftMonth(month, -1)"
|
||
><el-icon><ArrowLeft /></el-icon>上月</el-button
|
||
>
|
||
<el-date-picker
|
||
popper-class="manual-calendar-popper"
|
||
v-model="month"
|
||
type="month"
|
||
value-format="YYYY-MM"
|
||
format="YYYY年MM月"
|
||
:clearable="false"
|
||
:disabled-date="disabledDate"
|
||
aria-label="查看月份"
|
||
/>
|
||
<el-button :disabled="month === '2100-12'" @click="month = shiftMonth(month, 1)"
|
||
><el-icon><ArrowRight /></el-icon>下月</el-button
|
||
>
|
||
<el-button @click="locate(dateKey(new Date()))"
|
||
><el-icon><Calendar /></el-icon>今天</el-button
|
||
>
|
||
<el-select
|
||
popper-class="manual-calendar-popper"
|
||
v-model="vehicle"
|
||
filterable
|
||
clearable
|
||
placeholder="全部车辆"
|
||
aria-label="车辆筛选"
|
||
>
|
||
<el-option
|
||
v-for="option in filterOptions"
|
||
:key="option.key"
|
||
:label="option.name"
|
||
:value="option.key"
|
||
/>
|
||
</el-select>
|
||
<el-button
|
||
class="manual-print-button"
|
||
:disabled="loading || !!error || sessionChanged"
|
||
@click="print"
|
||
><el-icon><Printer /></el-icon>打印日历</el-button
|
||
>
|
||
</div>
|
||
<div v-if="sessionChanged" class="manual-message" role="alert"
|
||
>登录信息已变更,请重新打开页面。</div
|
||
>
|
||
<div v-else-if="error" class="manual-message" role="alert"
|
||
>{{ error
|
||
}}<el-button @click="load"
|
||
><el-icon><Refresh /></el-icon>重试</el-button
|
||
></div
|
||
>
|
||
<p v-else-if="!loading && !records.length" class="manual-message"
|
||
>本月暂无手工派车计划,可点击日期标题栏中的「新增」填写。</p
|
||
>
|
||
<div v-if="optionsError" class="manual-message" role="alert"
|
||
>{{ optionsError
|
||
}}<el-button @click="loadOptions"
|
||
><el-icon><Refresh /></el-icon>重试选项</el-button
|
||
></div
|
||
>
|
||
<div ref="calendarEl" v-loading="loading" class="manual-calendar-scroll">
|
||
<div class="manual-weekdays"
|
||
><span v-for="day in weekdays" :key="day">{{ day }}</span></div
|
||
>
|
||
<div class="manual-calendar-grid">
|
||
<article
|
||
v-for="day in days"
|
||
:key="day.date"
|
||
:data-date="day.date"
|
||
class="manual-day"
|
||
:class="{
|
||
outside: !day.inMonth,
|
||
today: day.date === dateKey(new Date()),
|
||
selected: day.date === selectedDate
|
||
}"
|
||
>
|
||
<div class="manual-day-heading">
|
||
<div class="manual-day-title">
|
||
<strong>{{ Number(day.date.slice(-2)) }}</strong>
|
||
</div>
|
||
<div v-if="day.inMonth" class="manual-day-actions">
|
||
<el-button
|
||
v-if="canManage"
|
||
size="small"
|
||
text
|
||
:disabled="sessionChanged || saving"
|
||
:aria-label="`新增${day.date}派车计划`"
|
||
@click="openCreate(day.date)"
|
||
><el-icon><Plus /></el-icon>新增</el-button
|
||
>
|
||
<el-button
|
||
size="small"
|
||
text
|
||
:disabled="!day.rows.length || loading || !!error"
|
||
:aria-label="`复制${day.date}派车计划`"
|
||
@click="copyDay(day.date, day.rows)"
|
||
><el-icon><CopyDocument /></el-icon>复制</el-button
|
||
>
|
||
</div>
|
||
</div>
|
||
<template v-if="day.inMonth">
|
||
<ManualDayContent v-if="day.rows.length" :day="day" @select="viewRow = $event" />
|
||
<p v-if="!day.rows.length" class="manual-empty">{{
|
||
vehicle ? '无匹配计划' : '暂无计划'
|
||
}}</p>
|
||
</template>
|
||
</article>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<el-dialog
|
||
v-model="editorOpen"
|
||
:title="editingId ? '编辑派车计划' : '新增派车计划'"
|
||
width="640px"
|
||
class="dialog-form-layout manual-calendar-dialog"
|
||
:close-on-click-modal="false"
|
||
:close-on-press-escape="!saving"
|
||
:show-close="!saving"
|
||
destroy-on-close
|
||
>
|
||
<el-form
|
||
data-testid="manual-editor"
|
||
label-position="top"
|
||
:disabled="saving || sessionChanged"
|
||
@submit.prevent="save"
|
||
>
|
||
<div class="form-grid-2">
|
||
<el-form-item label="派车日期" required
|
||
><el-date-picker
|
||
popper-class="manual-calendar-popper"
|
||
v-model="draft.dispatchDate"
|
||
type="date"
|
||
value-format="YYYY-MM-DD"
|
||
:clearable="false"
|
||
:disabled-date="disabledDate"
|
||
aria-label="派车日期"
|
||
/></el-form-item>
|
||
<el-form-item label="车牌号" required
|
||
><el-select
|
||
popper-class="manual-calendar-popper"
|
||
v-model="draft.vehicleId"
|
||
filterable
|
||
placeholder="选择车辆"
|
||
aria-label="车牌号"
|
||
:loading="optionsLoading"
|
||
><el-option
|
||
v-for="row in vehicles"
|
||
:key="row.id"
|
||
:value="row.id"
|
||
:label="row.licensePlate" /></el-select
|
||
></el-form-item>
|
||
<el-form-item label="产品名称" required
|
||
><el-select
|
||
popper-class="manual-calendar-popper"
|
||
v-model="draft.productId"
|
||
filterable
|
||
placeholder="选择产品"
|
||
aria-label="产品名称"
|
||
:loading="optionsLoading"
|
||
><el-option
|
||
v-for="row in products"
|
||
:key="row.id"
|
||
:value="row.id"
|
||
:label="row.productName" /></el-select
|
||
></el-form-item>
|
||
<el-form-item label="数量"
|
||
><el-input v-model="draft.quantity" maxlength="15" placeholder="选填" aria-label="数量"
|
||
><template #append>吨</template></el-input
|
||
></el-form-item
|
||
>
|
||
<el-form-item label="始发地"
|
||
><el-input v-model="draft.origin" maxlength="255" placeholder="请输入始发地"
|
||
/></el-form-item>
|
||
<el-form-item label="目的地"
|
||
><el-input v-model="draft.destination" maxlength="255" placeholder="请输入目的地"
|
||
/></el-form-item>
|
||
<el-form-item v-if="calendarKind === 'site'" label="单据类型" class="form-col-span-2">
|
||
<el-select
|
||
v-model="draft.documentType"
|
||
filterable
|
||
allow-create
|
||
default-first-option
|
||
clearable
|
||
popper-class="manual-calendar-popper"
|
||
placeholder="选择或输入单据类型"
|
||
aria-label="单据类型"
|
||
>
|
||
<el-option label="入库计划" value="入库计划" />
|
||
<el-option label="出库计划" value="出库计划" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="备注" class="form-col-span-2"
|
||
><el-input
|
||
v-model="draft.remark"
|
||
type="textarea"
|
||
maxlength="500"
|
||
show-word-limit
|
||
:rows="3"
|
||
/></el-form-item>
|
||
</div>
|
||
<div v-if="optionsError" class="manual-message" role="alert"
|
||
>{{ optionsError
|
||
}}<el-button @click="loadOptions"
|
||
><el-icon><Refresh /></el-icon>重试选项</el-button
|
||
></div
|
||
>
|
||
<p v-if="formError" class="manual-form-error" role="alert">{{ formError }}</p>
|
||
<div class="manual-form-actions"
|
||
><el-button :disabled="saving" @click="editorOpen = false"
|
||
><el-icon><Close /></el-icon>取消</el-button
|
||
><el-button
|
||
type="primary"
|
||
:loading="saving"
|
||
:disabled="optionsLoading || !!optionsError"
|
||
native-type="submit"
|
||
><el-icon><Check /></el-icon>保存</el-button
|
||
></div
|
||
>
|
||
</el-form>
|
||
</el-dialog>
|
||
<SystemViewDialog
|
||
dialog-class="manual-calendar-theme"
|
||
v-model:visible="viewOpen"
|
||
title="派车计划详情"
|
||
:sections="viewSections"
|
||
width="720px"
|
||
>
|
||
<template #hero-actions
|
||
><template v-if="canManage && viewRow && !viewRow.sourceRecordId"
|
||
><el-button :disabled="saving" @click="editViewed"
|
||
><el-icon><Edit /></el-icon>编辑</el-button
|
||
><el-button type="danger" :disabled="saving" @click="deleteViewed"
|
||
><el-icon><Delete /></el-icon>删除</el-button
|
||
></template
|
||
></template
|
||
>
|
||
</SystemViewDialog>
|
||
</div>
|
||
</template>
|
||
<script setup lang="ts">
|
||
import {
|
||
Plus,
|
||
ArrowLeft,
|
||
ArrowRight,
|
||
Calendar,
|
||
Refresh,
|
||
Printer,
|
||
CopyDocument,
|
||
Close,
|
||
Check,
|
||
Edit,
|
||
Delete
|
||
} from '@element-plus/icons-vue'
|
||
import SystemViewDialog from '@/components/business/system-view-dialog/index.vue'
|
||
import type { DispatchCalendarKind, DispatchCalendarRecord } from '@/api/pl/dispatch-calendar'
|
||
import ManualDayContent from './ManualDayContent.vue'
|
||
import { useManualCalendar } from './useManualCalendar'
|
||
import { manualQuantityLabel } from './manual-model'
|
||
import { dateKey, shiftMonth } from './model'
|
||
import { printCalendarElement } from './print'
|
||
const props = withDefaults(
|
||
defineProps<{ calendarKind?: DispatchCalendarKind; title?: string }>(),
|
||
{ calendarKind: 'acid', title: '酸派车日历' }
|
||
)
|
||
const {
|
||
month,
|
||
vehicle,
|
||
selectedDate,
|
||
records,
|
||
vehicles,
|
||
products,
|
||
loading,
|
||
optionsLoading,
|
||
optionsError,
|
||
error,
|
||
sessionChanged,
|
||
canManage,
|
||
editorOpen,
|
||
editingId,
|
||
saving,
|
||
formError,
|
||
draft,
|
||
days,
|
||
filterOptions,
|
||
load,
|
||
loadOptions,
|
||
openCreate,
|
||
openEdit,
|
||
save,
|
||
remove,
|
||
copyDay,
|
||
locate
|
||
} = useManualCalendar(undefined, props.calendarKind)
|
||
const calendarEl = ref<HTMLElement>()
|
||
const weekdays = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
|
||
const viewRow = ref<DispatchCalendarRecord>()
|
||
const viewOpen = computed({
|
||
get: () => !!viewRow.value,
|
||
set: (v: boolean) => {
|
||
if (!v) viewRow.value = undefined
|
||
}
|
||
})
|
||
const viewSections = computed(() => [
|
||
{
|
||
title: '派车信息',
|
||
fields: viewRow.value
|
||
? [
|
||
{ label: '派车日期', value: viewRow.value.dispatchDate },
|
||
...(viewRow.value.sourceRecordId
|
||
? [{ label: '维护方式', value: '自动同步,请在来源派车日历修改或删除' }]
|
||
: []),
|
||
...(viewRow.value.calendarKind === 'site'
|
||
? [
|
||
{
|
||
label: '单据类型',
|
||
value: viewRow.value.documentType,
|
||
tagType: 'primary' as const
|
||
}
|
||
]
|
||
: []),
|
||
{ label: '车牌号', value: viewRow.value.licensePlate },
|
||
{ label: '产品名称', value: viewRow.value.productName },
|
||
{ label: '始发地', value: viewRow.value.origin },
|
||
{ label: '目的地', value: viewRow.value.destination },
|
||
{ label: '数量', value: manualQuantityLabel(viewRow.value.quantity) || '—' },
|
||
{ label: '备注', value: viewRow.value.remark }
|
||
]
|
||
: []
|
||
}
|
||
])
|
||
const disabledDate = (date: Date) => date.getFullYear() < 1900 || date.getFullYear() > 2100
|
||
function editViewed() {
|
||
if (viewRow.value) openEdit(viewRow.value)
|
||
viewRow.value = undefined
|
||
}
|
||
async function deleteViewed() {
|
||
if (!viewRow.value) return
|
||
const row = viewRow.value
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确定删除 ${row.dispatchDate} ${row.licensePlate} 的这条派车计划?`,
|
||
'删除派车计划',
|
||
{ type: 'warning' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
if (await remove(row)) viewRow.value = undefined
|
||
}
|
||
function print() {
|
||
if (calendarEl.value) printCalendarElement(calendarEl.value, `${month.value} ${props.title}`)
|
||
}
|
||
watch([selectedDate, loading], async () => {
|
||
await nextTick()
|
||
if (!loading.value && !error.value)
|
||
calendarEl.value
|
||
?.querySelector(`[data-date="${selectedDate.value}"]`)
|
||
?.scrollIntoView({ block: 'nearest' })
|
||
})
|
||
watch(sessionChanged, () => {
|
||
viewRow.value = undefined
|
||
})
|
||
</script>
|
||
<style lang="scss" src="./manual-calendar.scss"></style>
|