myTaskList.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <view class="my-task-container">
  3. <!-- 任务列表 -->
  4. <scroll-view
  5. scroll-y
  6. @scrolltolower="loadMore"
  7. class="task-list"
  8. refresher-enabled
  9. :refresher-triggered="isRefreshing"
  10. @refresherrefresh="onRefresh"
  11. >
  12. <!-- 空数据提示 -->
  13. <view v-if="taskList.length === 0" class="empty-container">
  14. <image src="" mode="aspectFit" class="empty-image"></image>
  15. <text class="empty-text">暂无任务数据</text>
  16. </view>
  17. <!-- 任务列表内容 -->
  18. <template v-else>
  19. <view
  20. v-for="(item, index) in taskList"
  21. @click="handleTaskClick(item)"
  22. :key="index"
  23. class="task-item"
  24. >
  25. <view class="warehouse-info">
  26. <view class="info-row">
  27. <uni-icons type="home" size="20" color="#1976D2"></uni-icons>
  28. <text class="warehouse-name">库区名称: {{ item.kqmc }}</text>
  29. </view>
  30. <view class="info-row">
  31. <uni-icons type="location" size="20" color="#FFA726"></uni-icons>
  32. <text class="warehouse-address">库区地址: {{ item.jtdz }}</text>
  33. </view>
  34. </view>
  35. <view class="divider"></view>
  36. <view class="task-status">
  37. <text>通过数量: {{ item.hytgNum || "0" }}</text>
  38. <text>不通过数量: {{ item.hybtgNum || "0" }}</text>
  39. <!-- <text :class="['status']"
  40. >核验状态: {{ statusflutter(item.hyState) }}</text
  41. > -->
  42. <text
  43. >核验状态:
  44. {{ statusFun(item.hytgNum, item.hybtgNum, item.hyNum) }}</text
  45. >
  46. </view>
  47. </view>
  48. <!-- 加载更多提示 -->
  49. <view class="load-more" v-if="taskList.length > 0">
  50. <view v-if="loading" class="loading-box">
  51. <text class="loading-text">加载中...</text>
  52. </view>
  53. <view v-else-if="!hasMore" class="bottom-line">
  54. <text class="line"></text>
  55. <text class="text">已经到底了</text>
  56. <text class="line"></text>
  57. </view>
  58. </view>
  59. </template>
  60. </scroll-view>
  61. </view>
  62. </template>
  63. <script>
  64. import { getTaskList } from "@/api/task";
  65. export default {
  66. data() {
  67. return {
  68. pageNo: 1,
  69. pageSize: 10,
  70. loading: false,
  71. hasMore: true,
  72. taskList: [],
  73. isRefreshing: false,
  74. };
  75. },
  76. // 页面加载
  77. created() {
  78. this.getTaskList();
  79. },
  80. methods: {
  81. statusFun(hytgNum, hybtgNum, hyNum) {
  82. if (hytgNum === hyNum) {
  83. return "全部通过";
  84. } else if (hybtgNum === hyNum) {
  85. return "全部不通过";
  86. } else if (hytgNum + hybtgNum === hyNum) {
  87. return "核验完成";
  88. } else {
  89. return "核验中";
  90. }
  91. },
  92. initTaskList() {
  93. this.hasMore = true;
  94. this.pageNo = 1;
  95. this.taskList = [];
  96. this.getTaskList();
  97. },
  98. async getTaskList() {
  99. if (this.loading || !this.hasMore) return;
  100. try {
  101. this.loading = true;
  102. // 加载
  103. uni.showLoading({
  104. title: "加载中...",
  105. });
  106. const params = {
  107. pageNo: this.pageNo,
  108. pageSize: this.pageSize,
  109. listType: 2,
  110. };
  111. const res = await getTaskList(params);
  112. if (res.code === 0) {
  113. const list = res.data.records;
  114. if (this.pageNo === 1) {
  115. this.taskList = list;
  116. } else {
  117. // 否则追加到现有列表
  118. this.taskList = [...this.taskList, ...list];
  119. }
  120. // 判断是否还有更多数据
  121. this.hasMore = list.length >= this.pageSize;
  122. // 如果还有更多数据,页码加1
  123. if (this.hasMore) {
  124. this.pageNo++;
  125. }
  126. } else {
  127. uni.showToast({
  128. title: res.message || "获取任务列表失败",
  129. icon: "none",
  130. });
  131. }
  132. } catch (error) {
  133. console.error("获取任务列表失败:", error);
  134. uni.showToast({
  135. title: "获取任务列表失败",
  136. icon: "none",
  137. });
  138. } finally {
  139. this.loading = false;
  140. uni.hideLoading();
  141. }
  142. },
  143. handleTaskClick(item) {
  144. // 将对象转为 URL 参数
  145. const params = encodeURIComponent(
  146. JSON.stringify({
  147. kqmc: item.kqmc,
  148. // address: item.address,
  149. // roomCount: item.roomCount,
  150. // status: item.status,
  151. kqId: item.kqId,
  152. hyState: item.hyState,
  153. // 可以添加其他需要传递的参数
  154. })
  155. );
  156. uni.navigateTo({
  157. url: `/pages/myTask-verification/myTaskLayout?taskInfo=${params}`,
  158. });
  159. },
  160. // 核验状态(0:待查验,1:查验通过,2:查验不通过3:核验中)
  161. statusflutter(status) {
  162. if (status === 0) {
  163. return "待查验";
  164. } else if (status === 1) {
  165. return "查验通过";
  166. } else if (status === 2) {
  167. return "查验不通过";
  168. } else if (status === 3) {
  169. return "核验中";
  170. }
  171. },
  172. loadMore() {
  173. if (this.hasMore && !this.loading) {
  174. this.getTaskList(true);
  175. }
  176. },
  177. // 添加下拉刷新处理方法
  178. async onRefresh() {
  179. this.isRefreshing = true;
  180. try {
  181. await this.resetList();
  182. } finally {
  183. this.isRefreshing = false;
  184. }
  185. },
  186. // 修改重置列表方法
  187. async resetList() {
  188. this.pageNo = 1;
  189. this.hasMore = true;
  190. this.taskList = [];
  191. await this.getTaskList();
  192. },
  193. },
  194. };
  195. </script>
  196. <style lang="scss" scoped>
  197. .my-task-container {
  198. height: 100vh;
  199. background: linear-gradient(#cfddfc 0%, #e6eeff 10%, #fff 100%);
  200. }
  201. .header {
  202. padding: 30rpx 40rpx;
  203. display: flex;
  204. justify-content: space-between;
  205. align-items: center;
  206. background-color: #fff;
  207. .title {
  208. font-size: 36rpx;
  209. font-weight: bold;
  210. }
  211. }
  212. .task-list {
  213. height: calc(100vh - 100rpx);
  214. padding: 20rpx;
  215. box-sizing: border-box;
  216. }
  217. .task-item {
  218. // background-color: #;
  219. background: linear-gradient(#fff 0%, #fff 80%, #f4f6fb 100%);
  220. border-radius: 12rpx;
  221. padding: 30rpx;
  222. margin-bottom: 20rpx;
  223. box-shadow: 0 10rpx 10rpx rgba(0, 0, 0, 0.1);
  224. }
  225. .warehouse-info {
  226. .info-row {
  227. display: flex;
  228. align-items: center;
  229. margin-bottom: 20rpx;
  230. text {
  231. margin-left: 16rpx;
  232. font-size: 35rpx;
  233. }
  234. }
  235. }
  236. .task-status {
  237. display: flex;
  238. justify-content: space-between;
  239. margin-top: 20rpx;
  240. font-size: 28rpx;
  241. .status {
  242. &.status-pending {
  243. color: #ffa726;
  244. }
  245. &.status-processing {
  246. color: #1976d2;
  247. }
  248. &.status-failed {
  249. color: #f44336;
  250. }
  251. }
  252. }
  253. // 如果需要下拉刷新的加载动画
  254. .loading {
  255. display: flex;
  256. align-items: center;
  257. justify-content: center;
  258. &::before {
  259. content: "";
  260. width: 30rpx;
  261. height: 30rpx;
  262. margin-right: 10rpx;
  263. border: 2rpx solid #999;
  264. border-top-color: transparent;
  265. border-radius: 50%;
  266. animation: loading 0.8s linear infinite;
  267. }
  268. }
  269. @keyframes loading {
  270. from {
  271. transform: rotate(0deg);
  272. }
  273. to {
  274. transform: rotate(360deg);
  275. }
  276. }
  277. .empty-container {
  278. display: flex;
  279. flex-direction: column;
  280. align-items: center;
  281. justify-content: center;
  282. // padding: 100rpx 0;
  283. .empty-image {
  284. width: 200rpx;
  285. height: 200rpx;
  286. margin-bottom: 20rpx;
  287. }
  288. .empty-text {
  289. color: #999;
  290. font-size: 28rpx;
  291. }
  292. }
  293. .load-more {
  294. padding: 20rpx 30rpx 40rpx;
  295. .loading-box {
  296. text-align: center;
  297. .loading-text {
  298. color: #999;
  299. font-size: 24rpx;
  300. }
  301. }
  302. .bottom-line {
  303. display: flex;
  304. align-items: center;
  305. justify-content: center;
  306. padding: 0 30rpx;
  307. .line {
  308. flex: 1;
  309. height: 1rpx;
  310. background: #ddd;
  311. }
  312. .text {
  313. color: #999;
  314. font-size: 24rpx;
  315. padding: 0 30rpx;
  316. }
  317. }
  318. }
  319. .divider {
  320. height: 1rpx; /* 分割线的高度 */
  321. background-color: rgba(117, 117, 117, 0.1); /* 分割线的颜色 */
  322. margin: 10rpx 0; /* 分割线的上下间距 */
  323. width: 100%; /* 分割线的宽度 */
  324. }
  325. </style>