batch-audit.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 } 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. let isbns = orderDetail.value.detailVoList.map((item) => item.isbn);
  71. //订单总数本
  72. if (isbns.includes(isbn)) {
  73. let book = orderDetail.value.detailVoList.find((item) => item.isbn == isbn);
  74. if (book.auditCommentList?.length > 0) {
  75. //未审核数量
  76. let notAuditNum = book.auditCommentList.filter((item) => item.sts === 0).length || 0;
  77. //已扫描书籍中当前isbn的数量
  78. let scannedNum = scannedBooks.value.filter((item) => item == isbn).length || 0;
  79. if (scannedNum >= notAuditNum) {
  80. let text = `${isbn}已超出订单中的数量`;
  81. return uni.$u.ttsModule.speak(text);
  82. } else {
  83. //扫描到套装书
  84. if (book.suit == 1) {
  85. let text = `${isbn}请注意套装书是否齐全`;
  86. uni.$u.ttsModule.speak(text);
  87. }
  88. //扫描到需要取出的书
  89. if (book.bookWarn == 1) {
  90. let text = `请注意${isbn}需要取出`;
  91. uni.$u.ttsModule.speak(text);
  92. }
  93. scannedBooks.value.push(isbn);
  94. getBookInfo(isbn);
  95. }
  96. }
  97. } else {
  98. let text = `此订单中不存在${isbn}这本书 `;
  99. uni.$u.ttsModule.speak(text);
  100. }
  101. }
  102. //扫码
  103. function handleScanCode() {
  104. uni.scanCode({
  105. success: (res) => {
  106. handleScan(res.result);
  107. },
  108. });
  109. }
  110. const checkUserId = ref();
  111. const orderId = ref();
  112. const orderDetail = ref({});
  113. const showModal = ref(false);
  114. const isQualitySelected = ref(false);
  115. const showQualityModal = () => {
  116. showModal.value = true;
  117. };
  118. const closeModal = () => {
  119. showModal.value = false;
  120. playGlobalSound()
  121. };
  122. //点击全局音效
  123. function playGlobalSound(){
  124. uni.$u.playClickSound()
  125. }
  126. const toggleQuality = () => {
  127. isQualitySelected.value = !isQualitySelected.value;
  128. };
  129. //审核 /app/orderinfo/checkOrder
  130. const handleAudit = () => {
  131. playGlobalSound()
  132. if (!isQualitySelected.value) {
  133. uni.$u.toast("请选择品相");
  134. uni.$u.ttsModule.speak("请选择品相");
  135. return;
  136. }
  137. let checkUserInfo = uni.getStorageSync("checkUserInfo");
  138. if (checkUserInfo.userId) {
  139. checkUserId.value = checkUserInfo.userId;
  140. }
  141. uni.$u.http
  142. .post("/app/orderinfo/checkOrderBatch", {
  143. checkUserId: checkUserId.value,
  144. orderId: orderId.value,
  145. checkList: scannedBooks.value.map((isbn) => ({ sts: 1, com: "", isbn })),
  146. })
  147. .then((res) => {
  148. if (res.code == 200) {
  149. uni.showToast({ title: "审核成功", icon: "none" });
  150. uni.$u.ttsModule.speak("审核成功");
  151. uni.navigateBack({ delta: 2 });
  152. } else {
  153. uni.$u.toast(res.msg);
  154. }
  155. });
  156. };
  157. onLoad((options) => {
  158. orderId.value = options.orderId;
  159. orderDetail.value = uni.getStorageSync("orderDetail");
  160. scannedBooks.value = uni.getStorageSync("scannedBooks");
  161. scannedBooks.value.forEach((isbn) => {
  162. getBookInfo(isbn);
  163. });
  164. // #ifdef APP-PLUS
  165. uni.$u.useGlobalEvent((e) => {
  166. if (e.barcode) {
  167. handleScan(e.barcode);
  168. }
  169. });
  170. // #endif
  171. });
  172. onShow(() => {
  173. uni.$u.updateActivePageOnShow();
  174. checkUserId.value = uni.getStorageSync("userInfo")?.userId;
  175. orderDetail.value = uni.getStorageSync("orderDetail");
  176. });
  177. </script>
  178. <style lang="scss" scoped>
  179. .batch-audit {
  180. padding: 20rpx;
  181. box-sizing: border-box;
  182. padding-bottom: 140rpx;
  183. }
  184. .quality-selector {
  185. display: flex;
  186. justify-content: center;
  187. align-items: center;
  188. padding: 30rpx 0;
  189. }
  190. .quality-circle {
  191. width: 120rpx;
  192. height: 120rpx;
  193. border-radius: 50%;
  194. background-color: #ccc;
  195. display: flex;
  196. justify-content: center;
  197. align-items: center;
  198. cursor: pointer;
  199. text {
  200. color: #fff;
  201. font-size: 28rpx;
  202. }
  203. &.selected {
  204. background-color: #4caf50;
  205. }
  206. }
  207. </style>