Commit 0f73a9bb by Lin

feat: 在 FormAdd 组件中添加提交事件,允许将新数据提交到接待中心

- 更新 center.uvue 以处理 FormAdd 提交的数据并将其追加到客户录入列表
- 重命名获取模拟数据的函数为 getInitialEntryList,增强代码可读性
- 新增日期解析函数 parseArrivalDateToTimestamp,确保到店时间的正确处理
1 parent 75ea20e7
......@@ -108,7 +108,7 @@
<script setup lang="uts">
import { ref, onMounted } from 'vue'
import type { UnCascaderOption, UnPickerColumn, UnPickerColumnItem, UnPickerConfirmEvent } from '@/uni_modules/uview-unix'
import type { UnCascaderConfirmEvent, UnCascaderOption, UnPickerColumn, UnPickerColumnItem, UnPickerConfirmEvent } from '@/uni_modules/uview-unix'
import { saveRecCustomer } from '@/api/receiption.uts'
// 使用窗口实际尺寸,避免 100% 导致溢出
......@@ -139,6 +139,7 @@ function onPopupOpen(): void {
const emit = defineEmits<{
'close': []
'submit': [entry: UTSJSONObject]
}>()
// 表单数据:扁平结构,避免 UTS 对象字面量类型限制
......@@ -238,10 +239,9 @@ function onReceptionScenarioConfirm(e: UnPickerConfirmEvent): void {
}
}
function onBrandCascaderConfirm(e: any): void {
function onBrandCascaderConfirm(e: UnCascaderConfirmEvent): void {
brandCascaderShow.value = false
const evt = e as UTSJSONObject
const textArr = evt['text'] as string[] | null
const textArr = e.text
if (textArr != null && textArr.length > 0) {
formData.value.brandModel = textArr.join(' ')
}
......@@ -276,13 +276,10 @@ function handleSubmit(): void {
customerTags: formData.value.customerTags,
arrivalDate: formData.value.visitDate
}
saveRecCustomer(params).then(() => {
uni.showToast({ title: '提交成功' })
resetForm()
emit('close')
}).catch(() => {
uni.showToast({ title: '提交失败', icon: 'none' })
})
emit('submit', params)
uni.showToast({ title: '提交成功' })
resetForm()
emit('close')
}
</script>
......
......@@ -342,7 +342,7 @@
</scroll-view>
<un-picker :show="show" :columns="columns" @close="onClose" @cancel="onClose" @confirm="onConfirm" />
<!-- 预录信息:由 FormAdd 组件统一维护 -->
<FormAdd :show="preEntryPopupVisible" @close="onPreEntryClose" />
<FormAdd :show="preEntryPopupVisible" @close="onPreEntryClose" @submit="onPreEntrySubmit" />
</template>
<script setup lang="uts">
......@@ -386,8 +386,8 @@ const MOCK_CUSTOMER_LIST: UTSJSONObject[] = [
]
// 客户录入专用模拟数据:车主电话、品牌车型、客户标签、到店时间(arrivalTime 为时间戳)
// 运行时根据当前日期生成,保证「今日到店」筛选有数据
function getMockEntryList(): UTSJSONObject[] {
// 运行时根据当前日期生成,保证「今日到店」筛选有数据;FormAdd 提交的新数据会追加到此列表
function getInitialEntryList(): UTSJSONObject[] {
const now = new Date()
const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime()
const oneDay = 24 * 60 * 60 * 1000
......@@ -402,6 +402,8 @@ function getMockEntryList(): UTSJSONObject[] {
] as UTSJSONObject[]
}
const entryList = ref<UTSJSONObject[]>(getInitialEntryList())
const show = ref(false)
// 预录信息弹出层显示状态
const preEntryPopupVisible = ref(false)
......@@ -510,6 +512,42 @@ function getTs(data: UTSJSONObject, key: string): number | null {
return isNaN(n) ? null : n
}
// 将 YYYY-MM-DD 转为当日 12:00 的本地时间戳
function parseArrivalDateToTimestamp(dateStr: string): number {
if (dateStr == null || dateStr == '') {
return new Date().getTime()
}
const parts = dateStr.split('-')
if (parts.length < 3) { return new Date().getTime() }
const y = parseInt(parts[0], 10)
const m = parseInt(parts[1], 10) - 1
const d = parseInt(parts[2], 10)
if (isNaN(y) || isNaN(m) || isNaN(d)) { return new Date().getTime() }
return new Date(y, m, d, 12, 0, 0).getTime()
}
// 预录信息提交:将 FormAdd 提交的数据追加到 entryList
function onPreEntrySubmit(entry: UTSJSONObject): void {
const list = entryList.value
let maxId = 100
let i = 0
while (i < list.length) {
const id = getNum(list[i], 'id')
if (id > maxId) { maxId = id }
i++
}
const dateStr = getStr(entry, 'arrivalDate')
const newEntry: UTSJSONObject = {
id: maxId + 1,
ownerName: getStr(entry, 'ownerName'),
ownerPhone: getStr(entry, 'ownerPhone'),
brandModel: getStr(entry, 'brandModel'),
customerTags: getStr(entry, 'customerTags'),
arrivalTime: parseArrivalDateToTimestamp(dateStr)
}
entryList.value = [newEntry].concat(list)
}
// 是否有接待时间(startTime/endTime 或 receptionTime 有值则视为已复盘)
function hasReceptionTime(item: UTSJSONObject): boolean {
const start = getTs(item, 'startTime')
......@@ -536,7 +574,7 @@ function isToday(ts: number | null): boolean {
// 客户录入列表:按 今日到店/全部客户 筛选
const filteredEntryList = computed((): UTSJSONObject[] => {
const list = getMockEntryList()
const list = entryList.value
const arr: UTSJSONObject[] = []
let i = 0
while (i < list.length) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!