Commit 086d8b7b by Lin

feat: 修改申诉表单

1 parent 2f3a387e
......@@ -18,7 +18,7 @@ Component({
},
data: {
appealDays: '',
appealNum: '',
imageList: [],
remarks: '',
otherIssues: '',
......@@ -34,8 +34,22 @@ Component({
this.triggerEvent('close')
},
onAppealDaysInput(e) {
this.setData({ appealDays: e.detail.value.replace(/[^\d]/g, '').substring(0, 3) })
onAppealNumInput(e) {
const { appealType } = this.properties
let value = e.detail.value
if (appealType === 'recording') {
// daily 类型:只允许整数,最多3位
value = value.replace(/[^\d]/g, '').substring(0, 5)
} else {
// 其他类型:支持小数点后两位,格式:最多3位整数.最多2位小数
value = value.replace(/[^\d.]/g, '') // 只保留数字和小数点
// 限制格式:最多3位整数,可选的小数点和最多2位小数
const match = value.match(/^(\d{0,3})(\.?)(\d{0,2})/)
value = match ? match[0] : ''
}
this.setData({ appealNum: value })
},
onRemarksInput(e) {
......@@ -243,18 +257,33 @@ Component({
},
onConfirm() {
const { appealDays, imageList, remarks, otherIssues, actualDays } = this.data
const { appealLabel, unit, maxValue } = this.properties
if (!appealDays || appealDays.trim() === '') {
const { appealNum, imageList, remarks, otherIssues, actualDays } = this.data
const { appealLabel, unit, maxValue, appealType } = this.properties
// 验证输入是否为空
if (!appealNum || appealNum.trim() === '') {
wx.showToast({ title: `请输入${appealLabel}`, icon: 'none' })
return
}
const num = parseInt(appealDays, 10)
// 解析数值(daily 类型为整数,其他类型支持小数)
const num = appealType === 'daily' ? parseInt(appealNum, 10) : parseFloat(appealNum)
// 验证数值有效性
if (isNaN(num) || num < 0 || num > maxValue) {
wx.showToast({ title: `请输入正确的${unit}(0-${maxValue})`, icon: 'none' })
return
}
// 非 daily 类型额外验证:小数位数不超过2位
if (appealType !== 'daily' && appealNum.includes('.')) {
const decimalPart = appealNum.split('.')[1]
if (decimalPart && decimalPart.length > 2) {
wx.showToast({ title: `小数点后最多保留两位`, icon: 'none' })
return
}
}
// 只返回已完成上传的图片(status === 'done' 或没有 status 字段的)
const doneImageList = imageList
.filter(item => !item.status || item.status === 'done')
......@@ -263,7 +292,7 @@ Component({
this.triggerEvent('confirm', {
actualDays: Number(actualDays) || 0,
appealDays: num,
appealNum: num,
imageList: doneImageList,
remarks: remarks.trim(),
otherIssues: otherIssues.trim()
......@@ -273,7 +302,7 @@ Component({
resetForm() {
this.setData({
appealDays: '',
appealNum: '',
imageList: [],
remarks: '',
otherIssues: '',
......
......@@ -42,7 +42,7 @@
<view class="form-item form-item-row">
<view class="form-label">{{ appealLabel }}</view>
<view class="form-input-wrapper">
<input type="digit" class="form-input" placeholder="{{ appealType === 'daily' ? '输入正确条数' : '输入正确数字' }}" value="{{ appealDays }}" bindinput="onAppealDaysInput" maxlength="3" />
<input type="digit" class="form-input" placeholder="{{ appealType === 'recording' ? '输入正确条数' : '输入正确数字' }}" value="{{ appealNum }}" bindinput="onAppealNumInput" />
<text class="form-unit">{{ unit }}</text>
</view>
</view>
......
......@@ -100,7 +100,7 @@
display: flex;
justify-content: space-between;
align-items: center;
padding: var(--fontSize24);
padding: var(--fontSize24) 0;
border-bottom: var(--fontSize2) solid #eee;
font-size: var(--fontSize28);
}
......@@ -114,7 +114,7 @@
}
.option-item.checked .option-name {
color: #1989fa;
color: #347BFF;
}
.option-check {
......@@ -126,7 +126,7 @@
}
.option-check.checked {
color: #1989fa;
color: #347BFF;
}
.check-icon {
......
/**
* 工资申诉常量数据映射
* 将API返回的数据映射到 salaryItems 数据结构
*/
// 工资项基础配置
const SALARY_ITEM_CONFIG = [
{
id: 'attendance',
title: '实际出勤天数',
centerLeft: '根据打卡数据产生',
btnText: '申诉考勤',
unit: '天',
defaultValue: 0
},
{
id: 'daily',
title: '日报完成天数',
centerLeft: '填写驻店日报天数',
btnText: '去补日报',
unit: '天',
defaultValue: 0,
hasMissingDates: true
},
{
id: 'recording',
title: '平板录音总数',
centerLeft: '触客总数为',
btnText: '申诉平板',
unit: '条',
defaultValue: 0
}
]
// API字段映射配置
const API_FIELD_MAP = {
attendance: {
value: 'actualAttendanceDays',
deduction: 'attendanceDeductionAmount',
appealable: 'attendanceAppealable'
},
daily: {
value: 'dailyReportDays',
deduction: 'dailyReportDeductionAmount',
appealable: 'dailyReportable',
missingDates: 'missingDailyReportDates'
},
recording: {
value: 'padRecordNum',
deduction: 'padDeductionAmount',
appealable: 'padAppealable'
}
}
/**
* 格式化扣款金额显示
*/
const formatDeductionAmount = (amount) => {
if (!amount || amount === 0) return ''
return amount > 0 ? `-${amount}元` : `${amount}元`
}
/**
* 格式化缺失日期显示
*/
const formatMissingDates = (dates) => {
if (!dates || !Array.isArray(dates) || dates.length === 0) return ''
return dates.map(date => {
if (date.includes('-')) {
const day = date.split('-')[2]
return day.replace(/^0+/, '')
}
return date
}).join('、') + '号'
}
/**
* 格式化数值显示
*/
const formatValue = (value, unit, defaultValue = 0) => {
const num = value !== undefined && value !== null ? value : defaultValue
return `${num}${unit}`
}
/**
* 创建单个工资项数据
*/
const createSalaryItem = (config, apiData) => {
const fieldMap = API_FIELD_MAP[config.id]
const value = apiData[fieldMap.value]
const deductionAmount = apiData[fieldMap.deduction]
const appealable = apiData[fieldMap.appealable] || false
const missingDates = config.hasMissingDates ? apiData[fieldMap.missingDates] : null
return {
id: config.id,
title: config.title,
value: formatValue(value, config.unit, config.defaultValue),
centerLeft: config.centerLeft,
centerLeftNum: '',
centerRight: deductionAmount ? '扣款' : '',
centerRightPrice: formatDeductionAmount(deductionAmount),
bottomText: missingDates && missingDates.length > 0 ? '缺失天数为' : '',
bottomDays: config.hasMissingDates ? formatMissingDates(missingDates) : '',
btnText: appealable ? config.btnText : '',
btnType: config.id,
appealable
}
}
/**
* 将API数据映射到工资项数据结构
* @param {Object} apiData - API返回的数据对象
* @returns {Array} salaryItems 数组
*/
export function mapApiDataToSalaryItems(apiData = {}) {
return SALARY_ITEM_CONFIG.map(config => createSalaryItem(config, apiData))
}
/**
* 默认的工资项数据结构(用于初始化或兜底)
*/
export const defaultSalaryItems = mapApiDataToSalaryItems({})
// packageEquity/pages/salaryAppeal/salaryAppeal.js
import { getSummaryInfo } from './api'
Page({
/**
......@@ -31,26 +32,22 @@ Page({
title: '实际出勤天数',
value: '26天',
centerLeft: '根据打卡数据产生',
centerLeftNum: '11条',
centerRight: '扣款',
centerRightPrice: '-100元',
bottomText: '',
bottomDays: '',
btnText: '申诉考勤',
btnType: 'attendance'
btnType: 'attendance',
btnAble: true
},
{
id: 'daily',
title: '日报完成天数',
value: '26天',
centerLeft: '填写驻店日报天数',
centerLeftNum: '11条',
centerRight: '扣款',
centerRightPrice: '-100元',
bottomText: '缺失天数为',
bottomDays: '12、13、17号',
btnText: '去补日报',
btnType: 'daily'
btnType: 'daily',
btnAble: true
},
{
id: 'recording',
......@@ -60,10 +57,9 @@ Page({
centerLeftNum: '11条',
centerRight: '扣款',
centerRightPrice: '-100元',
bottomText: '',
bottomDays: '',
btnText: '申诉平板',
btnType: 'recording'
btnType: 'recording',
btnAble: true
}
],
orderList: [
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!