| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- export default class DealSeoData {
- constructor({$axios, req, app, redirect, error}) {
- this.$axios = $axios
- this.req = req
- this.app = app
- this.redirect = redirect
- this.error = error
- this.consultDetail= {}
- this.from = ''
- this.isExist = true
- }
- async dealData() {
- let {
- name,
- path,
- params,
- fullPath,
- query
- } = this.app.context.route
- const uid = params.id || ''
- const saleId = query.saleId || ''
- const act = query.act || ''
- this.from = query.from || ''
- // 重定向
- if (path.indexOf('/frontend/consult/user') > -1) {
- this.redirect(301, '/c/' + uid)
- }
- const consultDetail = await this._getConsultDetail(uid, saleId)
- this.consultDetail = consultDetail
- const skillList = await this._getSkillList(uid)
- return {
- isExist: this.isExist,
- uid,
- consultDetail,
- skillList,
- mobile: this.app.$deviceType.isMobile(),
- head: this.dealThisMeta(),
- act
- }
- }
- /** 获取咨询服务详情 */
- async _getConsultDetail (uid, sale_id = '') {
- const data = { uid }
- // 预览时仅展示一条咨询
- if (sale_id) {
- data.sale_id = sale_id
- }
- let res = await this.$axios.$post('/api/sale/uInfo', data)
- let consultDetail = {}
- if (Number(res.status) === 1) {
- consultDetail = res.data
- consultDetail.sale_list.forEach((item) => {
- item.expand = false
- item.loading = false
- if (item.content.length > 180 || (item.img_array.length && item.img_array[0])) {
- item.showExpand = true
- } else {
- item.showExpand = false
- }
- // 产品指定默认展开的咨询服务
- const defaultExpandConsult = ['33', '1009']
- if (defaultExpandConsult.indexOf(item.sale_id) > -1 && this.from == 'example') {
- item.expand = true
- }
- // 可预约的时间数组
- item.orderTime = []
- if (sale_id) {
- // 预览某一条咨询服务时,不显示展开,默认展开状态
- item.expand = true
- item.showExpand = false
- }
- })
- let zxRating = consultDetail.user.zx_rating || ''
- let zxRatingText = ''
- if (zxRating >= 0.8) {
- zxRatingText = '高'
- } else if (zxRating >= 0.6) {
- zxRatingText = '较高'
- } else if (zxRating >= 0.4) {
- zxRatingText = '中'
- } else if (zxRating >= 0.2) {
- zxRatingText = '较低'
- } else {
- zxRatingText = '低'
- }
- consultDetail.user.zxRatingText = zxRatingText
- consultDetail.user.zxRatingPercent = `${parseInt(zxRating * 100)}%`
- // 所有状态:0未咨询1待接单2进行中3已完成4待结薪5已拒绝6已结薪7退款中8已退款9卖方点击完成
- let saleOrderStatus = consultDetail.sale_order_status || 0
- if (saleOrderStatus == 0 || saleOrderStatus == 3 || saleOrderStatus == 4 || saleOrderStatus == 5 ||
- saleOrderStatus == 6 || saleOrderStatus == 7 || saleOrderStatus == 8) {
- // 未付款
- consultDetail.stepIndex = 1
- } else if (saleOrderStatus == 1) {
- // 待接单
- consultDetail.stepIndex = 2
- } else if (saleOrderStatus == 2) {
- // 咨询中
- consultDetail.stepIndex = 3
- } else if (saleOrderStatus == 9) {
- // 订单结束
- consultDetail.stepIndex = 4
- }
- } else if (Number(res.status) === 40001) {
- this.isExist = false
- }
- return consultDetail
- }
- /** 获取技能服务列表 */
- async _getSkillList (uid) {
- const data = {
- type: 1,
- page: 1,
- page_size: 10,
- status: 2,
- owner_type: 3,
- form_uid: uid
- }
- let skillList = []
- let res = await this.$axios.$post('/api/sale/saleList', data)
- if (Number(res.status) === 1) {
- let list = res.data.list || []
- list.forEach((item) => {
- let imageList = item.image.split(',')
- item.coverImage = imageList[0] || ''
- imageList.splice(0, 1)
- item.imageList = imageList
- })
- skillList = list
- }
- return skillList
- }
- dealThisMeta() {
- let title = ''
- let descriptionTitle = ''
- let description = ''
- let canonical = ''
- if (!this.isExist) {
- // 页面不存在时
- return {
- title: "页面不存在-程序员客栈",
- keyword: "",
- description: "",
- h1: "",
- canonical: "",
- metaLocation: ""
- }
- }
- const nickname = this.consultDetail.user.nickname
- this.consultDetail.sale_list.forEach((item, index) => {
- if (index === 0) {
- title = item.title.trim()
- description = item.content.trim()
- }
- // if (index !== this.consultDetail.sale_list.length - 1) {
- // description += `${item.title}、`
- // } else {
- // description += item.title
- // }
- })
- if (description.length > 15) {
- description = description.substring(0, 15)
- }
- if (title.length > 15) {
- descriptionTitle = title.substring(0, 15)
- } else {
- descriptionTitle = title
- }
- if (this.req) {
- const { headers: { host }, url } = this.req
- //拼接canonical
- if (host.indexOf('local') !== -1) {
- canonical = 'http://' + host + url
- } else {
- canonical = 'https://' + host + url
- }
- }
- let head = {
- title: `${title}-程序员客栈咨询服务`,
- keyword: `${this.consultDetail.user.company},${this.consultDetail.user.direction_name},${title}`,
- description: `${nickname}可以为您提供:${descriptionTitle},程序员客栈邀请到国内外互联网名企资深工作者,为您提供1对1技术咨询服务。`,
- h1: "",
- canonical: canonical,
- metaLocation: ""
- }
- return head
- }
- }
|