summary2.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import BaseModel from '../../../core/base'
  2. import { dateFormatter, formatMoney, splitMoney } from '@jy/util'
  3. /**
  4. * 摘要 Item 基础类
  5. */
  6. class SummaryItem {
  7. constructor(key, label, value) {
  8. this.key = key
  9. this.label = label
  10. this.value = value || '' // 如果为空,默认值则改为'-'
  11. }
  12. addKey(key, value) {
  13. this[key] = value
  14. }
  15. }
  16. // 联系人类
  17. class PersonTelSummaryItem extends SummaryItem {
  18. constructor(key, label, value, tel, expand) {
  19. const isFreeView = value === 'freeView'
  20. const value2 = isFreeView ? '点击查看' : value
  21. super(key, label, value2)
  22. this.expand = expand
  23. if (tel) {
  24. this.showMore = true
  25. this.tel = tel
  26. this.type = 'contact'
  27. }
  28. if (isFreeView) {
  29. this.isFreeView = true
  30. }
  31. }
  32. }
  33. class Unit {
  34. constructor(name, id) {
  35. this.name = name || ''
  36. this.id = id
  37. }
  38. }
  39. class Buyer extends Unit {
  40. constructor(name, id, { link }) {
  41. super(name, id)
  42. this.link = link
  43. this.type ='buyer'
  44. }
  45. }
  46. class Winner extends Unit {
  47. constructor(name, id, { seoId, winnerPerson, winnerTel, link, isCandidate, personTel }) {
  48. super(name, id)
  49. this.type ='winner'
  50. this.seoId = seoId || ''
  51. this.winnerPerson = winnerPerson || ''
  52. this.winnerTel = winnerTel || ''
  53. this.isCandidate = isCandidate
  54. this.personTel = personTel
  55. this.link = link
  56. }
  57. }
  58. class SummaryModel extends BaseModel {
  59. constructor(config) {
  60. super(config)
  61. }
  62. createModel() {
  63. return {
  64. // 是否超前项目
  65. isProposed: false,
  66. // 原始数据
  67. originMap: {},
  68. list: [],
  69. // 采购单位
  70. buyers: [],
  71. // 中标单位
  72. winners: []
  73. }
  74. }
  75. formatModel(data, isInit = false) {
  76. const { baseInfo, abstract } = data
  77. const isProposed = this.isProposedCheck(baseInfo?.subType)
  78. const model = isProposed
  79. ? this.tranSummaryOfProposed(abstract.proposed)
  80. : this.tranSummaryOfDefault(abstract.default)
  81. model.isProposed = isProposed
  82. return model
  83. }
  84. isProposedCheck(type) {
  85. return type === '拟建' || type === '采购意向'
  86. }
  87. formatTime(time) {
  88. if (time) {
  89. return dateFormatter(time * 1000, 'yyyy-MM-dd')
  90. } else {
  91. return time
  92. }
  93. }
  94. formatMoney(m) {
  95. return splitMoney(m, -1, true)
  96. }
  97. formatTel(name, tel) {
  98. if (name === 'freeView' || tel === 'freeView') {
  99. return 'freeView'
  100. } else {
  101. const arr = [name, tel]
  102. return arr.filter((item) => !!item).join(' / ')
  103. }
  104. }
  105. tranSummaryOfDefault(summary) {
  106. const result = this.createModel()
  107. if (!summary) {
  108. return result
  109. }
  110. const list = []
  111. // 采购单位
  112. const buyerInfo = new SummaryItem('buyer', '采购单位', summary?.buyer)
  113. // 是否可进行跳转
  114. buyerInfo.addKey('link', summary?.buyerPortraitShow)
  115. list.push(buyerInfo)
  116. result.buyers.push(
  117. new Buyer(summary?.buyer, summary?.buyer, { link: summary?.buyerPortraitShow })
  118. )
  119. // 采购人/联系电话
  120. const buyerContactInfoValue = this.formatTel(summary?.buyerPerson, summary?.buyerTel)
  121. const buyerContactInfo = new PersonTelSummaryItem('buyerContactInfo', '采购联系人/电话', buyerContactInfoValue, summary?.buyerTel, buyerInfo)
  122. list.push(buyerContactInfo)
  123. // 招标代理机构
  124. list.push(
  125. new SummaryItem('agency', '招标代理机构', summary?.agency)
  126. )
  127. // 代理联系人
  128. const agencyContactInfoValue = this.formatTel(summary?.agencyPerson, summary?.agencyTel)
  129. const agencyContactInfo = new PersonTelSummaryItem('agencyContactInfo', '代理联系人/电话', agencyContactInfoValue, summary?.agencyTel)
  130. list.push(agencyContactInfo)
  131. // 截止日期
  132. list.push(
  133. new SummaryItem('signEndTime', '报名截止日期', this.formatTime(summary?.signEndTime))
  134. )
  135. // 投标截止日期
  136. list.push(
  137. new SummaryItem('bidEndTime', '投标截止日期', this.formatTime(summary?.bidEndTime))
  138. )
  139. // 中标单位
  140. if (Array.isArray(summary.winnerInfos) && summary.winnerInfos.length > 0) {
  141. const winnerList = []
  142. const winnerSummaryList = []
  143. // 列表中是否有中标候选人
  144. let hasWaitWinner = false
  145. const winnerInfos = summary.winnerInfos
  146. let circularList = []
  147. const waitWinnerList = winnerInfos.filter((w) => w.isCandidate)
  148. if (Array.isArray(waitWinnerList) && waitWinnerList.length > 0) {
  149. // 有中标候选人,则循环中标候选人
  150. hasWaitWinner = true
  151. circularList = waitWinnerList.slice(0, 1)
  152. } else {
  153. // 无中标候选人,则循环原始数据
  154. circularList = winnerInfos
  155. }
  156. for (let i = 0; i < circularList.length; i++) {
  157. const w = circularList[i]
  158. const index = i
  159. // 有中标候选人,则“中标单位”文案修改为”中标候选人“,仅展示排名第1的中标候选人,其他候选人不展示;
  160. const labelText = hasWaitWinner ? '中标候选人' : '中标单位';
  161. const summaryWinner = new SummaryItem('winner', labelText, w.winner)
  162. // 是否可跳转
  163. summaryWinner.addKey('link', !!w.winnerId)
  164. summaryWinner.addKey('id', w.winnerId)
  165. const wContactInfoValue = this.formatTel(w?.winnerPerson, summary?.winnerTel)
  166. const winnerContactInfo = new PersonTelSummaryItem(`winnerContactInfo-${index}`, '中标联系人/电话', wContactInfoValue, w?.winnerTel, summaryWinner)
  167. list.push(summaryWinner)
  168. list.push(winnerContactInfo)
  169. let seoId = ''
  170. if (summary?.winnerSeoId) {
  171. seoId = summary?.winnerSeoId[w.winner]
  172. }
  173. winnerList.push(
  174. new Winner(w.winner, w.winnerId, {
  175. seoId: seoId || '',
  176. link: !!w.winnerId,
  177. winnerPerson: w.winnerPerson || '',
  178. winnerTel: w.winnerTel || '',
  179. isCandidate: w.isCandidate || false,
  180. personTel: winnerContactInfo
  181. })
  182. )
  183. }
  184. result.winners = winnerList
  185. }
  186. // 中标金额
  187. const bidAmountFormat = summary?.bidAmount ? this.formatMoney(summary?.bidAmount) : ''
  188. this.formatMoney()
  189. list.push(
  190. new SummaryItem('bidAmount', '中标金额(元)', bidAmountFormat)
  191. )
  192. result.list = list
  193. result.originMap = summary
  194. result._s = summary
  195. return result
  196. }
  197. tranSummaryOfProposed(summary) {
  198. const result = this.createModel()
  199. if (!summary) {
  200. return result
  201. }
  202. const list = []
  203. const summaryMap = {
  204. projectName: '项目名称',
  205. area: '省份',
  206. buyer: '业主单位',
  207. buyerClass: '业主类型',
  208. totalInvestment: '总投资',
  209. projectPeriod: '建设年限',
  210. address: '建设地点',
  211. approveDept: '审批机关',
  212. approveContent: '审批事项',
  213. approveCode: '审批代码',
  214. approvalNumber: '批准文号',
  215. approveTime: '审批时间',
  216. approveStatus: '审批结果',
  217. content: '建设内容'
  218. }
  219. for (const key in summaryMap) {
  220. const label = summaryMap[key]
  221. let s = null
  222. if (key === 'buyerClass') {
  223. s = new SummaryItem(key, label, summary?.buyerClass === '其它' ? '' : summary?.buyerClass)
  224. } else if (key === 'totalInvestment') {
  225. s = new SummaryItem(key, label, formatMoney(summary[key]))
  226. } else {
  227. s = new SummaryItem(key, label, summary[key] || '')
  228. }
  229. if (key === 'buyer') {
  230. s.addKey('link', summary?.buyerPortraitShow) // 是否可进行跳转
  231. if (summary?.buyer) {
  232. result.buyers.push(
  233. new Buyer(summary?.buyer, summary?.buyer, { link: summary?.buyerPortraitShow })
  234. )
  235. }
  236. } else if (key === 'address') {
  237. s.addKey('row', true)
  238. } else if (key === 'content') {
  239. s.addKey('row', true)
  240. }
  241. if (s) {
  242. list.push(s)
  243. }
  244. }
  245. result.list = list
  246. result.originMap = summary
  247. return result
  248. }
  249. }
  250. function useSummaryModel() {
  251. return new SummaryModel()
  252. }
  253. export default useSummaryModel