summary2.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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.tel = tel
  25. this.type = 'contact'
  26. }
  27. if (isFreeView) {
  28. this.isFreeView = true
  29. }
  30. }
  31. }
  32. class Unit {
  33. constructor(name, id) {
  34. this.name = name || ''
  35. this.id = id
  36. }
  37. }
  38. class Buyer extends Unit {
  39. constructor(name, id, { seoId, link }) {
  40. super(name, id)
  41. this.link = link
  42. this.type ='buyer'
  43. this.seoId = seoId || ''
  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, baseInfo)
  80. : this.tranSummaryOfDefault(abstract.default, baseInfo)
  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, baseInfo = {}) {
  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. if (summary?.buyer) {
  117. result.buyers.push(
  118. new Buyer(summary?.buyer, summary?.buyer, { seoId: baseInfo?.buyerSeoId, link: summary?.buyerPortraitShow })
  119. )
  120. }
  121. // 采购人/联系电话
  122. const buyerContactInfoValue = this.formatTel(summary?.buyerPerson, summary?.buyerTel)
  123. const buyerContactInfo = new PersonTelSummaryItem('buyerContactInfo', '采购联系人/电话', buyerContactInfoValue, summary?.buyerTel, buyerInfo)
  124. list.push(buyerContactInfo)
  125. // 招标代理机构
  126. list.push(
  127. new SummaryItem('agency', '招标代理机构', summary?.agency)
  128. )
  129. // 代理联系人
  130. const agencyContactInfoValue = this.formatTel(summary?.agencyPerson, summary?.agencyTel)
  131. const agencyContactInfo = new PersonTelSummaryItem('agencyContactInfo', '代理联系人/电话', agencyContactInfoValue, summary?.agencyTel)
  132. list.push(agencyContactInfo)
  133. // 截止日期
  134. list.push(
  135. new SummaryItem('signEndTime', '报名截止日期', this.formatTime(summary?.signEndTime))
  136. )
  137. // 投标截止日期
  138. list.push(
  139. new SummaryItem('bidEndTime', '投标截止日期', this.formatTime(summary?.bidEndTime))
  140. )
  141. // 中标单位
  142. if (Array.isArray(summary.winnerInfos) && summary.winnerInfos.length > 0) {
  143. const winnerList = []
  144. const winnerSummaryList = []
  145. // 列表中是否有中标候选人
  146. let hasWaitWinner = false
  147. const winnerInfos = summary.winnerInfos
  148. let circularList = []
  149. const waitWinnerList = winnerInfos.filter((w) => w.isCandidate)
  150. if (Array.isArray(waitWinnerList) && waitWinnerList.length > 0) {
  151. // 有中标候选人,则循环中标候选人
  152. hasWaitWinner = true
  153. circularList = waitWinnerList.slice(0, 1)
  154. } else {
  155. // 无中标候选人,则循环原始数据
  156. circularList = winnerInfos
  157. }
  158. for (let i = 0; i < circularList.length; i++) {
  159. const w = circularList[i]
  160. const index = i
  161. // 有中标候选人,则“中标单位”文案修改为”中标候选人“,仅展示排名第1的中标候选人,其他候选人不展示;
  162. const labelText = hasWaitWinner ? '中标候选人' : '中标单位';
  163. const summaryWinner = new SummaryItem('winner', labelText, w.winner)
  164. // 是否可跳转
  165. summaryWinner.addKey('link', !!w.winnerId)
  166. summaryWinner.addKey('id', w.winnerId)
  167. const wContactInfoValue = this.formatTel(w?.winnerPerson, w?.winnerTel)
  168. const winnerContactInfo = new PersonTelSummaryItem(`winnerContactInfo-${index}`, '中标联系人/电话', wContactInfoValue, w?.winnerTel, summaryWinner)
  169. list.push(summaryWinner)
  170. list.push(winnerContactInfo)
  171. let seoId = ''
  172. if (summary?.winnerSeoId) {
  173. seoId = summary?.winnerSeoId[w.winner]
  174. }
  175. winnerList.push(
  176. new Winner(w.winner, w.winnerId, {
  177. seoId: seoId || '',
  178. link: !!w.winnerId,
  179. winnerPerson: w.winnerPerson || '',
  180. winnerTel: w.winnerTel || '',
  181. isCandidate: w.isCandidate || false,
  182. personTel: winnerContactInfo
  183. })
  184. )
  185. }
  186. result.winners = winnerList
  187. }
  188. // 中标金额
  189. const bidAmountFormat = summary?.bidAmount ? this.formatMoney(summary?.bidAmount) : ''
  190. this.formatMoney()
  191. list.push(
  192. new SummaryItem('bidAmount', '中标金额(元)', bidAmountFormat)
  193. )
  194. result.list = list.filter((s) => !!s.value)
  195. result.originMap = summary
  196. result._s = summary
  197. return result
  198. }
  199. tranSummaryOfProposed(summary, baseInfo = {}) {
  200. const result = this.createModel()
  201. if (!summary) {
  202. return result
  203. }
  204. const list = []
  205. const summaryMap = {
  206. projectName: '项目名称',
  207. area: '省份',
  208. buyer: '业主单位',
  209. buyerClass: '业主类型',
  210. totalInvestment: '总投资',
  211. projectPeriod: '建设年限',
  212. address: '建设地点',
  213. approveDept: '审批机关',
  214. approveContent: '审批事项',
  215. approveCode: '审批代码',
  216. approvalNumber: '批准文号',
  217. approveTime: '审批时间',
  218. approveStatus: '审批结果',
  219. content: '建设内容'
  220. }
  221. for (const key in summaryMap) {
  222. const label = summaryMap[key]
  223. let s = null
  224. if (key === 'buyerClass') {
  225. s = new SummaryItem(key, label, summary?.buyerClass === '其它' ? '' : summary?.buyerClass)
  226. } else if (key === 'totalInvestment') {
  227. s = new SummaryItem(key, label, formatMoney(summary[key]))
  228. } else {
  229. s = new SummaryItem(key, label, summary[key] || '')
  230. }
  231. if (key === 'buyer') {
  232. s.addKey('link', summary?.buyerPortraitShow) // 是否可进行跳转
  233. if (summary?.buyer) {
  234. result.buyers.push(
  235. new Buyer(summary?.buyer, summary?.buyer, { seoId: baseInfo?.buyerSeoId, link: summary?.buyerPortraitShow })
  236. )
  237. }
  238. } else if (key === 'address') {
  239. s.addKey('row', true)
  240. } else if (key === 'content') {
  241. s.addKey('row', true)
  242. }
  243. if (s) {
  244. list.push(s)
  245. }
  246. }
  247. result.list = list
  248. result.originMap = summary
  249. return result
  250. }
  251. }
  252. function useSummaryModel() {
  253. return new SummaryModel()
  254. }
  255. export default useSummaryModel