warehouse-sign.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. } from '@dcloudio/uni-app'
  32. import WarehouseSelector from './components/WarehouseSelector.vue';
  33. const placeholderStyle = "font-size:32rpx"
  34. const customStyle = reactive({
  35. height: '90rpx'
  36. })
  37. const selectedWarehouse = ref('');
  38. const form = ref({
  39. "packageCode": "",
  40. "godownId": "",
  41. })
  42. const showSelector = ref(false);
  43. function openWarehouseSelector() {
  44. showSelector.value = true;
  45. }
  46. //选择仓库之后后处理
  47. function handleWarehouseSelected(item) {
  48. selectedWarehouse.value = item.godownName;
  49. form.value.godownId = item.id
  50. }
  51. function scanCode() {
  52. uni.scanCode({
  53. success: (res) => {
  54. form.value.packageCode = res.result;
  55. handleBarcode(res.result)
  56. },
  57. fail: (err) => {
  58. uni.$u.toast('扫码失败')
  59. }
  60. });
  61. }
  62. function handleBarcode(code) {
  63. if (!code) return uni.$u.toast('请输入物流单号')
  64. uni.$u.http.post('/app/ordersign/toGodownSign', form.value).then(res => {
  65. if (res.code == 200) {
  66. let text = code + '到仓签收成功'
  67. uni.$u.ttsModule.speak(text)
  68. } else {
  69. let text = code + '订单不存在'
  70. uni.$u.ttsModule.speak(text)
  71. }
  72. })
  73. }
  74. //获取用户绑定的仓库
  75. function getUserBindWarehouse() {
  76. uni.$u.http.get('/app/appUser/getUserBindGodown').then(res => {
  77. if (res.code == 200) {
  78. selectedWarehouse.value = res.data?.godownName
  79. form.value.godownId = res.data?.id
  80. }
  81. })
  82. }
  83. onLoad(() => {
  84. getUserBindWarehouse()
  85. // #ifdef APP-PLUS
  86. uni.$u.useGlobalEvent((e) => {
  87. form.value.packageCode = e.barcode;
  88. handleBarcode(e.barcode)
  89. })
  90. // #endif
  91. })
  92. onShow(() => {
  93. uni.$u.updateActivePageOnShow()
  94. })
  95. </script>
  96. <style lang="scss" scoped>
  97. .main-content {
  98. padding: 20px;
  99. gap: 20px;
  100. }
  101. .input-group {
  102. display: flex;
  103. gap: 10px;
  104. margin-bottom: 30rpx;
  105. :deep(.u-button) {
  106. width: 160rpx
  107. }
  108. .u-input {
  109. background-color: #fff;
  110. }
  111. }
  112. </style>