123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508 |
- // pages/yuezhan/pay_page/index.js
- const {
- request,
- serverName
- } = require('../../../utils/services');
- // const WxParse = require('../../../common/component/wxParse/wxParse.js');
- const {
- Toast,
- removeArrItem
- } = require('../../../utils/util.js');
- const {
- defaultImg
- } = require('../../../utils/images');
- const WxParse = require('../../../common/component/wxParse/wxParse.js');
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- isAgree: true,
- logo_img: serverName +"/company_logo.jpg",
- half_star_img: "../../../imgs/icon/half.png",
- empty_star_img: "../../../imgs/icon/empty.png",
- full_star_img: "../../../imgs/icon/full.png",
- show_star: [{
- }],
- exhibitionDetail: {}
- },
- clickCell: function() {
- console.log(this.data.active);
- this.setData({
- active: !this.data.active
- })
- },
- 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.half_star_img
- // })
- // break;
- // case numUnit <= 5:
- // show_Arr.push({
- // 'img': this.data.half_star_img
- // })
- // break;
- // default:
- // break
- // }
- show_Arr.push({
- 'img': this.data.half_star_img
- })
- } 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
- },
- readMore: function() {
- this.setData({
- readActive: !this.data.readActive
- })
- },
- 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();
- })
- // }
- },
- tapToCommentDetail: function() {
- let {
- exhibitionId
- } = this.data;
- console.log('detail')
- wx.navigateTo({
- // url: `../../zl_detail/create_evaluation/index?id=${exhibitionId}`,
- url: `../comment_detail/index?id=${exhibitionId}`,
- success: function(res) {},
- fail: function(res) {},
- complete: function(res) {},
- })
- },
- navigateToLocation: function() {
- let {
- latitude,
- longitude
- } = this.data;
- wx.openLocation({
- exhibitionId: 0,
- latitude: latitude,
- longitude: longitude,
- scale: 28,
- success: function(res) {},
- fail: function(res) {},
- complete: function(res) {}
- });
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- this.setData({
- defaultImg,
- exhibitionId: options.id,
- serverName
- })
- // this.getExhibitionDetail();
- 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])
- }
- }
- if (hasItem && id != undefined && (typeof(Number(id)) == 'number')) {
- cookieIDs.unshift(id)
- }
- console.log(id)
- 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,
- imageUrl
- } = exhibitionDetail;
- app.globalData.currentShareImg = imageUrl
- 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
- }
- }
- // console.log('asdasd', commentsCon)
- this.setData({
- exhibitionDetail,
- likeNum: exhibitionDetail.collectionsCount,
- type: exhibitionDetail.hasCollect,
- comments,
- show_star: _show_star
- });
- WxParse.wxParse('description', 'html', description, this, 5);
- WxParse.wxParse('openTime', 'html', openTime, this, 5);
- console.log(exhibitionDetail)
- })
- },
- bindAgreeChange: function(e) {
- this.setData({
- isAgree: !!e.detail.value.length
- });
- },
- tapToComement: function() {
- let {
- exhibitionId
- } = this.data;
- wx.navigateTo({
- url: `../../zl_detail/create_evaluation/index?id=${exhibitionId}`,
- success: function(res) {},
- fail: function(res) {},
- complete: function(res) {},
- })
- },
- tapToDetail: function() {
- wx.navigateTo({
- url: './rule_detail/index',
- success: function(res) {},
- fail: function(res) {},
- complete: function(res) {},
- })
- },
- doWeChatPay: function() {
- let loginSessionKey = wx.getStorageSync("token");
- let {
- exhibitionId,
- isAgree,
- exhibitionDetail
- } = this.data;
- let {
- hasPay
- } = exhibitionDetail;
- let {
- productPrice,
- showLink
- } = this.data.exhibitionDetail.product;
- console.log(productPrice)
- console.log(isAgree)
- if (hasPay) {
- app.globalData.currentUrl = showLink
- // console.log('dwdwdw', app.globalData.currentUrl)
- wx.navigateTo({
- url: `../../wv_page/index`,
- success: function(res) {},
- fail: function(res) {},
- complete: function(res) {},
- })
- } else {
- if (isAgree) {
- if (productPrice) {
- request['orderPay']({
- amount: productPrice,
- loginSessionKey,
- exhibitionId
- }, "post", res => {
- const {
- data: wechatPayModel
- } = res.data;
- const {
- timeStamp,
- nonceStr,
- signType,
- paySign,
- package: packageStr
- } = wechatPayModel;
- console.log(timeStamp,
- nonceStr,
- signType,
- paySign)
- // prettier-ignore
- wx.requestPayment({
- timeStamp,
- nonceStr,
- signType,
- paySign,
- 'package': packageStr,
- success: res => {
- console.log(res);
- app.globalData.currentUrl = showLink
- // console.log('dwdwdw', app.globalData.currentUrl)
- wx.navigateTo({
- url: `../../wv_page/index`,
- success: function (res) { },
- fail: function (res) { },
- complete: function (res) { },
- })
- },
- fail: err => {
- console.log(err);
- Toast.showToast2('warn', '支付取消');
- }
- });
- })
- } else {
- app.globalData.currentUrl = showLink
- wx.navigateTo({
- url: `../../wv_page/index`,
- success: function(res) {},
- fail: function(res) {},
- complete: function(res) {},
- })
- // Toast.showToast('tip', "暂时无法支付", () => {
- // return;
- // })
- }
- } else {
- Toast.showToast('tip', "购买/查看需要同意相关条款", () => {
- return;
- })
- }
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- this.getExhibitionDetail();
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
- }
- })
|