expand.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import BaseModel from '../../../core/base'
  2. import tranProjectProgress from '../transform/project-progress'
  3. import tranServices from '../transform/services'
  4. import { formatMoney } from '@jy/util'
  5. class ContentExpandModel extends BaseModel {
  6. constructor(config) {
  7. super(config)
  8. }
  9. createModel() {
  10. return {
  11. projectProgress: {
  12. list: [],
  13. name: ''
  14. },
  15. services: [],
  16. recommendProjects: {
  17. list: [],
  18. more: false,
  19. total: 0,
  20. title: '超前项目',
  21. popup: {}
  22. },
  23. recommendBuyers: {
  24. list: [],
  25. more: false,
  26. total: 0,
  27. title: '',
  28. popup: {}
  29. },
  30. recommendWinners: {
  31. list: [],
  32. more: false,
  33. total: 0,
  34. title: '',
  35. popup: {}
  36. },
  37. recommendCustomers: {}
  38. }
  39. }
  40. preSortBiddingList(list) {
  41. if (Array.isArray(list)) {
  42. return list.map((r) => {
  43. return this.preSortBiddingItem(r)
  44. })
  45. } else {
  46. return []
  47. }
  48. }
  49. preSortBiddingItem(item) {
  50. let bidAmount = ''
  51. // 有中标金额取中标金额,没有取预算,预算没有置空
  52. if (item?.bidAmount) {
  53. bidAmount = formatMoney(item?.bidAmount - 0)
  54. } else if (item?.budget) {
  55. bidAmount = formatMoney(item?.budget - 0)
  56. }
  57. const area = item.area || '全国'
  58. const type = item?.type || item?.subtype
  59. const buyerclass = item.buyerClass || ''
  60. const tagList = [
  61. area,
  62. buyerclass,
  63. type,
  64. bidAmount
  65. ].filter((v) => v)
  66. return {
  67. id: item.id,
  68. title: item.title,
  69. tags: tagList,
  70. area,
  71. type,
  72. buyerclass,
  73. bidAmount,
  74. time: item.publishTime ? item.publishTime * 1000 : undefined,
  75. _o: item
  76. }
  77. }
  78. formatModel(data, isInit = false) {
  79. const result = this.createModel()
  80. // 项目进度
  81. if (data?.schedule) {
  82. result.projectProgress = tranProjectProgress(data.schedule)
  83. }
  84. // 服务推荐
  85. if (data?.services) {
  86. result.services = tranServices(data.services)
  87. }
  88. if (data?.recommend?.ahead) {
  89. result.recommendProjects = data.recommend.ahead
  90. result.recommendProjects.list = this.preSortBiddingList(result.recommendProjects.list)
  91. }
  92. if (data?.recommend?.buyer) {
  93. result.recommendBuyers = data.recommend.buyer
  94. result.recommendBuyers.list = this.preSortBiddingList(result.recommendBuyers.list)
  95. }
  96. if (data?.recommend?.winner) {
  97. result.recommendWinners = data.recommend.winner
  98. result.recommendWinners.list = this.preSortBiddingList(result.recommendWinners.list)
  99. }
  100. if (data?.customerRec) {
  101. if (Array.isArray(data?.customerRec?.customer)) {
  102. data.customerRec.customer = data.customerRec.customer.map((c) => {
  103. const arr = []
  104. if (c.area) {
  105. arr.push(c.area)
  106. }
  107. if (c.city) {
  108. arr.push(c.city)
  109. }
  110. return {
  111. ...c,
  112. totalAmountFormatted: c.totalAmount ? formatMoney(c.totalAmount) : '',
  113. areaCity: arr.length >= 1 ? arr.filter(a => !!a).join(' ') : ''
  114. }
  115. })
  116. }
  117. result.recommendCustomers = data.customerRec
  118. }
  119. return result
  120. }
  121. }
  122. /**
  123. * /publicapply/detail/advancedInfo
  124. * 扩展信息接口数据模型转换
  125. */
  126. function useContentExpandModel() {
  127. return new ContentExpandModel()
  128. }
  129. export default useContentExpandModel