ContentAbstractEntList.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <section class="abstract-ent-list bg-white">
  3. <AbstractEnt
  4. class="abstract-ent-item"
  5. v-for="(ent, index) in entDetailList"
  6. v-show="ent.show"
  7. :entType="ent.type"
  8. :title="ent.name"
  9. :key="index"
  10. :isLink="ent.link"
  11. :contactCount="ent?.detail?.contactCount || 0"
  12. :cooperateCount="ent?.detail?.cooperate || 0"
  13. @click="toDetail(ent)"
  14. ></AbstractEnt>
  15. </section>
  16. </template>
  17. <script>
  18. import AbstractEnt from '@/views/article/components/AbstractEnt.vue'
  19. import { mapState } from 'vuex'
  20. import { LINKS } from '@/data'
  21. import { openAppOrWxPage } from '@/utils/'
  22. import { ajaxGetMiniEntInfo } from '@/api/modules'
  23. export default {
  24. name: 'ContentAbstractEntList',
  25. components: {
  26. AbstractEnt
  27. },
  28. props: {
  29. beforeLeavePage: Function
  30. },
  31. data() {
  32. return {
  33. req: {}
  34. }
  35. },
  36. computed: {
  37. ...mapState({
  38. summary: (state) => state.article.mainModel.summary
  39. }),
  40. entList() {
  41. const { winners, buyers } = this.summary
  42. let winners3 = []
  43. if (Array.isArray(winners) && winners.length > 3) {
  44. winners3 = winners.slice(0, 3)
  45. } else {
  46. winners3 = winners
  47. }
  48. return buyers.concat(winners3).filter((b) => b.link)
  49. },
  50. entDetailList() {
  51. return this.entList.map((e) => {
  52. const detail = this.req[e.id] || {}
  53. return {
  54. ...e,
  55. show: this.calcEntShow(detail),
  56. detail
  57. }
  58. })
  59. }
  60. },
  61. watch: {
  62. entList: {
  63. immediate: true,
  64. handler(eList) {
  65. if (Array.isArray(eList) && eList.length > 0) {
  66. eList.forEach((ent) => {
  67. this.getEntInfo(ent.type, ent.id)
  68. })
  69. }
  70. }
  71. }
  72. },
  73. methods: {
  74. calcEntShow(item = {}) {
  75. const contactCount = item.contactCount || 0
  76. const cooperate = item.cooperate || 0
  77. return contactCount || cooperate
  78. },
  79. async getEntInfo(type, id) {
  80. const { data, error_code: code } = await ajaxGetMiniEntInfo(type, id)
  81. if (code === 0 && data) {
  82. data._type = type
  83. this.$set(this.req, id, data)
  84. }
  85. },
  86. toDetail(ent) {
  87. if (!ent.link) {
  88. return
  89. }
  90. if (ent.type === 'buyer') {
  91. this.goToBuyerPortrait(ent)
  92. } else {
  93. this.goToEntPortrait(ent)
  94. }
  95. },
  96. async goToBuyerPortrait(item) {
  97. if (!item.link) {
  98. return
  99. }
  100. if (this.beforeLeavePage) {
  101. await this.beforeLeavePage()
  102. }
  103. openAppOrWxPage(LINKS.大会员超级订阅采购单位画像页面, {
  104. query: {
  105. entName: item.id
  106. }
  107. })
  108. },
  109. async goToEntPortrait(winner) {
  110. if (!winner.id) {
  111. return
  112. }
  113. if (this.beforeLeavePage) {
  114. await this.beforeLeavePage()
  115. }
  116. openAppOrWxPage(LINKS.企业画像页面, {
  117. query: {
  118. eId: winner.id
  119. }
  120. })
  121. }
  122. }
  123. }
  124. </script>
  125. <style lang="scss" scoped>
  126. .abstract-ent-list {
  127. border-top: 0.5px solid rgba(0, 0, 0, 0.05);
  128. padding: 12px 12px 8px;
  129. .abstract-ent-item {
  130. background: #fafafa;
  131. border-radius: 8px;
  132. border: 0.5px solid rgba(0, 0, 0, 0.05);
  133. }
  134. .abstract-ent-item:not(:last-of-type) {
  135. margin-bottom: 8px;
  136. }
  137. }
  138. </style>