bad-off.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <view class="container">
  3. <!-- 任务列表 -->
  4. <view class="task-list">
  5. <template v-if="!loading">
  6. <view
  7. v-if="taskList.length > 0"
  8. v-for="(item, index) in taskList"
  9. :key="index"
  10. class="task-card"
  11. @click="handleTaskClick(item)"
  12. >
  13. <view class="task-header">
  14. <text class="task-no">作业单号:{{ item.taskCode }}</text>
  15. </view>
  16. <view class="task-content">
  17. <view class="flex-a mb-10">
  18. <text class="label">仓库:</text>
  19. <text class="value">{{ item.godownName }}</text>
  20. </view>
  21. <view class="flex-a mb-10">
  22. <text class="label">订单数量:</text>
  23. <text class="value">{{ item.orderNum }}</text>
  24. </view>
  25. <view class="flex-a mb-10">
  26. <text class="label">创建时间:</text>
  27. <text class="value">{{ item.createTime }}</text>
  28. </view>
  29. <view class="flex-a">
  30. <text class="label">作业状态:</text>
  31. <text class="value">{{ getTaskStatusText(item.taskStatus) }}</text>
  32. </view>
  33. </view>
  34. </view>
  35. <view v-else class="empty-state">
  36. <text>暂无任务数据</text>
  37. </view>
  38. </template>
  39. <view v-else class="loading-state">
  40. <u-loading-icon></u-loading-icon>
  41. <text>加载中...</text>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script setup>
  47. import { ref, onMounted } from "vue";
  48. // 搜索文本
  49. const searchText = ref("");
  50. // 任务列表数据
  51. const taskList = ref([]);
  52. // 加载状态
  53. const loading = ref(false);
  54. // 作业状态枚举
  55. const taskStatusEnum = {
  56. 1: "待作业",
  57. 2: "作业中",
  58. 3: "已完成",
  59. 4: "已关闭",
  60. };
  61. // 获取状态文本
  62. const getTaskStatusText = (status) => {
  63. return taskStatusEnum[status] || "未知状态";
  64. };
  65. // 获取任务列表
  66. const fetchTaskList = async () => {
  67. loading.value = true;
  68. try {
  69. const response = await uni.$u.http.post("/app/appstock/getNeedStockList");
  70. console.log(response);
  71. taskList.value = response;
  72. if (response.code === 200) {
  73. taskList.value = response.data || [];
  74. } else {
  75. uni.showToast({
  76. title: response.msg || "获取任务列表失败",
  77. icon: "none",
  78. });
  79. }
  80. } catch (error) {
  81. uni.showToast({
  82. title: "获取任务列表失败",
  83. icon: "none",
  84. });
  85. } finally {
  86. loading.value = false;
  87. }
  88. };
  89. // 搜索处理
  90. const onSearch = () => {
  91. fetchTaskList();
  92. };
  93. // 打开扫码
  94. const openScan = () => {
  95. // #ifdef APP-PLUS || MP-WEIXIN
  96. uni.scanCode({
  97. success: (res) => {
  98. searchText.value = res.result;
  99. onSearch();
  100. },
  101. fail: (err) => {
  102. uni.showToast({
  103. title: "扫码失败",
  104. icon: "error",
  105. });
  106. },
  107. });
  108. // #endif
  109. // #ifdef H5
  110. uni.showToast({
  111. title: "H5环境不支持扫码",
  112. icon: "none",
  113. });
  114. // #endif
  115. };
  116. // 点击任务卡片
  117. const handleTaskClick = (task) => {
  118. uni.showModal({
  119. title: "领取确认",
  120. content: "是否确认领取下架任务?",
  121. cancelText: "取消",
  122. confirmText: "确认",
  123. success: async (res) => {
  124. if (res.confirm) {
  125. try {
  126. const response = await uni.$u.http.post(`/app/appstock/lockStockTask?taskCode=${task.taskCode}`);
  127. if (response.code === 200) {
  128. uni.navigateTo({
  129. url: `/pages/index/wms/task-detail?taskCode=${task.taskCode}`,
  130. });
  131. } else {
  132. uni.showToast({
  133. title: response.msg || "任务锁定失败",
  134. icon: "none",
  135. });
  136. }
  137. } catch (error) {
  138. uni.showToast({
  139. title: error,
  140. icon: "none",
  141. });
  142. }
  143. }
  144. },
  145. });
  146. };
  147. // 页面加载时获取任务列表
  148. onMounted(() => {
  149. fetchTaskList();
  150. });
  151. </script>
  152. <style scoped>
  153. .task-card {
  154. background-color: #ffffff;
  155. padding: 20rpx;
  156. margin-top: 16rpx;
  157. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  158. }
  159. .task-header {
  160. display: flex;
  161. justify-content: space-between;
  162. align-items: center;
  163. margin-bottom: 16rpx;
  164. }
  165. .task-no {
  166. font-size: 28rpx;
  167. font-weight: bold;
  168. }
  169. .empty-state {
  170. text-align: center;
  171. padding: 40rpx;
  172. color: #999;
  173. }
  174. .loading-state {
  175. text-align: center;
  176. padding: 40rpx;
  177. }
  178. .loading-state text {
  179. margin-left: 12rpx;
  180. color: #666;
  181. font-size: 28rpx;
  182. }
  183. </style>