index.vue 17 KB

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