commodity-scan.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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="form.isbn"
  6. placeholder="扫描ISBN" border="surround" />
  7. <u-button :customStyle="customStyle" type="info" color="#a4adb3"
  8. @click="handleSubmit" text="提交" />
  9. </view>
  10. </view>
  11. <view class="fixed-bottom">
  12. <u-button size="large" type="success" @click="scanCode" text="扫码" class="scan-button" />
  13. </view>
  14. </view>
  15. </template>
  16. <script setup>
  17. import {
  18. reactive,
  19. ref,
  20. onUnmounted
  21. } from 'vue';
  22. import {
  23. onLoad,
  24. onShow
  25. } from '@dcloudio/uni-app'
  26. const placeholderStyle = "font-size:32rpx"
  27. const customStyle = reactive({
  28. height: '90rpx'
  29. })
  30. const form = ref({
  31. "isbn": "",
  32. })
  33. function scanCode() {
  34. uni.scanCode({
  35. success: (res) => {
  36. form.value.isbn = res.result;
  37. handleSubmit();
  38. },
  39. fail: (err) => {
  40. uni.$u.toast('扫码失败');
  41. }
  42. });
  43. }
  44. function handleSubmit() {
  45. if (!form.value.isbn) return uni.$u.toast('请输入ISBN');
  46. // Call your API endpoint for commodity scanning
  47. uni.$u.http.post('/app/book/bookPushErp', form.value).then(res => {
  48. console.log(res);
  49. if (res.code == 200) {
  50. let text = form.value.isbn + res.msg;
  51. uni.$u.ttsModule.speak(text);
  52. form.value.isbn = '';
  53. } else {
  54. uni.$u.ttsModule.speak(res.msg);
  55. }
  56. }).catch(err => {
  57. uni.$u.toast('提交失败,请重试');
  58. });
  59. }
  60. // #ifdef APP-PLUS
  61. const { unregister } = uni.$u.useEventListener((e) => {
  62. form.value.isbn = e.barcode;
  63. handleSubmit();
  64. });
  65. // #endif
  66. onUnmounted(() => {
  67. unregister();
  68. });
  69. </script>
  70. <style lang="scss" scoped>
  71. .container {
  72. min-height: 100vh;
  73. background-color: #f5f5f5;
  74. }
  75. .header {
  76. background-color: #27ae60;
  77. padding: 20rpx;
  78. color: white;
  79. text-align: center;
  80. font-size: 36rpx;
  81. position: relative;
  82. .title {
  83. font-weight: bold;
  84. }
  85. }
  86. .main-content {
  87. padding: 20px;
  88. gap: 20px;
  89. }
  90. .input-group {
  91. display: flex;
  92. gap: 10px;
  93. margin-bottom: 30rpx;
  94. :deep(.u-button) {
  95. width: 160rpx;
  96. }
  97. .u-input {
  98. background-color: #fff;
  99. }
  100. }
  101. .status-box {
  102. margin: 20rpx;
  103. background-color: #fff;
  104. border-radius: 10rpx;
  105. overflow: hidden;
  106. border: 1px solid #f0f0f0;
  107. .status-header {
  108. background-color: #f1c40f;
  109. padding: 10rpx 20rpx;
  110. color: #333;
  111. font-weight: bold;
  112. }
  113. .status-message {
  114. padding: 20rpx;
  115. border-bottom: 1px solid #eee;
  116. font-weight: bold;
  117. }
  118. .status-option {
  119. padding: 10rpx 20rpx;
  120. border-bottom: 1px solid #eee;
  121. }
  122. .footer {
  123. padding: 10rpx 20rpx;
  124. color: #999;
  125. font-size: 24rpx;
  126. text-align: right;
  127. }
  128. }
  129. .fixed-bottom {
  130. position: fixed;
  131. bottom: 0;
  132. left: 0;
  133. right: 0;
  134. .scan-button {
  135. background-color: #27ae60;
  136. }
  137. }
  138. </style>