recycle.vue 3.7 KB

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