mall.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. type: 1
  44. }
  45. });
  46. if (res.code === 200) {
  47. if (res.data && res.data.id) {
  48. // 存在历史工单,跳转到历史工单页面
  49. uni.navigateTo({
  50. url: `/pages/index/work-order/history?workOrderId=${res.data.id}&type=1&waybillCode=${res.data.waybillCode || formData.value.search}&orderId=${res.data.orderId || ''}`,
  51. });
  52. } else {
  53. // 不存在历史工单,跳转到创建工单页面,携带回填信息
  54. const orderId = res.data?.orderId || '';
  55. const waybillCode = res.data?.waybillCode || formData.value.search;
  56. const expressType = res.data?.expressType || '';
  57. uni.navigateTo({
  58. url: `/pages/order/mall/created?waybillCode=${waybillCode}&orderId=${orderId}&expressType=${expressType}&readonly=1`,
  59. });
  60. }
  61. } else {
  62. uni.$u.toast(res.msg || "查询失败");
  63. }
  64. } catch (error) {
  65. console.error(error);
  66. uni.$u.toast("查询失败");
  67. }
  68. };
  69. // 处理扫码
  70. const handleScan = () => {
  71. uni.scanCode({
  72. success: (res) => {
  73. formData.value.search = res.result;
  74. handleSubmit();
  75. },
  76. });
  77. };
  78. // 全局监听事件
  79. // #ifdef APP-PLUS
  80. const { unregister } = uni.$u.useEventListener((e) => {
  81. formData.value.search = e.barcode;
  82. handleSubmit();
  83. });
  84. // #endif
  85. onUnmounted(() => {
  86. // #ifdef APP-PLUS
  87. unregister();
  88. // #endif
  89. });
  90. </script>
  91. <style lang="scss" scoped>
  92. @import "../components/common.scss";
  93. </style>