123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419 |
- // pages/details/details.js
- const getReq = require('./../../config.js').getReq;
- const app = getApp();
- var WxParse = require('../../wxParse/wxParse.js');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- imgUrls: [],
- datas: {},
- getOneSummary: [],
- webViewUrl: '',
- indicatorDots: true,
- vertical: false,
- autoplay: true,
- interval: 2000,
- duration: 500,
- animation_flag: false,
- isExplain: false,
- sec_index: 0,
- goodsNumber: 1,
- cartOrBuy: '',
- getgift: '',
- options_goods_id: '',
- countTime: 50, /// 测试倒计时
- basicStar: './../image/basic_star.png',
- activeStar: '../../image/star.png',
- halfStar: '../../image/half_star.png',
- starSrcs: [],
- comments: [],
- current: 0,
- carouselImgs: [],
- currentPrice: '', // 商品当前价格,
- promotionDays: ''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- // let webViewUrl = `https://passport.lrlz.com/mobile/index.php?act=goods_common&op=detail&goods_id=${options.goods_id}&client_type=ios`
- // this.setData({
- // webViewUrl,
- // options_goods_id: options.goods_id
- // })
- setInterval(() => {
- this.setData({
- countTime: --this.data.countTime
- })
- }, 1000);
-
- // console.log(options.goods_id);
- this.getDatas(options.goods_id)
- // this.getDatas(7636)
- // this.getDatas(2) // 特殊商品
- // this.getDatas(260) // 特殊商品
- // this.getDatas(4807) // a.lrlz.com 有多条评论
- var that = this;
- getReq({
- act: 'goods_common',
- op: 'detail',
- goods_id: options.goods_id
- // goods_id: 7636
- // goods_id: 4807
- // goods_id: 2
- }, function(res) {
- var str = res.split(/<[\/]?body>/gi)[1];
- WxParse.wxParse('article', 'html', str, that);
- });
- },
- getDatas(goods_id) {
- wx.showLoading({
- title: '加载中',
- })
- var self = this
- getReq({
- act: 'goods_common',
- op: 'index',
- goods_id
- }, function (res) {
- wx.hideLoading()
- if (res.code == 200) {
- console.log(res);
- self.createStars(res.datas.common_info.comments_rate)
- if(res.datas.comments) {
- self.createComments(res.datas.comments)
- }
-
- let oneSummary = self.getOneSummary(res.datas.summary, goods_id)
- console.log('oneSummary:', oneSummary);
- let getgift = self.getgift(res.datas.summary, goods_id)
- let differencePrice = (oneSummary.goods_price - oneSummary.bonus_price).toFixed(2)
- oneSummary = Object.assign({}, { differencePrice }, oneSummary)
- let promotionDays = ''
- if(oneSummary['act_type'] == 2) {
- promotionDays = self.getPromotionDays(oneSummary['act_id'], res.datas.limitime)
- }
- self.setData({
- datas: res.datas,
- getOneSummary: oneSummary,
- imgUrls: res.datas.common_info.images,
- getgift,
- promotionDays
- })
- }
- else {
- console.log('error:', res.message);
- wx.showToast({
- icon: 'none',
- title: res.message,
- duration: 1500
- })
- }
- })
- },
- getOneSummary(sumarys, goods_id) {
- let getOneSummary = sumarys.filter((item, index) => {
- return item.goods_id == goods_id
- })
- return getOneSummary[0]
- },
- secSku(e) {
- let goodsId = e.currentTarget.dataset.goodsid
- let sec_index = e.currentTarget.dataset.secindex
- if (this.data.sec_index == sec_index) {
- return
- }
- let getOneSummary = this.getOneSummary(this.data.datas.summary, goodsId)
- let getgift = this.getgift(this.data.datas.summary, goodsId)
- if (getOneSummary.goods_storage < 1) {
- wx.showToast({
- title: '客官!暂时没有库存!',
- icon: 'none',
- duration: 1500
- })
- return
- }
- this.setData({
- sec_index,
- getOneSummary,
- goodsNumber: 1,
- getgift
- })
- },
- goodsNumHandle(e) {
- let type = e.currentTarget.dataset.type
- if (type == 'minus') {
- if (this.data.goodsNumber <= 1) {
- wx.showToast({
- title: '客官!不能再少了!',
- icon: 'none',
- duration: 1500
- })
- return
- }
- else {
- this.setData({
- goodsNumber: --this.data.goodsNumber
- })
- }
- }
- else {
- if (this.data.goodsNumber >= this.data.getOneSummary['goods_storage']) {
- wx.showToast({
- title: '客官!只有这么多了!',
- icon: 'none',
- duration: 1500
- })
- return
- }
- else {
- this.setData({
- goodsNumber: ++this.data.goodsNumber
- })
- }
- }
- },
- checkSubmit() {
- if (!app.globalData.userInfo) {
- wx.navigateTo({
- url: '/pages/login/login'
- });
- return;
- }
- let cartOrBuy = this.data.cartOrBuy
- this.setData({
- animation_flag: false
- })
- if (cartOrBuy == 'isCart') {
- wx.showLoading({
- title: '加载中',
- })
- getReq({
- act: 'cart',
- op: 'addex',
- quantity: this.data.goodsNumber,
- goods_id: this.data.getOneSummary.goods_id
- }, function (res) {
- wx.hideLoading()
- if (res.code == 200) {
- wx.showToast({
- icon: 'none',
- title: '添加成功!',
- duration: 1500
- })
- }
- else {
- wx.showToast({
- icon: 'none',
- title: res.message,
- duration: 1500
- })
- }
- })
- }
- else if (cartOrBuy == 'isBuy') {
- if (this.data.getOneSummary.goods_storage < 1) {
- wx.showToast({
- title: '客官!暂时没有库存!',
- icon: 'none',
- duration: 1500
- })
- return
- }
- wx.navigateTo({
- url: `/pages/confirmOrder/confirmOrder?goods_id=${this.data.getOneSummary.goods_id}&iscart=0&num=${this.data.goodsNumber}`
- })
- }
- else {
- return
- }
- },
- toWebView() {
- let webViewUrl = encodeURIComponent(this.data.webViewUrl)
- wx.navigateTo({
- url: `/pages/webView/webView?url=${webViewUrl}`
- })
- },
- animation_flag(e) {
- let cartOrBuy = e.currentTarget.dataset.cartorbuy || 'none'
- let flag = e.currentTarget.dataset.flag
- let animation_flag = flag == 'true' ? true : false
- this.setData({
- animation_flag,
- cartOrBuy,
- })
- },
- isExplain_flag(e) {
- let flag = e.currentTarget.dataset.flag
- let isExplain = flag == 'true' ? true : false
- this.setData({
- isExplain
- })
- },
- getgift(sumarys, goods_id) {
- let goods = this.getOneSummary(sumarys, goods_id)
- let giftSummary = ''
- if (goods.have_gift) {
- giftSummary = this.getGiftSummary(sumarys, goods.gifts)
- }
- return giftSummary
- },
- getGiftSummary(sumarys, gifts) {
- let arr = []
- gifts.map(item => {
- sumarys.filter(sum => {
- if (item.gift_goods_id == sum.goods_id) {
- arr.push({
- sum,
- gifts: item
- })
- }
- })
- })
- return arr
- },
- getPromotionDays(actId, limitime) {
- // console.log(this.data.datas);
- let limit = limitime.filter(item => {
- return item['xianshi_id'] == actId
- })
- let days = Math.floor((limit[0]['end_time'] * 1000 - new Date().getTime()) / (60 * 60 * 24 * 1000));
- return days;
- },
- createStars(rate) {
- let starSrcs = []
- for(let i = 0; i < 5; i++) {
- if(i < Math.floor(rate)) {
- starSrcs.push(this.data.activeStar)
- continue
- }
- if(i < Math.round(rate)) {
- starSrcs.push(this.data.halfStar)
- continue
- }
- starSrcs.push(this.data.basicStar)
- }
- this.setData({
- starSrcs
- })
- },
- createComments(basicComments) {
- let comments = []
- comments = basicComments.map(item => {
- let addtime = item.addtime || ''
- if (addtime) {
- let date = new Date(addtime * 1000);
- let year = date.getFullYear();
- let month = date.getMonth() + 1;
- let day = date.getDate();
- let transform_addtime = `${year}-${month}-${day}`
- item['transform_addtime'] = transform_addtime
- }
- return item
- })
- // console.log(comments);
- this.setData({
- comments
- })
- },
- allComments() {
- wx.navigateTo({
- url: `/pages/comments/comments?common_id=${this.data.datas.comment.common_id}`
- });
- return;
- },
- showCarousel(e) {
- let carouselImgs = e.currentTarget.dataset.images
- let current = e.currentTarget.dataset.current
- this.setData({
- show_carousel: true,
- carouselImgs,
- current
- })
- },
- hideCarousel() {
- this.setData({
- show_carousel: false
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- if (app.globalData.fcodeErr) {
- wx.showToast({
- icon: 'none',
- title: app.globalData.fcodeErr,
- duration: 1500
- })
- app.globalData.fcodeErr = ''
- this.setData({
- animation_flag: false
- })
- setTimeout(() => {
- this.getDatas(this.data.options_goods_id)
- }, 1500)
- }
- if (app.globalData.backLogin) {
- this.getDatas(this.data.getOneSummary.goods_id);
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- let goods_id = this.data.options_goods_id
- let goods_name = this.data.getOneSummary.goods_mobile_name
- let imageUrl = this.data.imgUrls[0];
- return {
- title: `熊猫美妆为您推荐:${goods_name}`,
- path: `/pages/details/details?goods_id=${goods_id}`,
- imageUrl: imageUrl
- }
- }
- })
|