batch-audit.vue 6.5 KB

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