hookehuyr

refactor(CheckinDetailPage): 优化作业选择和目标添加逻辑

移除未使用的selectedTaskValue绑定,改为直接使用作业ID
将添加按钮点击事件提取为独立方法openAddTargetDialog
调整计数对象加载时机,在作业确认时直接加载
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
31 <van-field v-model="selectedTaskText" is-link readonly label="选择作业" placeholder="请选择本次打卡的作业" 31 <van-field v-model="selectedTaskText" is-link readonly label="选择作业" placeholder="请选择本次打卡的作业"
32 @click="showTaskPicker = true" class="rounded-lg border border-gray-100" /> 32 @click="showTaskPicker = true" class="rounded-lg border border-gray-100" />
33 <van-popup v-model:show="showTaskPicker" round position="bottom"> 33 <van-popup v-model:show="showTaskPicker" round position="bottom">
34 - <van-picker v-model="selectedTaskValue" :columns="taskOptions" @cancel="showTaskPicker = false" 34 + <van-picker :columns="taskOptions" @cancel="showTaskPicker = false"
35 @confirm="onConfirmTask" /> 35 @confirm="onConfirmTask" />
36 </van-popup> 36 </van-popup>
37 </template> 37 </template>
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
41 <div class="flex justify-between items-center mb-2 mx-2"> 41 <div class="flex justify-between items-center mb-2 mx-2">
42 <div class="text-sm font-bold text-gray-700">{{ dynamicFieldText }}对象</div> 42 <div class="text-sm font-bold text-gray-700">{{ dynamicFieldText }}对象</div>
43 <van-button size="small" type="primary" plain icon="plus" 43 <van-button size="small" type="primary" plain icon="plus"
44 - @click="showAddTargetDialog = true" class="!h-7">添加</van-button> 44 + @click="openAddTargetDialog" class="!h-7">添加</van-button>
45 </div> 45 </div>
46 46
47 <div class="bg-gray-50 rounded-lg p-2"> 47 <div class="bg-gray-50 rounded-lg p-2">
...@@ -242,7 +242,7 @@ const taskType = computed(() => route.query.task_type) ...@@ -242,7 +242,7 @@ const taskType = computed(() => route.query.task_type)
242 const showTaskPicker = ref(false) 242 const showTaskPicker = ref(false)
243 const taskOptions = ref([]) 243 const taskOptions = ref([])
244 244
245 -// TODO: 模拟任务选项数据 245 +// TODO: 模拟任务选项数据, 不同作业有不同的计数对象, 这里根据作业ID模拟不同的计数对象
246 const mockData = { 246 const mockData = {
247 'task1': [ 247 'task1': [
248 { name: '张老师', city: '北京', school: '北京大学' }, 248 { name: '张老师', city: '北京', school: '北京大学' },
...@@ -269,6 +269,7 @@ const fetchTargetList = async (subTaskId) => { ...@@ -269,6 +269,7 @@ const fetchTargetList = async (subTaskId) => {
269 }, 500) 269 }, 500)
270 } 270 }
271 271
272 +// 确认作业选择
272 const onConfirmTask = ({ selectedOptions }) => { 273 const onConfirmTask = ({ selectedOptions }) => {
273 const option = selectedOptions[0] 274 const option = selectedOptions[0]
274 selectedTaskText.value = option.text 275 selectedTaskText.value = option.text
...@@ -282,12 +283,13 @@ const onConfirmTask = ({ selectedOptions }) => { ...@@ -282,12 +283,13 @@ const onConfirmTask = ({ selectedOptions }) => {
282 } 283 }
283 } 284 }
284 285
285 -// 监听作业选择变化 286 +// 监听作业选择变化, 当选中的作业ID变化时, 查询对应的计数对象
286 -watch(selectedTaskValue, (newVal) => { 287 +// watch(selectedTaskValue, (newVal) => {
287 - if (taskType.value === 'count' && newVal && newVal.length > 0) { 288 +// if (taskType.value === 'count' && newVal && newVal.length > 0) {
288 - fetchTargetList(newVal[0]) 289 +// // fetchTargetList(newVal[0])
289 - } 290 +// console.warn('选中的作业ID:', newVal[0]);
290 -}) 291 +// }
292 +// })
291 293
292 /********* TODO: *******/ 294 /********* TODO: *******/
293 295
...@@ -298,7 +300,7 @@ const selectedTargets = ref([]) ...@@ -298,7 +300,7 @@ const selectedTargets = ref([])
298 const targetList = ref([]) 300 const targetList = ref([])
299 const showAddTargetDialog = ref(false) 301 const showAddTargetDialog = ref(false)
300 302
301 -// 动态表单字段 Mock 数据 303 +// TODO: 动态表单字段 Mock 数据
302 const dynamicFormFields = ref([ 304 const dynamicFormFields = ref([
303 { id: 'name', label: '姓名', type: 'text', required: true }, 305 { id: 'name', label: '姓名', type: 'text', required: true },
304 { id: 'city', label: '城市', type: 'text', required: true }, 306 { id: 'city', label: '城市', type: 'text', required: true },
...@@ -315,6 +317,10 @@ const toggleTarget = (item) => { ...@@ -315,6 +317,10 @@ const toggleTarget = (item) => {
315 } 317 }
316 } 318 }
317 319
320 +const openAddTargetDialog = () => {
321 + showAddTargetDialog.value = true;
322 +}
323 +
318 /** 324 /**
319 * 确认添加对象 325 * 确认添加对象
320 * @param {Object} formData - 表单数据 326 * @param {Object} formData - 表单数据
...@@ -322,6 +328,8 @@ const toggleTarget = (item) => { ...@@ -322,6 +328,8 @@ const toggleTarget = (item) => {
322 const confirmAddTarget = (formData) => { 328 const confirmAddTarget = (formData) => {
323 console.log(`新增${dynamicFieldText.value}对象信息:`, formData) 329 console.log(`新增${dynamicFieldText.value}对象信息:`, formData)
324 330
331 + // TODO: 这里根据实际情况调整动态字段的处理逻辑, 暂时没有正式数据, 要等一等.
332 +
325 // 添加到列表(适配原有的数据结构) 333 // 添加到列表(适配原有的数据结构)
326 targetList.value.push({ 334 targetList.value.push({
327 name: formData.name, 335 name: formData.name,
...@@ -808,7 +816,7 @@ onMounted(async () => { ...@@ -808,7 +816,7 @@ onMounted(async () => {
808 } 816 }
809 817
810 // 初始化选中的子任务ID 818 // 初始化选中的子任务ID
811 - selectedTaskValue.value = [+route.query.subtask_id] 819 + selectedTaskValue.value = route.query.subtask_id ? [+route.query.subtask_id] : []
812 820
813 // 获取小作业列表 821 // 获取小作业列表
814 const subtask_list = await getSubtaskListAPI({ task_id: route.query.task_id, date: current_date }) 822 const subtask_list = await getSubtaskListAPI({ task_id: route.query.task_id, date: current_date })
...@@ -828,6 +836,11 @@ onMounted(async () => { ...@@ -828,6 +836,11 @@ onMounted(async () => {
828 selectedTaskText.value = option.text 836 selectedTaskText.value = option.text
829 isMakeup.value = !!option.is_makeup 837 isMakeup.value = !!option.is_makeup
830 } 838 }
839 +
840 + // 如果是计数打卡,根据选中的作业ID查询计数对象
841 + if (taskType.value === 'count') {
842 + fetchTargetList(option.value)
843 + }
831 } 844 }
832 845
833 // 初始化编辑数据 846 // 初始化编辑数据
......