dealSeoDetail.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. export default class DealSeoData {
  2. constructor({$axios, req, app, redirect, error}) {
  3. this.$axios = $axios
  4. this.req = req
  5. this.app = app
  6. this.redirect = redirect
  7. this.error = error
  8. this.consultDetail= {}
  9. this.from = ''
  10. this.isExist = true
  11. }
  12. async dealData() {
  13. let {
  14. name,
  15. path,
  16. params,
  17. fullPath,
  18. query
  19. } = this.app.context.route
  20. const uid = params.id || ''
  21. const saleId = query.saleId || ''
  22. const act = query.act || ''
  23. this.from = query.from || ''
  24. // 重定向
  25. if (path.indexOf('/frontend/consult/user') > -1) {
  26. this.redirect(301, '/c/' + uid)
  27. }
  28. const consultDetail = await this._getConsultDetail(uid, saleId)
  29. this.consultDetail = consultDetail
  30. const skillList = await this._getSkillList(uid)
  31. return {
  32. isExist: this.isExist,
  33. uid,
  34. consultDetail,
  35. skillList,
  36. mobile: this.app.$deviceType.isMobile(),
  37. head: this.dealThisMeta(),
  38. act
  39. }
  40. }
  41. /** 获取咨询服务详情 */
  42. async _getConsultDetail (uid, sale_id = '') {
  43. const data = { uid }
  44. // 预览时仅展示一条咨询
  45. if (sale_id) {
  46. data.sale_id = sale_id
  47. }
  48. let res = await this.$axios.$post('/api/sale/uInfo', data)
  49. let consultDetail = {}
  50. if (Number(res.status) === 1) {
  51. consultDetail = res.data
  52. consultDetail.sale_list.forEach((item) => {
  53. item.expand = false
  54. item.loading = false
  55. if (item.content.length > 180 || (item.img_array.length && item.img_array[0])) {
  56. item.showExpand = true
  57. } else {
  58. item.showExpand = false
  59. }
  60. // 产品指定默认展开的咨询服务
  61. const defaultExpandConsult = ['33', '1009']
  62. if (defaultExpandConsult.indexOf(item.sale_id) > -1 && this.from == 'example') {
  63. item.expand = true
  64. }
  65. // 可预约的时间数组
  66. item.orderTime = []
  67. if (sale_id) {
  68. // 预览某一条咨询服务时,不显示展开,默认展开状态
  69. item.expand = true
  70. item.showExpand = false
  71. }
  72. })
  73. let zxRating = consultDetail.user.zx_rating || ''
  74. let zxRatingText = ''
  75. if (zxRating >= 0.8) {
  76. zxRatingText = '高'
  77. } else if (zxRating >= 0.6) {
  78. zxRatingText = '较高'
  79. } else if (zxRating >= 0.4) {
  80. zxRatingText = '中'
  81. } else if (zxRating >= 0.2) {
  82. zxRatingText = '较低'
  83. } else {
  84. zxRatingText = '低'
  85. }
  86. consultDetail.user.zxRatingText = zxRatingText
  87. consultDetail.user.zxRatingPercent = `${parseInt(zxRating * 100)}%`
  88. // 所有状态:0未咨询1待接单2进行中3已完成4待结薪5已拒绝6已结薪7退款中8已退款9卖方点击完成
  89. let saleOrderStatus = consultDetail.sale_order_status || 0
  90. if (saleOrderStatus == 0 || saleOrderStatus == 3 || saleOrderStatus == 4 || saleOrderStatus == 5 ||
  91. saleOrderStatus == 6 || saleOrderStatus == 7 || saleOrderStatus == 8) {
  92. // 未付款
  93. consultDetail.stepIndex = 1
  94. } else if (saleOrderStatus == 1) {
  95. // 待接单
  96. consultDetail.stepIndex = 2
  97. } else if (saleOrderStatus == 2) {
  98. // 咨询中
  99. consultDetail.stepIndex = 3
  100. } else if (saleOrderStatus == 9) {
  101. // 订单结束
  102. consultDetail.stepIndex = 4
  103. }
  104. } else if (Number(res.status) === 40001) {
  105. this.isExist = false
  106. }
  107. return consultDetail
  108. }
  109. /** 获取技能服务列表 */
  110. async _getSkillList (uid) {
  111. const data = {
  112. type: 1,
  113. page: 1,
  114. page_size: 10,
  115. status: 2,
  116. owner_type: 3,
  117. form_uid: uid
  118. }
  119. let skillList = []
  120. let res = await this.$axios.$post('/api/sale/saleList', data)
  121. if (Number(res.status) === 1) {
  122. let list = res.data.list || []
  123. list.forEach((item) => {
  124. let imageList = item.image.split(',')
  125. item.coverImage = imageList[0] || ''
  126. imageList.splice(0, 1)
  127. item.imageList = imageList
  128. })
  129. skillList = list
  130. }
  131. return skillList
  132. }
  133. dealThisMeta() {
  134. let title = ''
  135. let descriptionTitle = ''
  136. let description = ''
  137. let canonical = ''
  138. if (!this.isExist) {
  139. // 页面不存在时
  140. return {
  141. title: "页面不存在-程序员客栈",
  142. keyword: "",
  143. description: "",
  144. h1: "",
  145. canonical: "",
  146. metaLocation: ""
  147. }
  148. }
  149. const nickname = this.consultDetail.user.nickname
  150. this.consultDetail.sale_list.forEach((item, index) => {
  151. if (index === 0) {
  152. title = item.title.trim()
  153. description = item.content.trim()
  154. }
  155. // if (index !== this.consultDetail.sale_list.length - 1) {
  156. // description += `${item.title}、`
  157. // } else {
  158. // description += item.title
  159. // }
  160. })
  161. if (description.length > 15) {
  162. description = description.substring(0, 15)
  163. }
  164. if (title.length > 15) {
  165. descriptionTitle = title.substring(0, 15)
  166. } else {
  167. descriptionTitle = title
  168. }
  169. if (this.req) {
  170. const { headers: { host }, url } = this.req
  171. //拼接canonical
  172. if (host.indexOf('local') !== -1) {
  173. canonical = 'http://' + host + url
  174. } else {
  175. canonical = 'https://' + host + url
  176. }
  177. }
  178. let head = {
  179. title: `${title}-程序员客栈咨询服务`,
  180. keyword: `${this.consultDetail.user.company},${this.consultDetail.user.direction_name},${title}`,
  181. description: `${nickname}可以为您提供:${descriptionTitle},程序员客栈邀请到国内外互联网名企资深工作者,为您提供1对1技术咨询服务。`,
  182. h1: "",
  183. canonical: canonical,
  184. metaLocation: ""
  185. }
  186. return head
  187. }
  188. }