summary2.js 9.7 KB

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