batch-audit.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <view class="batch-audit">
  3. <BookItem
  4. v-for="(item, index) in scannedBooksDetail"
  5. :key="item.isbn"
  6. :item="item"
  7. showClose
  8. @close="(isbn) => handleClose(index, isbn)"
  9. />
  10. <view class="fixed-bottom">
  11. <u-button type="warning" size="large" @click="handleScanCode"
  12. >扫码</u-button
  13. >
  14. <u-button type="primary" size="large" @click="showQualityModal"
  15. >确定</u-button
  16. >
  17. </view>
  18. <u-modal
  19. :show="showModal"
  20. :title="'品相选择'"
  21. @cancel="closeModal"
  22. :showCancelButton="true"
  23. :closeOnClickOverlay="true"
  24. @confirm="handleAudit"
  25. >
  26. <view class="quality-selector" @click="playGlobalSound">
  27. <view
  28. class="quality-circle"
  29. :class="{ selected: isQualitySelected }"
  30. @click="toggleQuality"
  31. >
  32. <text>良好</text>
  33. </view>
  34. </view>
  35. </u-modal>
  36. </view>
  37. </template>
  38. <script setup>
  39. import { ref, onUnmounted } from "vue";
  40. import { onLoad, onShow } from "@dcloudio/uni-app";
  41. import BookItem from "./components/BookItem2.vue";
  42. const detailMap = ref({});
  43. const scannedBooksDetail = ref([]);
  44. // 获取图书详情 /app/book/getSimpleBookInfoByIsbn/{isbn}
  45. const getBookInfo = (isbn) => {
  46. if (detailMap.value[isbn]) {
  47. scannedBooksDetail.value.push(detailMap.value[isbn]);
  48. return;
  49. }
  50. uni.$u.http.get(`/app/book/getSimpleBookInfoByIsbn/${isbn}`).then((res) => {
  51. if (res.code == 200) {
  52. detailMap.value[isbn] = res.data;
  53. scannedBooksDetail.value.push(res.data);
  54. }
  55. });
  56. };
  57. const handleClose = (index, isbn) => {
  58. scannedBooksDetail.value.splice(index, 1);
  59. scannedBooks.value = scannedBooks.value.filter((item) => item != isbn);
  60. };
  61. //isbn正则校验是否符合
  62. function checkIsbn(isbn) {
  63. const isbn13Regex = /^(?:97[89]-?\d{1,5}-?\d{1,7}-?\d{1,6}-?\d)$/;
  64. if (isbn13Regex.test(isbn)) {
  65. return true;
  66. }
  67. return false;
  68. }
  69. //存储已经扫码的图书
  70. const scannedBooks = ref([]);
  71. //扫码之后的逻辑
  72. function handleScan(isbn) {
  73. if (!checkIsbn(isbn)) {
  74. let text = `不是正确的ISBN码`;
  75. uni.$u.ttsModule.speak(text);
  76. return;
  77. }
  78. //取 isbn 的后四位字符串进行播报
  79. let isbnStr = `${isbn.slice(-4)}`;
  80. let isbns = orderDetail.value.detailVoList.map((item) => item.isbn);
  81. //订单总数本
  82. if (isbns.includes(isbn)) {
  83. let book = orderDetail.value.detailVoList.find(
  84. (item) => item.isbn == isbn
  85. );
  86. if (book.auditCommentList?.length > 0) {
  87. //未审核数量
  88. let notAuditNum =
  89. book.auditCommentList.filter((item) => item.sts === 0).length ||
  90. 0;
  91. //已扫描书籍中当前isbn的数量
  92. let scannedNum =
  93. scannedBooks.value.filter((item) => item == isbn).length || 0;
  94. if (scannedNum >= notAuditNum) {
  95. let text = `${isbnStr}已超出订单中的数量`;
  96. return uni.$u.ttsModule.speak(text);
  97. } else {
  98. //扫描到套装书
  99. if (book.suit == 1) {
  100. let text = `${isbnStr}请注意套装书是否齐全`;
  101. uni.$u.ttsModule.speak(text);
  102. }
  103. //扫描到需要取出的书
  104. if (book.bookWarn == 1) {
  105. let text = `请注意${isbnStr}需要取出`;
  106. uni.$u.ttsModule.speak(text);
  107. }
  108. scannedBooks.value.push(isbn);
  109. getBookInfo(isbn);
  110. }
  111. }
  112. } else {
  113. let text = `此订单中不存在${isbnStr}这本书 `;
  114. uni.$u.ttsModule.speak(text);
  115. }
  116. }
  117. //扫码
  118. function handleScanCode() {
  119. uni.scanCode({
  120. success: (res) => {
  121. handleScan(res.result);
  122. },
  123. });
  124. }
  125. const checkUserId = ref();
  126. const orderId = ref();
  127. const orderDetail = ref({});
  128. const showModal = ref(false);
  129. const isQualitySelected = ref(false);
  130. const showQualityModal = () => {
  131. showModal.value = true;
  132. };
  133. const closeModal = () => {
  134. showModal.value = false;
  135. playGlobalSound();
  136. };
  137. //点击全局音效
  138. function playGlobalSound() {
  139. uni.$u.playClickSound();
  140. }
  141. const toggleQuality = () => {
  142. isQualitySelected.value = !isQualitySelected.value;
  143. };
  144. //审核 /app/orderinfo/checkOrder
  145. const handleAudit = () => {
  146. playGlobalSound();
  147. if (!isQualitySelected.value) {
  148. uni.$u.toast("请选择品相");
  149. uni.$u.ttsModule.speak("请选择品相");
  150. return;
  151. }
  152. let checkUserInfo = uni.getStorageSync("checkUserInfo");
  153. if (checkUserInfo.userId) {
  154. checkUserId.value = checkUserInfo.userId;
  155. }
  156. uni.$u.http
  157. .post("/app/orderinfo/checkOrderBatch", {
  158. checkUserId: checkUserId.value,
  159. orderId: orderId.value,
  160. checkList: scannedBooks.value.map((isbn) => ({
  161. sts: 1,
  162. com: "",
  163. isbn,
  164. })),
  165. })
  166. .then((res) => {
  167. if (res.code == 200) {
  168. uni.showToast({ title: "审核成功", icon: "none" });
  169. uni.$u.ttsModule.speak("审核成功");
  170. uni.navigateBack({ delta: 2 });
  171. } else {
  172. uni.$u.toast(res.msg);
  173. }
  174. });
  175. };
  176. // #ifdef APP-PLUS
  177. const { unregister, register } = uni.$u.useEventListener((e) => {
  178. if (e.barcode) {
  179. handleScan(e.barcode);
  180. }
  181. },true);
  182. // #endif
  183. onLoad((options) => {
  184. orderId.value = options.orderId;
  185. orderDetail.value = uni.getStorageSync("orderDetail");
  186. if (options.isbn) {
  187. scannedBooks.value = [options.isbn];
  188. if (options.isbn2) {
  189. scannedBooks.value.push(options.isbn2);
  190. }
  191. scannedBooks.value.forEach((isbn) => {
  192. getBookInfo(isbn);
  193. });
  194. }
  195. });
  196. onShow(() => {
  197. checkUserId.value = uni.getStorageSync("userInfo")?.userId;
  198. orderDetail.value = uni.getStorageSync("orderDetail");
  199. register();
  200. });
  201. onUnmounted(() => {
  202. // #ifdef APP-PLUS
  203. unregister();
  204. // #endif
  205. });
  206. </script>
  207. <style lang="scss" scoped>
  208. .batch-audit {
  209. padding: 20rpx;
  210. box-sizing: border-box;
  211. padding-bottom: 140rpx;
  212. }
  213. .quality-selector {
  214. display: flex;
  215. justify-content: center;
  216. align-items: center;
  217. padding: 30rpx 0;
  218. }
  219. .quality-circle {
  220. width: 120rpx;
  221. height: 120rpx;
  222. border-radius: 50%;
  223. background-color: #ccc;
  224. display: flex;
  225. justify-content: center;
  226. align-items: center;
  227. cursor: pointer;
  228. text {
  229. color: #fff;
  230. font-size: 28rpx;
  231. }
  232. &.selected {
  233. background-color: #4caf50;
  234. }
  235. }
  236. </style>