任务半成品

This commit is contained in:
砂糖
2025-07-11 18:05:05 +08:00
parent 561601910f
commit 0246dc128c
12 changed files with 2376 additions and 43 deletions

View File

@@ -14,6 +14,10 @@
<image class="entry-icon" src="/static/images/shigong.png" mode="aspectFit" />
<text class="entry-text">施工进度</text>
</view>
<view class="entry-item" @click="goTask">
<image class="entry-icon" src="/static/images/task.png" mode="aspectFit"></image>
<text class="entry-text">任务中心</text>
</view>
</view>
</view>
</template>
@@ -35,7 +39,12 @@ export default {
uni.navigateTo({
url: '/pages/workbench/construction/construction'
});
}
},
goTask() {
uni.navigateTo({
url: '/pages/workbench/task/task'
})
}
}
};
</script>

View File

@@ -227,8 +227,8 @@ export default {
const tabHeight = 100; // tab高度
const containerPadding = 40; // 容器padding
// 悬浮按钮是固定定位,不需要预留空间,让卡片列表到达底部
// 我也不知道为什么要 + 100, 不然滚动高度下面一大片空白,这个不太好调试
this.scrollHeight = systemInfo.windowHeight - tabHeight - containerPadding + 100;
// 我也不知道为什么要 + 80, 不然滚动高度下面一大片空白,这个不太好调试
this.scrollHeight = systemInfo.windowHeight - tabHeight - containerPadding + 80;
},
// 切换tab

View File

@@ -0,0 +1,972 @@
<template>
<view class="create-task-container">
<!-- 表单内容 -->
<view class="form-container">
<form @submit="submitForm">
<!-- 任务主题 -->
<view class="form-item">
<view class="form-label">
<text class="label-text">任务主题</text>
<text class="required">*</text>
</view>
<input
v-model="form.taskTitle"
class="form-input"
placeholder="请输入任务主题"
maxlength="100"
/>
</view>
<!-- 工作类型 -->
<view class="form-item">
<view class="form-label">
<text class="label-text">工作类型</text>
<text class="required">*</text>
</view>
<picker
@change="onTaskTypeChange"
:value="taskTypeIndex"
:range="taskTypeOptions"
range-key="label"
class="form-picker"
>
<view class="picker-text">
{{ taskTypeOptions[taskTypeIndex] ? taskTypeOptions[taskTypeIndex].label : '请选择工作类型' }}
</view>
</picker>
</view>
<!-- 任务模式 -->
<view class="form-item">
<view class="form-label">
<text class="label-text">任务模式</text>
</view>
<view class="radio-group">
<view
class="radio-item"
:class="{ active: form.status === 0 }"
@click="form.status = 0"
>
<view class="radio-circle"></view>
<text class="radio-text">单任务模式</text>
</view>
<view
class="radio-item"
:class="{ active: form.status === 1 }"
@click="form.status = 1"
>
<view class="radio-circle"></view>
<text class="radio-text">报工模式</text>
</view>
</view>
</view>
<!-- 报工周期 -->
<view class="form-item" v-if="form.status === 1">
<view class="form-label">
<text class="label-text">报工周期</text>
</view>
<input
v-model="form.timeGap"
type="number"
class="form-input"
placeholder="请输入报工周期"
min="1"
max="10"
/>
</view>
<!-- 任务时间 -->
<view class="form-item">
<view class="form-label">
<text class="label-text">开始时间</text>
<text class="required">*</text>
</view>
<picker
mode="date"
@change="onBeginTimeChange"
class="form-picker"
>
<view class="picker-text">
{{ form.beginTime || '请选择开始时间' }}
</view>
</picker>
</view>
<view class="form-item" v-if="form.status === 0">
<view class="form-label">
<text class="label-text">结束时间</text>
<text class="required">*</text>
</view>
<picker
mode="date"
@change="onFinishTimeChange"
class="form-picker"
>
<view class="picker-text">
{{ form.finishTime || '请选择结束时间' }}
</view>
</picker>
</view>
<!-- 优先级 -->
<view class="form-item">
<view class="form-label">
<text class="label-text">优先级</text>
</view>
<view class="radio-group">
<view
class="radio-item"
:class="{ active: form.taskGrade === '0' }"
@click="form.taskGrade = '0'"
>
<view class="radio-circle"></view>
<text class="radio-text">一般</text>
</view>
<view
class="radio-item"
:class="{ active: form.taskGrade === '1' }"
@click="form.taskGrade = '1'"
>
<view class="radio-circle"></view>
<text class="radio-text">中等</text>
</view>
<view
class="radio-item"
:class="{ active: form.taskGrade === '2' }"
@click="form.taskGrade = '2'"
>
<view class="radio-circle"></view>
<text class="radio-text">紧急</text>
</view>
</view>
</view>
<!-- 关联项目 -->
<view class="form-item">
<view class="form-label">
<text class="label-text">关联项目</text>
</view>
<picker
@change="onProjectChange"
:value="projectIndex"
:range="projectList"
range-key="projectName"
class="form-picker"
>
<view class="picker-text">
{{ projectIndex === -1 ? '请选择项目' : projectList[projectIndex].projectName }}
</view>
</picker>
<view v-if="projectIndex !== -1" class="selected-project" style="margin-top: 10rpx;">
<text>{{ projectList[projectIndex].projectName }}</text>
<text class="remove-btn" @click="removeProject" style="color:#ff4757;margin-left:20rpx;">移除</text>
</view>
</view>
<!-- 执行人 -->
<view class="form-item">
<view class="form-label">
<text class="label-text">执行人</text>
<text class="required">*</text>
</view>
<!-- 已选用户标签 -->
<view v-if="selectedUsers.length > 0" class="user-tags">
<view v-for="user in selectedUsers" :key="user.userId" class="user-tag">
<text>{{ user.nickName }}</text>
<text class="remove-btn" @click="removeUser(user)">×</text>
</view>
</view>
<button type="primary" size="mini" @click="openUserPopup">点击选择</button>
<!-- 弹窗 -->
<uni-popup ref="userPopup" type="center">
<view class="user-select-popup">
<view class="popup-header">
<text>选择执行人</text>
<text class="close-btn" @click="closeUserPopup">×</text>
</view>
<scroll-view scroll-y class="user-list" style="height: 400rpx;">
<view
v-for="user in userList"
:key="user.userId"
class="user-row"
@click="toggleUser(user)"
>
<checkbox :checked="isSelected(user)" />
<text>{{ user.nickName }}</text>
<text class="user-dept">{{ user.deptName }}</text>
</view>
</scroll-view>
<view class="popup-footer">
<button type="primary" size="mini" @click="confirmUserSelect">确定</button>
</view>
</view>
</uni-popup>
</view>
<!-- 详细描述 -->
<view class="form-item">
<view class="form-label">
<text class="label-text">详细描述</text>
</view>
<textarea
v-model="form.content"
class="form-textarea"
placeholder="请输入详细描述"
maxlength="1000"
auto-height
/>
</view>
<!-- 附件 -->
<view class="form-item">
<view class="form-label">
<text class="label-text">附件</text>
</view>
<view class="file-upload">
<view class="upload-btn" @click="chooseFile">
<text class="upload-icon">+</text>
<text class="upload-text">选择文件</text>
</view>
<view class="file-list" v-if="fileList.length > 0">
<view
class="file-item"
v-for="(file, index) in fileList"
:key="index"
>
<text class="file-name">{{ file.name }}</text>
<text class="file-size">{{ formatFileSize(file.size) }}</text>
<text class="remove-file" @click="removeFile(index)">×</text>
</view>
</view>
</view>
</view>
<!-- 提交按钮 -->
<view class="submit-container">
<button
type="primary"
class="submit-btn"
:loading="loading"
@click="submitForm"
>
{{ loading ? '提交中...' : '提交' }}
</button>
</view>
</form>
</view>
</view>
</template>
<script>
import { addTask } from '@/api/oa/task'
import { listProject } from '@/api/oa/project'
import { selectUser, deptTreeSelect } from '@/api/oa/user'
import { uploadImage } from '@/api/common/upload'
export default {
name: 'CreateTask',
data() {
return {
loading: false,
form: {
taskTitle: '',
taskType: '',
status: 0,
timeGap: 3,
beginTime: '',
finishTime: '',
taskGrade: '0',
projectId: '',
workerIds: '',
content: '',
accessory: ''
},
taskTypeOptions: [
{ label: '技术审查', value: 1 },
{ label: '初步设计', value: 2 },
{ label: '图纸详细设计', value: 3 },
{ label: 'PLC程序设计', value: 4 },
{ label: '画面设计', value: 5 },
{ label: '调试(传动、打点、精度)', value: 6 },
{ label: '验收资料', value: 7 },
{ label: '验收报告/差旅记录', value: 8 },
{ label: '项目结项', value: 9 }
],
taskTypeIndex: 0,
projectList: [],
projectIndex: -1,
userList: [],
selectedUsers: [],
// userPopupVisible: false, // 不再需要
fileList: [],
uploadedFiles: []
}
},
onLoad() {
this.initData()
},
methods: {
// 初始化数据
async initData() {
await Promise.all([
this.getProjectList(),
this.getUserList()
])
},
// 获取项目列表
async getProjectList() {
try {
const res = await listProject({
pageNum: 1,
pageSize: 999
})
this.projectList = res.rows || []
} catch (error) {
console.error('获取项目列表失败:', error)
uni.showToast({
title: '获取项目列表失败',
icon: 'none'
})
}
},
// 获取用户列表
async getUserList() {
try {
// const res = await selectUser({ pageNum: 1, pageSize: 999, deptId: 100 })
const resr = await deptTreeSelect()
// this.userList = res.rows || []
} catch (error) {
console.error('获取用户列表失败:', error)
uni.showToast({
title: '获取用户列表失败',
icon: 'none'
})
}
},
// 工作类型选择
onTaskTypeChange(e) {
this.taskTypeIndex = e.detail.value
this.form.taskType = this.taskTypeOptions[this.taskTypeIndex].value
},
// 开始时间选择
onBeginTimeChange(e) {
this.form.beginTime = e.detail.value + ' 00:00:00'
},
// 结束时间选择
onFinishTimeChange(e) {
this.form.finishTime = e.detail.value + ' 23:59:59'
},
// 项目选择
onProjectChange(e) {
this.projectIndex = e.detail.value
this.form.projectId = this.projectList[this.projectIndex].projectId
},
// 移除项目
removeProject() {
this.projectIndex = -1
this.form.projectId = ''
},
// 打开用户选择器
openUserPopup() {
this.$refs.userPopup.open()
},
// 关闭用户选择器
closeUserPopup() {
this.$refs.userPopup.close()
},
// 勾选/取消用户
toggleUser(user) {
const index = this.selectedUsers.findIndex(u => u.userId === user.userId)
if (index > -1) {
this.selectedUsers.splice(index, 1)
} else {
this.selectedUsers.push(user)
}
},
// 判断用户是否已选
isSelected(user) {
return this.selectedUsers.some(u => u.userId === user.userId)
},
// 移除已选用户
removeUser(user) {
const index = this.selectedUsers.findIndex(u => u.userId === user.userId)
if (index > -1) {
this.selectedUsers.splice(index, 1)
}
},
// 确认选择
confirmUserSelect() {
this.form.workerIds = this.selectedUsers.map(u => u.userId).join(',')
this.closeUserPopup()
},
// 选择文件
chooseFile() {
uni.chooseFile({
count: 5,
type: 'all',
success: (res) => {
this.fileList = [...this.fileList, ...res.tempFiles]
}
})
},
// 移除文件
removeFile(index) {
this.fileList.splice(index, 1)
},
// 格式化文件大小
formatFileSize(size) {
if (size < 1024) {
return size + 'B'
} else if (size < 1024 * 1024) {
return (size / 1024).toFixed(2) + 'KB'
} else {
return (size / (1024 * 1024)).toFixed(2) + 'MB'
}
},
// 上传文件
async uploadFiles() {
const uploadPromises = this.fileList.map(async (file) => {
try {
const result = await uploadImage(file.path)
return {
originalName: file.name,
url: result.url,
ossId: result.ossId
}
} catch (error) {
console.error('文件上传失败:', error)
throw error
}
})
return Promise.all(uploadPromises)
},
// 表单验证
validateForm() {
if (!this.form.taskTitle.trim()) {
uni.showToast({
title: '请输入任务主题',
icon: 'none'
})
return false
}
if (!this.form.taskType) {
uni.showToast({
title: '请选择工作类型',
icon: 'none'
})
return false
}
if (!this.form.beginTime) {
uni.showToast({
title: '请选择开始时间',
icon: 'none'
})
return false
}
if (this.form.status === 0 && !this.form.finishTime) {
uni.showToast({
title: '请选择结束时间',
icon: 'none'
})
return false
}
if (this.form.workerIds === '') {
uni.showToast({
title: '请选择执行人',
icon: 'none'
})
return false
}
return true
},
// 提交表单
async submitForm() {
if (!this.validateForm()) {
return
}
this.loading = true
try {
// 上传文件
if (this.fileList.length > 0) {
const uploadedFiles = await this.uploadFiles()
this.form.accessory = uploadedFiles.map(file => file.ossId).join(',')
}
// 提交任务
await addTask(this.form)
uni.showToast({
title: '任务创建成功',
icon: 'success'
})
// 返回上一页
setTimeout(() => {
uni.navigateBack()
}, 1500)
} catch (error) {
console.error('创建任务失败:', error)
uni.showToast({
title: '创建任务失败',
icon: 'none'
})
} finally {
this.loading = false
}
}
}
}
</script>
<style lang="scss" scoped>
.create-task-container {
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
background-color: #f5f5f5;
padding-bottom: 120rpx;
}
.form-container {
max-width: 90vw;
margin: 0 auto;
box-sizing: border-box;
padding: 30rpx 20rpx;
}
.form-item {
border-radius: 12rpx;
box-sizing: border-box;
padding: 30rpx;
margin-bottom: 20rpx;
}
.form-label {
display: flex;
align-items: center;
margin-bottom: 20rpx;
.label-text {
font-size: 28rpx;
color: #333;
font-weight: 500;
}
.required {
color: #ff4757;
margin-left: 8rpx;
}
}
.form-input {
width: 100%;
height: 80rpx;
border: 1rpx solid #ddd;
border-radius: 8rpx;
padding: 0 20rpx;
font-size: 28rpx;
background-color: #fff;
}
.form-picker {
width: 100%;
height: 80rpx;
border: 1rpx solid #ddd;
border-radius: 8rpx;
display: flex;
align-items: center;
padding: 0 20rpx;
background-color: #fff;
.picker-text {
font-size: 28rpx;
color: #333;
}
}
.radio-group {
display: flex;
flex-wrap: wrap;
gap: 20rpx;
}
.radio-item {
display: flex;
align-items: center;
padding: 20rpx 30rpx;
border: 1rpx solid #ddd;
border-radius: 8rpx;
background-color: #fff;
&.active {
border-color: #007aff;
background-color: #f0f8ff;
.radio-circle {
background-color: #007aff;
&::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 12rpx;
height: 12rpx;
background-color: #fff;
border-radius: 50%;
}
}
}
.radio-circle {
width: 32rpx;
height: 32rpx;
border: 2rpx solid #ddd;
border-radius: 50%;
margin-right: 16rpx;
position: relative;
}
.radio-text {
font-size: 28rpx;
color: #333;
}
}
.user-selector {
min-height: 80rpx;
border: 1rpx solid #ddd;
border-radius: 8rpx;
padding: 20rpx;
background-color: #fff;
.selected-users {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
}
.user-tag {
display: flex;
align-items: center;
background-color: #f0f8ff;
border: 1rpx solid #007aff;
border-radius: 20rpx;
padding: 8rpx 16rpx;
.user-name {
font-size: 24rpx;
color: #007aff;
margin-right: 8rpx;
}
.remove-btn {
font-size: 24rpx;
color: #007aff;
font-weight: bold;
}
}
.placeholder {
font-size: 28rpx;
color: #999;
}
}
.form-textarea {
width: 100%;
min-height: 200rpx;
border: 1rpx solid #ddd;
border-radius: 8rpx;
padding: 20rpx;
font-size: 28rpx;
background-color: #fff;
line-height: 1.5;
}
.file-upload {
.upload-btn {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 160rpx;
border: 2rpx dashed #ddd;
border-radius: 8rpx;
background-color: #fafafa;
.upload-icon {
font-size: 48rpx;
color: #999;
margin-bottom: 16rpx;
}
.upload-text {
font-size: 28rpx;
color: #999;
}
}
.file-list {
margin-top: 20rpx;
}
.file-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20rpx;
background-color: #f8f9fa;
border-radius: 8rpx;
margin-bottom: 16rpx;
.file-name {
font-size: 28rpx;
color: #333;
flex: 1;
margin-right: 16rpx;
}
.file-size {
font-size: 24rpx;
color: #999;
margin-right: 16rpx;
}
.remove-file {
font-size: 32rpx;
color: #ff4757;
font-weight: bold;
}
}
}
.submit-container {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background-color: #fff;
padding: 30rpx;
border-top: 1rpx solid #eee;
.submit-btn {
width: 100%;
height: 88rpx;
background-color: #007aff;
color: #fff;
border-radius: 8rpx;
font-size: 32rpx;
font-weight: 500;
}
}
.user-popup {
background-color: #fff;
border-radius: 20rpx 20rpx 0 0;
max-height: 80vh;
display: flex;
flex-direction: column;
.popup-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 30rpx;
border-bottom: 1rpx solid #eee;
.popup-title {
font-size: 32rpx;
font-weight: bold;
color: #333;
}
.close-btn {
font-size: 40rpx;
color: #999;
font-weight: bold;
}
}
.user-list {
flex: 1;
overflow-y: auto;
padding: 0 30rpx;
}
.user-item {
display: flex;
align-items: center;
padding: 30rpx 0;
border-bottom: 1rpx solid #f5f5f5;
.user-avatar {
margin-right: 20rpx;
.avatar-img {
width: 80rpx;
height: 80rpx;
border-radius: 50%;
}
}
.user-info {
flex: 1;
.user-nickname {
font-size: 28rpx;
color: #333;
font-weight: 500;
display: block;
}
.user-dept {
font-size: 24rpx;
color: #999;
margin-top: 8rpx;
display: block;
}
}
.user-check {
width: 40rpx;
height: 40rpx;
border: 2rpx solid #007aff;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
background-color: #007aff;
.check-icon {
color: #fff;
font-size: 24rpx;
font-weight: bold;
}
}
}
.popup-footer {
padding: 30rpx;
border-top: 1rpx solid #eee;
.confirm-btn {
width: 100%;
height: 88rpx;
background-color: #007aff;
color: #fff;
border-radius: 8rpx;
font-size: 32rpx;
font-weight: 500;
}
}
}
.user-tags {
display: flex;
flex-wrap: wrap;
margin-bottom: 10rpx;
}
.user-tag {
background: #e6f7ff;
color: #007aff;
border-radius: 20rpx;
padding: 6rpx 16rpx;
margin-right: 10rpx;
margin-bottom: 10rpx;
display: flex;
align-items: center;
}
.remove-btn {
margin-left: 8rpx;
color: #ff4757;
font-weight: bold;
cursor: pointer;
}
.user-select-popup {
width: 90vw;
max-width: 700rpx;
background: #fff;
border-radius: 16rpx;
overflow: hidden;
}
.popup-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 24rpx;
border-bottom: 1rpx solid #eee;
font-size: 32rpx;
font-weight: bold;
}
.close-btn {
font-size: 40rpx;
color: #999;
font-weight: bold;
}
.popup-body {
display: flex;
height: 400rpx;
}
.dept-tree {
width: 180rpx;
border-right: 1rpx solid #eee;
background: #f8f8f8;
padding: 10rpx 0;
}
.dept-item {
padding: 16rpx 24rpx;
cursor: pointer;
}
.dept-item.active {
background: #e6f7ff;
color: #007aff;
}
.dept-children {
margin-left: 10rpx;
}
.user-list {
flex: 1;
padding: 10rpx 0 10rpx 10rpx;
overflow-y: auto;
}
.user-row {
display: flex;
align-items: center;
padding: 10rpx 0;
border-bottom: 1rpx solid #f5f5f5;
}
.user-row .user-dept {
margin-left: 16rpx;
color: #999;
font-size: 24rpx;
}
.popup-footer {
padding: 20rpx;
text-align: right;
}
</style>

View File

@@ -0,0 +1,239 @@
<template>
<view class="detail-container">
<view v-if="loading" class="loading"><u-loading mode="circle" text="加载中..." /></view>
<view v-else-if="taskDetail">
<view class="title">{{ taskDetail.taskTitle }}</view>
<view class="row"><text class="label">负责人</text>{{ taskDetail.workerNickName || '-' }}</view>
<view class="row"><text class="label">开始时间</text>{{ taskDetail.beginTime || '-' }}</view>
<view class="row"><text class="label">结束时间</text>{{ taskDetail.finishTime || '-' }}</view>
<view class="row"><text class="label">创建人</text>{{ taskDetail.createUserNickName || '-' }}</view>
<view class="row"><text class="label">创建时间</text>{{ taskDetail.createTime || '-' }}</view>
<view class="section-title">任务描述</view>
<mp-html v-if="taskDetail.content" :content="taskDetail.content" />
<view class="section-title">报工进度</view>
<view v-if="taskDetail.taskItemVoList && taskDetail.taskItemVoList.length">
<view v-for="item in taskDetail.taskItemVoList" :key="item.itemId" class="item-block">
<view class="item-row"><text class="item-label">进度时间</text>{{ item.signTime || '-' }}</view>
<view class="item-row"><text class="item-label">进度区间</text>{{ item.beginTime || '-' }} ~ {{ item.endTime || '-' }}</view>
<view class="item-row"><text class="item-label">进度内容</text></view>
<mp-html v-if="item.content" :content="item.content" />
<view class="item-row"><text class="item-label">完成时间</text>{{ item.completedTime || '-' }}</view>
</view>
</view>
<view v-else class="empty-progress">暂无报工进度</view>
<u-button type="primary" class="add-btn" @click="openAddPopup">新增报工</u-button>
<uni-popup ref="addPopup" type="bottom" :mask-click="true">
<view class="add-dialog-bottom">
<view class="dialog-title">新增报工</view>
<u-form :model="addForm" ref="addFormRef">
<u-form-item label="进度区间">
<view class="period-row">{{ addForm.beginTime }} ~ {{ addForm.endTime }}</view>
</u-form-item>
<u-form-item label="进度时间">
<view class="period-row">{{ addForm.signTime }}</view>
</u-form-item>
<u-form-item label="完成时间">
<view class="period-row">{{ addForm.completedTime }}</view>
</u-form-item>
<u-form-item label="进度内容">
<u-textarea v-model="addForm.content" placeholder="请输入进度内容" autoHeight />
</u-form-item>
<u-form-item label="备注">
<u-textarea v-model="addForm.remark" placeholder="备注(可选)" autoHeight />
</u-form-item>
</u-form>
<view class="dialog-actions">
<u-button type="primary" @click="submitAdd">提交</u-button>
<u-button @click="$refs.addPopup.close()">取消</u-button>
</view>
</view>
</uni-popup>
</view>
<view v-else class="empty">未查询到任务详情</view>
</view>
</template>
<script>
import { getTask } from '@/api/oa/task.js'
import { addOaTaskItem } from '@/api/oa/taskItem.js'
import mpHtml from 'uni_modules/mp-html/components/mp-html/mp-html.vue'
export default {
components: { mpHtml },
data() {
return {
taskDetail: null,
loading: true,
addForm: {
beginTime: '',
endTime: '',
content: '',
remark: ''
}
}
},
onLoad(options) {
const taskId = options.id
if (taskId) {
this.taskId = taskId
this.fetchDetail(taskId)
} else {
this.loading = false
}
},
methods: {
async fetchDetail(taskId) {
this.loading = true
try {
const res = await getTask(taskId)
if (res.code === 200 && res.data) {
this.taskDetail = res.data
} else {
uni.showToast({ title: res.msg || '获取详情失败', icon: 'none' })
}
} catch (e) {
uni.showToast({ title: '网络错误', icon: 'none' })
} finally {
this.loading = false
}
},
openAddPopup() {
// 自动获取进度区间
let begin = '', end = '';
const items = this.taskDetail?.taskItemVoList || [];
if (items.length > 0) {
// 取最后一个item的endTime为下一个周期的beginTime
const last = items[items.length - 1];
begin = last.endTime || this.taskDetail.beginTime;
// 结束时间=begin+timeGap天
const gap = this.taskDetail.timeGap || 7;
const bDate = new Date(begin.replace(/-/g, '/'));
bDate.setDate(bDate.getDate() + gap);
end = bDate.getFullYear() + '-' + String(bDate.getMonth() + 1).padStart(2, '0') + '-' + String(bDate.getDate()).padStart(2, '0');
} else {
begin = this.taskDetail.beginTime;
end = this.taskDetail.finishTime;
}
// 进度时间=beginTime完成时间=当天
const today = new Date();
const todayStr = today.getFullYear() + '-' + String(today.getMonth() + 1).padStart(2, '0') + '-' + String(today.getDate()).padStart(2, '0');
this.addForm = {
beginTime: begin,
endTime: end,
signTime: begin,
completedTime: todayStr,
content: '',
remark: ''
};
this.$refs.addPopup.open();
},
async submitAdd() {
if (!this.addForm.beginTime || !this.addForm.endTime || !this.addForm.content) {
uni.showToast({ title: '请填写进度内容', icon: 'none' })
return
}
const data = {
taskId: this.taskId,
beginTime: this.addForm.beginTime,
endTime: this.addForm.endTime,
signTime: this.addForm.signTime,
completedTime: this.addForm.completedTime,
content: this.addForm.content,
remark: this.addForm.remark || null,
status: 0
}
try {
const res = await addOaTaskItem(data)
if (res.code === 200) {
uni.showToast({ title: '新增报工成功', icon: 'success' })
this.$refs.addPopup.close()
this.addForm = { beginTime: '', endTime: '', signTime: '', completedTime: '', content: '', remark: '' }
this.fetchDetail(this.taskId)
} else {
uni.showToast({ title: res.msg || '新增失败', icon: 'none' })
}
} catch (e) {
uni.showToast({ title: '网络错误', icon: 'none' })
}
}
}
}
</script>
<style scoped>
.detail-container {
padding: 32rpx;
}
.title {
font-size: 36rpx;
font-weight: bold;
margin-bottom: 24rpx;
}
.row {
font-size: 28rpx;
margin-bottom: 12rpx;
}
.label {
color: #888;
}
.section-title {
margin-top: 32rpx;
font-size: 30rpx;
font-weight: 600;
color: #333;
margin-bottom: 16rpx;
}
.item-block {
background: #f8f9fa;
border-radius: 12rpx;
padding: 20rpx;
margin-bottom: 20rpx;
}
.item-row {
font-size: 26rpx;
margin-bottom: 8rpx;
}
.item-label {
color: #666;
}
.empty-progress, .empty {
text-align: center;
color: #bbb;
margin: 40rpx 0;
}
.loading {
text-align: center;
margin: 80rpx 0;
}
.add-btn {
margin-top: 40rpx;
width: 100%;
}
.add-dialog-bottom {
background: #fff;
border-radius: 24rpx 24rpx 0 0;
padding: 40rpx 32rpx 32rpx 32rpx;
width: 100vw;
max-width: 750rpx;
box-sizing: border-box;
}
.dialog-title {
font-size: 32rpx;
font-weight: 600;
margin-bottom: 32rpx;
text-align: center;
}
.dialog-actions {
display: flex;
gap: 24rpx;
margin-top: 32rpx;
justify-content: center;
}
.period-row {
font-size: 28rpx;
color: #333;
padding: 12rpx 0 12rpx 8rpx;
}
</style>

View File

@@ -0,0 +1,800 @@
<template>
<view class="task-container">
<!-- 搜索栏 -->
<view class="search-bar">
<u-search
v-model="searchKeyword"
placeholder="搜索任务名称"
:show-action="false"
@search="handleSearch"
@clear="handleClear"
></u-search>
</view>
<!-- 任务列表 -->
<view class="task-list">
<uni-swipe-action>
<uni-swipe-action-item
v-for="(task, index) in taskList"
:key="task.taskId"
:right-options="getSwipeOptions(task)"
@click="handleSwipeClick($event, index)"
>
<view
class="task-item"
@click="handleTaskClick(task)"
>
<view v-if="task.status === 0" class="task-checkbox" @click.stop="handleTaskComplete(task)">
<view v-if="task.state === 0" class="checkbox-container">
<u-checkbox
:value="false"
:active-color="'#ff9500'"
size="20"
></u-checkbox>
</view>
<view v-else-if="task.state === 1" class="checkbox-container">
<u-icon name="checkmark" size="20" color="#999"></u-icon>
</view>
<view v-else-if="task.state === 2" class="checkbox-container">
<u-icon name="checkmark" size="20" color="#52c41a"></u-icon>
</view>
<view v-else class="checkbox-container">
<u-checkbox
:value="false"
:disabled="true"
:active-color="'#999'"
size="20"
></u-checkbox>
</view>
</view>
<view class="task-content">
<view class="task-title">{{ task.taskTitle || '未命名任务' }}</view>
<view class="task-status" :class="getStatusClass(task.state)">
{{ getStatusText(task.state) }}
</view>
</view>
<view v-if="task.ownRank === 1" class="top-badge">
<u-icon name="arrow-up" size="12" color="#ff9500"></u-icon>
</view>
</view>
</uni-swipe-action-item>
</uni-swipe-action>
</view>
<!-- 空状态 -->
<view v-if="taskList.length === 0 && !loading" class="empty-state">
<u-empty text="暂无发布的任务" mode="list"></u-empty>
</view>
<!-- 加载更多 -->
<u-load-more
:status="loadMoreStatus"
@loadmore="loadMore"
></u-load-more>
<!-- 悬浮按钮 -->
<view class="fab-button" @click="createTask">
<u-icon name="plus" color="#fff" size="24"></u-icon>
</view>
<!-- 任务详情弹窗 -->
<uni-popup ref="taskDetailPopup" type="bottom" :mask-click="true">
<view class="popup-content">
<view class="popup-header">
<text class="popup-title">任务详情</text>
<u-icon name="close" size="20" @click="closeTaskDetail"></u-icon>
</view>
<scroll-view class="popup-body" scroll-y>
<view v-if="currentTask" class="task-detail">
<view class="detail-section">
<view class="section-title">基本信息</view>
<view class="detail-item">
<text class="label">任务标题</text>
<text class="value">{{ currentTask.taskTitle }}</text>
</view>
<view class="detail-item">
<text class="label">任务状态</text>
<text class="value status-tag" :class="getStatusClass(currentTask.state)">
{{ getStatusText(currentTask.state) }}
</text>
</view>
<view class="detail-item">
<text class="label">优先级</text>
<text class="value priority-tag" :class="getPriorityClass(currentTask.taskRank)">
{{ getPriorityText(currentTask.taskRank) }}
</text>
</view>
<view class="detail-item">
<text class="label">所属项目</text>
<text class="value">{{ currentTask.projectName }}</text>
</view>
</view>
<view class="detail-section">
<view class="section-title">时间信息</view>
<view class="detail-item">
<text class="label">开始时间</text>
<text class="value">{{ formatDate(currentTask.beginTime) }}</text>
</view>
<view class="detail-item">
<text class="label">结束时间</text>
<text class="value">{{ formatDate(currentTask.finishTime) }}</text>
</view>
<view class="detail-item" v-if="currentTask.overDays > 0">
<text class="label">超期天数</text>
<text class="value over-days">{{ currentTask.overDays }}</text>
</view>
</view>
<view class="detail-section">
<view class="section-title">人员信息</view>
<view class="detail-item">
<text class="label">负责人</text>
<text class="value">{{ currentTask.workerNickName }}</text>
</view>
<view class="detail-item">
<text class="label">创建人</text>
<text class="value">{{ currentTask.createUserNickName }}</text>
</view>
<view class="detail-item">
<text class="label">创建时间</text>
<text class="value">{{ formatDate(currentTask.createTime) }}</text>
</view>
</view>
<view class="detail-section" v-if="currentTask.content">
<view class="section-title">任务描述</view>
<view class="task-content-text">{{ currentTask.content }}</view>
</view>
<view class="detail-section" v-if="currentTask.remark">
<view class="section-title">备注</view>
<view class="task-content-text">{{ currentTask.remark }}</view>
</view>
</view>
</scroll-view>
<!-- <view class="popup-footer">
<u-button type="primary" @click="editCurrentTask">编辑任务</u-button>
<u-button type="error" @click="deleteCurrentTask">删除任务</u-button>
</view> -->
</view>
</uni-popup>
</view>
</template>
<script>
import { listTaskWork, delTask, updateTask } from '@/api/oa/task.js'
export default {
data() {
return {
taskList: [],
loading: false,
searchKeyword: '',
queryParams: {
pageNum: 1,
pageSize: 10,
taskTitle: ''
},
loadMoreStatus: 'more', // more, loading, noMore
total: 0,
currentTask: null
}
},
onLoad() {
this.loadTaskList()
},
onPullDownRefresh() {
this.refreshList()
},
onReachBottom() {
this.loadMore()
},
methods: {
// 加载任务列表
async loadTaskList() {
if (this.loading) return
this.loading = true
try {
const response = await listTaskWork(this.queryParams)
if (response.code === 200) {
const { rows, total } = response
if (this.queryParams.pageNum === 1) {
this.taskList = rows || []
} else {
this.taskList = [...this.taskList, ...(rows || [])]
}
this.total = total
this.updateLoadMoreStatus(rows, total)
} else {
uni.showToast({
title: response.msg || '获取任务列表失败',
icon: 'none'
})
}
} catch (error) {
console.error('加载任务列表失败:', error)
uni.showToast({
title: '网络错误,请重试',
icon: 'none'
})
} finally {
this.loading = false
uni.stopPullDownRefresh()
}
},
// 刷新列表
refreshList() {
this.queryParams.pageNum = 1
this.loadTaskList()
},
// 加载更多
loadMore() {
if (this.loadMoreStatus === 'noMore' || this.loading) return
this.queryParams.pageNum++
this.loadTaskList()
},
// 更新加载更多状态
updateLoadMoreStatus(rows, total) {
const currentTotal = this.taskList.length
if (currentTotal >= total) {
this.loadMoreStatus = 'noMore'
} else if (rows && rows.length < this.queryParams.pageSize) {
this.loadMoreStatus = 'noMore'
} else {
this.loadMoreStatus = 'more'
}
},
// 搜索
handleSearch() {
this.queryParams.taskTitle = this.searchKeyword
this.queryParams.pageNum = 1
this.loadTaskList()
},
// 清除搜索
handleClear() {
this.searchKeyword = ''
this.queryParams.taskTitle = ''
this.queryParams.pageNum = 1
this.loadTaskList()
},
// 显示任务详情弹窗
showTaskDetail(task) {
this.currentTask = task
this.$refs.taskDetailPopup.open()
},
// 关闭任务详情弹窗
closeTaskDetail() {
this.$refs.taskDetailPopup.close()
this.currentTask = null
},
// 获取左划操作选项
getSwipeOptions(task) {
const options = []
if (task.ownRank === 1) {
// 已置顶,显示取消置顶
options.push({
text: '取消置顶',
style: {
backgroundColor: '#999',
color: '#fff'
}
})
} else {
// 未置顶,显示置顶
options.push({
text: '置顶',
style: {
backgroundColor: '#ff9500',
color: '#fff'
}
})
}
return options
},
// 处理左划操作点击
async handleSwipeClick(e, index) {
console.log('swipe click event:', e, 'index:', index)
const { content, position } = e
if (!content) {
console.error('Invalid swipe event:', e)
return
}
const task = this.taskList[index]
if (!task) {
console.error('Task not found at index:', index)
return
}
if (content.text === '置顶') {
await this.setTaskTop(task, 1)
} else if (content.text === '取消置顶') {
await this.setTaskTop(task, 0)
}
},
// 设置任务置顶状态
async setTaskTop(task, ownRank) {
try {
const response = await updateTask({
taskId: task.taskId,
ownRank: ownRank
})
if (response.code === 200) {
uni.showToast({
title: ownRank === 1 ? '置顶成功' : '取消置顶成功',
icon: 'success'
})
// 重新请求数据以获取最新排序
this.refreshList()
} else {
uni.showToast({
title: response.msg || '操作失败',
icon: 'none'
})
}
} catch (error) {
console.error('设置置顶失败:', error)
uni.showToast({
title: '操作失败,请重试',
icon: 'none'
})
}
},
// 处理任务完成
async handleTaskComplete(task) {
// 只有单任务status为0且状态为0进行中的任务才能完成
if (task.status !== 0 || task.state !== 0) {
return
}
uni.showModal({
title: '确认完成',
content: `确定要将任务"${task.taskTitle}"标记为完成吗?`,
success: async (res) => {
if (res.confirm) {
await this.completeTask(task)
}
}
})
},
// 完成任务
async completeTask(task) {
try {
const response = await updateTask({
taskId: task.taskId,
state: 1 // 设置为完成等待评分状态
})
if (response.code === 200) {
uni.showToast({
title: '任务完成',
icon: 'success'
})
// 重新请求数据
this.refreshList()
} else {
uni.showToast({
title: response.msg || '操作失败',
icon: 'none'
})
}
} catch (error) {
console.error('完成任务失败:', error)
uni.showToast({
title: '操作失败,请重试',
icon: 'none'
})
}
},
// 删除任务
async deleteTask(task) {
uni.showModal({
title: '确认删除',
content: `确定要删除任务"${task.taskTitle}"吗?`,
success: async (res) => {
if (res.confirm) {
try {
const response = await delTask(task.taskId)
if (response.code === 200) {
uni.showToast({
title: '删除成功',
icon: 'success'
})
this.refreshList()
} else {
uni.showToast({
title: response.msg || '删除失败',
icon: 'none'
})
}
} catch (error) {
console.error('删除任务失败:', error)
uni.showToast({
title: '删除失败,请重试',
icon: 'none'
})
}
}
}
})
},
// 创建任务
createTask() {
uni.navigateTo({
url: '/pages/workbench/task/create'
})
},
// 格式化日期
formatDate(dateStr) {
if (!dateStr) return '未设置'
const date = new Date(dateStr)
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`
},
// 获取状态文本
getStatusText(state) {
const statusMap = {
15: '申请延期',
0: '进行中',
1: '完成等待评分',
2: '完成'
}
return statusMap[state] || '未知状态'
},
// 获取状态样式类
getStatusClass(state) {
const classMap = {
15: 'status-pending',
0: 'status-processing',
1: 'status-waiting',
2: 'status-completed'
}
return classMap[state] || 'status-unknown'
},
// 获取优先级文本
getPriorityText(priority) {
const priorityMap = {
0: '普通',
1: '低',
2: '中',
3: '高',
4: '紧急'
}
return priorityMap[priority] || '未设置'
},
// 获取优先级样式类
getPriorityClass(priority) {
const classMap = {
0: 'priority-normal',
1: 'priority-low',
2: 'priority-medium',
3: 'priority-high',
4: 'priority-urgent'
}
return classMap[priority] || 'priority-unknown'
},
// 新增:区分任务类型的点击事件
handleTaskClick(task) {
if (task.status === 1) {
// 报工任务,跳转到报工任务详情页
uni.navigateTo({
url: `/pages/workbench/task/reportTaskDetail?id=${task.taskId}`
});
} else {
// 单任务,弹出详情弹窗
this.showTaskDetail(task);
}
}
}
}
</script>
<style lang="scss" scoped>
.task-container {
min-height: 100vh;
background-color: #f5f5f5;
padding-bottom: 120rpx;
}
.search-bar {
padding: 20rpx;
position: sticky;
top: 0;
z-index: 100;
}
.task-list {
padding: 20rpx;
}
.task-item {
box-sizing: border-box;
padding: 24rpx;
display: flex;
align-items: center;
position: relative;
transition: all 0.3s ease;
}
.task-checkbox {
margin-right: 20rpx;
flex-shrink: 0;
}
.checkbox-container {
display: flex;
align-items: center;
justify-content: center;
width: 40rpx;
height: 40rpx;
}
.task-content {
flex: 1;
display: flex;
justify-content: space-between;
align-items: center;
}
.task-title {
font-size: 32rpx;
font-weight: 600;
color: #333;
flex: 1;
margin-right: 20rpx;
line-height: 1.4;
height: 88rpx; /* 两行文字的高度32rpx * 1.4 * 2 */
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
text-overflow: ellipsis;
}
.task-status {
padding: 8rpx 16rpx;
border-radius: 20rpx;
font-size: 24rpx;
font-weight: 500;
box-shadow: 0 1rpx 3rpx rgba(0, 0, 0, 0.1);
&.status-pending {
background-color: #fff2e8;
color: #fa8c16;
}
&.status-processing {
background-color: #e6f7ff;
color: #1890ff;
}
&.status-waiting {
background-color: #fff7e6;
color: #fa8c16;
}
&.status-completed {
background-color: #f6ffed;
color: #52c41a;
}
}
.empty-state {
padding: 100rpx 20rpx;
text-align: center;
}
.fab-button {
position: fixed;
right: 40rpx;
bottom: 40rpx;
width: 100rpx;
height: 100rpx;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 4rpx 16rpx rgba(102, 126, 234, 0.4);
z-index: 999;
}
// 弹窗样式
.popup-content {
background-color: #fff;
border-radius: 24rpx 24rpx 0 0;
max-height: 80vh;
display: flex;
flex-direction: column;
z-index: 1001;
}
.top-badge {
position: absolute;
top: 8rpx;
right: 8rpx;
background-color: #fff8e6;
border: 1rpx solid #ff9500;
border-radius: 50%;
width: 28rpx;
height: 28rpx;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 2rpx 6rpx rgba(255, 149, 0, 0.2);
}
.popup-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 32rpx 24rpx 24rpx;
border-bottom: 1rpx solid #f0f0f0;
}
.popup-title {
font-size: 36rpx;
font-weight: 600;
color: #333;
}
.popup-body {
flex: 1;
padding: 24rpx;
max-height: 60vh;
}
.task-detail {
display: flex;
flex-direction: column;
gap: 32rpx;
}
.detail-section {
display: flex;
flex-direction: column;
gap: 16rpx;
}
.section-title {
font-size: 32rpx;
font-weight: 600;
color: #333;
padding-bottom: 12rpx;
border-bottom: 1rpx solid #f0f0f0;
}
.detail-item {
display: flex;
align-items: flex-start;
font-size: 28rpx;
line-height: 1.5;
}
.detail-item .label {
color: #666;
width: 160rpx;
flex-shrink: 0;
}
.detail-item .value {
color: #333;
flex: 1;
&.status-tag {
padding: 4rpx 12rpx;
border-radius: 12rpx;
font-size: 24rpx;
font-weight: 500;
&.status-pending {
background-color: #fff2e8;
color: #fa8c16;
}
&.status-processing {
background-color: #e6f7ff;
color: #1890ff;
}
&.status-waiting {
background-color: #fff7e6;
color: #fa8c16;
}
&.status-completed {
background-color: #f6ffed;
color: #52c41a;
}
}
&.priority-tag {
padding: 4rpx 12rpx;
border-radius: 12rpx;
font-size: 24rpx;
font-weight: 500;
&.priority-normal {
background-color: #f5f5f5;
color: #666;
}
&.priority-low {
background-color: #f6ffed;
color: #52c41a;
}
&.priority-medium {
background-color: #fff7e6;
color: #fa8c16;
}
&.priority-high {
background-color: #fff2f0;
color: #ff4d4f;
}
&.priority-urgent {
background-color: #f9f0ff;
color: #722ed1;
}
}
&.over-days {
color: #ff4d4f;
font-weight: 600;
}
}
.task-content-text {
font-size: 28rpx;
color: #333;
line-height: 1.6;
background-color: #f8f9fa;
padding: 20rpx;
border-radius: 12rpx;
border-left: 4rpx solid #1890ff;
}
.popup-footer {
display: flex;
gap: 20rpx;
padding: 24rpx;
border-top: 1rpx solid #f0f0f0;
}
</style>