summary2.js 8.0 KB

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