task-detail.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <view class="container" @click="playGlobalSound">
  3. <!-- 顶部导航栏 -->
  4. <u-navbar title="下架任务" :border="false" fixed safe-area-inset-top>
  5. <template #left>
  6. <u-icon name="arrow-left" color="#333333" size="20" @click="goBack"></u-icon>
  7. </template>
  8. <template #right>
  9. <u-text type="primary" text="提交" @click="onSubmit"></u-text>
  10. </template>
  11. </u-navbar>
  12. <!-- 任务进度 -->
  13. <view class="progress-section">
  14. <u-alert title="当前任务" type="info" center></u-alert>
  15. <view class="flex flex-j-c pad-10" style="padding-right: 40rpx">
  16. <!-- <view class="next-task" @click="handleNextTask">
  17. <text>上一个</text>
  18. </view> -->
  19. <view class="flex-c">
  20. <text
  21. >{{ currentTask }}<text class="progress-text font-20 color-green">/{{ totalTasks }}</text></text
  22. >
  23. </view>
  24. <!-- <view class="color-green" @click="handleNextTask">
  25. <text>下一个</text>
  26. </view> -->
  27. </view>
  28. </view>
  29. <!-- 库位信息 -->
  30. <view class="flex flex-j-b pad-10 next-location" style="padding-right: 40rpx; align-items: center">
  31. <view class="font-14 mb-20">{{ currentTask + 1 }}/{{ totalTasks }}</view>
  32. <view class="flex-d">
  33. <view class="font-20 text-center">
  34. {{ curTaskInfo.positionCode }}
  35. </view>
  36. <view class="location-detail font-13 mt-10" v-if="nextLocation"
  37. >下一库位 {{ nextLocation || "无" }}</view
  38. >
  39. </view>
  40. <image
  41. v-if="!curTaskInfo.isValid"
  42. src="/static/img/location.png"
  43. mode="widthFix"
  44. style="width: 70rpx; height: 70rpx"
  45. ></image>
  46. <image
  47. v-else
  48. src="/static/img/location-active.png"
  49. mode="widthFix"
  50. style="width: 70rpx; height: 70rpx"
  51. ></image>
  52. </view>
  53. <!-- 订单信息 -->
  54. <view class="order-info">
  55. <view class="info-item">订单编号:{{ curTaskInfo.orderId }}</view>
  56. <view class="info-item">物流单号:{{ curTaskInfo.waybillCode || "-" }}</view>
  57. <view class="info-item">不良数量:{{ curTaskInfo.badNum }}</view>
  58. </view>
  59. <!-- 极差商品列表 -->
  60. <view class="bad-list">
  61. <view class="list-title mb-6 mt-20">极差</view>
  62. <view v-for="(item, index) in badList" :key="index">
  63. <BadOutCard :item="item" />
  64. </view>
  65. </view>
  66. <!-- 底部搜索框 -->
  67. <view class="fixed-bottom pad-20" style="background: #ffffff">
  68. <u-search
  69. v-model="searchText"
  70. placeholder="请输入订单编号/物流单号/库位号"
  71. :show-action="false"
  72. :clearabled="true"
  73. @search="checkScanText(searchText)"
  74. height="40"
  75. >
  76. </u-search>
  77. <u-icon name="scan" size="28" color="#19be6b" @click="openScan"></u-icon>
  78. </view>
  79. </view>
  80. </template>
  81. <script setup>
  82. import { ref, onMounted, computed, onUnmounted } from "vue";
  83. import BadOutCard from "@/pages/index/wms/components/BadOutCard.vue";
  84. import { onLoad, onShow } from "@dcloudio/uni-app";
  85. // 任务进度
  86. const currentTask = ref(0);
  87. const totalTasks = ref(0);
  88. const curTaskInfo = ref({});
  89. const nextLocation = ref("");
  90. // 订单信息
  91. const orderList = ref([]);
  92. const ttsModule = ref(null);
  93. const taskCode = ref("");
  94. // #ifdef APP-PLUS
  95. const { unregister } = uni.$u.useEventListener((e) => {
  96. if (e.barcode) {
  97. searchText.value = e.barcode;
  98. checkScanText(e.barcode);
  99. }
  100. });
  101. // #endif
  102. onUnmounted(() => {
  103. uni.$u.ttsModule.stop();
  104. unregister();
  105. });
  106. // 点击全局音效
  107. function playGlobalSound(){
  108. uni.$u.playClickSound()
  109. }
  110. // 搜索文本
  111. const searchText = ref("");
  112. // 极差商品列表 - 使用detailVoList中的数据
  113. const badList = ref([]);
  114. // 处理下一个任务
  115. const handleNextTask = () => {
  116. if (currentTask.value < totalTasks.value) {
  117. currentTask.value++;
  118. if (currentTask.value == totalTasks.value) {
  119. uni.$u.ttsModule.speak("任务完成");
  120. } else {
  121. curTaskInfo.value = orderList.value[currentTask.value];
  122. badList.value = curTaskInfo.value.detailVoList || [];
  123. let nextInfo = orderList.value[currentTask.value + 1];
  124. nextLocation.value = nextInfo.positionCode;
  125. }
  126. }
  127. };
  128. // 搜索处理
  129. const onSearch = () => {
  130. // TODO: 调用API获取订单详情
  131. uni.$u.http.get(`/app/appstock/getStockTaskDetail?taskCode=${taskCode.value}`).then((res) => {
  132. if (res.code == 200) {
  133. orderList.value = res.data;
  134. totalTasks.value = res.data.length;
  135. //默认选中第一个任务
  136. curTaskInfo.value = res.data[currentTask.value];
  137. badList.value = curTaskInfo.value.detailVoList || [];
  138. }
  139. });
  140. };
  141. // 确认下架任务
  142. const confirmStockTask = () => {
  143. const params = {
  144. positionCode: curTaskInfo.value.positionCode,
  145. orderId: curTaskInfo.value.orderId,
  146. taskCode: taskCode.value,
  147. };
  148. uni.$u.http.post("/app/appstock/setStockTask", params).then((res) => {
  149. if (res.code === 200) {
  150. curTaskInfo.value.isCompleted = true;
  151. orderList.value[currentTask.value] = curTaskInfo.value;
  152. handleNextTask();
  153. isFirstScan.value = false;
  154. uni.$u.ttsModule.speak("下架成功");
  155. } else {
  156. uni.showToast({
  157. title: res.msg,
  158. icon: "error",
  159. });
  160. }
  161. });
  162. };
  163. //解锁任务
  164. const unlockTask = () => {
  165. uni.$u.http.post("/app/appstock/unlockStockTask?taskCode=" + taskCode.value).then((res) => {
  166. if (res.code == 200) {
  167. uni.showToast({
  168. title: "解锁成功",
  169. icon: "success",
  170. });
  171. } else {
  172. uni.showToast({
  173. title: res.msg || "解锁失败",
  174. icon: "error",
  175. });
  176. }
  177. });
  178. };
  179. // 提交处理
  180. const onSubmit = () => {
  181. uni.showModal({
  182. title: "确认提示",
  183. content: "是否确认提交本次下架?",
  184. success: (res) => {
  185. playGlobalSound()
  186. if (res.confirm) {
  187. uni.navigateBack();
  188. uni.$u.ttsModule.speak("任务已提交");
  189. unlockTask();
  190. }
  191. },
  192. });
  193. };
  194. function goBack() {
  195. uni.showModal({
  196. title: "确认提示",
  197. content: "是否确认放弃本次下架?",
  198. success: (res) => {
  199. playGlobalSound()
  200. if (res.confirm) {
  201. uni.navigateBack();
  202. uni.$u.ttsModule.speak("任务已放弃");
  203. unlockTask();
  204. }
  205. },
  206. });
  207. }
  208. let isFirstScan = ref(false); //是否验证了库位号
  209. //扫码首先校验库位号,如果库位号不正确,则提示库位号不正确 如果正确,curTaskInfo.isValid = true
  210. //正确后继续校验物流号或者订单号,如果正确,则调用
  211. //库位号格式 字母+数字+横杠- 物流号格式 必须有字母+数字组合 订单号 数字
  212. const checkScanText = (scanText) => {
  213. console.log(scanText, "scanText");
  214. let length = scanText ? scanText.length : 0;
  215. //先判断扫描到的scanText是库位号还是物流号或者订单号
  216. let isPositionCode = scanText.indexOf("-") > -1 && length == 9;
  217. let isWaybillCode = /^(?=.*[A-Z])(?=.*\d)[A-Z0-9]+$/.test(scanText);
  218. let isOrderId = /^\d+$/.test(scanText);
  219. //库位号校验
  220. if (isPositionCode) {
  221. let positionCode = curTaskInfo.value.positionCode;
  222. if (positionCode != scanText) {
  223. uni.showToast({
  224. title: "库位号不正确",
  225. icon: "error",
  226. });
  227. } else {
  228. isFirstScan.value = true;
  229. curTaskInfo.value.isValid = true;
  230. }
  231. }
  232. if (!isFirstScan.value) {
  233. uni.$u.ttsModule.speak("请先校验库位号");
  234. return;
  235. }
  236. //物流号或者订单号校验
  237. if (isWaybillCode || isOrderId) {
  238. let waybillCode = curTaskInfo.value.waybillCode;
  239. let orderId = curTaskInfo.value.orderId;
  240. if (waybillCode == scanText || orderId == scanText) {
  241. confirmStockTask();
  242. } else {
  243. uni.showToast({
  244. title: "订单号或物流号不匹配",
  245. icon: "error",
  246. });
  247. curTaskInfo.value.isValid = true;
  248. }
  249. }
  250. };
  251. // 打开扫码
  252. const openScan = () => {
  253. // #ifdef APP-PLUS || MP-WEIXIN
  254. uni.scanCode({
  255. success: (res) => {
  256. searchText.value = res.result;
  257. checkScanText(res.result);
  258. },
  259. fail: (err) => {
  260. uni.showToast({
  261. title: "扫码失败",
  262. icon: "error",
  263. });
  264. },
  265. });
  266. // #endif
  267. // #ifdef H5
  268. uni.showToast({
  269. title: "H5环境不支持扫码",
  270. icon: "none",
  271. });
  272. // #endif
  273. };
  274. onLoad((opts) => {
  275. taskCode.value = opts.taskCode;
  276. onSearch();
  277. });
  278. </script>
  279. <style scoped>
  280. .progress-section {
  281. background-color: #fff;
  282. display: flex;
  283. flex-direction: column;
  284. justify-content: center;
  285. padding: 10rpx;
  286. padding-top: 56px;
  287. }
  288. .next-location {
  289. background-color: #fff;
  290. border-bottom: 1rpx solid #f0f0f0;
  291. border-top: 1rpx solid #f0f0f0;
  292. padding: 20rpx;
  293. }
  294. .color-green {
  295. color: #4caf50;
  296. }
  297. .location-info {
  298. background-color: #fff;
  299. padding: 20rpx;
  300. margin-top: 2rpx;
  301. }
  302. .location-detail {
  303. color: #666;
  304. }
  305. .order-info {
  306. background-color: #fff;
  307. padding: 20rpx;
  308. }
  309. .info-item {
  310. line-height: 1.8;
  311. }
  312. .list-title {
  313. font-size: 32rpx;
  314. font-weight: bold;
  315. background-color: rgb(222, 134, 143, 0.5);
  316. padding: 10rpx 0;
  317. padding-left: 30rpx;
  318. }
  319. .container {
  320. /* #ifdef H5 */
  321. padding-bottom: 70px;
  322. /* #endif */
  323. }
  324. </style>