check-order.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <view class="container">
  3. <view class="book-list">
  4. <book-item v-for="(book, index) in bookList" :key="index" :book="book" @remove="removeBook" />
  5. </view>
  6. <!-- 底部信息和按钮 -->
  7. <view class="footer fixed-bottom flex-d" style="padding-top:10rpx">
  8. <text class="pad-10" v-if="bookList.length > 0">共 <text style="color: #ff0000;">{{ totalBooks }}</text>
  9. 本,预估回收价 <text style="color: #ff0000;">¥{{ totalPrice }}</text></text>
  10. <view class="flex-a mt-12">
  11. <u-button size="large" type="primary" text="提交" @click="handleSubmit" />
  12. <u-button size="large" type="warning" text="扫码" @click="handleScan" />
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script setup>
  18. import { ref, computed } from 'vue';
  19. import { onLoad } from '@dcloudio/uni-app';
  20. import BookItem from '../components/BookItemOrder.vue';
  21. const bookList = ref([]);
  22. const totalBooks = computed(() => bookList.value.length);
  23. const totalPrice = computed(() => bookList.value.reduce((sum, book) => sum + parseFloat(book.auditPrice), 0).toFixed(2));
  24. const removeBook = ({ book, index }) => {
  25. bookList.value.splice(index, 1);
  26. };
  27. const handleSubmit = () => {
  28. if (bookList.value.length === 0) {
  29. uni.$u.toast('请先添加书籍');
  30. return;
  31. }
  32. uni.$u.http.post('/app/offlineorder/submitOfflineOrder', bookList.value).then(res => {
  33. if (res.code == 200) {
  34. uni.$u.toast('提交成功');
  35. bookList.value.length = 0
  36. }
  37. });
  38. };
  39. const handleScan = () => {
  40. uni.scanCode({
  41. success: (res) => {
  42. handleBarcode(res.result);
  43. console.log('扫码结果:', res.result);
  44. // 添加新书逻辑
  45. },
  46. fail: (res) => {
  47. console.log('扫码失败:', res);
  48. uni.$u.toast('扫码失败');
  49. }
  50. });
  51. };
  52. //处理扫码数据
  53. const handleBarcode = (barcode) => {
  54. console.log('扫码结果:', barcode);
  55. // 添加新书逻辑,根据barcode查询书籍信息
  56. uni.$u.http.get(`/app/offlineorder/getBookInfo/${barcode}`).then(res => {
  57. if (res.code == 200) {
  58. res.data.quantity = 1
  59. let item = bookList.value.find(item => item.isbn === res.data.isbn)
  60. if (item) {
  61. item.quantity += 1
  62. item.auditPrice = (item.expectPrice * item.quantity).toFixed(2)
  63. return;
  64. } else {
  65. res.data.auditPrice = (res.data.expectPrice * res.data.quantity).toFixed(2)
  66. bookList.value.push(res.data);
  67. }
  68. }
  69. })
  70. }
  71. onLoad(() => {
  72. // #ifdef APP-PLUS
  73. uni.$u.useGlobalEvent((e) => {
  74. handleBarcode(e.barcode)
  75. })
  76. // #endif
  77. })
  78. </script>
  79. <style scoped>
  80. .container {
  81. display: flex;
  82. flex-direction: column;
  83. padding: 12px;
  84. box-sizing: border-box;
  85. height: 100%;
  86. .book-list {
  87. height: calc(100% - 96px);
  88. overflow: auto;
  89. }
  90. }
  91. .footer {
  92. background-color: #fff;
  93. border-top: 1px solid #eee;
  94. font-size: 32rpx;
  95. color: #999999;
  96. }
  97. </style>