commodity-scan.vue 2.9 KB

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