recycle.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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(formData.value.searchType === '1' ? "请扫描/输入订单号" : "请扫描/输入物流单号");
  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. const waybillCode = res.data.waybillCode || reqWaybillCode || '';
  57. const orderId = res.data.orderId || reqOrderId || '';
  58. uni.navigateTo({
  59. url: `/pages/index/work-order/history?workOrderId=${res.data.id}&type=2&waybillCode=${encodeURIComponent(waybillCode)}&orderId=${encodeURIComponent(orderId)}`,
  60. });
  61. } else {
  62. const orderId = res.data?.orderId || reqOrderId;
  63. const waybillCode = res.data?.waybillCode || reqWaybillCode;
  64. const expressType = res.data?.expressType || '';
  65. if (!orderId && !waybillCode) {
  66. uni.$u.toast('未查询到关联订单/物流信息');
  67. return;
  68. }
  69. uni.navigateTo({
  70. url: `/pages/order/recycle/created?waybillCode=${encodeURIComponent(waybillCode)}&orderId=${encodeURIComponent(orderId)}&expressType=${expressType}&readonly=1`,
  71. });
  72. }
  73. } else {
  74. uni.$u.toast(res.msg || "查询失败");
  75. }
  76. } catch (error) {
  77. console.error(error);
  78. uni.$u.toast("查询失败");
  79. }
  80. };
  81. // 处理扫码
  82. const handleScan = () => {
  83. uni.scanCode({
  84. success: (res) => {
  85. formData.value.search = res.result;
  86. handleSubmit();
  87. },
  88. });
  89. };
  90. // 全局监听事件
  91. // #ifdef APP-PLUS
  92. const { unregister } = uni.$u.useEventListener((e) => {
  93. formData.value.search = e.barcode;
  94. handleSubmit();
  95. });
  96. // #endif
  97. onUnmounted(() => {
  98. // #ifdef APP-PLUS
  99. unregister();
  100. // #endif
  101. });
  102. </script>
  103. <style lang="scss" scoped>
  104. @import "../components/common.scss";
  105. </style>