修改提交任务
This commit is contained in:
parent
62d84fcc38
commit
3d0ea8cc69
|
|
@ -13,7 +13,7 @@
|
|||
<view class="form-item">
|
||||
<view class="form-icon"></view>
|
||||
<textarea
|
||||
v-model="formData.description"
|
||||
v-model="formData.description"
|
||||
class="description-input"
|
||||
placeholder="输入提交说明"
|
||||
placeholder-style="color: #999;"
|
||||
|
|
@ -112,7 +112,7 @@
|
|||
:disabled="!canSubmit"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
确认提交
|
||||
{{ isEditMode ? '确认更新' : '确认提交' }}
|
||||
</uv-button>
|
||||
</view>
|
||||
</view>
|
||||
|
|
@ -132,6 +132,10 @@ const formData = ref({
|
|||
|
||||
// 任务ID
|
||||
const taskId = ref(null);
|
||||
// 编辑模式标识
|
||||
const isEditMode = ref(false);
|
||||
const editRecordIndex = ref(-1);
|
||||
const editRecordData = ref(null);
|
||||
|
||||
// 进度选择弹窗
|
||||
const showProgressPicker = ref(false);
|
||||
|
|
@ -156,6 +160,42 @@ const canSubmit = computed(() => {
|
|||
// 页面加载
|
||||
onLoad((options) => {
|
||||
taskId.value = options.taskId || options.id;
|
||||
|
||||
// 检查是否是编辑模式
|
||||
if (options.mode === 'edit' || options.recordIndex !== undefined) {
|
||||
isEditMode.value = true;
|
||||
editRecordIndex.value = parseInt(options.recordIndex || -1);
|
||||
|
||||
// 从存储中获取编辑数据
|
||||
const editData = uni.getStorageSync('editSubmitRecord');
|
||||
if (editData && editData.record) {
|
||||
editRecordData.value = editData.record;
|
||||
|
||||
// 预填充表单数据
|
||||
formData.value.description = editData.record.content || '';
|
||||
formData.value.progress = editData.record.progress !== null && editData.record.progress !== undefined
|
||||
? editData.record.progress
|
||||
: null;
|
||||
|
||||
// 处理附件
|
||||
if (editData.record.attachments && editData.record.attachments.length > 0) {
|
||||
editData.record.attachments.forEach(attachment => {
|
||||
if (attachment.type === 'image' && attachment.path) {
|
||||
formData.value.images.push(attachment.path);
|
||||
} else if (attachment.type === 'file') {
|
||||
formData.value.files.push({
|
||||
name: attachment.name || '文件',
|
||||
path: attachment.path || '',
|
||||
size: attachment.size || 0
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 清除存储的编辑数据
|
||||
uni.removeStorageSync('editSubmitRecord');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 取消
|
||||
|
|
@ -374,7 +414,7 @@ const handleSubmit = () => {
|
|||
}
|
||||
|
||||
uni.showLoading({
|
||||
title: '提交中...'
|
||||
title: isEditMode.value ? '更新中...' : '提交中...'
|
||||
});
|
||||
|
||||
// 准备提交数据
|
||||
|
|
@ -393,8 +433,8 @@ const handleSubmit = () => {
|
|||
// TODO: 调用提交接口
|
||||
// 实际使用时,应该调用API接口上传数据
|
||||
// uni.request({
|
||||
// url: '/api/task/submit',
|
||||
// method: 'POST',
|
||||
// url: isEditMode.value ? '/api/task/submit/update' : '/api/task/submit',
|
||||
// method: isEditMode.value ? 'PUT' : 'POST',
|
||||
// data: submitData,
|
||||
// success: (res) => {
|
||||
// // 处理成功响应
|
||||
|
|
@ -408,27 +448,54 @@ const handleSubmit = () => {
|
|||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
|
||||
// 提交成功后,将数据传递回任务详情页
|
||||
const submitRecord = {
|
||||
userName: '当前用户', // TODO: 从用户信息获取
|
||||
time: formatTimeToChinese(new Date()),
|
||||
content: submitData.description || '',
|
||||
progress: submitData.progress,
|
||||
attachments: [
|
||||
...submitData.images.map(img => ({ type: 'image', path: img })),
|
||||
...submitData.files.map(file => ({ type: 'file', name: file.name, path: file.path }))
|
||||
],
|
||||
canEdit: true,
|
||||
showDelayBtn: false
|
||||
};
|
||||
if (isEditMode.value) {
|
||||
// 编辑模式:更新现有记录
|
||||
const updatedRecord = {
|
||||
userName: editRecordData.value?.userName || '当前用户', // 保持原用户名
|
||||
time: formatTimeToChinese(new Date()), // 更新时间
|
||||
content: submitData.description || '',
|
||||
progress: submitData.progress,
|
||||
attachments: [
|
||||
...submitData.images.map(img => ({ type: 'image', path: img })),
|
||||
...submitData.files.map(file => ({ type: 'file', name: file.name, path: file.path }))
|
||||
],
|
||||
canEdit: true, // 保持可编辑权限
|
||||
showDelayBtn: editRecordData.value?.showDelayBtn || false
|
||||
};
|
||||
|
||||
// 将提交记录存储到本地,供任务详情页使用
|
||||
uni.setStorageSync('newSubmitRecord', submitRecord);
|
||||
// 将更新的记录存储到本地,供任务详情页使用
|
||||
uni.setStorageSync('updatedSubmitRecord', {
|
||||
recordIndex: editRecordIndex.value,
|
||||
record: updatedRecord
|
||||
});
|
||||
|
||||
uni.showToast({
|
||||
title: '提交成功',
|
||||
icon: 'success'
|
||||
});
|
||||
uni.showToast({
|
||||
title: '更新成功',
|
||||
icon: 'success'
|
||||
});
|
||||
} else {
|
||||
// 新建模式:添加新记录
|
||||
const submitRecord = {
|
||||
userName: '当前用户', // TODO: 从用户信息获取
|
||||
time: formatTimeToChinese(new Date()),
|
||||
content: submitData.description || '',
|
||||
progress: submitData.progress,
|
||||
attachments: [
|
||||
...submitData.images.map(img => ({ type: 'image', path: img })),
|
||||
...submitData.files.map(file => ({ type: 'file', name: file.name, path: file.path }))
|
||||
],
|
||||
canEdit: true,
|
||||
showDelayBtn: false
|
||||
};
|
||||
|
||||
// 将提交记录存储到本地,供任务详情页使用
|
||||
uni.setStorageSync('newSubmitRecord', submitRecord);
|
||||
|
||||
uni.showToast({
|
||||
title: '提交成功',
|
||||
icon: 'success'
|
||||
});
|
||||
}
|
||||
|
||||
// 延迟返回,让用户看到成功提示
|
||||
setTimeout(() => {
|
||||
|
|
|
|||
|
|
@ -225,10 +225,28 @@ const closeMenu = () => {
|
|||
|
||||
// 编辑记录
|
||||
const editRecord = (index) => {
|
||||
uni.showToast({
|
||||
title: '编辑记录',
|
||||
icon: 'none'
|
||||
const record = task.value.submitRecords[index];
|
||||
if (!record) {
|
||||
uni.showToast({
|
||||
title: '记录不存在',
|
||||
icon: 'none'
|
||||
});
|
||||
showMenuIndex.value = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
// 将编辑数据存储到本地,供提交任务页面使用
|
||||
uni.setStorageSync('editSubmitRecord', {
|
||||
recordIndex: index,
|
||||
record: record,
|
||||
taskId: task.value.id
|
||||
});
|
||||
|
||||
// 跳转到提交任务页面
|
||||
uni.navigateTo({
|
||||
url: `/pages/submit-task/index?taskId=${task.value.id}&mode=edit&recordIndex=${index}`
|
||||
});
|
||||
|
||||
showMenuIndex.value = -1;
|
||||
};
|
||||
|
||||
|
|
@ -353,8 +371,9 @@ onLoad((options) => {
|
|||
}
|
||||
});
|
||||
|
||||
// 页面显示时检查是否有新的提交记录
|
||||
// 页面显示时检查是否有新的提交记录或更新的记录
|
||||
onShow(() => {
|
||||
// 检查是否有新的提交记录
|
||||
const newSubmitRecord = uni.getStorageSync('newSubmitRecord');
|
||||
if (newSubmitRecord) {
|
||||
// 将新提交记录添加到列表开头
|
||||
|
|
@ -364,6 +383,20 @@ onShow(() => {
|
|||
// 清除存储的记录
|
||||
uni.removeStorageSync('newSubmitRecord');
|
||||
}
|
||||
|
||||
// 检查是否有更新的提交记录(编辑后的记录)
|
||||
const updatedSubmitRecord = uni.getStorageSync('updatedSubmitRecord');
|
||||
if (updatedSubmitRecord) {
|
||||
const { recordIndex, record } = updatedSubmitRecord;
|
||||
if (recordIndex !== undefined && recordIndex >= 0 && recordIndex < task.value.submitRecords.length) {
|
||||
// 更新指定索引的记录
|
||||
task.value.submitRecords[recordIndex] = record;
|
||||
// 切换到提交记录标签页
|
||||
activeTab.value = 'records';
|
||||
}
|
||||
// 清除存储的记录
|
||||
uni.removeStorageSync('updatedSubmitRecord');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user