task-detail.vue 10 KB

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