index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  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.area }}亩</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.crop }}</text>
  14. </view>
  15. <view class="plot-item">
  16. <text class="item-label">负责人:</text>
  17. <text class="item-value">{{ plotData.manager }}</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 === 'pending' && 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
  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="index" @click="viewTaskDetail(task)">
  48. <!-- 头部区域:任务名称和状态标签 -->
  49. <view class="task-header">
  50. <view class="task-name">{{ task.name }}</view>
  51. <view class="task-status" :class="{ 'status-completed': task.status === 'completed' }">
  52. {{ task.status === 'pending' ? '待完成' : '已完成' }}
  53. </view>
  54. </view>
  55. <!-- 信息行:类型、时间、责任人统一放在一行,类型在前 -->
  56. <view class="task-info-row">
  57. <!-- 类型标签放在最左侧 -->
  58. <view class="info-type">
  59. <image src="/static/icons/task_icon.png" mode="aspectFit" class="info-icon"></image>
  60. <text class="info-text">{{ task.type }}</text>
  61. </view>
  62. <!-- 时间信息放在中间 -->
  63. <view class="info-time">
  64. <image src="/static/icons/clock_icon.png" mode="aspectFit" class="info-icon"></image>
  65. <text class="info-text">{{ task.executeTime }}</text>
  66. </view>
  67. <!-- 责任人信息放在右侧 -->
  68. <view class="info-person">
  69. <image src="/static/icons/user.png" mode="aspectFit" class="info-icon"></image>
  70. <text class="info-text">{{ task.assignee }}</text>
  71. </view>
  72. </view>
  73. <!-- 备注区域 -->
  74. <view class="task-remark" v-if="task.remark" @click.stop="toggleRemark(index)">
  75. <text class="remark-label">备注:</text>
  76. <text class="remark-content" :class="{'remark-expanded': task.remarkExpanded}">{{ task.remark }}</text>
  77. <text class="expand-btn" v-if="task.remark.length > 50 && !task.remarkExpanded">展开</text>
  78. <text class="expand-btn" v-if="task.remarkExpanded">收起</text>
  79. </view>
  80. </view>
  81. <view class="loading-more" v-if="isLoading">
  82. <view class="loading-icon"></view>
  83. <text>加载中...</text>
  84. </view>
  85. <view class="no-more-data" v-if="noMoreData && taskList.length > 0">
  86. <text>没有更多数据了</text>
  87. </view>
  88. <view class="empty-list" v-if="taskList.length === 0 && !isLoading">
  89. <image src="/static/icons/warning_icon.png" mode="aspectFit"></image>
  90. <text>暂无农事任务</text>
  91. </view>
  92. </view>
  93. </scroll-view>
  94. <!-- 新增任务按钮 -->
  95. <view class="add-task-button" @click="createNewTask">
  96. <image src="/static/icons/add_task.png" mode="aspectFit" class="add-icon"></image>
  97. </view>
  98. </view>
  99. </template>
  100. <script>
  101. export default {
  102. data() {
  103. return {
  104. // 地块数据
  105. plotData: {
  106. id: 1,
  107. name: '东区水稻田',
  108. area: '128',
  109. crop: '水稻',
  110. manager: '张农夫'
  111. },
  112. // 待完成任务数
  113. pendingTaskCount: 5,
  114. // 当前筛选状态
  115. currentStatus: 'all',
  116. // 筛选相关数据
  117. taskStatus: [
  118. { label: '全部', value: 'all' },
  119. { label: '待完成', value: 'pending' },
  120. { label: '已完成', value: 'completed' }
  121. ],
  122. // 任务列表数据
  123. taskList: [],
  124. isLoading: false,
  125. isRefreshing: false,
  126. noMoreData: false,
  127. page: 1,
  128. pageSize: 10,
  129. // 模拟任务数据
  130. mockTasks: [
  131. {
  132. id: 1,
  133. name: '水稻田施肥',
  134. type: '施肥',
  135. status: 'pending',
  136. executeTime: '2023-06-15',
  137. assignee: '李明',
  138. remark: '使用复合肥,每亩用量20kg',
  139. remarkExpanded: false
  140. },
  141. {
  142. id: 2,
  143. name: '病虫害防治喷药',
  144. type: '喷药',
  145. status: 'completed',
  146. executeTime: '2023-06-10',
  147. assignee: '王强',
  148. remark: '使用杀虫剂,注意安全防护',
  149. remarkExpanded: false
  150. },
  151. {
  152. id: 3,
  153. name: '早稻收割',
  154. type: '采摘',
  155. status: 'pending',
  156. executeTime: '2023-06-20',
  157. assignee: '张农夫',
  158. remark: '天气晴好时进行',
  159. remarkExpanded: false
  160. },
  161. {
  162. id: 4,
  163. name: '水渠疏通',
  164. type: '灌溉',
  165. status: 'pending',
  166. executeTime: '2023-06-12',
  167. assignee: '周华',
  168. remark: '',
  169. remarkExpanded: false
  170. },
  171. {
  172. id: 5,
  173. name: '田间除草',
  174. type: '除草',
  175. status: 'pending',
  176. executeTime: '2023-06-18',
  177. assignee: '刘艳',
  178. remark: '使用除草剂,避开雨天',
  179. remarkExpanded: false
  180. }
  181. ]
  182. }
  183. },
  184. components: {
  185. // No longer needed as we're using standard image icons
  186. },
  187. methods: {
  188. // 根据任务类型返回颜色
  189. getTypeColor(type, mode = 'bg') {
  190. const colors = {
  191. '施肥': {
  192. bg: 'linear-gradient(135deg, rgba(59, 180, 74, 0.8), rgba(59, 180, 74, 0.6))',
  193. text: '#3BB44A'
  194. },
  195. '喷药': {
  196. bg: 'linear-gradient(135deg, rgba(255, 82, 82, 0.8), rgba(255, 82, 82, 0.6))',
  197. text: '#FF5252'
  198. },
  199. '灌溉': {
  200. bg: 'linear-gradient(135deg, rgba(64, 158, 255, 0.8), rgba(64, 158, 255, 0.6))',
  201. text: '#409EFF'
  202. },
  203. '采摘': {
  204. bg: 'linear-gradient(135deg, rgba(250, 173, 20, 0.8), rgba(250, 173, 20, 0.6))',
  205. text: '#FAAD14'
  206. },
  207. '播种': {
  208. bg: 'linear-gradient(135deg, rgba(121, 85, 72, 0.8), rgba(121, 85, 72, 0.6))',
  209. text: '#795548'
  210. },
  211. '除草': {
  212. bg: 'linear-gradient(135deg, rgba(156, 39, 176, 0.8), rgba(156, 39, 176, 0.6))',
  213. text: '#9C27B0'
  214. }
  215. };
  216. const defaultColor = {
  217. bg: 'linear-gradient(135deg, rgba(158, 158, 158, 0.8), rgba(158, 158, 158, 0.6))',
  218. text: '#909399'
  219. };
  220. return (colors[type] || defaultColor)[mode];
  221. },
  222. // 切换任务状态筛选
  223. switchStatus(status) {
  224. if (this.currentStatus === status) return;
  225. this.currentStatus = status;
  226. this.page = 1;
  227. this.noMoreData = false;
  228. this.loadTaskData();
  229. },
  230. // 加载任务数据
  231. loadTaskData() {
  232. this.isLoading = true;
  233. // 模拟API请求延迟
  234. setTimeout(() => {
  235. // 模拟筛选
  236. let filteredTasks = [...this.mockTasks];
  237. // 按状态筛选
  238. if (this.currentStatus !== 'all') {
  239. filteredTasks = filteredTasks.filter(task => task.status === this.currentStatus);
  240. }
  241. // 分页处理
  242. const start = (this.page - 1) * this.pageSize;
  243. const end = start + this.pageSize;
  244. const pageData = filteredTasks.slice(start, end);
  245. if (this.page === 1) {
  246. this.taskList = pageData;
  247. } else {
  248. this.taskList = [...this.taskList, ...pageData];
  249. }
  250. this.noMoreData = end >= filteredTasks.length;
  251. this.isLoading = false;
  252. this.isRefreshing = false;
  253. // 更新待完成任务数
  254. this.pendingTaskCount = this.mockTasks.filter(task => task.status === 'pending').length;
  255. }, 500);
  256. },
  257. // 下拉刷新
  258. refreshData(e) {
  259. this.isRefreshing = true;
  260. this.page = 1;
  261. this.noMoreData = false;
  262. // 模拟API请求延迟
  263. setTimeout(() => {
  264. this.loadTaskData();
  265. // 显示刷新成功的提示
  266. uni.showToast({
  267. title: '刷新成功',
  268. icon: 'success',
  269. duration: 1000
  270. });
  271. }, 1000);
  272. },
  273. // 上拉加载更多
  274. loadMore() {
  275. if (!this.isLoading && !this.noMoreData) {
  276. this.page++;
  277. this.loadTaskData();
  278. }
  279. },
  280. // 查看任务详情
  281. viewTaskDetail(task) {
  282. // 根据任务状态决定跳转到不同模式的页面
  283. let mode = '';
  284. if (task.status === 'pending') {
  285. // 待完成任务跳转到编辑页面
  286. mode = 'edit';
  287. } else if (task.status === 'completed') {
  288. // 已完成任务跳转到查看页面
  289. mode = 'view';
  290. }
  291. console.log(`点击任务: ${task.name}, 状态: ${task.status}, 跳转模式: ${mode}`);
  292. console.log('地块数据:', this.plotData);
  293. console.log('任务数据:', task);
  294. // 使用简化的URL参数传递
  295. const url = `/pages/activity/activity-detail?id=${task.id}&mode=${mode}&plotName=${encodeURIComponent(this.plotData.name)}&crop=${encodeURIComponent(this.plotData.crop)}&manager=${encodeURIComponent(this.plotData.manager)}&taskName=${encodeURIComponent(task.name)}&taskType=${encodeURIComponent(task.type)}&executeTime=${encodeURIComponent(task.executeTime)}&taskRemark=${encodeURIComponent(task.remark || '')}&taskStatus=${task.status}&assignee=${encodeURIComponent(task.assignee)}`;
  296. console.log('跳转URL:', url);
  297. uni.navigateTo({
  298. url: url
  299. });
  300. },
  301. // 创建新任务
  302. createNewTask() {
  303. console.log('点击新建任务按钮,跳转到创建页面');
  304. console.log('地块数据:', this.plotData);
  305. // 使用简化的URL参数传递
  306. const url = `/pages/activity/activity-detail?id=new&mode=create&plotName=${encodeURIComponent(this.plotData.name)}&crop=${encodeURIComponent(this.plotData.crop)}&manager=${encodeURIComponent(this.plotData.manager)}`;
  307. console.log('跳转URL:', url);
  308. // 跳转到新建任务页面
  309. uni.navigateTo({
  310. url: url
  311. });
  312. },
  313. // 切换备注展开/收起状态
  314. toggleRemark(index) {
  315. if (this.taskList[index].remark && this.taskList[index].remark.length > 50) {
  316. this.$set(this.taskList[index], 'remarkExpanded', !this.taskList[index].remarkExpanded);
  317. }
  318. }
  319. },
  320. // 页面加载时获取数据
  321. onLoad() {
  322. this.loadTaskData();
  323. }
  324. }
  325. </script>
  326. <style scoped>
  327. .activity-container {
  328. position: relative;
  329. height: 100vh;
  330. background-color: #f8f8f8;
  331. display: flex;
  332. flex-direction: column;
  333. overflow: hidden;
  334. }
  335. /* 固定内容区域 */
  336. .fixed-content {
  337. flex-shrink: 0;
  338. width: 100%;
  339. }
  340. /* 地块信息卡片 */
  341. .plot-info-card {
  342. margin: 20rpx 30rpx 30rpx;
  343. padding: 30rpx;
  344. background: linear-gradient(135deg, #3BB44A, #2D8C3C);
  345. border-radius: 16rpx;
  346. box-shadow: 0 4rpx 12rpx rgba(59, 180, 74, 0.2);
  347. position: relative;
  348. color: #fff;
  349. width: calc(100% - 60rpx);
  350. box-sizing: border-box;
  351. }
  352. .plot-header {
  353. display: flex;
  354. justify-content: space-between;
  355. align-items: center;
  356. margin-bottom: 20rpx;
  357. }
  358. .plot-name {
  359. font-size: 32rpx;
  360. font-weight: bold;
  361. }
  362. .plot-area {
  363. font-size: 28rpx;
  364. background-color: rgba(255, 255, 255, 0.2);
  365. padding: 4rpx 16rpx;
  366. border-radius: 20rpx;
  367. }
  368. .plot-details {
  369. display: flex;
  370. flex-wrap: wrap;
  371. }
  372. .plot-item {
  373. display: flex;
  374. align-items: center;
  375. margin-right: 40rpx;
  376. margin-bottom: 10rpx;
  377. }
  378. .item-label {
  379. font-size: 26rpx;
  380. opacity: 0.8;
  381. }
  382. .item-value {
  383. font-size: 28rpx;
  384. font-weight: 500;
  385. }
  386. /* 任务状态筛选 */
  387. .tab-filter {
  388. margin: 0 30rpx 20rpx;
  389. background-color: #fff;
  390. border-radius: 16rpx;
  391. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  392. overflow: hidden;
  393. z-index: 10;
  394. width: calc(100% - 60rpx);
  395. box-sizing: border-box;
  396. }
  397. .tab-container {
  398. display: flex;
  399. width: 100%;
  400. height: 90rpx;
  401. }
  402. .tab-item {
  403. flex: 1;
  404. position: relative;
  405. display: flex;
  406. justify-content: center;
  407. align-items: center;
  408. height: 100%;
  409. min-width: 150rpx;
  410. transition: all 0.3s ease;
  411. }
  412. .tab-item text {
  413. font-size: 28rpx;
  414. color: #666;
  415. transition: color 0.3s ease;
  416. }
  417. .tab-item.active text {
  418. color: #3BB44A;
  419. font-weight: bold;
  420. }
  421. .active-line {
  422. position: absolute;
  423. bottom: 0;
  424. left: 25%;
  425. width: 50%;
  426. height: 4rpx;
  427. background-color: #3BB44A;
  428. border-radius: 4rpx;
  429. transition: all 0.3s ease;
  430. }
  431. .badge {
  432. position: absolute;
  433. top: 16rpx;
  434. right: 20%;
  435. min-width: 32rpx;
  436. height: 32rpx;
  437. line-height: 32rpx;
  438. border-radius: 16rpx;
  439. background: linear-gradient(135deg, #FF5252, #FF7676);
  440. color: #fff;
  441. font-size: 20rpx;
  442. padding: 0 8rpx;
  443. text-align: center;
  444. box-shadow: 0 2rpx 4rpx rgba(255, 82, 82, 0.2);
  445. transform: scale(0.9);
  446. }
  447. /* 滚动区域 */
  448. .task-list-scroll {
  449. flex: 1;
  450. height: 0; /* 关键属性:使滚动区域占据剩余高度 */
  451. overflow: hidden;
  452. }
  453. .task-list {
  454. padding: 0 30rpx;
  455. box-sizing: border-box;
  456. width: 100%;
  457. }
  458. .task-card {
  459. background-color: #fff;
  460. border-radius: 16rpx;
  461. padding: 24rpx;
  462. margin-bottom: 20rpx;
  463. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  464. position: relative;
  465. transition: transform 0.3s ease;
  466. width: calc(100% - 0rpx);
  467. box-sizing: border-box;
  468. overflow: hidden;
  469. }
  470. .task-card:active {
  471. transform: scale(0.98);
  472. }
  473. /* 任务卡片头部样式优化 */
  474. .task-header {
  475. display: flex;
  476. justify-content: space-between;
  477. align-items: center;
  478. margin-bottom: 16rpx;
  479. }
  480. .task-name {
  481. font-size: 32rpx;
  482. font-weight: bold;
  483. color: #333;
  484. padding-right: 80rpx; /* 为右侧状态标签留出空间 */
  485. }
  486. .task-status {
  487. position: absolute;
  488. top: 24rpx;
  489. right: 24rpx;
  490. font-size: 24rpx;
  491. padding: 4rpx 16rpx;
  492. border-radius: 20rpx;
  493. background: linear-gradient(135deg, rgba(255, 82, 82, 0.8), rgba(255, 82, 82, 0.6));
  494. color: #fff;
  495. z-index: 1;
  496. max-width: 120rpx;
  497. white-space: nowrap;
  498. overflow: hidden;
  499. text-overflow: ellipsis;
  500. }
  501. .status-completed {
  502. background: linear-gradient(135deg, rgba(59, 180, 74, 0.8), rgba(59, 180, 74, 0.6));
  503. }
  504. /* 信息行样式优化 */
  505. .task-info-row {
  506. display: flex;
  507. align-items: center;
  508. margin-bottom: 16rpx;
  509. padding: 6rpx 0;
  510. width: 100%;
  511. }
  512. .info-type, .info-time, .info-person {
  513. display: flex;
  514. align-items: center;
  515. }
  516. .info-type {
  517. flex: 0 0 auto;
  518. margin-right: 30rpx;
  519. }
  520. .info-time {
  521. flex: 0 0 auto;
  522. margin-right: 30rpx;
  523. }
  524. .info-person {
  525. flex: 0 0 auto;
  526. min-width: 100rpx;
  527. }
  528. .info-icon {
  529. width: 28rpx;
  530. height: 28rpx;
  531. margin-right: 8rpx;
  532. opacity: 0.7;
  533. flex-shrink: 0;
  534. }
  535. .info-text {
  536. font-size: 26rpx;
  537. color: #666;
  538. white-space: nowrap;
  539. overflow: hidden;
  540. text-overflow: ellipsis;
  541. }
  542. /* 删除旧的类型标签样式 */
  543. .type-tag {
  544. display: none;
  545. }
  546. .task-remark {
  547. background-color: rgba(0, 0, 0, 0.03);
  548. padding: 16rpx;
  549. border-radius: 10rpx;
  550. display: flex;
  551. margin-bottom: 10rpx;
  552. position: relative;
  553. flex-wrap: wrap;
  554. }
  555. .remark-label {
  556. font-size: 26rpx;
  557. color: #999;
  558. margin-right: 8rpx;
  559. }
  560. .remark-content {
  561. flex: 1;
  562. font-size: 26rpx;
  563. color: #666;
  564. display: -webkit-box;
  565. -webkit-box-orient: vertical;
  566. -webkit-line-clamp: 2;
  567. overflow: hidden;
  568. text-overflow: ellipsis;
  569. word-break: break-all;
  570. }
  571. .remark-expanded {
  572. -webkit-line-clamp: unset;
  573. }
  574. .expand-btn {
  575. font-size: 24rpx;
  576. color: #3BB44A;
  577. margin-left: auto;
  578. padding-left: 20rpx;
  579. }
  580. .loading-more, .no-more-data, .empty-list {
  581. text-align: center;
  582. padding: 30rpx 0;
  583. }
  584. .loading-icon {
  585. display: inline-block;
  586. width: 40rpx;
  587. height: 40rpx;
  588. border: 3rpx solid #f3f3f3;
  589. border-top: 3rpx solid #3BB44A;
  590. border-radius: 50%;
  591. vertical-align: middle;
  592. animation: spin 1s linear infinite;
  593. }
  594. @keyframes spin {
  595. 0% { transform: rotate(0deg); }
  596. 100% { transform: rotate(360deg); }
  597. }
  598. .loading-more text, .no-more-data text {
  599. font-size: 24rpx;
  600. color: #999;
  601. margin-left: 10rpx;
  602. }
  603. .empty-list {
  604. padding: 100rpx 0;
  605. display: flex;
  606. flex-direction: column;
  607. align-items: center;
  608. }
  609. .empty-list image {
  610. width: 120rpx;
  611. height: 120rpx;
  612. margin-bottom: 20rpx;
  613. opacity: 0.5;
  614. }
  615. .empty-list text {
  616. font-size: 28rpx;
  617. color: #999;
  618. }
  619. /* 新增任务按钮 */
  620. .add-task-button {
  621. position: fixed;
  622. right: 40rpx;
  623. bottom: 120rpx;
  624. width: 100rpx;
  625. height: 100rpx;
  626. border-radius: 50%;
  627. background: linear-gradient(135deg, #3BB44A, #2D8C3C);
  628. display: flex;
  629. justify-content: center;
  630. align-items: center;
  631. box-shadow: 0 6rpx 16rpx rgba(59, 180, 74, 0.3);
  632. z-index: 100;
  633. transition: transform 0.2s ease;
  634. }
  635. .add-task-button:active {
  636. transform: scale(0.95);
  637. }
  638. .add-icon {
  639. width: 48rpx;
  640. height: 48rpx;
  641. }
  642. </style>