recycle.vue 3.7 KB

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