commodity-scan.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. onLoad(() => {
  61. // #ifdef APP-PLUS
  62. uni.$u.useGlobalEvent((e) => {
  63. if (e.barcode) {
  64. form.value.isbn = e.barcode;
  65. handleSubmit();
  66. }
  67. })
  68. // #endif
  69. })
  70. // #ifdef APP-PLUS
  71. onShow(() => {
  72. uni.$u.updateActivePageOnShow();
  73. })
  74. onUnmounted(() => {
  75. uni.$u.cleanupOnPageUnload();
  76. });
  77. // #endif
  78. </script>
  79. <style lang="scss" scoped>
  80. .container {
  81. min-height: 100vh;
  82. background-color: #f5f5f5;
  83. }
  84. .header {
  85. background-color: #27ae60;
  86. padding: 20rpx;
  87. color: white;
  88. text-align: center;
  89. font-size: 36rpx;
  90. position: relative;
  91. .title {
  92. font-weight: bold;
  93. }
  94. }
  95. .main-content {
  96. padding: 20px;
  97. gap: 20px;
  98. }
  99. .input-group {
  100. display: flex;
  101. gap: 10px;
  102. margin-bottom: 30rpx;
  103. :deep(.u-button) {
  104. width: 160rpx;
  105. }
  106. .u-input {
  107. background-color: #fff;
  108. }
  109. }
  110. .status-box {
  111. margin: 20rpx;
  112. background-color: #fff;
  113. border-radius: 10rpx;
  114. overflow: hidden;
  115. border: 1px solid #f0f0f0;
  116. .status-header {
  117. background-color: #f1c40f;
  118. padding: 10rpx 20rpx;
  119. color: #333;
  120. font-weight: bold;
  121. }
  122. .status-message {
  123. padding: 20rpx;
  124. border-bottom: 1px solid #eee;
  125. font-weight: bold;
  126. }
  127. .status-option {
  128. padding: 10rpx 20rpx;
  129. border-bottom: 1px solid #eee;
  130. }
  131. .footer {
  132. padding: 10rpx 20rpx;
  133. color: #999;
  134. font-size: 24rpx;
  135. text-align: right;
  136. }
  137. }
  138. .fixed-bottom {
  139. position: fixed;
  140. bottom: 0;
  141. left: 0;
  142. right: 0;
  143. .scan-button {
  144. background-color: #27ae60;
  145. }
  146. }
  147. </style>