summary2.js 7.5 KB

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