/** * Purpose: formatPrice supports format.js by holding or executing the format price page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function formatPrice(value) { return Number(value || 0).toFixed(2) } /** * Purpose: getProductTitle supports format.js by holding or executing the get product title page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function getProductTitle(product) { return (product && (product.title || product.name)) || '未命名作品' } /** * Purpose: splitCsv supports format.js by holding or executing the split csv page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function splitCsv(value) { return String(value || '') .split(',') .map(item => item.trim()) .filter(Boolean) } /** * Purpose: sameId supports format.js by holding or executing the same id page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function sameId(left, right) { return String(left || '') === String(right || '') } /** * Purpose: formatDateTime supports format.js by holding or executing the format date time page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function formatDateTime(value) { if (!value) { return '' } return String(value).replace('T', ' ').slice(0, 16) } /** * Purpose: parseAppointmentParts supports format.js by holding or executing the parse appointment parts page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function parseAppointmentParts(value) { const text = formatDateTime(value) if (!text) { return { date: '', clock: '' } } const parts = text.split(' ') return { date: parts[0] || '', clock: parts[1] || '' } } /** * Purpose: buildAppointmentValue supports format.js by holding or executing the build appointment value page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function buildAppointmentValue(date, clock) { if (!date || !clock) { return '' } return `${date} ${clock}:00` } /** * Purpose: isPastAppointment supports format.js by holding or executing the is past appointment page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function isPastAppointment(value) { if (!value) { return false } return new Date(String(value).replace(' ', 'T')).getTime() < Date.now() + 5 * 60 * 1000 } /** * Purpose: getMinDateText supports format.js by holding or executing the get min date text page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function getMinDateText() { const now = new Date() const year = now.getFullYear() const month = String(now.getMonth() + 1).padStart(2, '0') const date = String(now.getDate()).padStart(2, '0') return `${year}-${month}-${date}` } /** * Purpose: getOrderStatusText supports format.js by holding or executing the get order status text page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function getOrderStatusText(order) { if (order && order.statusText) { return order.statusText } const status = Number(order && order.status) if (status === 1) { return '待服务' } if (status === 2) { return '已完成' } return '已取消' } /** * Purpose: getOrderStatusClass supports format.js by holding or executing the get order status class page or API role. * Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow. */ function getOrderStatusClass(order) { const status = Number(order && order.status) if (status === 1) { return 'pending' } if (status === 2) { return 'completed' } return 'cancelled' } module.exports = { formatPrice, getProductTitle, splitCsv, sameId, formatDateTime, parseAppointmentParts, buildAppointmentValue, isPastAppointment, getMinDateText, getOrderStatusText, getOrderStatusClass }