123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417 |
- // pages/zl_detail/index.js
- const { request, serverName, imgServer } = require('../../utils/services');
- const WxParse = require('../../common/component/wxParse/wxParse.js');
- const { Toast, removeArrItem } = require('../../utils/util.js');
- const { defaultImg } = require('../../utils/images');
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- logo_img: "../../imgs/logo.jpg",
- half_star_img: "../../imgs/icon/half.png",
- empty_star_img: "../../imgs/icon/empty.png",
- full_star_img: "../../imgs/icon/full.png",
- testImg: '../../imgs/testImg/thumbSmallImg2.jpg',
- avatar: '../../imgs/testImg/1.jpg',
- icon_quanping: '../../imgs/quanping.png',
- active: false,
- readActive: false,
- isLike: false,
- likeNum: 526,
- animationData: {},
- imgServer,
- tour_info_data: [{
- title: '地址:',
- txt: '北京市朝阳区崔各乡庄各庄村顺白马路马嘻路口100米路北'
- }, {
- title: '开放时间',
- txt: '周二到周日10:00-18:00 (每周一闭馆)'
- }, {
- title: '电话:',
- txt: '+86 10 8456654654'
- }]
- },
- clickCell: function () {
- console.log(this.data.active);
- this.setData({
- active: !this.data.active
- })
- },
- readMore: function () {
- this.setData({
- readActive: true
- })
- },
- fix_starImg: function (points) {
- let strPoints = String(Number(points).toFixed(2));
- let show_Arr = [];
- let ten = strPoints.split('.')[0] || 0;
- let unit = strPoints.split('.')[1] || 0;
- let surPlus = 0;
- if (strPoints < 0) {
- return
- }
- if (ten) {
- for (let i = 0; i < Number(ten); i++) {
- show_Arr.push({
- 'img': this.data.full_star_img
- })
- }
- surPlus = 5 - Number(ten);
- }
- if (unit && surPlus > 0) {
- let numUnit = Number(unit.substr(0, 1)) || 0
- if (numUnit > 0) {
- // let fix_unit = Math.round(numUnit);
- switch (true) {
- case numUnit > 5:
- show_Arr.push({
- 'img': this.data.full_star_img
- })
- break;
- case numUnit <= 5:
- show_Arr.push({
- 'img': this.data.half_star_img
- })
- break;
- default:
- break
- }
- } else if (numUnit == 0) {
- show_Arr.push({
- 'img': this.data.empty_star_img
- })
- } else {
- return
- }
- }
- if (surPlus > 0) {
- for (let i = 0; i < surPlus - 1; i++) {
- show_Arr.push({
- 'img': this.data.empty_star_img
- })
- }
- }
- return show_Arr
- },
- tapToCommentDetail: function () {
- let {
- exhibitionId
- } = this.data;
- console.log('detail')
- wx.navigateTo({
- // url: `../../zl_detail/create_evaluation/index?id=${exhibitionId}`,
- url: `../yuezhan/comment_detail/index?id=${exhibitionId}`,
- success: function (res) { },
- fail: function (res) { },
- complete: function (res) { },
- })
- },
- addCommentLike: function (e) {
- let {
- type,
- id,
- idx
- } = e.currentTarget.dataset;
- console.log(idx, type, id)
- let {
- comments
- } = this.data;
- Toast.showToast2('loading');
- let loginSessionKey = wx.getStorageSync('token') || "";
- // if (loginSessionKey){
- request['commentLike']({
- loginSessionKey,
- commentId: id,
- type: Number(type),
- }, "post", res => {
- if (res.data.code > -1) {
- console.log("asdw", comments.content[idx].hasLike)
- comments.content[idx].hasLike = res.data.data.hasLike
- if (res.data.data.hasLike) {
- comments.content[idx].likeCount += 1;
- } else {
- comments.content[idx].likeCount -= 1;
- }
- this.setData({
- comments: comments
- })
- }
- }, err => {
- }, complete => {
- Toast.hideLoading();
- })
- // }
- },
- addLike: function () {
- // if (this.data.isLike) {
- // this.setData({
- // isLike: !this.data.isLike,
- // likeNum: this.data.likeNum - 1
- // })
- // } else {
- // this.setData({
- // isLike: !this.data.isLike,
- // likeNum: this.data.likeNum + 1
- // })
- // }
- let loginSessionKey = wx.getStorageSync('token') || "";
- let {
- exhibitionId,
- exhibitionDetail,
- type: isChange
- } = this.data;
- let {
- collectedArr,
- collectedChange
- } = app.globalData, hasItem = true;
- let type = exhibitionDetail.hasCollect
- // if (loginSessionKey){
- request['isCollect']({
- loginSessionKey,
- exhibitionId: exhibitionId,
- type: Number(type),
- }, "post", res => {
- if (res.data.code > -1) {
- for (let i = 0; i < collectedArr.length; i++) {
- if (collectedArr[i].collectedId && exhibitionId == collectedArr[i].collectedId) {
- console.log("true")
- collectedArr[i] = {
- collectedId: exhibitionId,
- status: res.data.data.hasCollect,
- }
- hasItem = false;
- }
- }
- if (hasItem) {
- collectedArr.push({
- collectedId: exhibitionId,
- status: res.data.data.hasCollect,
- })
- }
- app.globalData.collectedArr = collectedArr;
- console.log(isChange, res.data.data.hasCollect)
- if (isChange == res.data.data.hasCollect) {
- app.globalData.collectedChange = false;
- } else {
- app.globalData.collectedChange = true;
- }
- exhibitionDetail.hasCollect = res.data.data.hasCollect
- if (exhibitionDetail.hasCollect) {
- exhibitionDetail.collectionsCount += 1;
- } else {
- exhibitionDetail.collectionsCount -= 1;
- }
- this.setData({
- exhibitionDetail: exhibitionDetail,
- })
- }
- }, err => {
- }, complete => {
- Toast.hideLoading();
- })
- // }
- },
-
- clickCell: function () {
- console.log(this.data.active);
- this.setData({
- active: !this.data.active
- })
- },
- navigateToLocation: function () {
- let { latitude, longitude, addressName } = this.data;
- console.log("dasdw",latitude,longitude)
- wx.openLocation({
- // exhibitionId: 0,
- latitude: latitude,
- longitude: longitude,
- scale: 28,
- name: addressName,
- success: function (res) {
- console.log('success')
- },
- fail: function (res) { },
- complete: function (res) { }
- });
- },
- tapToComement: function () {
- let {
- exhibitionId
- } = this.data;
- wx.navigateTo({
- url: `./create_evaluation/index?id=${exhibitionId}`,
- success: function (res) { },
- fail: function (res) { },
- complete: function (res) { },
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- defaultImg,
- exhibitionId: options.id,
- serverName
- })
- let { cookieIDs=[] } = app.globalData;
- let id = options.id;
- let hasItem = true;
- for (let i = 0; i < cookieIDs.length; i++) {
- if (cookieIDs[i] && id == cookieIDs[i]) {
- cookieIDs = removeArrItem(cookieIDs, cookieIDs[i])
- }
- }
- console.log((typeof (Number(id))))
- if (hasItem && id != undefined && (typeof(Number(id)) == 'number')) {
- cookieIDs.unshift(id)
- }
- console.log(id)
- console.log(cookieIDs)
-
- app.globalData.cookieIDs = cookieIDs
- console.log(app.globalData.cookieIDs)
-
- },
- getExhibitionDetail: function () {
- let exhibitionId = this.data.exhibitionId;
- request["getExhibitionDetail"]({
- exhibitionId: exhibitionId
- }, "", res => {
- let { data: exhibitionDetail } = res.data;
- let { description, openTime, comments } = exhibitionDetail;
- let _show_star = this.fix_starImg(exhibitionDetail.score || '0.0');
- if (comments) {
- let commentsCon = comments.content;
- for (let i = 0; i < commentsCon.length; i++) {
- let comments_star = this.fix_starImg(commentsCon[i].score || '0.0')
- commentsCon[i]['imgObj'] = comments_star
- }
- }
- this.setData({
- exhibitionDetail,
- likeNum: exhibitionDetail.collectionsCount,
- latitude: exhibitionDetail.latitude || 23.099994,
- addressName: exhibitionDetail.address,
- longitude: exhibitionDetail.longitude || 113.324520,
- type: exhibitionDetail.hasCollect,
- comments,
- _show_star: _show_star,
- markers: [
- {
- iconPath: '../../imgs/icon/mapIcon.png',
- id: 0,
- latitude: exhibitionDetail.latitude,
- longitude: exhibitionDetail.longitude,
- width: 15,
- height: 20,
- callout: {
- content: exhibitionDetail.address,
- borderRadius: 4,
- display: 'ALWAYS',
- padding: 8
- }
- }
- ]
- });
- WxParse.wxParse('description', 'html', description, this, 5);
- WxParse.wxParse('openTime', 'html', openTime, this, 5);
-
- console.log(this.data._show_star)
- console.log(exhibitionDetail)
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.getExhibitionDetail();
-
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|