expand.js 3.4 KB

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