task-detail.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. @change="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 } 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. };
  135. uni.$u.http.post("/app/appstock/setStockTask", params).then((res) => {
  136. if (res.code === 200) {
  137. curTaskInfo.value.isCompleted = true;
  138. orderList.value[currentTask.value] = curTaskInfo.value;
  139. handleNextTask();
  140. ttsModule.value.speak("下架成功");
  141. } else {
  142. uni.showToast({
  143. title: res.msg,
  144. icon: "error",
  145. });
  146. }
  147. });
  148. };
  149. //解锁任务
  150. const unlockTask = () => {
  151. uni.$u.http.post("/app/appstock/unlockStockTask?taskCode=" + taskCode.value).then((res) => {
  152. if (res.code == 200) {
  153. uni.showToast({
  154. title: "解锁成功",
  155. icon: "success",
  156. });
  157. } else {
  158. uni.showToast({
  159. title: res.msg || "解锁失败",
  160. icon: "error",
  161. });
  162. }
  163. });
  164. };
  165. // 提交处理
  166. const onSubmit = () => {
  167. uni.showModal({
  168. title: "确认提示",
  169. content: "是否确认提交本次下架?",
  170. success: (res) => {
  171. if (res.confirm) {
  172. uni.navigateBack();
  173. ttsModule.value.speak("任务已提交");
  174. unlockTask();
  175. }
  176. },
  177. });
  178. };
  179. function goBack() {
  180. uni.showModal({
  181. title: "确认提示",
  182. content: "是否确认放弃本次下架?",
  183. success: (res) => {
  184. if (res.confirm) {
  185. uni.navigateBack();
  186. ttsModule.value.speak("任务已放弃");
  187. unlockTask();
  188. }
  189. },
  190. });
  191. }
  192. let isFirstScan = ref(false); //是否验证了库位号
  193. //扫码首先校验库位号,如果库位号不正确,则提示库位号不正确 如果正确,curTaskInfo.isValid = true
  194. //正确后继续校验物流号或者订单号,如果正确,则调用
  195. //库位号格式 字母+数字+横杠- 物流号格式 必须有字母+数字组合 订单号 数字
  196. const checkScanText = (scanText) => {
  197. console.log(scanText, "scanText");
  198. //先判断扫描到的scanText是库位号还是物流号或者订单号
  199. let isPositionCode = scanText.indexOf("-") > -1;
  200. let isWaybillCode = /^(?=.*[A-Z])(?=.*\d)[A-Z0-9]+$/.test(scanText);
  201. let isOrderId = /^\d+$/.test(scanText);
  202. console.log(
  203. isPositionCode,
  204. isWaybillCode,
  205. isOrderId,
  206. isFirstScan.value,
  207. "isPositionCode, isWaybillCode, isOrderId"
  208. );
  209. //库位号校验
  210. if (isPositionCode) {
  211. let positionCode = curTaskInfo.value.positionCode;
  212. if (positionCode != scanText) {
  213. uni.showToast({
  214. title: "库位号不正确",
  215. icon: "error",
  216. });
  217. } else {
  218. isFirstScan.value = true;
  219. curTaskInfo.value.isValid = true;
  220. }
  221. }
  222. if (!isFirstScan.value) {
  223. ttsModule.value.speak("请先校验库位号");
  224. return;
  225. }
  226. //物流号校验
  227. if (isWaybillCode && !isOrderId) {
  228. let waybillCode = curTaskInfo.value.waybillCode;
  229. if (waybillCode == scanText) {
  230. confirmStockTask();
  231. } else {
  232. uni.showToast({
  233. title: "物流号不正确",
  234. icon: "error",
  235. });
  236. }
  237. }
  238. //订单号校验
  239. if (isOrderId && !isWaybillCode) {
  240. let orderId = curTaskInfo.value.orderId;
  241. if (orderId == scanText) {
  242. confirmStockTask();
  243. } else {
  244. curTaskInfo.value.isValid = true;
  245. }
  246. }
  247. };
  248. // 打开扫码
  249. const openScan = () => {
  250. // #ifdef APP-PLUS || MP-WEIXIN
  251. uni.scanCode({
  252. success: (res) => {
  253. searchText.value = res.result;
  254. checkScanText(res.result);
  255. },
  256. fail: (err) => {
  257. uni.showToast({
  258. title: "扫码失败",
  259. icon: "error",
  260. });
  261. },
  262. });
  263. // #endif
  264. // #ifdef H5
  265. uni.showToast({
  266. title: "H5环境不支持扫码",
  267. icon: "none",
  268. });
  269. // #endif
  270. };
  271. onLoad((opts) => {
  272. taskCode.value = opts.taskCode;
  273. onSearch();
  274. // #ifdef APP-PLUS
  275. ttsModule.value = new VolumeTTS();
  276. uni.$u.useGlobalEvent((e) => {
  277. if (e.barcode) {
  278. searchText.value = e.barcode;
  279. checkScanText(e.barcode);
  280. }
  281. });
  282. // #endif
  283. });
  284. </script>
  285. <style scoped>
  286. .progress-section {
  287. background-color: #fff;
  288. display: flex;
  289. flex-direction: column;
  290. justify-content: center;
  291. padding: 10rpx;
  292. padding-top: 56px;
  293. }
  294. .next-location {
  295. background-color: #fff;
  296. border-bottom: 1rpx solid #f0f0f0;
  297. border-top: 1rpx solid #f0f0f0;
  298. padding: 20rpx;
  299. }
  300. .color-green {
  301. color: #4caf50;
  302. }
  303. .location-info {
  304. background-color: #fff;
  305. padding: 20rpx;
  306. margin-top: 2rpx;
  307. }
  308. .location-detail {
  309. color: #666;
  310. }
  311. .order-info {
  312. background-color: #fff;
  313. padding: 20rpx;
  314. }
  315. .info-item {
  316. line-height: 1.8;
  317. }
  318. .list-title {
  319. font-size: 32rpx;
  320. font-weight: bold;
  321. background-color: rgb(222, 134, 143, 0.5);
  322. padding: 10rpx 0;
  323. padding-left: 30rpx;
  324. }
  325. .container {
  326. /* #ifdef H5 */
  327. padding-bottom: 70px;
  328. /* #endif */
  329. }
  330. </style>