scan-order.vue 5.6 KB

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