express-order.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <view class="container">
  3. <!-- 底部按钮 -->
  4. <view class="footer">
  5. <!-- 查询区域 -->
  6. <view class="query-section">
  7. <u-radio-group v-model="form.searchType" @change="playGlobalSound">
  8. <u-radio label="查订单" name="1" label-size="17" />
  9. <u-radio label="查物流" custom-style="margin-left:20px" name="2" label-size="17" />
  10. </u-radio-group>
  11. <view class="search-box">
  12. <u-input custom-style="width:100rpx" v-model="form.search"
  13. :placeholder="form.searchType == '1' ? '扫描/输入订单编号' : '扫描/输入物流单号'" border="surround" clearable
  14. @focus="playGlobalSound" placeholder-style="font-size:32rpx"
  15. :customStyle="{ 'fontSize': '32rpx' }">
  16. </u-input>
  17. <u-button color="#c8c8c8" text="查询" @click="handleSearch" />
  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 {
  29. ref,
  30. onUnmounted
  31. } from 'vue';
  32. import {
  33. onLoad,
  34. onShow
  35. } from '@dcloudio/uni-app'
  36. const form = ref({
  37. searchType: '2',
  38. search: ''
  39. });
  40. //点击全局音效
  41. function playGlobalSound() {
  42. uni.$u.playClickSound()
  43. }
  44. // 处理查询
  45. const handleSearch = () => {
  46. if (!form.value.search) {
  47. let text = form.value.searchType == '1' ? '请输入订单编号' : '请输入物流单号'
  48. uni.$u.ttsModule.speak(text)
  49. return
  50. }
  51. // TODO: 查询订单
  52. uni.$u.http.get('/app/orderinfo/getOrderInfoForCheck', {
  53. params: {
  54. ...form.value
  55. }
  56. }).then(res => {
  57. if (res.code == 200) {
  58. uni.setStorageSync('orderDetail', res.data)
  59. uni.navigateTo({
  60. url: `/pages/index/detail/index?id=${res.data.orderId}`
  61. })
  62. } else {
  63. let text = form.value.search + res.msg
  64. uni.$u.ttsModule.speak(text)
  65. }
  66. })
  67. playGlobalSound()
  68. };
  69. // 处理扫码
  70. const handleScan = () => {
  71. playGlobalSound()
  72. uni.scanCode({
  73. success: (res) => {
  74. form.value.search = res.result;
  75. handleSearch();
  76. }
  77. });
  78. }
  79. // #ifdef APP-PLUS
  80. const { unregister } = uni.$u.useEventListener((e) => {
  81. form.value.search = e.barcode
  82. handleSearch()
  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>