index.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. // pages/zl_detail/index.js
  2. const { request, serverName, imgServer } = require('../../utils/services');
  3. const WxParse = require('../../common/component/wxParse/wxParse.js');
  4. const { Toast, removeArrItem } = require('../../utils/util.js');
  5. const { defaultImg } = require('../../utils/images');
  6. const app = getApp();
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. logo_img: "../../imgs/logo.jpg",
  13. half_star_img: "../../imgs/icon/half.png",
  14. empty_star_img: "../../imgs/icon/empty.png",
  15. full_star_img: "../../imgs/icon/full.png",
  16. testImg: '../../imgs/testImg/thumbSmallImg2.jpg',
  17. avatar: '../../imgs/testImg/1.jpg',
  18. icon_quanping: '../../imgs/quanping.png',
  19. active: false,
  20. readActive: false,
  21. isLike: false,
  22. likeNum: 526,
  23. animationData: {},
  24. imgServer,
  25. tour_info_data: [{
  26. title: '地址:',
  27. txt: '北京市朝阳区崔各乡庄各庄村顺白马路马嘻路口100米路北'
  28. }, {
  29. title: '开放时间',
  30. txt: '周二到周日10:00-18:00 (每周一闭馆)'
  31. }, {
  32. title: '电话:',
  33. txt: '+86 10 8456654654'
  34. }]
  35. },
  36. clickCell: function () {
  37. console.log(this.data.active);
  38. this.setData({
  39. active: !this.data.active
  40. })
  41. },
  42. readMore: function () {
  43. this.setData({
  44. readActive: true
  45. })
  46. },
  47. fix_starImg: function (points) {
  48. let strPoints = String(Number(points).toFixed(2));
  49. let show_Arr = [];
  50. let ten = strPoints.split('.')[0] || 0;
  51. let unit = strPoints.split('.')[1] || 0;
  52. let surPlus = 0;
  53. if (strPoints < 0) {
  54. return
  55. }
  56. if (ten) {
  57. for (let i = 0; i < Number(ten); i++) {
  58. show_Arr.push({
  59. 'img': this.data.full_star_img
  60. })
  61. }
  62. surPlus = 5 - Number(ten);
  63. }
  64. if (unit && surPlus > 0) {
  65. let numUnit = Number(unit.substr(0, 1)) || 0
  66. if (numUnit > 0) {
  67. // let fix_unit = Math.round(numUnit);
  68. switch (true) {
  69. case numUnit > 5:
  70. show_Arr.push({
  71. 'img': this.data.full_star_img
  72. })
  73. break;
  74. case numUnit <= 5:
  75. show_Arr.push({
  76. 'img': this.data.half_star_img
  77. })
  78. break;
  79. default:
  80. break
  81. }
  82. } else if (numUnit == 0) {
  83. show_Arr.push({
  84. 'img': this.data.empty_star_img
  85. })
  86. } else {
  87. return
  88. }
  89. }
  90. if (surPlus > 0) {
  91. for (let i = 0; i < surPlus - 1; i++) {
  92. show_Arr.push({
  93. 'img': this.data.empty_star_img
  94. })
  95. }
  96. }
  97. return show_Arr
  98. },
  99. tapToCommentDetail: function () {
  100. let {
  101. exhibitionId
  102. } = this.data;
  103. wx.navigateTo({
  104. // url: `../../zl_detail/create_evaluation/index?id=${exhibitionId}`,
  105. url: `../yuezhan/comment_detail/index?id=${exhibitionId}`,
  106. success: function (res) { },
  107. fail: function (res) { },
  108. complete: function (res) { },
  109. })
  110. },
  111. addCommentLike: function (e) {
  112. let {
  113. type,
  114. id,
  115. idx
  116. } = e.currentTarget.dataset;
  117. console.log(idx, type, id)
  118. let {
  119. comments
  120. } = this.data;
  121. Toast.showToast2('loading');
  122. let loginSessionKey = wx.getStorageSync('token') || "";
  123. // if (loginSessionKey){
  124. request['commentLike']({
  125. loginSessionKey,
  126. commentId: id,
  127. type: Number(type),
  128. }, "post", res => {
  129. if (res.data.code > -1) {
  130. comments.content[idx].hasLike = res.data.data.hasLike
  131. if (res.data.data.hasLike) {
  132. comments.content[idx].likeCount += 1;
  133. } else {
  134. comments.content[idx].likeCount -= 1;
  135. }
  136. this.setData({
  137. comments: comments
  138. })
  139. }
  140. }, err => {
  141. }, complete => {
  142. Toast.hideLoading();
  143. })
  144. // }
  145. },
  146. addLike: function () {
  147. // if (this.data.isLike) {
  148. // this.setData({
  149. // isLike: !this.data.isLike,
  150. // likeNum: this.data.likeNum - 1
  151. // })
  152. // } else {
  153. // this.setData({
  154. // isLike: !this.data.isLike,
  155. // likeNum: this.data.likeNum + 1
  156. // })
  157. // }
  158. let loginSessionKey = wx.getStorageSync('token') || "";
  159. let {
  160. exhibitionId,
  161. exhibitionDetail,
  162. type: isChange
  163. } = this.data;
  164. let {
  165. collectedArr,
  166. collectedChange
  167. } = app.globalData, hasItem = true;
  168. let type = exhibitionDetail.hasCollect
  169. // if (loginSessionKey){
  170. request['isCollect']({
  171. loginSessionKey,
  172. exhibitionId: exhibitionId,
  173. type: Number(type),
  174. }, "post", res => {
  175. if (res.data.code > -1) {
  176. for (let i = 0; i < collectedArr.length; i++) {
  177. if (collectedArr[i].collectedId && exhibitionId == collectedArr[i].collectedId) {
  178. console.log("true")
  179. collectedArr[i] = {
  180. collectedId: exhibitionId,
  181. status: res.data.data.hasCollect,
  182. }
  183. hasItem = false;
  184. }
  185. }
  186. if (hasItem) {
  187. collectedArr.push({
  188. collectedId: exhibitionId,
  189. status: res.data.data.hasCollect,
  190. })
  191. }
  192. app.globalData.collectedArr = collectedArr;
  193. console.log(isChange, res.data.data.hasCollect)
  194. if (isChange == res.data.data.hasCollect) {
  195. app.globalData.collectedChange = false;
  196. } else {
  197. app.globalData.collectedChange = true;
  198. }
  199. exhibitionDetail.hasCollect = res.data.data.hasCollect
  200. if (exhibitionDetail.hasCollect) {
  201. exhibitionDetail.collectionsCount += 1;
  202. } else {
  203. exhibitionDetail.collectionsCount -= 1;
  204. }
  205. this.setData({
  206. exhibitionDetail: exhibitionDetail,
  207. })
  208. }
  209. }, err => {
  210. }, complete => {
  211. Toast.hideLoading();
  212. })
  213. // }
  214. },
  215. clickCell: function () {
  216. console.log(this.data.active);
  217. this.setData({
  218. active: !this.data.active
  219. })
  220. },
  221. navigateToLocation: function () {
  222. let { latitude, longitude, addressName } = this.data;
  223. console.log("dasdw",latitude,longitude)
  224. wx.openLocation({
  225. // exhibitionId: 0,
  226. latitude: latitude,
  227. longitude: longitude,
  228. scale: 28,
  229. name: addressName,
  230. success: function (res) {
  231. console.log('success')
  232. },
  233. fail: function (res) { },
  234. complete: function (res) { }
  235. });
  236. },
  237. tapToComement: function () {
  238. let {
  239. exhibitionId
  240. } = this.data;
  241. wx.navigateTo({
  242. url: `./create_evaluation/index?id=${exhibitionId}`,
  243. success: function (res) { },
  244. fail: function (res) { },
  245. complete: function (res) { },
  246. })
  247. },
  248. /**
  249. * 生命周期函数--监听页面加载
  250. */
  251. onLoad: function (options) {
  252. this.setData({
  253. defaultImg,
  254. exhibitionId: options.id,
  255. serverName
  256. })
  257. let { cookieIDs=[] } = app.globalData;
  258. let id = options.id;
  259. let hasItem = true;
  260. for (let i = 0; i < cookieIDs.length; i++) {
  261. if (cookieIDs[i] && id == cookieIDs[i]) {
  262. cookieIDs = removeArrItem(cookieIDs, cookieIDs[i])
  263. }
  264. }
  265. if (hasItem && id != undefined && (typeof(Number(id)) == 'number')) {
  266. cookieIDs.unshift(id)
  267. }
  268. app.globalData.cookieIDs = cookieIDs
  269. },
  270. getExhibitionDetail: function () {
  271. let exhibitionId = this.data.exhibitionId;
  272. request["getExhibitionDetail"]({
  273. exhibitionId: exhibitionId
  274. }, "", res => {
  275. let { data: exhibitionDetail } = res.data;
  276. let { description, openTime, comments } = exhibitionDetail;
  277. let _show_star = this.fix_starImg(exhibitionDetail.score || '0.0');
  278. if (comments) {
  279. let commentsCon = comments;
  280. for (let i = 0; i < commentsCon.length; i++) {
  281. let comments_star = this.fix_starImg(commentsCon[i].score || '0.0')
  282. commentsCon[i]['imgObj'] = comments_star
  283. }
  284. }
  285. this.setData({
  286. exhibitionDetail,
  287. likeNum: exhibitionDetail.collectionsCount,
  288. latitude: exhibitionDetail.latitude || 23.099994,
  289. addressName: exhibitionDetail.address,
  290. longitude: exhibitionDetail.longitude || 113.324520,
  291. type: exhibitionDetail.hasCollect,
  292. comments,
  293. _show_star: _show_star,
  294. markers: [
  295. {
  296. iconPath: '../../imgs/icon/mapIcon.png',
  297. id: 0,
  298. latitude: exhibitionDetail.latitude,
  299. longitude: exhibitionDetail.longitude,
  300. width: 15,
  301. height: 20,
  302. callout: {
  303. content: exhibitionDetail.address,
  304. borderRadius: 4,
  305. display: 'ALWAYS',
  306. padding: 8
  307. }
  308. }
  309. ]
  310. });
  311. WxParse.wxParse('description', 'html', description, this, 5);
  312. WxParse.wxParse('openTime', 'html', openTime, this, 5);
  313. if (exhibitionDetail.name){
  314. wx.setNavigationBarTitle({
  315. title: exhibitionDetail.name
  316. })
  317. }
  318. })
  319. },
  320. /**
  321. * 生命周期函数--监听页面初次渲染完成
  322. */
  323. onReady: function () {
  324. },
  325. /**
  326. * 生命周期函数--监听页面显示
  327. */
  328. onShow: function () {
  329. this.getExhibitionDetail();
  330. },
  331. /**
  332. * 生命周期函数--监听页面隐藏
  333. */
  334. onHide: function () {
  335. },
  336. /**
  337. * 生命周期函数--监听页面卸载
  338. */
  339. onUnload: function () {
  340. },
  341. /**
  342. * 页面相关事件处理函数--监听用户下拉动作
  343. */
  344. onPullDownRefresh: function () {
  345. },
  346. /**
  347. * 页面上拉触底事件的处理函数
  348. */
  349. onReachBottom: function () {
  350. },
  351. /**
  352. * 用户点击右上角分享
  353. */
  354. onShareAppMessage: function () {
  355. }
  356. })