scan-order.vue 4.7 KB

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