index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. <template>
  2. <view class="activity-container">
  3. <view class="fixed-content">
  4. <!-- 顶部地块信息卡片 -->
  5. <view class="plot-info-card">
  6. <view class="plot-header">
  7. <text class="plot-name">{{ plotData.name || '未选择地块'}}</text>
  8. <text class="plot-area">{{ plotData.size || 0 }}亩</text>
  9. </view>
  10. <view class="plot-details">
  11. <view class="plot-item">
  12. <text class="item-label">作物:</text>
  13. <text class="item-value">{{ plotData.growCrops || '未选择地块' }}</text>
  14. </view>
  15. <view class="plot-item">
  16. <text class="item-label">负责人:</text>
  17. <text class="item-value">{{ plotData.managerName || '未选择地块'}}</text>
  18. </view>
  19. </view>
  20. </view>
  21. <!-- 任务状态筛选 -->
  22. <view class="tab-filter">
  23. <view class="tab-container">
  24. <view
  25. class="tab-item"
  26. v-for="(status, index) in taskStatus"
  27. :key="index"
  28. :class="{ active: currentStatus === status.value }"
  29. @click="switchStatus(status.value)"
  30. >
  31. <text>{{ status.label }}</text>
  32. <view class="badge" v-if="status.value === 0 && pendingTaskCount > 0">
  33. {{ pendingTaskCount > 99 ? '99+' : pendingTaskCount }}
  34. </view>
  35. <view class="active-line" v-if="currentStatus === status.value"></view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <!-- 任务列表 - 可滚动区域 -->
  41. <scroll-view class="task-list-scroll" scroll-y lower-threshold="120"
  42. @scrolltolower="loadMore"
  43. @refresherrefresh="refreshData"
  44. refresher-enabled
  45. :refresher-triggered="isRefreshing">
  46. <view class="task-list">
  47. <view class="task-card" v-for="(task, index) in taskList" :key="task.id" @click="viewTaskDetail(task)">
  48. <!-- 头部区域:任务名称和状态标签 -->
  49. <view class="task-header">
  50. <view class="task-name">{{ task.taskName }}</view>
  51. <dict-tag
  52. dict-type="task_status"
  53. :value="task.taskStatus"
  54. class="task-status-tag"
  55. />
  56. </view>
  57. <!-- 信息行:类型、时间、责任人统一放在一行,类型在前 -->
  58. <view class="task-info-row">
  59. <!-- 类型标签放在最左侧 -->
  60. <view class="info-type">
  61. <image src="/static/icons/task_icon.png" mode="aspectFit" class="info-icon"></image>
  62. <dict-tag
  63. dict-type="task_type"
  64. :value="task.typeName"
  65. :colored="false"
  66. class="info-type-tag"
  67. />
  68. </view>
  69. <!-- 时间信息放在中间 -->
  70. <view class="info-time">
  71. <image src="/static/icons/clock_icon.png" mode="aspectFit" class="info-icon"></image>
  72. <text class="info-text">{{ formatDate(task.executeTime) }}</text>
  73. </view>
  74. <!-- 责任人信息放在右侧 -->
  75. <view class="info-person">
  76. <image src="/static/icons/user.png" mode="aspectFit" class="info-icon"></image>
  77. <text class="info-text">{{ task.assigneeName || '未分配' }}</text>
  78. </view>
  79. </view>
  80. <!-- 备注区域 -->
  81. <view class="task-remark" v-if="task.remark" @click.stop="toggleRemark(index)">
  82. <text class="remark-label">备注:</text>
  83. <text class="remark-content" :class="{'remark-expanded': task.remarkExpanded}">{{ task.remark }}</text>
  84. <text class="expand-btn" v-if="task.remark.length > 50 && !task.remarkExpanded">展开</text>
  85. <text class="expand-btn" v-if="task.remarkExpanded">收起</text>
  86. </view>
  87. </view>
  88. <view class="loading-more" v-if="isLoading">
  89. <view class="loading-icon"></view>
  90. <text>加载中...</text>
  91. </view>
  92. <view class="no-more-data" v-if="noMoreData && taskList.length > 0">
  93. <text>没有更多数据了</text>
  94. </view>
  95. <view class="empty-list" v-if="taskList.length === 0 && !isLoading">
  96. <image src="/static/icons/warning_icon.png" mode="aspectFit"></image>
  97. <text>暂无农事任务</text>
  98. </view>
  99. </view>
  100. </scroll-view>
  101. <!-- 新增任务按钮 -->
  102. <view class="add-task-button" @click="createNewTask">
  103. <image src="/static/icons/add_task.png" mode="aspectFit" class="add-icon"></image>
  104. </view>
  105. </view>
  106. </template>
  107. <script setup>
  108. import { ref, reactive } from 'vue'
  109. import storage from "@/utils/storage.js"
  110. import { onShow, onLoad } from '@dcloudio/uni-app'
  111. import { getAgriculturalTasksList, countStatusTypeTasks } from '@/api/services/activity.js'
  112. import { useDict } from '@/utils/composables/useDict'
  113. import DictTag from '@/components/common/dict-tag'
  114. // 使用字典组合式函数
  115. const { dictData } = useDict(['task_type', 'task_status'])
  116. // 地块数据
  117. const plotData = ref({})
  118. // 待完成任务数
  119. const pendingTaskCount = ref(0)
  120. // 当前筛选状态
  121. const currentStatus = ref('all')
  122. // 筛选相关数据
  123. const taskStatus = [
  124. { label: '全部', value: 'all' },
  125. { label: '待完成', value: 0 },
  126. { label: '已完成', value: 1 }
  127. ]
  128. // 任务列表数据
  129. const taskList = ref([])
  130. const isLoading = ref(false)
  131. const isRefreshing = ref(false)
  132. const noMoreData = ref(false)
  133. const pageNum = ref(1)
  134. const pageSize = ref(10)
  135. // 格式化日期
  136. const formatDate = (dateStr) => {
  137. if (!dateStr) return ''
  138. // 如果是时间戳,转换为日期对象
  139. let date
  140. if (typeof dateStr === 'number') {
  141. date = new Date(dateStr)
  142. } else {
  143. date = new Date(dateStr.replace(/-/g, '/'))
  144. }
  145. const year = date.getFullYear()
  146. const month = String(date.getMonth() + 1).padStart(2, '0')
  147. const day = String(date.getDate()).padStart(2, '0')
  148. return `${year}-${month}-${day}`
  149. }
  150. // 切换任务状态筛选
  151. const switchStatus = (status) => {
  152. if (currentStatus.value === status) return
  153. currentStatus.value = status
  154. pageNum.value = 1
  155. noMoreData.value = false
  156. loadTaskData()
  157. }
  158. // 加载任务数据
  159. const loadTaskData = () => {
  160. plotData.value = JSON.parse(storage.getPlots() || '{}')
  161. const plotId = plotData.value?.id
  162. // 判断地块是否存在且有 id
  163. if (plotId == undefined) {
  164. uni.showToast({
  165. title: '请选择地块!',
  166. icon: 'none'
  167. })
  168. return
  169. }
  170. console.log("plotData.value", plotData.value)
  171. isLoading.value = true
  172. // 构建查询参数
  173. const params = {
  174. pageNum: pageNum.value,
  175. pageSize: pageSize.value,
  176. plotId: plotId
  177. }
  178. // 如果不是查询全部,添加状态过滤条件
  179. if (currentStatus.value !== 'all') {
  180. params.taskStatus = currentStatus.value
  181. }
  182. getAgriculturalTasksList(params).then(res => {
  183. if (res.data.code === 200) {
  184. const { rows, total } = res.data
  185. // 处理返回的数据
  186. const tasks = rows.map(item => {
  187. // 确保每个任务都有remarkExpanded属性
  188. item.remarkExpanded = false
  189. return item
  190. })
  191. if (pageNum.value === 1) {
  192. taskList.value = tasks
  193. } else {
  194. taskList.value = [...taskList.value, ...tasks]
  195. }
  196. // 判断是否还有更多数据
  197. noMoreData.value = taskList.value.length >= total
  198. // 统计待完成任务数量
  199. countPendingTasks()
  200. } else {
  201. uni.showToast({
  202. title: res.data.msg || '获取任务列表失败',
  203. icon: 'none'
  204. })
  205. }
  206. }).catch(err => {
  207. console.error('获取任务列表失败:', err)
  208. uni.showToast({
  209. title: '获取任务列表失败',
  210. icon: 'none'
  211. })
  212. }).finally(() => {
  213. isLoading.value = false
  214. isRefreshing.value = false
  215. })
  216. }
  217. // 统计待完成任务数量
  218. const countPendingTasks = () => {
  219. // 如果当前已经是按状态筛选,直接使用当前列表长度
  220. if (currentStatus.value === 'pending') {
  221. pendingTaskCount.value = taskList.value.length
  222. return
  223. }
  224. // 否则,请求获取待完成任务数量
  225. const params = {
  226. plotId: plotData.value.id,
  227. taskStatus: 0
  228. }
  229. countStatusTypeTasks(params).then(res => {
  230. console.log("nongsh", res)
  231. if (res.data.code === 200) {
  232. pendingTaskCount.value = res.data.data || 0
  233. }
  234. })
  235. }
  236. // 下拉刷新
  237. const refreshData = (plotId) => {
  238. isRefreshing.value = true
  239. pageNum.value = 1
  240. noMoreData.value = false
  241. loadTaskData(plotId)
  242. }
  243. // 上拉加载更多
  244. const loadMore = () => {
  245. if (!isLoading.value && !noMoreData.value) {
  246. pageNum.value++
  247. loadTaskData()
  248. }
  249. }
  250. // 查看任务详情
  251. const viewTaskDetail = (task) => {
  252. // 根据任务状态决定跳转到不同模式的页面
  253. let mode = ''
  254. if (task.taskStatus === '0') {
  255. // 待完成任务跳转到编辑页面
  256. mode = 'edit'
  257. } else if (task.taskStatus === '1') {
  258. // 已完成任务跳转到查看页面
  259. mode = 'view'
  260. }
  261. console.log("plotData.value", plotData.value)
  262. // 使用简化的URL参数传递
  263. const url = `/pages/activity/activity-detail?id=${task.id}&mode=${mode}&fieldName=${encodeURIComponent(plotData.value.name)}&growCrops=${encodeURIComponent(plotData.value.growCrops)}&farmId=${encodeURIComponent(plotData.value.farmId)}&manager=${encodeURIComponent(plotData.value.managerName)}&plotId=${plotData.value.id}`
  264. uni.navigateTo({
  265. url: url
  266. })
  267. }
  268. // 创建新任务
  269. const createNewTask = () => {
  270. // 使用简化的URL参数传递
  271. const url = `/pages/activity/activity-detail?id=new&mode=create&fieldName=${encodeURIComponent(plotData.value.name)}&growCrops=${encodeURIComponent(plotData.value.growCrops)}&farmId=${encodeURIComponent(plotData.value.farmId)}&manager=${encodeURIComponent(plotData.value.managerName)}&plotId=${plotData.value.id}`
  272. uni.navigateTo({
  273. url: url
  274. })
  275. }
  276. // 切换备注展开/收起状态
  277. const toggleRemark = (index) => {
  278. if (taskList.value[index].remark && taskList.value[index].remark.length > 50) {
  279. taskList.value[index].remarkExpanded = !taskList.value[index].remarkExpanded
  280. }
  281. }
  282. // 页面加载时获取数据
  283. onLoad(()=>{
  284. loadTaskData()
  285. })
  286. // 页面显示时刷新数据
  287. onShow(()=>{
  288. refreshData()
  289. })
  290. </script>
  291. <style scoped>
  292. .activity-container {
  293. position: relative;
  294. height: 100vh;
  295. background-color: #f8f8f8;
  296. display: flex;
  297. flex-direction: column;
  298. overflow: hidden;
  299. }
  300. /* 固定内容区域 */
  301. .fixed-content {
  302. flex-shrink: 0;
  303. width: 100%;
  304. }
  305. /* 地块信息卡片 */
  306. .plot-info-card {
  307. margin: 20rpx 30rpx 30rpx;
  308. padding: 30rpx;
  309. background: linear-gradient(135deg, #3BB44A, #2D8C3C);
  310. border-radius: 16rpx;
  311. box-shadow: 0 4rpx 12rpx rgba(59, 180, 74, 0.2);
  312. position: relative;
  313. color: #fff;
  314. width: calc(100% - 60rpx);
  315. box-sizing: border-box;
  316. }
  317. .plot-header {
  318. display: flex;
  319. justify-content: space-between;
  320. align-items: center;
  321. margin-bottom: 20rpx;
  322. }
  323. .plot-name {
  324. font-size: 32rpx;
  325. font-weight: bold;
  326. }
  327. .plot-area {
  328. font-size: 28rpx;
  329. background-color: rgba(255, 255, 255, 0.2);
  330. padding: 4rpx 16rpx;
  331. border-radius: 20rpx;
  332. }
  333. .plot-details {
  334. display: flex;
  335. flex-wrap: wrap;
  336. }
  337. .plot-item {
  338. display: flex;
  339. align-items: center;
  340. margin-right: 40rpx;
  341. margin-bottom: 10rpx;
  342. }
  343. .item-label {
  344. font-size: 26rpx;
  345. opacity: 0.8;
  346. }
  347. .item-value {
  348. font-size: 28rpx;
  349. font-weight: 500;
  350. }
  351. /* 任务状态筛选 */
  352. .tab-filter {
  353. margin: 0 30rpx 20rpx;
  354. background-color: #fff;
  355. border-radius: 16rpx;
  356. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  357. overflow: hidden;
  358. z-index: 10;
  359. width: calc(100% - 60rpx);
  360. box-sizing: border-box;
  361. }
  362. .tab-container {
  363. display: flex;
  364. width: 100%;
  365. height: 90rpx;
  366. }
  367. .tab-item {
  368. flex: 1;
  369. position: relative;
  370. display: flex;
  371. justify-content: center;
  372. align-items: center;
  373. height: 100%;
  374. min-width: 150rpx;
  375. transition: all 0.3s ease;
  376. }
  377. .tab-item text {
  378. font-size: 28rpx;
  379. color: #666;
  380. transition: color 0.3s ease;
  381. }
  382. .tab-item.active text {
  383. color: #3BB44A;
  384. font-weight: bold;
  385. }
  386. .active-line {
  387. position: absolute;
  388. bottom: 0;
  389. left: 25%;
  390. width: 50%;
  391. height: 4rpx;
  392. background-color: #3BB44A;
  393. border-radius: 4rpx;
  394. transition: all 0.3s ease;
  395. }
  396. .badge {
  397. position: absolute;
  398. top: 16rpx;
  399. right: 20%;
  400. min-width: 32rpx;
  401. height: 32rpx;
  402. line-height: 32rpx;
  403. border-radius: 16rpx;
  404. background: linear-gradient(135deg, #FF5252, #FF7676);
  405. color: #fff;
  406. font-size: 20rpx;
  407. padding: 0 8rpx;
  408. text-align: center;
  409. box-shadow: 0 2rpx 4rpx rgba(255, 82, 82, 0.2);
  410. transform: scale(0.9);
  411. }
  412. /* 滚动区域 */
  413. .task-list-scroll {
  414. flex: 1;
  415. height: 0; /* 关键属性:使滚动区域占据剩余高度 */
  416. overflow: hidden;
  417. }
  418. .task-list {
  419. padding: 0 30rpx;
  420. /* 预留底部空间,避免被悬浮新增按钮遮挡,并兼容安全区 */
  421. padding-bottom: 160rpx;
  422. padding-bottom: calc(160rpx + constant(safe-area-inset-bottom));
  423. padding-bottom: calc(160rpx + env(safe-area-inset-bottom));
  424. box-sizing: border-box;
  425. width: 100%;
  426. }
  427. .task-card {
  428. background-color: #fff;
  429. border-radius: 16rpx;
  430. padding: 24rpx;
  431. margin-bottom: 20rpx;
  432. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  433. position: relative;
  434. transition: transform 0.3s ease;
  435. width: calc(100% - 0rpx);
  436. box-sizing: border-box;
  437. overflow: hidden;
  438. }
  439. .task-card:active {
  440. transform: scale(0.98);
  441. }
  442. /* 任务卡片头部样式优化 */
  443. .task-header {
  444. display: flex;
  445. justify-content: space-between;
  446. align-items: center;
  447. margin-bottom: 16rpx;
  448. }
  449. .task-name {
  450. font-size: 32rpx;
  451. font-weight: bold;
  452. color: #333;
  453. padding-right: 80rpx; /* 为右侧状态标签留出空间 */
  454. }
  455. .task-status {
  456. position: absolute;
  457. top: 24rpx;
  458. right: 24rpx;
  459. font-size: 24rpx;
  460. padding: 4rpx 16rpx;
  461. border-radius: 20rpx;
  462. background: linear-gradient(135deg, rgba(255, 82, 82, 0.8), rgba(255, 82, 82, 0.6));
  463. color: #fff;
  464. z-index: 1;
  465. max-width: 120rpx;
  466. white-space: nowrap;
  467. overflow: hidden;
  468. text-overflow: ellipsis;
  469. }
  470. .status-completed {
  471. background: linear-gradient(135deg, rgba(59, 180, 74, 0.8), rgba(59, 180, 74, 0.6));
  472. }
  473. /* 信息行样式优化 */
  474. .task-info-row {
  475. display: flex;
  476. align-items: center;
  477. margin-bottom: 16rpx;
  478. padding: 6rpx 0;
  479. width: 100%;
  480. }
  481. .info-type, .info-time, .info-person {
  482. display: flex;
  483. align-items: center;
  484. }
  485. .info-type {
  486. flex: 0 0 auto;
  487. margin-right: 30rpx;
  488. }
  489. .info-time {
  490. flex: 0 0 auto;
  491. margin-right: 30rpx;
  492. }
  493. .info-person {
  494. flex: 0 0 auto;
  495. min-width: 100rpx;
  496. }
  497. .info-icon {
  498. width: 28rpx;
  499. height: 28rpx;
  500. margin-right: 8rpx;
  501. opacity: 0.7;
  502. flex-shrink: 0;
  503. }
  504. .info-text {
  505. font-size: 26rpx;
  506. color: #666;
  507. white-space: nowrap;
  508. overflow: hidden;
  509. text-overflow: ellipsis;
  510. }
  511. /* 删除旧的类型标签样式 */
  512. .type-tag {
  513. display: none;
  514. }
  515. .task-remark {
  516. background-color: rgba(0, 0, 0, 0.03);
  517. padding: 16rpx;
  518. border-radius: 10rpx;
  519. display: flex;
  520. margin-bottom: 10rpx;
  521. position: relative;
  522. flex-wrap: wrap;
  523. }
  524. .remark-label {
  525. font-size: 26rpx;
  526. color: #999;
  527. margin-right: 8rpx;
  528. }
  529. .remark-content {
  530. flex: 1;
  531. font-size: 26rpx;
  532. color: #666;
  533. display: -webkit-box;
  534. -webkit-box-orient: vertical;
  535. -webkit-line-clamp: 2;
  536. line-clamp: 2;
  537. overflow: hidden;
  538. text-overflow: ellipsis;
  539. word-break: break-all;
  540. }
  541. .remark-expanded {
  542. -webkit-line-clamp: unset;
  543. line-clamp: unset;
  544. }
  545. .expand-btn {
  546. font-size: 24rpx;
  547. color: #3BB44A;
  548. margin-left: auto;
  549. padding-left: 20rpx;
  550. }
  551. .loading-more, .no-more-data, .empty-list {
  552. text-align: center;
  553. padding: 30rpx 0;
  554. }
  555. .loading-icon {
  556. display: inline-block;
  557. width: 40rpx;
  558. height: 40rpx;
  559. border: 3rpx solid #f3f3f3;
  560. border-top: 3rpx solid #3BB44A;
  561. border-radius: 50%;
  562. vertical-align: middle;
  563. animation: spin 1s linear infinite;
  564. }
  565. @keyframes spin {
  566. 0% { transform: rotate(0deg); }
  567. 100% { transform: rotate(360deg); }
  568. }
  569. .loading-more text, .no-more-data text {
  570. font-size: 24rpx;
  571. color: #999;
  572. margin-left: 10rpx;
  573. }
  574. .empty-list {
  575. padding: 100rpx 0;
  576. display: flex;
  577. flex-direction: column;
  578. align-items: center;
  579. }
  580. .empty-list image {
  581. width: 120rpx;
  582. height: 120rpx;
  583. margin-bottom: 20rpx;
  584. opacity: 0.5;
  585. }
  586. .empty-list text {
  587. font-size: 28rpx;
  588. color: #999;
  589. }
  590. /* 新增任务按钮 */
  591. .add-task-button {
  592. position: fixed;
  593. right: 40rpx;
  594. bottom: 120rpx;
  595. width: 100rpx;
  596. height: 100rpx;
  597. border-radius: 50%;
  598. background: linear-gradient(135deg, #3BB44A, #2D8C3C);
  599. display: flex;
  600. justify-content: center;
  601. align-items: center;
  602. box-shadow: 0 6rpx 16rpx rgba(59, 180, 74, 0.3);
  603. z-index: 100;
  604. transition: transform 0.2s ease;
  605. }
  606. .add-task-button:active {
  607. transform: scale(0.95);
  608. }
  609. .add-icon {
  610. width: 48rpx;
  611. height: 48rpx;
  612. }
  613. /* 添加字典标签相关样式 */
  614. .task-status-tag {
  615. position: absolute;
  616. top: 24rpx;
  617. right: 24rpx;
  618. z-index: 1;
  619. max-width: 120rpx;
  620. }
  621. /* 移除空规则 .info-type-tag 以避免 linter 警告 */
  622. </style>