Commit 2db8fc03 by 张立顺

feat 功能开发

1 parent 4252830a
...@@ -8,7 +8,8 @@ import { ...@@ -8,7 +8,8 @@ import {
resolveMonthOnly, resolveMonthOnly,
resolveDayOnly, resolveDayOnly,
buildMonthSetDataPayload, buildMonthSetDataPayload,
shouldUseSingleMonthView shouldUseSingleMonthView,
shouldRebuildMonthListOnBoundsChange
} from './calendarMonth.helpers.js' } from './calendarMonth.helpers.js'
const CalendarFunction = Symbol('CalendarFunction') const CalendarFunction = Symbol('CalendarFunction')
...@@ -155,6 +156,36 @@ Component({ ...@@ -155,6 +156,36 @@ Component({
changeModel() { changeModel() {
let { dayType } = this.data let { dayType } = this.data
this.setData({ dayType: dayType == 0 ? 1 : 0 }) this.setData({ dayType: dayType == 0 ? 1 : 0 })
},
/**
* minDate/maxDate 变更时失效 lazy monthList,弹层打开时立即重建
* @param {string} minDate
* @param {string} maxDate
*/
onCalendarBoundsChange(minDate, maxDate) {
if (!this[CalendarFunction]) return
const prevMin = this._lastBoundsMin
const prevMax = this._lastBoundsMax
this._lastBoundsMin = minDate
this._lastBoundsMax = maxDate
if (prevMin === undefined && prevMax === undefined) return
if (
!shouldRebuildMonthListOnBoundsChange(prevMin, prevMax, minDate, maxDate)
) {
return
}
this._monthListReady = false
if (this.data.show && !this._monthOnlyMode) {
this[CalendarFunction].setMonthList()
this._monthListReady = true
}
}
},
observers: {
'minDate, maxDate': function (minDate, maxDate) {
this.onCalendarBoundsChange(minDate, maxDate)
} }
}, },
......
...@@ -412,3 +412,20 @@ export function buildMonthSetDataPayload(componentData, partial = {}) { ...@@ -412,3 +412,20 @@ export function buildMonthSetDataPayload(componentData, partial = {}) {
} }
return payload return payload
} }
/**
* min/max 边界是否变化,需重建 monthList
* @param {string} prevMin
* @param {string} prevMax
* @param {string} nextMin
* @param {string} nextMax
* @returns {boolean}
*/
export function shouldRebuildMonthListOnBoundsChange(
prevMin,
prevMax,
nextMin,
nextMax
) {
return (prevMin || '') !== (nextMin || '') || (prevMax || '') !== (nextMax || '')
}
...@@ -3,6 +3,10 @@ import { getSelectOrderGoodsList,quotationGoodsList, defeatOrderCreate } from '. ...@@ -3,6 +3,10 @@ import { getSelectOrderGoodsList,quotationGoodsList, defeatOrderCreate } from '.
import commonApi from '~/api/api' import commonApi from '~/api/api'
import NP from 'number-precision' import NP from 'number-precision'
import { checkStudyTask, checkAbnormalOrder } from '~/store/ModalToQueueControl' import { checkStudyTask, checkAbnormalOrder } from '~/store/ModalToQueueControl'
import {
coalesceYmd,
isDateOnOrBeforeToday
} from '~/utils/calendarDateBounds.helpers.js'
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
...@@ -91,8 +95,9 @@ Page({ ...@@ -91,8 +95,9 @@ Page({
}, },
/**设置日期 */ /**设置日期 */
setTimeList(dateNum) { setTimeList(dateNum) {
let maxDate = new Date().format('yyyy-MM-dd') const todayYmd = new Date().format('yyyy-MM-dd')
let today = dateNum || new Date().format('yyyy-MM-dd') const maxDate = coalesceYmd(todayYmd, todayYmd)
let today = dateNum || todayYmd
/** /**
* 根据日期字符串获取星期几 * 根据日期字符串获取星期几
* @param dateString 日期字符串(如:2020-05-02) * @param dateString 日期字符串(如:2020-05-02)
...@@ -121,6 +126,13 @@ Page({ ...@@ -121,6 +126,13 @@ Page({
// 获取选中天数 // 获取选中天数
rangeSelect(e) { rangeSelect(e) {
let { date } = e.detail let { date } = e.detail
const today = coalesceYmd(
this.data.dateObj?.maxDate,
new Date().format('yyyy-MM-dd')
)
if (!isDateOnOrBeforeToday(date, today)) {
return this.showToast('战败日期不能晚于今天')
}
this.setTimeList(date) this.setTimeList(date)
}, },
...@@ -139,7 +151,9 @@ Page({ ...@@ -139,7 +151,9 @@ Page({
}) })
}, },
onShow: function () {}, onShow: function () {
this.setTimeList()
},
toSelectReason(e) { toSelectReason(e) {
let { deafeatReason } = this.data let { deafeatReason } = this.data
const { item, index } = e.currentTarget.dataset const { item, index } = e.currentTarget.dataset
...@@ -494,6 +508,13 @@ Page({ ...@@ -494,6 +508,13 @@ Page({
return return
} }
if (!deafeatReason) return this.showToast(`请输入战败原因`) if (!deafeatReason) return this.showToast(`请输入战败原因`)
const today = coalesceYmd(
dateObj.maxDate,
new Date().format('yyyy-MM-dd')
)
if (!isDateOnOrBeforeToday(dateObj.today, today)) {
return this.showToast('战败日期不能晚于今天')
}
params.owner.owner = customer.customerName params.owner.owner = customer.customerName
params.owner.phone = customer.customerPhone params.owner.phone = customer.customerPhone
params.owner.salesType = customer.salesType params.owner.salesType = customer.salesType
......
...@@ -6,6 +6,10 @@ import { ...@@ -6,6 +6,10 @@ import {
defencedetail, defencedetail,
} from "../../api"; } from "../../api";
import NP from "number-precision"; import NP from "number-precision";
import {
coalesceYmd,
isDateOnOrBeforeToday
} from '~/utils/calendarDateBounds.helpers.js'
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
...@@ -84,8 +88,9 @@ Page({ ...@@ -84,8 +88,9 @@ Page({
}, },
/**设置日期 */ /**设置日期 */
setTimeList(dateNum) { setTimeList(dateNum) {
let maxDate = new Date().format("yyyy-MM-dd"); const todayYmd = new Date().format("yyyy-MM-dd");
let today = dateNum || new Date().format("yyyy-MM-dd"); const maxDate = coalesceYmd(todayYmd, todayYmd);
let today = dateNum || todayYmd;
/** /**
* 根据日期字符串获取星期几 * 根据日期字符串获取星期几
* @param dateString 日期字符串(如:2020-05-02) * @param dateString 日期字符串(如:2020-05-02)
...@@ -114,6 +119,13 @@ Page({ ...@@ -114,6 +119,13 @@ Page({
// 获取选中天数 // 获取选中天数
rangeSelect(e) { rangeSelect(e) {
let { date } = e.detail; let { date } = e.detail;
const today = coalesceYmd(
this.data.dateObj?.maxDate,
new Date().format("yyyy-MM-dd")
);
if (!isDateOnOrBeforeToday(date, today)) {
return this.showToast("战败日期不能晚于今天");
}
this.setTimeList(date); this.setTimeList(date);
}, },
...@@ -141,7 +153,9 @@ Page({ ...@@ -141,7 +153,9 @@ Page({
} }
// this.getDefencedetail(858); // this.getDefencedetail(858);
}, },
onShow: function () { }, onShow: function () {
this.setTimeList();
},
getDefencedetail(id) { getDefencedetail(id) {
defencedetail({ receptionId: id }) defencedetail({ receptionId: id })
// defencedetail({ receptionId: id }) // defencedetail({ receptionId: id })
...@@ -448,6 +462,13 @@ Page({ ...@@ -448,6 +462,13 @@ Page({
return; return;
} }
if (!deafeatReason) return this.showToast(`请输入战败原因`); if (!deafeatReason) return this.showToast(`请输入战败原因`);
const today = coalesceYmd(
dateObj.maxDate,
new Date().format("yyyy-MM-dd")
);
if (!isDateOnOrBeforeToday(dateObj.today, today)) {
return this.showToast("战败日期不能晚于今天");
}
params.owner.owner = customer.customerName; params.owner.owner = customer.customerName;
params.owner.phone = customer.customerPhone; params.owner.phone = customer.customerPhone;
params.owner.salesType = customer.salesType; params.owner.salesType = customer.salesType;
......
...@@ -5,6 +5,20 @@ import api from '../../api' ...@@ -5,6 +5,20 @@ import api from '../../api'
import { getYQorderInfo } from '~/store/index' import { getYQorderInfo } from '~/store/index'
import { checkStudyTask, checkAbnormalOrder } from '~/store/ModalToQueueControl' import { checkStudyTask, checkAbnormalOrder } from '~/store/ModalToQueueControl'
import { navigateToStaffDailyReport } from '~/utils/staffDailyReportNavigation.js' import { navigateToStaffDailyReport } from '~/utils/staffDailyReportNavigation.js'
import {
coalesceYmd,
isDateOnOrBeforeToday
} from '~/utils/calendarDateBounds.helpers.js'
import {
buildPreliminaryOrderSubmitItem,
isInviteDateOnOrAfterToday,
resolveInviteDateMin
} from './services/createArchivesDate.helpers.js'
import {
normalizeSceneColumns,
resolveAutoScene,
toSceneFields
} from '../../services/sceneAutoSelection.helpers.js'
const app = getApp() const app = getApp()
let toastList = { let toastList = {
employeeName: '销售顾问不能为空', employeeName: '销售顾问不能为空',
...@@ -36,9 +50,7 @@ Page({ ...@@ -36,9 +50,7 @@ Page({
}, },
goodsData: [], goodsData: [],
userInfo: {}, userInfo: {},
showSceneSelect: false,
sceneColumns: [], sceneColumns: [],
sceneDefaultIndex: 0,
notUpgradeOrderList: [ notUpgradeOrderList: [
{ {
customerName: '', customerName: '',
...@@ -112,7 +124,9 @@ Page({ ...@@ -112,7 +124,9 @@ Page({
) )
this.setData({ this.setData({
userInfo, userInfo,
notUpgradeOrderList: next notUpgradeOrderList: next,
'orderObj.baseSceneCode': baseSceneCode,
'orderObj.sceneType': recent?.sceneType
}) })
} catch (e) {} } catch (e) {}
}, },
...@@ -201,11 +215,23 @@ Page({ ...@@ -201,11 +215,23 @@ Page({
deliveryDate: '', deliveryDate: '',
deliveryDateShow: '' deliveryDateShow: ''
} }
let notUpgradeOrderList = this.ensureNotUpgradeOrderList() let { notUpgradeOrderList, sceneColumns } = this.data
notUpgradeOrderList = this.ensureNotUpgradeOrderList()
const newIndex = notUpgradeOrderList.length
notUpgradeOrderList.push(customer) notUpgradeOrderList.push(customer)
this.setData({ if (sceneColumns?.length) {
notUpgradeOrderList const patch = { notUpgradeOrderList }
const inheritCode = this.data.orderObj?.baseSceneCode || ''
this.buildCustomerScenePatch(patch, newIndex, inheritCode, sceneColumns)
this.setData(patch, () => {
this.__lastValidNotUpgradeOrderList = this.data.notUpgradeOrderList
})
} else {
this.setData({ notUpgradeOrderList }, () => {
this.__lastValidNotUpgradeOrderList = this.data.notUpgradeOrderList
this.getUserSceneList()
}) })
}
setTimeout(() => { setTimeout(() => {
this.setData({ this.setData({
...@@ -283,9 +309,9 @@ Page({ ...@@ -283,9 +309,9 @@ Page({
).format('yyyy-MM-dd') ).format('yyyy-MM-dd')
if (field === 'createDate') { if (field === 'createDate') {
minDate = '2020-10-01' minDate = '2020-10-01'
maxDate = dateObj.maxDate maxDate = coalesceYmd(dateObj.maxDate, new Date().format('yyyy-MM-dd'))
} else if (field === 'inviteDate') { } else if (field === 'inviteDate') {
minDate = inviteDateMin minDate = resolveInviteDateMin(inviteDateMin, dateObj.maxDate)
maxDate = farFutureDate maxDate = farFutureDate
} else if (field === 'deliveryDate') { } else if (field === 'deliveryDate') {
minDate = '2020-10-01' minDate = '2020-10-01'
...@@ -325,9 +351,24 @@ Page({ ...@@ -325,9 +351,24 @@ Page({
const { date } = e.detail const { date } = e.detail
const { field, index } = this.data.datePickerConfig || {} const { field, index } = this.data.datePickerConfig || {}
if (field === 'createDate') { if (field === 'createDate') {
const today = coalesceYmd(
this.data.dateObj?.maxDate,
new Date().format('yyyy-MM-dd')
)
if (!isDateOnOrBeforeToday(date, today)) {
this.showToast('建档日期不能晚于今天')
return
}
this.setTimeList(date) this.setTimeList(date)
return return
} }
if (
field === 'inviteDate' &&
!isInviteDateOnOrAfterToday(date, this.data.dateObj?.maxDate)
) {
this.showToast('到店日期不能早于今天')
return
}
const notUpgradeOrderList = this.ensureNotUpgradeOrderList() const notUpgradeOrderList = this.ensureNotUpgradeOrderList()
notUpgradeOrderList[index][field] = date notUpgradeOrderList[index][field] = date
notUpgradeOrderList[index][`${field}Show`] = this.formatDateShow(date) notUpgradeOrderList[index][`${field}Show`] = this.formatDateShow(date)
...@@ -468,10 +509,27 @@ Page({ ...@@ -468,10 +509,27 @@ Page({
[showName]: true, [showName]: true,
selectCustomIndex: index selectCustomIndex: index
}) })
if (showName === 'showSceneSelect') {
this.getUserSceneList()
}
}, },
/**
* 为指定客户行写入自动解析的场景字段
* @param {object} patch setData 补丁
* @param {number} index 客户行下标
* @param {string} currentCode 当前 baseSceneCode
* @param {Array<object>} sceneColumns 场景列表
* @returns {object|null}
*/
buildCustomerScenePatch(patch, index, currentCode, sceneColumns) {
const { scene } = resolveAutoScene(currentCode, sceneColumns)
if (!scene) return null
const fields = toSceneFields(scene)
patch[`notUpgradeOrderList[${index}].baseSceneCode`] = fields.baseSceneCode
patch[`notUpgradeOrderList[${index}].baseSceneName`] = fields.baseSceneName
patch[`notUpgradeOrderList[${index}].sceneType`] = fields.sceneType
return scene
},
/**
* 拉取场景列表并为每位客户自动选中:优先记忆值,否则取第一项
*/
async getUserSceneList() { async getUserSceneList() {
const freshUserInfo = wx.$util.getUserInfo() || {} const freshUserInfo = wx.$util.getUserInfo() || {}
const userInfo = const userInfo =
...@@ -485,34 +543,24 @@ Page({ ...@@ -485,34 +543,24 @@ Page({
}) })
const list = const list =
res?.code == 0 && res?.data?.length ? res.data : [] res?.code == 0 && res?.data?.length ? res.data : []
const sceneColumns = list.map(item => ({ const sceneColumns = normalizeSceneColumns(list)
...item, const { orderObj } = this.data
name: item.name || item.staffName const customers = this.ensureNotUpgradeOrderList()
})) const inheritCode = orderObj?.baseSceneCode || ''
const { notUpgradeOrderList, selectCustomIndex } = this.data const patch = { userInfo, sceneColumns }
const currentCustomer = notUpgradeOrderList?.[selectCustomIndex] || {} customers.forEach((customer, index) => {
const currentScene = const code = customer?.baseSceneCode || inheritCode
currentCustomer.baseSceneCode && this.buildCustomerScenePatch(patch, index, code, sceneColumns)
sceneColumns.find( })
item => item.baseSceneCode == currentCustomer.baseSceneCode const { scene: orderScene } = resolveAutoScene(inheritCode, sceneColumns)
) if (orderScene) {
const currentIndex = currentCustomer.baseSceneCode const fields = toSceneFields(orderScene)
? sceneColumns.findIndex( patch['orderObj.baseSceneCode'] = fields.baseSceneCode
item => item.baseSceneCode == currentCustomer.baseSceneCode patch['orderObj.baseSceneName'] = fields.baseSceneName
) patch['orderObj.sceneType'] = fields.sceneType
: 0 }
this.setData({ this.setData(patch, () => {
userInfo, this.__lastValidNotUpgradeOrderList = this.data.notUpgradeOrderList
sceneColumns,
sceneDefaultIndex: currentIndex >= 0 ? currentIndex : 0,
...(currentScene
? {
[`notUpgradeOrderList[${selectCustomIndex}].baseSceneName`]:
currentScene.name || '',
[`notUpgradeOrderList[${selectCustomIndex}].sceneType`]:
currentScene.sceneType
}
: {})
}) })
} catch (e) { } catch (e) {
this.setData({ this.setData({
...@@ -521,41 +569,6 @@ Page({ ...@@ -521,41 +569,6 @@ Page({
}) })
} }
}, },
onCloseSceneSelect() {
this.setData({
showSceneSelect: false
})
},
onConfirmSceneSelect(e) {
const scene = e.detail.value || {}
const userInfo = this.data.userInfo || wx.$util.getUserInfo() || {}
const list = this.ensureNotUpgradeOrderList()
const rawIndex = this.data.selectCustomIndex
const selectCustomIndex =
typeof rawIndex === 'number' ? rawIndex : Number(rawIndex)
const safeIndex =
Number.isFinite(selectCustomIndex) && list[selectCustomIndex]
? selectCustomIndex
: 0
this.setData({
showSceneSelect: false,
[`notUpgradeOrderList[${safeIndex}].baseSceneCode`]:
scene.baseSceneCode || '',
[`notUpgradeOrderList[${safeIndex}].baseSceneName`]:
scene.name || scene.staffName || '',
[`notUpgradeOrderList[${safeIndex}].sceneType`]: scene.sceneType
}, () => {
this.__lastValidNotUpgradeOrderList = this.data.notUpgradeOrderList
})
scene.baseSceneCode &&
api
.saveUserScene({
baseSceneCode: scene.baseSceneCode,
sceneType: userInfo.sceneType,
phone: userInfo.phone
})
.catch(() => {})
},
input(e) { input(e) {
let { notUpgradeOrderList } = this.data let { notUpgradeOrderList } = this.data
let { value } = e.detail let { value } = e.detail
...@@ -682,6 +695,13 @@ Page({ ...@@ -682,6 +695,13 @@ Page({
if (!notUpgradeOrderList[index].deliveryDate) { if (!notUpgradeOrderList[index].deliveryDate) {
return this.showToast(`请选择第${index + 1}位客户交付日期`) return this.showToast(`请选择第${index + 1}位客户交付日期`)
} }
const today = dateObj.maxDate
if (
notUpgradeOrderList[index].inviteDate &&
!isInviteDateOnOrAfterToday(notUpgradeOrderList[index].inviteDate, today)
) {
return this.showToast(`第${index + 1}位客户到店日期不能早于今天`)
}
// if (isStandNo && !notUpgradeOrderList[index].standNo) { // if (isStandNo && !notUpgradeOrderList[index].standNo) {
// return this.showToast(`请输入第${index + 1}位客户车架号`) // return this.showToast(`请输入第${index + 1}位客户车架号`)
// } // }
...@@ -693,14 +713,9 @@ Page({ ...@@ -693,14 +713,9 @@ Page({
createDate: dateObj.today createDate: dateObj.today
} }
if (type == 'success') { if (type == 'success') {
orderObj.preliminaryOrders = (notUpgradeOrderList || []).map(item => { orderObj.preliminaryOrders = (notUpgradeOrderList || []).map(
const { inviteDateShow, deliveryDateShow, ...rest } = item buildPreliminaryOrderSubmitItem
return { )
...rest,
baseSceneCode: item.baseSceneCode,
sceneType: item.sceneType
}
})
} else { } else {
orderObj.notUpgradeOrderList = notUpgradeOrderList orderObj.notUpgradeOrderList = notUpgradeOrderList
} }
...@@ -871,6 +886,7 @@ Page({ ...@@ -871,6 +886,7 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow: function () { onShow: function () {
this.setTimeList()
}, },
onRoute(res) { onRoute(res) {
console.log(res, 'onroute') console.log(res, 'onroute')
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
"car-brands": "/components/CarBrands/CarBrands", "car-brands": "/components/CarBrands/CarBrands",
"merchant-seles": "/components/Merchant-Seles/Merchant-Seles", "merchant-seles": "/components/Merchant-Seles/Merchant-Seles",
"sub-shop-merchant" : "/tabWorkOrder/components/subShopMerchant/subShopMerchant", "sub-shop-merchant" : "/tabWorkOrder/components/subShopMerchant/subShopMerchant",
"study-permission-modal": "/components/studyPermissionModal/studyPermissionModal", "study-permission-modal": "/components/studyPermissionModal/studyPermissionModal"
"van-popup": "/miniprogram_npm/@vant/weapp/popup/index",
"van-picker": "/miniprogram_npm/@vant/weapp/picker/index"
} }
} }
...@@ -128,25 +128,6 @@ ...@@ -128,25 +128,6 @@
data-name="customerName" data-name="customerName"
always-embed></input> always-embed></input>
</gl-cell> </gl-cell>
<view class="baseSceneCode">
<gl-cell
border
valueAlign="right"
label="场景名称"
requiredAfter
labelWidth="var(--fontSize140)"
required
haveArrow
bindclick="showPopup"
data-show-name="showSceneSelect"
data-index="{{ind}}"
placeholder="点击选择"
>
<block wx:if="{{ li.baseSceneName }}">
<view class="between">{{li.baseSceneName}}</view>
</block>
</gl-cell>
</view>
<gl-cell <gl-cell
border border
valueAlign="right" valueAlign="right"
...@@ -342,14 +323,3 @@ ...@@ -342,14 +323,3 @@
selectedSelesMerchantId="{{orderObj.merchantId || ''}}" selectedSelesMerchantId="{{orderObj.merchantId || ''}}"
selectedSubShopMerchantId="{{orderObj.subShopMerchantId || ''}}" /> selectedSubShopMerchantId="{{orderObj.subShopMerchantId || ''}}" />
<study-permission-modal id="customModal" /> <study-permission-modal id="customModal" />
<van-popup show="{{ showSceneSelect }}" position="bottom" bind:close="onCloseSceneSelect">
<van-picker
show-toolbar
title="场景名称"
bind:cancel="onCloseSceneSelect"
columns="{{ sceneColumns }}"
default-index="{{ sceneDefaultIndex }}"
value-key="name"
bind:confirm="onConfirmSceneSelect"
/>
</van-popup>
...@@ -237,6 +237,7 @@ scroll-view ::-webkit-scrollbar { ...@@ -237,6 +237,7 @@ scroll-view ::-webkit-scrollbar {
.list { .list {
transition: all .25s; transition: all .25s;
padding-bottom: var(--fontSize80);
} }
.addBtn .addIcon { .addBtn .addIcon {
......
/**
* @file createArchives 日期字段 — 纯函数层(无 setData、无 API)
*
* 到店/交付日期提交格式与到店日期「仅今天及未来」校验。
*/
import {
coalesceYmd,
formatDayStartForSubmit,
isDateOnOrAfterToday
} from '../../../../utils/calendarDateBounds.helpers.js'
/**
* 解析到店日历 minDate;inviteDateMin 为空时回退为今天
* @param {string} inviteDateMin
* @param {string} todayYmd
* @returns {string}
*/
export function resolveInviteDateMin(inviteDateMin, todayYmd) {
return coalesceYmd(inviteDateMin, todayYmd)
}
/** @see formatDayStartForSubmit */
export function formatArchiveDateTimeForSubmit(dateYmd) {
return formatDayStartForSubmit(dateYmd)
}
/** @see isDateOnOrAfterToday */
export function isInviteDateOnOrAfterToday(inviteDateYmd, todayYmd) {
return isDateOnOrAfterToday(inviteDateYmd, todayYmd)
}
/**
* 组装单条预录工单提交项:去掉展示字段,格式化 inviteDate / deliveryDate
* @param {Object} item 客户行数据
* @returns {Object}
*/
export function buildPreliminaryOrderSubmitItem(item) {
const { inviteDateShow, deliveryDateShow, ...rest } = item || {}
return {
...rest,
baseSceneCode: item?.baseSceneCode,
sceneType: item?.sceneType,
inviteDate: item?.inviteDate
? formatDayStartForSubmit(item.inviteDate)
: item?.inviteDate,
deliveryDate: item?.deliveryDate
? formatDayStartForSubmit(item.deliveryDate)
: item?.deliveryDate
}
}
...@@ -10,6 +10,10 @@ import { ...@@ -10,6 +10,10 @@ import {
resolveAutoScene, resolveAutoScene,
toSceneFields toSceneFields
} from '../../services/sceneAutoSelection.helpers' } from '../../services/sceneAutoSelection.helpers'
import {
coalesceYmd,
isDateOnOrBeforeToday
} from '~/utils/calendarDateBounds.helpers.js'
const phoneRex = /^[1]([3-9])[0-9]{9}$/ const phoneRex = /^[1]([3-9])[0-9]{9}$/
const app = getApp() const app = getApp()
let toastList = { let toastList = {
...@@ -302,8 +306,9 @@ Page({ ...@@ -302,8 +306,9 @@ Page({
}, },
/**设置日期 */ /**设置日期 */
setTimeList(dateNum) { setTimeList(dateNum) {
let maxDate = new Date().format('yyyy-MM-dd') const todayYmd = new Date().format('yyyy-MM-dd')
let today = dateNum || new Date().format('yyyy-MM-dd') const maxDate = coalesceYmd(todayYmd, todayYmd)
let today = dateNum || todayYmd
/** /**
* 根据日期字符串获取星期几 * 根据日期字符串获取星期几
* @param dateString 日期字符串(如:2020-05-02) * @param dateString 日期字符串(如:2020-05-02)
...@@ -358,6 +363,13 @@ Page({ ...@@ -358,6 +363,13 @@ Page({
// 获取选中天数 // 获取选中天数
rangeSelect(e) { rangeSelect(e) {
let { date } = e.detail let { date } = e.detail
const today = coalesceYmd(
this.data.dateObj?.maxDate,
new Date().format('yyyy-MM-dd')
)
if (!isDateOnOrBeforeToday(date, today)) {
return this.showToast('战败日期不能晚于今天')
}
this.setTimeList(date) this.setTimeList(date)
}, },
delBtn(e) { delBtn(e) {
...@@ -1006,6 +1018,13 @@ Page({ ...@@ -1006,6 +1018,13 @@ Page({
notUpgradeOrderList, notUpgradeOrderList,
createDate: dateObj.today createDate: dateObj.today
} }
const today = coalesceYmd(
dateObj.maxDate,
new Date().format('yyyy-MM-dd')
)
if (!isDateOnOrBeforeToday(dateObj.today, today)) {
return this.showToast('战败日期不能晚于今天')
}
delete orderObj.customer delete orderObj.customer
delete orderObj?.packageGoodsList delete orderObj?.packageGoodsList
delete orderObj?.subOrderList delete orderObj?.subOrderList
...@@ -1382,7 +1401,9 @@ Page({ ...@@ -1382,7 +1401,9 @@ Page({
/** /**
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow: function (res) {}, onShow: function () {
this.setTimeList()
},
onRoute(res) { onRoute(res) {
console.log(res, 'onroute') console.log(res, 'onroute')
this.setData({ isExpiredTraffic: res?.isExpiredTraffic }) this.setData({ isExpiredTraffic: res?.isExpiredTraffic })
......
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
coalesceYmd,
formatDayStartForSubmit,
isDateOnOrAfterToday,
isDateOnOrBeforeToday
} from '../utils/calendarDateBounds.helpers.js'
describe('coalesceYmd', () => {
it('returns bound when set', () => {
assert.equal(coalesceYmd('2026-07-05', '2026-07-06'), '2026-07-05')
})
it('falls back when bound empty', () => {
assert.equal(coalesceYmd('', '2026-07-06'), '2026-07-06')
assert.equal(coalesceYmd(' ', '2026-07-06'), '2026-07-06')
})
})
describe('formatDayStartForSubmit', () => {
it('appends 00:00:00', () => {
assert.equal(formatDayStartForSubmit('2026-07-06'), '2026-07-06 00:00:00')
})
it('does not double-append', () => {
assert.equal(
formatDayStartForSubmit('2026-07-06 00:00:00'),
'2026-07-06 00:00:00'
)
})
})
describe('isDateOnOrAfterToday', () => {
const today = '2026-07-06'
it('true for today and future', () => {
assert.equal(isDateOnOrAfterToday('2026-07-06', today), true)
assert.equal(isDateOnOrAfterToday('2026-07-07', today), true)
})
it('false for past', () => {
assert.equal(isDateOnOrAfterToday('2026-07-05', today), false)
})
})
describe('isDateOnOrBeforeToday', () => {
const today = '2026-07-06'
it('true for today and past', () => {
assert.equal(isDateOnOrBeforeToday('2026-07-06', today), true)
assert.equal(isDateOnOrBeforeToday('2026-07-05', today), true)
})
it('false for future', () => {
assert.equal(isDateOnOrBeforeToday('2026-07-07', today), false)
})
})
...@@ -10,7 +10,8 @@ import { ...@@ -10,7 +10,8 @@ import {
shouldUseSingleMonthView, shouldUseSingleMonthView,
buildAllMonthsMeta, buildAllMonthsMeta,
buildDisplayMonthWindow, buildDisplayMonthWindow,
getMonthDifference getMonthDifference,
shouldRebuildMonthListOnBoundsChange
} from '../components/CalendarMonth/calendarMonth.helpers.js' } from '../components/CalendarMonth/calendarMonth.helpers.js'
describe('calendarMonthMode', () => { describe('calendarMonthMode', () => {
...@@ -96,4 +97,33 @@ describe('calendarMonthMode', () => { ...@@ -96,4 +97,33 @@ describe('calendarMonthMode', () => {
assert.equal(shouldUseSingleMonthView(false), false) assert.equal(shouldUseSingleMonthView(false), false)
assert.equal(shouldUseSingleMonthView(true, true), false) assert.equal(shouldUseSingleMonthView(true, true), false)
}) })
it('CAL-14 shouldRebuildMonthListOnBoundsChange detects bound changes', () => {
assert.equal(
shouldRebuildMonthListOnBoundsChange('', '2026-07-06', '', '2026-07-06'),
false
)
assert.equal(
shouldRebuildMonthListOnBoundsChange('', '', '', '2026-07-06'),
true
)
assert.equal(
shouldRebuildMonthListOnBoundsChange('2026-01-01', '2026-07-06', '2026-01-01', '2026-07-07'),
true
)
})
it('CAL-15 buildAllMonthsMeta disables future days when maxDate is today', () => {
const now = new Date(2026, 6, 6)
const built = buildAllMonthsMeta({
minDate: '2026-01-01',
maxDate: '2026-07-06',
nowDate: now
})
const july = built.monthList.find(m => m.mark === 7)
assert.ok(july)
const futureDay = july.data.find(d => d.data === '2026-07-07')
assert.ok(futureDay)
assert.equal(futureDay.disable, true)
})
}) })
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
buildPreliminaryOrderSubmitItem,
formatArchiveDateTimeForSubmit,
isInviteDateOnOrAfterToday,
resolveInviteDateMin
} from '../tabWorkOrder/pages/createArchives/services/createArchivesDate.helpers.js'
describe('formatArchiveDateTimeForSubmit', () => {
it('appends 00:00:00 for yyyy-MM-dd', () => {
assert.equal(
formatArchiveDateTimeForSubmit('2026-07-06'),
'2026-07-06 00:00:00'
)
})
it('returns empty string for empty input', () => {
assert.equal(formatArchiveDateTimeForSubmit(''), '')
assert.equal(formatArchiveDateTimeForSubmit(' '), '')
})
it('does not double-append when already formatted', () => {
assert.equal(
formatArchiveDateTimeForSubmit('2026-07-06 00:00:00'),
'2026-07-06 00:00:00'
)
})
})
describe('resolveInviteDateMin', () => {
it('uses inviteDateMin when set', () => {
assert.equal(resolveInviteDateMin('2026-07-06', '2026-07-05'), '2026-07-06')
})
it('falls back to today when inviteDateMin is empty', () => {
assert.equal(resolveInviteDateMin('', '2026-07-06'), '2026-07-06')
assert.equal(resolveInviteDateMin(' ', '2026-07-06'), '2026-07-06')
})
})
describe('isInviteDateOnOrAfterToday', () => {
const today = '2026-07-06'
it('returns true for today and future', () => {
assert.equal(isInviteDateOnOrAfterToday('2026-07-06', today), true)
assert.equal(isInviteDateOnOrAfterToday('2026-07-07', today), true)
})
it('returns false for past dates', () => {
assert.equal(isInviteDateOnOrAfterToday('2026-07-05', today), false)
})
it('returns false when invite or today is missing', () => {
assert.equal(isInviteDateOnOrAfterToday('', today), false)
assert.equal(isInviteDateOnOrAfterToday('2026-07-06', ''), false)
})
})
describe('buildPreliminaryOrderSubmitItem', () => {
it('strips show fields and formats dates for submit', () => {
const item = {
customerName: '张三',
inviteDate: '2026-07-06',
inviteDateShow: '2026年07月06日',
deliveryDate: '2026-08-01',
deliveryDateShow: '2026年08月01日',
baseSceneCode: 'SC1',
sceneType: 1
}
const result = buildPreliminaryOrderSubmitItem(item)
assert.equal(result.customerName, '张三')
assert.equal(result.inviteDate, '2026-07-06 00:00:00')
assert.equal(result.deliveryDate, '2026-08-01 00:00:00')
assert.equal(result.baseSceneCode, 'SC1')
assert.equal(result.sceneType, 1)
assert.equal(result.inviteDateShow, undefined)
assert.equal(result.deliveryDateShow, undefined)
})
it('leaves empty inviteDate unchanged', () => {
const result = buildPreliminaryOrderSubmitItem({
deliveryDate: '2026-08-01',
inviteDate: ''
})
assert.equal(result.inviteDate, '')
assert.equal(result.deliveryDate, '2026-08-01 00:00:00')
})
})
/**
* @file 日历边界与日期提交格式 — 纯函数(无 setData、无 API)
*
* 解决 CalendarMonth 在 minDate/maxDate 为空串时不限制选日的问题。
*/
const DAY_START_SUFFIX = ' 00:00:00'
/**
* 空串回退为 fallback,避免日历 bound 失效
* @param {string} bound 页面传入的 minDate/maxDate
* @param {string} fallback 通常 today yyyy-MM-dd
* @returns {string}
*/
export function coalesceYmd(bound, fallback) {
const value = (bound || '').trim()
const fb = (fallback || '').trim()
return value || fb
}
/**
* 提交用日期时间:yyyy-MM-dd → yyyy-MM-dd 00:00:00
* @param {string} dateYmd 日期字符串
* @returns {string}
*/
export function formatDayStartForSubmit(dateYmd) {
const date = (dateYmd || '').trim()
if (!date) return ''
if (date.endsWith(DAY_START_SUFFIX)) return date
return `${date}${DAY_START_SUFFIX}`
}
/**
* 日期是否 >= 今天(到店类)
* @param {string} dateYmd
* @param {string} todayYmd
* @returns {boolean}
*/
export function isDateOnOrAfterToday(dateYmd, todayYmd) {
const date = (dateYmd || '').trim()
const today = (todayYmd || '').trim()
if (!date || !today) return false
return date >= today
}
/**
* 日期是否 <= 今天(建档/战败类)
* @param {string} dateYmd
* @param {string} todayYmd
* @returns {boolean}
*/
export function isDateOnOrBeforeToday(dateYmd, todayYmd) {
const date = (dateYmd || '').trim()
const today = (todayYmd || '').trim()
if (!date || !today) return false
return date <= today
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!