西藏巴青项目

livestockResourceDetail.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /** 畜牧资源详情展示辅助(对接 GET /app/livestockResource/{id}?type=1|2) */
  2. const CONSULT_MODE_KEYS = {
  3. 1: 'consultMode1',
  4. 2: 'consultMode2',
  5. 3: 'consultMode3'
  6. }
  7. const ORG_LEVEL_KEYS = {
  8. 1: 'orgLevel1',
  9. 2: 'orgLevel2'
  10. }
  11. function isEmpty(val) {
  12. if (val == null) return true
  13. if (typeof val === 'string') return val.trim() === ''
  14. if (Array.isArray(val)) return !val.length
  15. return false
  16. }
  17. function pickText(val) {
  18. if (val == null) return ''
  19. return String(val).trim()
  20. }
  21. export function formatPublishTime(val) {
  22. const s = pickText(val)
  23. if (!s) return ''
  24. return s.length >= 10 ? s.slice(0, 10) : s
  25. }
  26. export function formatWeekdays(raw, list, t) {
  27. let days = []
  28. if (Array.isArray(list) && list.length) {
  29. days = list.map((n) => parseInt(n, 10)).filter((n) => n >= 1 && n <= 7)
  30. } else if (!isEmpty(raw)) {
  31. days = String(raw)
  32. .split(',')
  33. .map((s) => parseInt(s.trim(), 10))
  34. .filter((n) => n >= 1 && n <= 7)
  35. }
  36. if (!days.length) return ''
  37. return days.map((n) => t(`livestockResourceDetailPage.weekday.${n}`)).join('、')
  38. }
  39. export function formatConsultModes(raw, list, t) {
  40. let modes = []
  41. if (Array.isArray(list) && list.length) {
  42. modes = list.map((n) => parseInt(n, 10))
  43. } else if (!isEmpty(raw)) {
  44. modes = String(raw)
  45. .split(',')
  46. .map((s) => parseInt(s.trim(), 10))
  47. .filter((n) => n >= 1 && n <= 3)
  48. }
  49. if (!modes.length) return ''
  50. return modes
  51. .map((n) => {
  52. const key = CONSULT_MODE_KEYS[n]
  53. return key ? t(`livestockResourceDetailPage.${key}`) : String(n)
  54. })
  55. .join('、')
  56. }
  57. function formatMoney(val) {
  58. if (val == null || val === '') return ''
  59. const n = Number(val)
  60. if (Number.isNaN(n)) return pickText(val)
  61. return n.toLocaleString('zh-CN', { minimumFractionDigits: 0, maximumFractionDigits: 2 })
  62. }
  63. function formatServiceHours(start, end) {
  64. const s = pickText(start)
  65. const e = pickText(end)
  66. if (s && e) return `${s} - ${e}`
  67. return s || e || ''
  68. }
  69. function pushRow(rows, label, value) {
  70. const v = pickText(value)
  71. if (!v) return
  72. rows.push({ label, value: v })
  73. }
  74. /**
  75. * @param {object} d 详情 data
  76. * @param {number} sourceType 1 医疗 / 2 科技
  77. * @param {(key:string)=>string} t i18n
  78. */
  79. export function buildLivestockDetailRows(d, sourceType, t) {
  80. if (!d) return []
  81. const rows = []
  82. const rt = pickText(d.resourceType)
  83. const prefix = 'livestockResourceDetailPage'
  84. if (sourceType === 1) {
  85. pushRow(rows, t(`${prefix}.affiliatedUnit`), d.affiliatedUnit)
  86. pushRow(rows, t(`${prefix}.detailAddress`), d.detailAddress)
  87. pushRow(rows, t(`${prefix}.contactPhone`), d.contactPhone)
  88. pushRow(rows, t(`${prefix}.personInCharge`), d.personInCharge)
  89. pushRow(rows, t(`${prefix}.teamSize`), d.teamSize != null ? String(d.teamSize) : '')
  90. pushRow(rows, t(`${prefix}.teamMembers`), d.teamMembers)
  91. if (d.establishDate) {
  92. pushRow(rows, t(`${prefix}.establishDate`), formatPublishTime(d.establishDate))
  93. }
  94. pushRow(rows, t(`${prefix}.serviceArea`), d.serviceArea)
  95. pushRow(rows, t(`${prefix}.consultModes`), formatConsultModes(d.consultModes, d.consultModesList, t))
  96. if (d.feeStandard != null && d.feeStandard !== '') {
  97. pushRow(rows, t(`${prefix}.feeStandard`), `${formatMoney(d.feeStandard)} ${t(`${prefix}.feeUnit`)}`)
  98. }
  99. pushRow(rows, t(`${prefix}.serviceHours`), formatServiceHours(d.serviceStartTime, d.serviceEndTime))
  100. pushRow(rows, t(`${prefix}.serviceWeekdays`), formatWeekdays(d.serviceWeekdays, d.serviceWeekdaysList, t))
  101. if (d.orgLevel != null && ORG_LEVEL_KEYS[d.orgLevel]) {
  102. pushRow(rows, t(`${prefix}.orgLevel`), t(`${prefix}.${ORG_LEVEL_KEYS[d.orgLevel]}`))
  103. }
  104. pushRow(rows, t(`${prefix}.equipmentModel`), d.equipmentModel)
  105. return rows
  106. }
  107. pushRow(rows, t(`${prefix}.affiliatedUnit`), d.affiliatedUnit)
  108. pushRow(rows, t(`${prefix}.completionUnit`), d.completionUnit)
  109. pushRow(rows, t(`${prefix}.contactPhone`), d.contactPhone)
  110. pushRow(rows, t(`${prefix}.personInCharge`), d.personInCharge)
  111. pushRow(rows, t(`${prefix}.detailAddress`), d.detailAddress)
  112. pushRow(rows, t(`${prefix}.serviceArea`), d.serviceArea)
  113. if (rt === '004006') {
  114. pushRow(rows, t(`${prefix}.achievementSummary`), d.achievementSummary)
  115. pushRow(rows, t(`${prefix}.keyTechPrinciple`), d.keyTechPrinciple)
  116. pushRow(rows, t(`${prefix}.techAdvantage`), d.techAdvantage)
  117. pushRow(rows, t(`${prefix}.researchDirection`), d.researchDirection)
  118. }
  119. if (rt === '004007') {
  120. pushRow(rows, t(`${prefix}.instrumentModel`), d.instrumentModel)
  121. pushRow(rows, t(`${prefix}.storageLocation`), d.storageLocation)
  122. pushRow(rows, t(`${prefix}.reservationProcess`), d.reservationProcess)
  123. if (d.borrowFee != null && d.borrowFee !== '') {
  124. pushRow(rows, t(`${prefix}.borrowFee`), `${formatMoney(d.borrowFee)} ${t(`${prefix}.feeUnit`)}`)
  125. }
  126. if (d.feeStandard != null && d.feeStandard !== '') {
  127. pushRow(rows, t(`${prefix}.feeStandard`), `${formatMoney(d.feeStandard)} ${t(`${prefix}.feeUnit`)}`)
  128. }
  129. pushRow(rows, t(`${prefix}.serviceHours`), formatServiceHours(d.serviceStartTime, d.serviceEndTime))
  130. pushRow(rows, t(`${prefix}.serviceWeekdays`), formatWeekdays(d.serviceWeekdays, d.serviceWeekdaysList, t))
  131. }
  132. if (rt === '004008') {
  133. pushRow(rows, t(`${prefix}.courseTopic`), d.courseTopic)
  134. }
  135. return rows
  136. }
  137. export function resolveDetailCover(d, sourceType) {
  138. if (!d) return ''
  139. if (sourceType === 1) {
  140. return pickText(d.photoFileUrl)
  141. }
  142. return pickText(d.coverFileUrl) || pickText(d.photoFileUrl)
  143. }
  144. export function resolveDetailVideo(d) {
  145. return pickText(d && d.videoFileUrl)
  146. }