warehouse-sign.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view class="container">
  3. <view class="main-content">
  4. <view class="input-group">
  5. <u-input :customStyle="customStyle" :placeholder-style="placeholderStyle" v-model="selectedWarehouse"
  6. placeholder="请选择仓库" readonly border="surround" />
  7. <u-button :customStyle="customStyle" type="info" color="#a4adb3" @click="openWarehouseSelector"
  8. text="选择" />
  9. </view>
  10. <view class="input-group">
  11. <u-input :customStyle="customStyle" :placeholder-style="placeholderStyle" v-model="form.packageCode"
  12. placeholder="扫描/输入物流单号" border="surround" />
  13. <u-button :customStyle="customStyle" type="info" color="#a4adb3" v-permission="'app:express:warehouseSign:confirm'"
  14. @click="handleBarcode(form.packageCode)" text="确定" />
  15. </view>
  16. </view>
  17. <view class="fixed-bottom">
  18. <u-button size="large" type="success" @click="scanCode" text="扫码" class="scan-button" />
  19. </view>
  20. <WarehouseSelector v-model:show="showSelector" @warehouse-selected="handleWarehouseSelected" />
  21. </view>
  22. </template>
  23. <script setup>
  24. import {
  25. reactive,
  26. ref
  27. } from 'vue';
  28. import {
  29. onLoad,
  30. onShow,
  31. onUnload
  32. } from '@dcloudio/uni-app'
  33. import WarehouseSelector from './components/WarehouseSelector.vue';
  34. const placeholderStyle = "font-size:32rpx"
  35. const customStyle = reactive({
  36. height: '90rpx'
  37. })
  38. const selectedWarehouse = ref('');
  39. const form = ref({
  40. "packageCode": "",
  41. "godownId": "",
  42. })
  43. const showSelector = ref(false);
  44. function openWarehouseSelector() {
  45. showSelector.value = true;
  46. }
  47. //选择仓库之后后处理
  48. function handleWarehouseSelected(item) {
  49. selectedWarehouse.value = item.godownName;
  50. form.value.godownId = item.id
  51. }
  52. function scanCode() {
  53. uni.scanCode({
  54. success: (res) => {
  55. form.value.packageCode = res.result;
  56. handleBarcode(res.result)
  57. },
  58. fail: (err) => {
  59. uni.$u.toast('扫码失败')
  60. }
  61. });
  62. }
  63. function handleBarcode(code) {
  64. if (!code) return uni.$u.toast('请输入物流单号')
  65. uni.$u.http.post('/app/ordersign/toGodownSign', form.value).then(res => {
  66. if (res.code == 200) {
  67. let text = code + '到仓签收成功'
  68. uni.$u.ttsModule.speak(text)
  69. } else {
  70. let text = code + '订单不存在'
  71. uni.$u.ttsModule.speak(text)
  72. }
  73. })
  74. }
  75. //获取用户绑定的仓库
  76. function getUserBindWarehouse() {
  77. uni.$u.http.get('/app/appUser/getUserBindGodown').then(res => {
  78. if (res.code == 200) {
  79. selectedWarehouse.value = res.data?.godownName
  80. form.value.godownId = res.data?.id
  81. }
  82. })
  83. }
  84. onLoad(() => {
  85. getUserBindWarehouse()
  86. // #ifdef APP-PLUS
  87. uni.$u.useGlobalEvent((e) => {
  88. form.value.packageCode = e.barcode;
  89. handleBarcode(e.barcode)
  90. })
  91. // #endif
  92. })
  93. onShow(() => {
  94. uni.$u.updateActivePageOnShow()
  95. })
  96. onUnload(() => {
  97. uni.$u.cleanupOnPageUnload();
  98. });
  99. </script>
  100. <style lang="scss" scoped>
  101. .main-content {
  102. padding: 20px;
  103. gap: 20px;
  104. }
  105. .input-group {
  106. display: flex;
  107. gap: 10px;
  108. margin-bottom: 30rpx;
  109. :deep(.u-button) {
  110. width: 160rpx
  111. }
  112. .u-input {
  113. background-color: #fff;
  114. }
  115. }
  116. </style>