scan-order.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 {
  52. ref,
  53. computed,
  54. onUnmounted
  55. } from 'vue';
  56. import { onLoad, onShow } from "@dcloudio/uni-app"
  57. //点击全局音效
  58. function playGlobalSound(){
  59. uni.$u.playClickSound()
  60. }
  61. // ISBN列表数据
  62. const isbnList = ref([]);
  63. const showModal = ref(false);
  64. const newIsbn = ref('');
  65. // 移除项目
  66. const removeItem = (index) => {
  67. isbnList.value.splice(index, 1);
  68. };
  69. const goBack = () => {
  70. uni.navigateBack()
  71. };
  72. //清除全部
  73. function clearAll() {
  74. isbnList.value.length = 0
  75. }
  76. // 添加或更新ISBN
  77. const addOrUpdateIsbn = (isbn) => {
  78. const existingItem = isbnList.value.find(item => item.isbn === isbn);
  79. if (existingItem) {
  80. existingItem.quantity += 1;
  81. } else {
  82. isbnList.value.push({
  83. isbn: isbn,
  84. quantity: 1
  85. });
  86. }
  87. };
  88. //处理isbn
  89. function handleIsbn(isbn) {
  90. if (isValidISBN(isbn)) {
  91. addOrUpdateIsbn(isbn);
  92. } else {
  93. uni.$u.ttsModule.speak('不正确的ISBN码')
  94. }
  95. }
  96. // 扫码处理
  97. const handleScan = () => {
  98. uni.scanCode({
  99. success: (res) => {
  100. handleIsbn(res.result)
  101. }
  102. });
  103. };
  104. // ISBN格式验证
  105. const isValidISBN = (isbn) => {
  106. // 简单的ISBN-13验证
  107. return /^97[89]\d{10}$/.test(isbn);
  108. };
  109. // 查询处理
  110. const handleQuery = () => {
  111. if (isbnList.value.length === 0) {
  112. uni.showToast({
  113. title: '请先添加ISBN',
  114. icon: 'none'
  115. });
  116. return;
  117. }
  118. uni.setStorageSync('isbnList', isbnList.value);
  119. uni.navigateTo({
  120. url: '/pages/index/audit/isbn-order'
  121. });
  122. };
  123. const addIsbn = () => {
  124. if (isValidISBN(newIsbn.value)) {
  125. addOrUpdateIsbn(newIsbn.value)
  126. showModal.value = false;
  127. newIsbn.value = '';
  128. } else {
  129. uni.$u.ttsModule.speak('不正确的ISBN码')
  130. }
  131. };
  132. onLoad(() => {
  133. // #ifdef APP-PLUS
  134. uni.$u.useGlobalEvent((e) => {
  135. handleIsbn(e.barcode);
  136. });
  137. // #endif
  138. });
  139. onShow(() => {
  140. uni.$u.updateActivePageOnShow();
  141. });
  142. onUnmounted(() => {
  143. uni.$u.cleanupOnPageUnload();
  144. });
  145. </script>
  146. <style lang="scss" scoped>
  147. .container {
  148. min-height: 100vh;
  149. display: flex;
  150. flex-direction: column;
  151. background-color: #f5f5f5;
  152. // #ifdef APP-PLUS
  153. padding-top: 84px;
  154. // #endif
  155. }
  156. .header {
  157. padding: 12px;
  158. background-color: #999;
  159. color: #fff;
  160. text-align: center;
  161. }
  162. .tips {
  163. padding: 16px;
  164. background-color: #f8f8f8;
  165. text-align: center;
  166. text {
  167. display: block;
  168. color: #666;
  169. font-size: 16px;
  170. }
  171. .sub-tips {
  172. font-size: 14px;
  173. margin-top: 4px;
  174. }
  175. }
  176. .isbn-list {
  177. flex: 1;
  178. padding: 12px;
  179. box-sizing: border-box;
  180. padding-top: 44px;
  181. // #ifdef APP-PLUS
  182. padding-top: 10px;
  183. // #endif
  184. }
  185. .isbn-item {
  186. display: flex;
  187. justify-content: space-between;
  188. align-items: center;
  189. padding: 12px;
  190. background-color: #fff;
  191. margin-bottom: 8px;
  192. border-radius: 4px;
  193. .item-left {
  194. display: flex;
  195. align-items: center;
  196. gap: 8px;
  197. }
  198. .index {
  199. color: #666;
  200. }
  201. .isbn {
  202. color: #333;
  203. }
  204. }
  205. .modal-content {
  206. padding: 20px;
  207. background-color: #fff;
  208. border-radius: 8px;
  209. text-align: center;
  210. }
  211. .modal-buttons {
  212. display: flex;
  213. justify-content: space-between;
  214. margin-top: 20px;
  215. gap: 10px;
  216. }
  217. </style>