index.js 9.9 KB

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