articleDetail.js 3.14 KB
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
//articleDetail.js 文章详情
// 网络请求工具类
var networkUtil = require('../../utils/network_util.js')
var api = require('../../utils/apiFile.js')
var util = require('../../utils/util.js')
var event = require('../../utils/event.js')

var category = ''
var articleId = ''
var categoryIndex = ''
var articleIdIndex = ''

Page({
data: {
articleDetail: '',
category:'',
pageType:'1' // 1是文章 2是高危
},
/*---------生命周期--------*/
onLoad: function (options) {
// 记录上层传递的信息
category = options.category
articleId = options.id
categoryIndex = options.categoryIndex
articleIdIndex = options.artIndex
wx.setNavigationBarTitle({
title: options.category || '文章详情',
success: function(res) {
}
})
networkUtil.showLoading()
if(category == '健康评级') {
this.requestRiskData(options.id)
} else {
this.requestData(options.id)
}
if (options.doctorId){
this.requestDoctor(options.hospitalId, options.doctorId)
this.setData({showDoc:true})
}
},
/*---------自定义函数--------*/
requestData(articleId){
var self = this
var imgH = wx.getSystemInfoSync().windowHeight * 0.33
networkUtil._get(api.article + '/' + articleId,{},function(res){
console.log(res)
// res.data.content = util.convertHtmlToText(res.data.content)
res.data.imgH = imgH
self.setData({
articleDetail : res.data,
category : category
})
},function(res){

})
},
// 点赞
articleLike(){
var self = this
// 已经点赞
if(self.data.articleDetail.isLike == 1){
networkUtil.showErrorToast('您已经点过赞啦')
return;
}
networkUtil._post(api.articleLike,{id:articleId},function(res){
console.log(res)
var art = self.data.articleDetail
art.likeCount ++
art.isLike = 1
self.setData({
articleDetail : art
})
if(categoryIndex){
// 更新首页数据
event.emit('likeChanged', {categoryIndex:categoryIndex,articleIdIndex:articleIdIndex});
} else {
event.emit('listLikeChanged', {categoryIndex:categoryIndex,articleIdIndex:articleIdIndex});
}
},function(res){
console.log(res)
})
},
// 高危详情页面
requestRiskData(articleId){
var self = this
networkUtil._get(api.riskDetails,{id:articleId},function(res){
console.log(res)
// res.data.content = util.convertHtmlToText(res.data.desc)
res.data.imgH = '0px'
self.setData({
articleDetail : res.data,
category : category,
pageType : '2'
})
},function(res){

})
},
/*---------自定义函数--------*/
requestDoctor(hospitalId, doctorId) {
var self = this
networkUtil._get(api.doctorInfo, { hospitalId: hospitalId, id: doctorId, }, function (res) {
self.setData({
doctorInfo: res.data.doctorObj,
hospitalName: res.data.hospitalName,
deptName: res.data.deptName,
doctorLevel: res.data.doctorLevel,
hxName: res.data.hxName
})
console.log(res)
}, function (res) {

})
},
})