scan-order.vue 5.5 KB

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