check-order.vue 3.3 KB

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