detail.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <div class="w-full h-full">
  3. <van-tabs v-model:active="tabActive" :swipe-threshold="3">
  4. <van-tab title="销售订单信息" name="销售订单信息">
  5. <OrderInfo :info="infoData" />
  6. </van-tab>
  7. <van-tab title="相关任务" name="相关任务">
  8. <RelatedTasks :infoList="relatedTasksList" />
  9. </van-tab>
  10. <van-tab title="相关产品" name="相关产品">
  11. <RelatedProducts :infoList="relatedProductsList" />
  12. </van-tab>
  13. <van-tab title="回款" name="回款">
  14. <PaymentCollection :info="infoData" @changePaymentCollection="changePaymentCollection" />
  15. </van-tab>
  16. </van-tabs>
  17. </div>
  18. </template>
  19. <script setup>
  20. import { ref, onActivated, watch } from 'vue';
  21. import { useLifecycle } from '@hooks/useCommon.js';
  22. import { GET_ORDER_RELATED_TASKS, OBTAIN_ORDER_RELATED_PRODUCTS, SALES_ORDER_DETAILS } from "@hooks/useApi"
  23. import requests from "@common/requests";
  24. import OrderInfo from './orderInfo.vue';
  25. import RelatedTasks from '../tasks/relatedTasks.vue';
  26. import RelatedProducts from '../product/relatedProducts.vue';
  27. import PaymentCollection from './paymentCollection.vue';
  28. import useShowToast from '@hooks/useToast'
  29. const { toastSuccess, toastLoading, toastFail, toastText, clearToast } = useShowToast()
  30. const props = defineProps({
  31. info: {
  32. type: Object,
  33. required: true,
  34. default: () => ({})
  35. }
  36. })
  37. const tabActive = ref('销售订单信息');
  38. const relatedTasksList = ref([]);
  39. const relatedProductsList = ref([]);
  40. const infoData = ref(props.info);
  41. const timeout = ref(null);
  42. watch(() => props.info, (newValue) => {
  43. tabActive.value = '销售订单信息';
  44. processingData(newValue.id)
  45. })
  46. function getDetailedData(id) {
  47. requests.post(SALES_ORDER_DETAILS, { id }).then(({ data }) => {
  48. infoData.value = data || []
  49. })
  50. requests.post(GET_ORDER_RELATED_TASKS, { id }).then(({ data }) => {
  51. relatedTasksList.value = data || []
  52. })
  53. requests.post(OBTAIN_ORDER_RELATED_PRODUCTS, { id }).then(({ data }) => {
  54. const list = (data || []).map((item) => {
  55. const { id, productName, productCode, unit, unitName, typeName, type, price, inventory, orderProductDetail } = item
  56. return {
  57. id, productId: id, productName, productCode, unit, unitName, typeName, type, price, inventory,
  58. productType: typeName,
  59. quantity: +orderProductDetail?.num,
  60. discount: +orderProductDetail?.discount,
  61. sellingPrice: +orderProductDetail?.sealPrice,
  62. totalPrice: +orderProductDetail?.totalPrice
  63. }
  64. })
  65. relatedProductsList.value = list
  66. }).finally(() => {
  67. setTimeout(() => {
  68. clearToast()
  69. }, 200)
  70. })
  71. }
  72. function changePaymentCollection(id) {
  73. getDetailedData(id)
  74. }
  75. function processingData(id) {
  76. clearTimeout(timeout.value);
  77. toastLoading('加载中...', 0)
  78. timeout.value = setTimeout(() => {
  79. getDetailedData(id)
  80. }, 100);
  81. }
  82. useLifecycle({
  83. init: () => {
  84. tabActive.value = '销售订单信息';
  85. processingData(props.info.id)
  86. },
  87. load: () => {
  88. tabActive.value = '销售订单信息';
  89. processingData(props.info.id)
  90. },
  91. unload: () => {
  92. clearTimeout(timeout.value)
  93. }
  94. });
  95. </script>
  96. <style lang='scss' scoped>
  97. /* 样式代码 */
  98. </style>