myTaskList.vue 8.6 KB

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