diff --git a/src/views/index/supplierTimePhone.vue b/src/views/index/supplierTimePhone.vue index 72ac8fdc..8e4b1b42 100644 --- a/src/views/index/supplierTimePhone.vue +++ b/src/views/index/supplierTimePhone.vue @@ -3,7 +3,7 @@
{{ item.startTime }} — {{ item.endTime }} -
+
编辑 删除
@@ -107,17 +107,12 @@ export default { } this.loadData() }, - activated() { - // 从编辑页返回时刷新本地草稿 - if (this.supplierId) { - this.loadDraft() - } - }, methods: { async loadData() { Toast.loading({ message: '加载中...', forbidClick: true, duration: 0 }) try { - const res = await getSupplierPhoneList({ supplierId: this.supplierId }) + const result = await getSupplierPhoneList({ supplierId: this.supplierId }) + const res=result?.data || '' this.supplierName = res?.supplierName || '' this.approvalId = res?.approvalId || null this.approvalState = res?.approvalState || null @@ -127,8 +122,8 @@ export default { this.approvalRemark = res?.approvalRemark || '' const cached = this.getCachedDraft() - if (cached && cached.approvalId === this.approvalId && cached.approvalState === this.approvalState) { - this.phoneList = cached.phoneList || [] + if (cached && Array.isArray(cached.phoneList)) { + this.phoneList = cached.phoneList } else { this.phoneList = res?.phoneList || [] this.saveDraft() @@ -139,12 +134,6 @@ export default { Toast.clear() } }, - loadDraft() { - const cached = this.getCachedDraft() - if (cached) { - this.phoneList = cached.phoneList || [] - } - }, visiblePhones(item) { const list = [] for (let i = 1; i <= 3; i++) { @@ -176,10 +165,16 @@ export default { } localStorage.setItem(getDraftKey(this.supplierId), JSON.stringify(draft)) }, + onNavBack() { + localStorage.removeItem(getDraftKey(this.supplierId)) + this.goBack() + }, goAdd() { + this.saveDraft() this.goPage('supplierTimePhoneEdit', { supplierId: this.supplierId, index: -1 }) }, goEdit(index) { + this.saveDraft() this.goPage('supplierTimePhoneEdit', { supplierId: this.supplierId, index }) }, deleteItem(index) { @@ -191,6 +186,40 @@ export default { this.saveDraft() }).catch(() => {}) }, + // 将 HH:mm 转换为分钟数,兼容中英文冒号 + timeToMinutes(timeStr) { + if (!timeStr) return null + const normalized = String(timeStr).trim().replace(/:/g, ':') + const [h, m] = normalized.split(':').map(Number) + if (isNaN(h) || isNaN(m)) return null + return h * 60 + m + }, + // 校验时间段:重叠、00:00 开始、23:59 结束、遗漏(允许 1 分钟误差) + validateTimePeriods(list) { + const periods = list.map(item => ({ + start: this.timeToMinutes(item.startTime), + end: this.timeToMinutes(item.endTime) + })) + if (periods.some(p => p.start === null || p.end === null)) { + return '存在格式不正确的时间段' + } + periods.sort((a, b) => a.start - b.start) + if (periods[0].start !== 0) { + return '时间段未从 00:00 开始!' + } + if (periods[periods.length - 1].end !== 23 * 60 + 59) { + return '时间段未到 23:59 结束!' + } + for (let i = 1; i < periods.length; i++) { + if (periods[i].start < periods[i - 1].end) { + return '时间段重叠' + } + if (periods[i].start - periods[i - 1].end > 1) { + return '时间段有遗漏' + } + } + return null + }, async onSubmitClick() { if (this.inApproval) return if (!this.phoneList.length) { @@ -201,6 +230,11 @@ export default { Toast('每条时段电话1均必填') return } + const timeError = this.validateTimePeriods(this.phoneList) + if (timeError) { + Toast(timeError) + return + } Toast.loading({ message: '提交中...', forbidClick: true, duration: 0 }) try { diff --git a/src/views/index/supplierTimePhoneEdit.vue b/src/views/index/supplierTimePhoneEdit.vue index 78a20440..4ae4a971 100644 --- a/src/views/index/supplierTimePhoneEdit.vue +++ b/src/views/index/supplierTimePhoneEdit.vue @@ -3,7 +3,7 @@
@@ -56,18 +54,29 @@