summary2.js 10 KB

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