scan-order.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <view class="container" @click="playGlobalSound">
  3. <u-navbar title="扫书查单" :border="false" fixed bgColor="#22ac38" leftIconColor="#fff"
  4. titleStyle="font-size:36rpx;color:#fff">
  5. <template #left>
  6. <u-icon name="arrow-left" color="#fff" size="20" @click="goBack"></u-icon>
  7. </template>
  8. <template #right>
  9. <text style="color: #fff;font-size: 32rpx;" type="primary" @click="showModal = true">新增</text>
  10. </template>
  11. </u-navbar>
  12. <!-- 顶部操作栏 -->
  13. <u-sticky>
  14. <view class="header" @click="clearAll">清除全部</view>
  15. <!-- 提示信息 -->
  16. <view class="tips">
  17. <text>请勿录入审核为不良的书籍ISBN!</text>
  18. <text class="sub-tips">不良书籍的ISBN可能是错误的!</text>
  19. </view>
  20. </u-sticky>
  21. <!-- ISBN列表 -->
  22. <scroll-view scroll-y class="isbn-list">
  23. <view v-for="(item, index) in isbnList" :key="index" class="isbn-item">
  24. <view class="item-left">
  25. <u-icon name="minus-circle-fill" color="#dd524d" size="24" @click="removeItem(index)" />
  26. <text class="index">{{ index + 1 }}、</text>
  27. <text class="isbn">{{ item.isbn }}</text>
  28. </view>
  29. <u-number-box v-model="item.quantity" :disableMinus="item.quantity <= 1"></u-number-box>
  30. </view>
  31. </scroll-view>
  32. <!-- 底部按钮 -->
  33. <view class="fixed-bottom">
  34. <u-button size="large" type="warning" text="扫码加书" @click="handleScan" />
  35. <u-button size="large" type="primary" text="查询" @click="handleQuery" />
  36. </view>
  37. <!-- ISBN Input Modal -->
  38. <u-popup :show="showModal" mode="center" customStyle="width: 84%;border-radius:10px">
  39. <view class="modal-content">
  40. <text>输入ISBN码</text>
  41. <u-input v-model="newIsbn" placeholder="请输入ISBN码" custom-style="margin:60rpx 0" />
  42. <view class="modal-buttons">
  43. <u-button text="取消" @click="showModal = false" />
  44. <u-button type="primary" text="确定" @click="addIsbn" />
  45. </view>
  46. </view>
  47. </u-popup>
  48. </view>
  49. </template>
  50. <script setup>
  51. import { ref, onUnmounted } from 'vue';
  52. // ISBN列表数据
  53. const isbnList = ref([]);
  54. const showModal = ref(false);
  55. const newIsbn = ref('');
  56. // 移除项目
  57. const removeItem = (index) => {
  58. isbnList.value.splice(index, 1);
  59. };
  60. const goBack = () => {
  61. uni.navigateBack()
  62. };
  63. //清除全部
  64. function clearAll() {
  65. isbnList.value.length = 0
  66. }
  67. // 添加或更新ISBN
  68. const addOrUpdateIsbn = (isbn) => {
  69. const existingItem = isbnList.value.find(item => item.isbn === isbn);
  70. if (existingItem) {
  71. existingItem.quantity += 1;
  72. } else {
  73. isbnList.value.push({
  74. isbn: isbn,
  75. quantity: 1
  76. });
  77. }
  78. };
  79. //处理isbn(统计调用次数并打印)
  80. function handleIsbn(isbn) {
  81. if (isValidISBN(isbn)) {
  82. addOrUpdateIsbn(isbn);
  83. } else {
  84. uni.$u.ttsModule.speak('不正确的ISBN码')
  85. }
  86. }
  87. // 扫码处理
  88. const handleScan = () => {
  89. uni.scanCode({
  90. success: (res) => {
  91. handleIsbn(res.result)
  92. }
  93. });
  94. };
  95. // ISBN格式验证
  96. const isValidISBN = (isbn) => {
  97. // 简单的ISBN-13验证
  98. return /^97[89]\d{10}$/.test(isbn);
  99. };
  100. // 查询处理
  101. const handleQuery = () => {
  102. if (isbnList.value.length === 0) {
  103. uni.showToast({
  104. title: '请先添加ISBN',
  105. icon: 'none'
  106. });
  107. return;
  108. }
  109. uni.setStorageSync('isbnList', isbnList.value);
  110. uni.navigateTo({
  111. url: '/pages/index/audit/isbn-order'
  112. });
  113. };
  114. const addIsbn = () => {
  115. if (isValidISBN(newIsbn.value)) {
  116. addOrUpdateIsbn(newIsbn.value)
  117. showModal.value = false;
  118. newIsbn.value = '';
  119. } else {
  120. uni.$u.ttsModule.speak('不正确的ISBN码')
  121. }
  122. };
  123. //使用监听事件
  124. const { unregister } = uni.$u.useEventListener((e) => {
  125. handleIsbn(e.barcode)
  126. })
  127. onUnmounted(() => {
  128. unregister()
  129. })
  130. </script>
  131. <style lang="scss" scoped>
  132. .container {
  133. min-height: 100vh;
  134. display: flex;
  135. flex-direction: column;
  136. background-color: #f5f5f5;
  137. // #ifdef APP-PLUS
  138. padding-top: 84px;
  139. // #endif
  140. }
  141. .header {
  142. padding: 12px;
  143. background-color: #999;
  144. color: #fff;
  145. text-align: center;
  146. }
  147. .tips {
  148. padding: 16px;
  149. background-color: #f8f8f8;
  150. text-align: center;
  151. text {
  152. display: block;
  153. color: #666;
  154. font-size: 16px;
  155. }
  156. .sub-tips {
  157. font-size: 14px;
  158. margin-top: 4px;
  159. }
  160. }
  161. .isbn-list {
  162. flex: 1;
  163. padding: 12px;
  164. box-sizing: border-box;
  165. padding-top: 44px;
  166. // #ifdef APP-PLUS
  167. padding-top: 10px;
  168. // #endif
  169. }
  170. .isbn-item {
  171. display: flex;
  172. justify-content: space-between;
  173. align-items: center;
  174. padding: 12px;
  175. background-color: #fff;
  176. margin-bottom: 8px;
  177. border-radius: 4px;
  178. .item-left {
  179. display: flex;
  180. align-items: center;
  181. gap: 8px;
  182. }
  183. .index {
  184. color: #666;
  185. }
  186. .isbn {
  187. color: #333;
  188. }
  189. }
  190. .modal-content {
  191. padding: 20px;
  192. background-color: #fff;
  193. border-radius: 8px;
  194. text-align: center;
  195. }
  196. .modal-buttons {
  197. display: flex;
  198. justify-content: space-between;
  199. margin-top: 20px;
  200. gap: 10px;
  201. }
  202. </style>