index.vue 17 KB

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