index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. console.log('detail')
  104. wx.navigateTo({
  105. // url: `../../zl_detail/create_evaluation/index?id=${exhibitionId}`,
  106. url: `../yuezhan/comment_detail/index?id=${exhibitionId}`,
  107. success: function (res) { },
  108. fail: function (res) { },
  109. complete: function (res) { },
  110. })
  111. },
  112. addCommentLike: function (e) {
  113. let {
  114. type,
  115. id,
  116. idx
  117. } = e.currentTarget.dataset;
  118. console.log(idx, type, id)
  119. let {
  120. comments
  121. } = this.data;
  122. Toast.showToast2('loading');
  123. let loginSessionKey = wx.getStorageSync('token') || "";
  124. // if (loginSessionKey){
  125. request['commentLike']({
  126. loginSessionKey,
  127. commentId: id,
  128. type: Number(type),
  129. }, "post", res => {
  130. if (res.data.code > -1) {
  131. console.log("asdw", comments.content[idx].hasLike)
  132. comments.content[idx].hasLike = res.data.data.hasLike
  133. if (res.data.data.hasLike) {
  134. comments.content[idx].likeCount += 1;
  135. } else {
  136. comments.content[idx].likeCount -= 1;
  137. }
  138. this.setData({
  139. comments: comments
  140. })
  141. }
  142. }, err => {
  143. }, complete => {
  144. Toast.hideLoading();
  145. })
  146. // }
  147. },
  148. addLike: function () {
  149. // if (this.data.isLike) {
  150. // this.setData({
  151. // isLike: !this.data.isLike,
  152. // likeNum: this.data.likeNum - 1
  153. // })
  154. // } else {
  155. // this.setData({
  156. // isLike: !this.data.isLike,
  157. // likeNum: this.data.likeNum + 1
  158. // })
  159. // }
  160. let loginSessionKey = wx.getStorageSync('token') || "";
  161. let {
  162. exhibitionId,
  163. exhibitionDetail,
  164. type: isChange
  165. } = this.data;
  166. let {
  167. collectedArr,
  168. collectedChange
  169. } = app.globalData, hasItem = true;
  170. let type = exhibitionDetail.hasCollect
  171. // if (loginSessionKey){
  172. request['isCollect']({
  173. loginSessionKey,
  174. exhibitionId: exhibitionId,
  175. type: Number(type),
  176. }, "post", res => {
  177. if (res.data.code > -1) {
  178. for (let i = 0; i < collectedArr.length; i++) {
  179. if (collectedArr[i].collectedId && exhibitionId == collectedArr[i].collectedId) {
  180. console.log("true")
  181. collectedArr[i] = {
  182. collectedId: exhibitionId,
  183. status: res.data.data.hasCollect,
  184. }
  185. hasItem = false;
  186. }
  187. }
  188. if (hasItem) {
  189. collectedArr.push({
  190. collectedId: exhibitionId,
  191. status: res.data.data.hasCollect,
  192. })
  193. }
  194. app.globalData.collectedArr = collectedArr;
  195. console.log(isChange, res.data.data.hasCollect)
  196. if (isChange == res.data.data.hasCollect) {
  197. app.globalData.collectedChange = false;
  198. } else {
  199. app.globalData.collectedChange = true;
  200. }
  201. exhibitionDetail.hasCollect = res.data.data.hasCollect
  202. if (exhibitionDetail.hasCollect) {
  203. exhibitionDetail.collectionsCount += 1;
  204. } else {
  205. exhibitionDetail.collectionsCount -= 1;
  206. }
  207. this.setData({
  208. exhibitionDetail: exhibitionDetail,
  209. })
  210. }
  211. }, err => {
  212. }, complete => {
  213. Toast.hideLoading();
  214. })
  215. // }
  216. },
  217. clickCell: function () {
  218. console.log(this.data.active);
  219. this.setData({
  220. active: !this.data.active
  221. })
  222. },
  223. navigateToLocation: function () {
  224. let { latitude, longitude, addressName } = this.data;
  225. console.log("dasdw",latitude,longitude)
  226. wx.openLocation({
  227. // exhibitionId: 0,
  228. latitude: latitude,
  229. longitude: longitude,
  230. scale: 28,
  231. name: addressName,
  232. success: function (res) {
  233. console.log('success')
  234. },
  235. fail: function (res) { },
  236. complete: function (res) { }
  237. });
  238. },
  239. tapToComement: function () {
  240. let {
  241. exhibitionId
  242. } = this.data;
  243. wx.navigateTo({
  244. url: `./create_evaluation/index?id=${exhibitionId}`,
  245. success: function (res) { },
  246. fail: function (res) { },
  247. complete: function (res) { },
  248. })
  249. },
  250. /**
  251. * 生命周期函数--监听页面加载
  252. */
  253. onLoad: function (options) {
  254. this.setData({
  255. defaultImg,
  256. exhibitionId: options.id,
  257. serverName
  258. })
  259. let { cookieIDs=[] } = app.globalData;
  260. let id = options.id;
  261. let hasItem = true;
  262. for (let i = 0; i < cookieIDs.length; i++) {
  263. if (cookieIDs[i] && id == cookieIDs[i]) {
  264. cookieIDs = removeArrItem(cookieIDs, cookieIDs[i])
  265. }
  266. }
  267. console.log((typeof (Number(id))))
  268. if (hasItem && id != undefined && (typeof(Number(id)) == 'number')) {
  269. cookieIDs.unshift(id)
  270. }
  271. console.log(id)
  272. console.log(cookieIDs)
  273. app.globalData.cookieIDs = cookieIDs
  274. console.log(app.globalData.cookieIDs)
  275. },
  276. getExhibitionDetail: function () {
  277. let exhibitionId = this.data.exhibitionId;
  278. request["getExhibitionDetail"]({
  279. exhibitionId: exhibitionId
  280. }, "", res => {
  281. let { data: exhibitionDetail } = res.data;
  282. let { description, openTime, comments } = exhibitionDetail;
  283. let _show_star = this.fix_starImg(exhibitionDetail.score || '0.0');
  284. if (comments) {
  285. let commentsCon = comments.content;
  286. for (let i = 0; i < commentsCon.length; i++) {
  287. let comments_star = this.fix_starImg(commentsCon[i].score || '0.0')
  288. commentsCon[i]['imgObj'] = comments_star
  289. }
  290. }
  291. this.setData({
  292. exhibitionDetail,
  293. likeNum: exhibitionDetail.collectionsCount,
  294. latitude: exhibitionDetail.latitude || 23.099994,
  295. addressName: exhibitionDetail.address,
  296. longitude: exhibitionDetail.longitude || 113.324520,
  297. type: exhibitionDetail.hasCollect,
  298. comments,
  299. _show_star: _show_star,
  300. markers: [
  301. {
  302. iconPath: '../../imgs/icon/mapIcon.png',
  303. id: 0,
  304. latitude: exhibitionDetail.latitude,
  305. longitude: exhibitionDetail.longitude,
  306. width: 15,
  307. height: 20,
  308. callout: {
  309. content: exhibitionDetail.address,
  310. borderRadius: 4,
  311. display: 'ALWAYS',
  312. padding: 8
  313. }
  314. }
  315. ]
  316. });
  317. WxParse.wxParse('description', 'html', description, this, 5);
  318. WxParse.wxParse('openTime', 'html', openTime, this, 5);
  319. console.log(this.data._show_star)
  320. console.log(exhibitionDetail)
  321. })
  322. },
  323. /**
  324. * 生命周期函数--监听页面初次渲染完成
  325. */
  326. onReady: function () {
  327. },
  328. /**
  329. * 生命周期函数--监听页面显示
  330. */
  331. onShow: function () {
  332. this.getExhibitionDetail();
  333. },
  334. /**
  335. * 生命周期函数--监听页面隐藏
  336. */
  337. onHide: function () {
  338. },
  339. /**
  340. * 生命周期函数--监听页面卸载
  341. */
  342. onUnload: function () {
  343. },
  344. /**
  345. * 页面相关事件处理函数--监听用户下拉动作
  346. */
  347. onPullDownRefresh: function () {
  348. },
  349. /**
  350. * 页面上拉触底事件的处理函数
  351. */
  352. onReachBottom: function () {
  353. },
  354. /**
  355. * 用户点击右上角分享
  356. */
  357. onShareAppMessage: function () {
  358. }
  359. })