summary2.js 10 KB

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