scan-order.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <view class="container">
  3. <!-- 顶部操作栏 -->
  4. <view class="header">
  5. <text>清除全部</text>
  6. </view>
  7. <!-- 提示信息 -->
  8. <view class="tips">
  9. <text>请勿录入审核为不良的书籍ISBN!</text>
  10. <text class="sub-tips">不良书籍的ISBN可能是错误的!</text>
  11. </view>
  12. <!-- ISBN列表 -->
  13. <scroll-view scroll-y class="isbn-list">
  14. <view
  15. v-for="(item, index) in isbnList"
  16. :key="index"
  17. class="isbn-item"
  18. >
  19. <view class="item-left">
  20. <u-icon
  21. name="minus-circle-fill"
  22. color="#dd524d"
  23. size="24"
  24. @click="removeItem(index)"
  25. />
  26. <text class="index">{{ index + 1 }}、</text>
  27. <text class="isbn">{{ item.isbn }}</text>
  28. </view>
  29. <view class="quantity-control">
  30. <u-button
  31. text="-"
  32. size="mini"
  33. @click="decreaseQuantity(index)"
  34. :disabled="item.quantity <= 1"
  35. />
  36. <text class="quantity">{{ item.quantity }}</text>
  37. <u-button
  38. text="+"
  39. size="mini"
  40. @click="increaseQuantity(index)"
  41. />
  42. </view>
  43. </view>
  44. </scroll-view>
  45. <!-- 底部按钮 -->
  46. <view class="footer">
  47. <u-button
  48. type="warning"
  49. text="扫码加书"
  50. @click="handleScan"
  51. />
  52. <u-button
  53. type="primary"
  54. text="查询"
  55. @click="handleQuery"
  56. />
  57. </view>
  58. </view>
  59. </template>
  60. <script setup>
  61. import { ref } from 'vue';
  62. // ISBN列表数据
  63. const isbnList = ref([
  64. { isbn: '9787050405548', quantity: 1 },
  65. { isbn: '9787050405548', quantity: 3 },
  66. { isbn: '9787050405548', quantity: 3 },
  67. { isbn: '9787050405548', quantity: 3 },
  68. { isbn: '9787050405548', quantity: 3 },
  69. { isbn: '9787050405548', quantity: 3 },
  70. { isbn: '9787050405548', quantity: 3 },
  71. { isbn: '9787050405548', quantity: 3 },
  72. { isbn: '9787050405548', quantity: 3 }
  73. ]);
  74. // 移除项目
  75. const removeItem = (index) => {
  76. isbnList.value.splice(index, 1);
  77. };
  78. // 减少数量
  79. const decreaseQuantity = (index) => {
  80. if (isbnList.value[index].quantity > 1) {
  81. isbnList.value[index].quantity--;
  82. }
  83. };
  84. // 增加数量
  85. const increaseQuantity = (index) => {
  86. isbnList.value[index].quantity++;
  87. };
  88. // 扫码处理
  89. const handleScan = () => {
  90. uni.scanCode({
  91. success: (res) => {
  92. // 验证ISBN格式
  93. if (isValidISBN(res.result)) {
  94. isbnList.value.push({
  95. isbn: res.result,
  96. quantity: 1
  97. });
  98. } else {
  99. uni.showToast({
  100. title: '无效的ISBN',
  101. icon: 'none'
  102. });
  103. }
  104. }
  105. });
  106. };
  107. // ISBN格式验证
  108. const isValidISBN = (isbn) => {
  109. // 简单的ISBN-13验证
  110. return /^97[89]\d{10}$/.test(isbn);
  111. };
  112. // 查询处理
  113. const handleQuery = () => {
  114. if (isbnList.value.length === 0) {
  115. uni.showToast({
  116. title: '请先添加ISBN',
  117. icon: 'none'
  118. });
  119. return;
  120. }
  121. console.log('查询ISBN列表:', isbnList.value);
  122. };
  123. </script>
  124. <style lang="scss" scoped>
  125. .container {
  126. min-height: 100vh;
  127. display: flex;
  128. flex-direction: column;
  129. background-color: #f5f5f5;
  130. }
  131. .header {
  132. padding: 12px;
  133. background-color: #999;
  134. color: #fff;
  135. text-align: center;
  136. }
  137. .tips {
  138. padding: 16px;
  139. background-color: #f8f8f8;
  140. text-align: center;
  141. text {
  142. display: block;
  143. color: #666;
  144. font-size: 14px;
  145. }
  146. .sub-tips {
  147. font-size: 12px;
  148. margin-top: 4px;
  149. }
  150. }
  151. .isbn-list {
  152. flex: 1;
  153. padding: 12px;
  154. }
  155. .isbn-item {
  156. display: flex;
  157. justify-content: space-between;
  158. align-items: center;
  159. padding: 12px;
  160. background-color: #fff;
  161. margin-bottom: 8px;
  162. border-radius: 4px;
  163. .item-left {
  164. display: flex;
  165. align-items: center;
  166. gap: 8px;
  167. }
  168. .index {
  169. color: #666;
  170. }
  171. .isbn {
  172. color: #333;
  173. }
  174. }
  175. .quantity-control {
  176. display: flex;
  177. align-items: center;
  178. gap: 12px;
  179. .quantity {
  180. min-width: 24px;
  181. text-align: center;
  182. }
  183. :deep(.u-button) {
  184. min-width: 32px;
  185. height: 32px;
  186. padding: 0;
  187. }
  188. }
  189. .footer {
  190. padding: 12px;
  191. display: flex;
  192. gap: 12px;
  193. background-color: #fff;
  194. .u-button {
  195. flex: 1;
  196. }
  197. }
  198. </style>