summary2.js 7.6 KB

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