task-detail.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <view class="container">
  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 } from "vue";
  83. import BadOutCard from "@/pages/index/wms/components/BadOutCard.vue";
  84. import VolumeTTS from "@/utils/VolumeTTS.js";
  85. import { onLoad, onUnload, onShow } from "@dcloudio/uni-app";
  86. // 任务进度
  87. const currentTask = ref(0);
  88. const totalTasks = ref(0);
  89. const curTaskInfo = ref({});
  90. const nextLocation = ref("");
  91. // 订单信息
  92. const orderList = ref([]);
  93. const ttsModule = ref(null);
  94. const taskCode = ref("");
  95. onUnload(() => {
  96. ttsModule.value.stop();
  97. });
  98. // 搜索文本
  99. const searchText = ref("");
  100. // 极差商品列表 - 使用detailVoList中的数据
  101. const badList = ref([]);
  102. // 处理下一个任务
  103. const handleNextTask = () => {
  104. if (currentTask.value < totalTasks.value) {
  105. currentTask.value++;
  106. if (currentTask.value == totalTasks.value) {
  107. ttsModule.value.speak("任务完成");
  108. } else {
  109. curTaskInfo.value = orderList.value[currentTask.value];
  110. badList.value = curTaskInfo.value.detailVoList || [];
  111. let nextInfo = orderList.value[currentTask.value + 1];
  112. nextLocation.value = nextInfo.positionCode;
  113. }
  114. }
  115. };
  116. // 搜索处理
  117. const onSearch = () => {
  118. // TODO: 调用API获取订单详情
  119. uni.$u.http.get(`/app/appstock/getStockTaskDetail?taskCode=${taskCode.value}`).then((res) => {
  120. if (res.code == 200) {
  121. orderList.value = res.data;
  122. totalTasks.value = res.data.length;
  123. //默认选中第一个任务
  124. curTaskInfo.value = res.data[currentTask.value];
  125. badList.value = curTaskInfo.value.detailVoList || [];
  126. }
  127. });
  128. };
  129. // 确认下架任务
  130. const confirmStockTask = () => {
  131. const params = {
  132. positionCode: curTaskInfo.value.positionCode,
  133. orderId: curTaskInfo.value.orderId,
  134. taskCode: taskCode.value,
  135. };
  136. uni.$u.http.post("/app/appstock/setStockTask", params).then((res) => {
  137. if (res.code === 200) {
  138. curTaskInfo.value.isCompleted = true;
  139. orderList.value[currentTask.value] = curTaskInfo.value;
  140. handleNextTask();
  141. isFirstScan.value = false;
  142. ttsModule.value.speak("下架成功");
  143. } else {
  144. uni.showToast({
  145. title: res.msg,
  146. icon: "error",
  147. });
  148. }
  149. });
  150. };
  151. //解锁任务
  152. const unlockTask = () => {
  153. uni.$u.http.post("/app/appstock/unlockStockTask?taskCode=" + taskCode.value).then((res) => {
  154. if (res.code == 200) {
  155. uni.showToast({
  156. title: "解锁成功",
  157. icon: "success",
  158. });
  159. } else {
  160. uni.showToast({
  161. title: res.msg || "解锁失败",
  162. icon: "error",
  163. });
  164. }
  165. });
  166. };
  167. // 提交处理
  168. const onSubmit = () => {
  169. uni.showModal({
  170. title: "确认提示",
  171. content: "是否确认提交本次下架?",
  172. success: (res) => {
  173. if (res.confirm) {
  174. uni.navigateBack();
  175. ttsModule.value.speak("任务已提交");
  176. unlockTask();
  177. }
  178. },
  179. });
  180. };
  181. function goBack() {
  182. uni.showModal({
  183. title: "确认提示",
  184. content: "是否确认放弃本次下架?",
  185. success: (res) => {
  186. if (res.confirm) {
  187. uni.navigateBack();
  188. ttsModule.value.speak("任务已放弃");
  189. unlockTask();
  190. }
  191. },
  192. });
  193. }
  194. let isFirstScan = ref(false); //是否验证了库位号
  195. //扫码首先校验库位号,如果库位号不正确,则提示库位号不正确 如果正确,curTaskInfo.isValid = true
  196. //正确后继续校验物流号或者订单号,如果正确,则调用
  197. //库位号格式 字母+数字+横杠- 物流号格式 必须有字母+数字组合 订单号 数字
  198. const checkScanText = (scanText) => {
  199. console.log(scanText, "scanText");
  200. let length = scanText ? scanText.length : 0;
  201. //先判断扫描到的scanText是库位号还是物流号或者订单号
  202. let isPositionCode = scanText.indexOf("-") > -1 && length == 9;
  203. let isWaybillCode = /^(?=.*[A-Z])(?=.*\d)[A-Z0-9]+$/.test(scanText);
  204. let isOrderId = /^\d+$/.test(scanText);
  205. //库位号校验
  206. if (isPositionCode) {
  207. let positionCode = curTaskInfo.value.positionCode;
  208. if (positionCode != scanText) {
  209. uni.showToast({
  210. title: "库位号不正确",
  211. icon: "error",
  212. });
  213. } else {
  214. isFirstScan.value = true;
  215. curTaskInfo.value.isValid = true;
  216. }
  217. }
  218. if (!isFirstScan.value) {
  219. ttsModule.value.speak("请先校验库位号");
  220. return;
  221. }
  222. //物流号或者订单号校验
  223. if (isWaybillCode || isOrderId) {
  224. let waybillCode = curTaskInfo.value.waybillCode;
  225. let orderId = curTaskInfo.value.orderId;
  226. if (waybillCode == scanText || orderId == scanText) {
  227. confirmStockTask();
  228. } else {
  229. uni.showToast({
  230. title: "订单号或物流号不匹配",
  231. icon: "error",
  232. });
  233. curTaskInfo.value.isValid = true;
  234. }
  235. }
  236. };
  237. // 打开扫码
  238. const openScan = () => {
  239. // #ifdef APP-PLUS || MP-WEIXIN
  240. uni.scanCode({
  241. success: (res) => {
  242. searchText.value = res.result;
  243. checkScanText(res.result);
  244. },
  245. fail: (err) => {
  246. uni.showToast({
  247. title: "扫码失败",
  248. icon: "error",
  249. });
  250. },
  251. });
  252. // #endif
  253. // #ifdef H5
  254. uni.showToast({
  255. title: "H5环境不支持扫码",
  256. icon: "none",
  257. });
  258. // #endif
  259. };
  260. onLoad((opts) => {
  261. taskCode.value = opts.taskCode;
  262. onSearch();
  263. // #ifdef APP-PLUS
  264. ttsModule.value = new VolumeTTS();
  265. uni.$u.useGlobalEvent((e) => {
  266. if (e.barcode) {
  267. searchText.value = e.barcode;
  268. checkScanText(e.barcode);
  269. }
  270. });
  271. // #endif
  272. });
  273. onShow(() => {
  274. uni.$u.updateActivePageOnShow();
  275. });
  276. </script>
  277. <style scoped>
  278. .progress-section {
  279. background-color: #fff;
  280. display: flex;
  281. flex-direction: column;
  282. justify-content: center;
  283. padding: 10rpx;
  284. padding-top: 56px;
  285. }
  286. .next-location {
  287. background-color: #fff;
  288. border-bottom: 1rpx solid #f0f0f0;
  289. border-top: 1rpx solid #f0f0f0;
  290. padding: 20rpx;
  291. }
  292. .color-green {
  293. color: #4caf50;
  294. }
  295. .location-info {
  296. background-color: #fff;
  297. padding: 20rpx;
  298. margin-top: 2rpx;
  299. }
  300. .location-detail {
  301. color: #666;
  302. }
  303. .order-info {
  304. background-color: #fff;
  305. padding: 20rpx;
  306. }
  307. .info-item {
  308. line-height: 1.8;
  309. }
  310. .list-title {
  311. font-size: 32rpx;
  312. font-weight: bold;
  313. background-color: rgb(222, 134, 143, 0.5);
  314. padding: 10rpx 0;
  315. padding-left: 30rpx;
  316. }
  317. .container {
  318. /* #ifdef H5 */
  319. padding-bottom: 70px;
  320. /* #endif */
  321. }
  322. </style>