task-detail.vue 10 KB

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