mall.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <view class="container">
  3. <!-- 底部按钮 -->
  4. <view class="footer">
  5. <!-- 查询区域 -->
  6. <view class="query-section">
  7. <view class="search-box">
  8. <u-input
  9. custom-style="font-size:32rpx"
  10. placeholder-style="fong-size:32rpx"
  11. v-model="formData.search"
  12. placeholder="扫描/输入物流单号"
  13. border="surround"
  14. clearable
  15. >
  16. </u-input>
  17. <u-button color="#c8c8c8" text="查询" @click="handleSubmit" />
  18. </view>
  19. </view>
  20. <u-divider></u-divider>
  21. <view style="display: flex">
  22. <u-button size="large" type="success" text="扫码" @click="handleScan" />
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script setup>
  28. import { ref, onUnmounted } from "vue";
  29. import { onLoad, onShow } from "@dcloudio/uni-app";
  30. const formData = ref({
  31. search: "",
  32. });
  33. // 处理查询
  34. const handleSubmit = async () => {
  35. if (!formData.value.search) {
  36. uni.$u.toast("请扫描/输入物流单号");
  37. return;
  38. }
  39. try {
  40. const res = await uni.$u.http.get("/app/workOrder/scanWorkOrder", {
  41. params: {
  42. waybillCode: formData.value.search
  43. }
  44. });
  45. if (res.code === 200) {
  46. if (res.data && res.data.id) {
  47. // 存在历史工单,跳转到历史工单页面
  48. uni.navigateTo({
  49. url: `/pages/index/work-order/history?workOrderId=${res.data.id}&type=1&waybillCode=${res.data.waybillCode || formData.value.search}&orderId=${res.data.orderId || ''}`,
  50. });
  51. } else {
  52. // 不存在历史工单,跳转到创建工单页面,携带回填信息
  53. const orderId = res.data?.orderId || '';
  54. const waybillCode = res.data?.waybillCode || formData.value.search;
  55. const expressType = res.data?.expressType || '';
  56. uni.navigateTo({
  57. url: `/pages/order/mall/created?waybillCode=${waybillCode}&orderId=${orderId}&expressType=${expressType}&readonly=1`,
  58. });
  59. }
  60. } else {
  61. uni.$u.toast(res.msg || "查询失败");
  62. }
  63. } catch (error) {
  64. console.error(error);
  65. uni.$u.toast("查询失败");
  66. }
  67. };
  68. // 处理扫码
  69. const handleScan = () => {
  70. uni.scanCode({
  71. success: (res) => {
  72. formData.value.search = res.result;
  73. handleSubmit();
  74. },
  75. });
  76. };
  77. // 全局监听事件
  78. // #ifdef APP-PLUS
  79. const { unregister } = uni.$u.useEventListener((e) => {
  80. formData.value.search = e.barcode;
  81. handleSubmit();
  82. });
  83. // #endif
  84. onUnmounted(() => {
  85. // #ifdef APP-PLUS
  86. unregister();
  87. // #endif
  88. });
  89. </script>
  90. <style lang="scss" scoped>
  91. @import "../components/common.scss";
  92. </style>