caseDetail.js 3.9 KB
// pages/caseDetail/caseDetail.js
var WxParse = require('../../wxParse/wxParse.js');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
    data: {
        imgUrls: [],
        connectButton: [
          { className: "", text: "在线客服", bindtap: "" }
        ],
        currentSwiper: 0,
        listStatus: 0,
        data: {},
        minscreenHeight: 0,
        scrollTop: 0,
        isPlay: false,
        content_1: "",
        content_2: "",
        srcList: [],
    },
    changeIndicatorDots(e) {
        this.setData({
            indicatorDots: !this.data.indicatorDots
        })
    },
    changeAutoplay(e) {
        this.setData({
            autoplay: !this.data.autoplay
        })
    },
    intervalChange(e) {
        this.setData({
            interval: e.detail.value
        })
    },
    swiperChange: function (e) {
        this.setData({
            currentSwiper: e.detail.current
        })
    },
    durationChange(e) {
        this.setData({
            duration: e.detail.value
        })
    },
    toggleFun(e) {
        this.setData({
            listStatus: e.currentTarget.dataset.id
        })
    },
    onPageScroll: function (e) { // 获取滚动条当前位置
    // console.log(e)
        this.setData({
            scrollTop: e.scrollTop
        })
    },
    goTop: function () {
        app.goTop()
    },

    //点击图片切换视频
    play() {
      this.setData({ isPlay: !this.data.isPlay });
    },
    //视频暂停
    // clickStop() {
    //   this.setData({ isPlay: false });
    // },
    swiperChange: function (e) { //切换轮播图
      this.setData({
        currentSwiper: e.detail.current
      })
    },
    /** 
	 * 预览图片
	 */
    previewImage: function (e) {
        console.log(111);
        // var current = e.target.dataset.src;
        wx.previewImage({
            //current: current, // 当前显示图片的http链接
            urls: this.data.srcList // 需要预览的图片http链接列表
        })
    },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      
    // console.log(options);
    let url = '/portal/Api/category';
    let data = {
        categoryId: options.id,
    };
    let srcListArr = [];
    app.post(url, data).then((res) => {
        // console.log('res', res);
        for (var index in res.image) {
          res.image[index].type = "image";
        }
        for (var x = 0; x < res.image.length; x++) {
            srcListArr.push(res.image[x].url);
        }
        if (res.video_type == true) {
          res.image.splice(0, 0, {
            url: res.video,
            type: "video",
            video_img: res.video_img,
          });
        }
        
        
        this.setData({
            imgUrls: res.image,
            data: res,
            srcList: srcListArr,
            content_1: res.content_1,
            content_2: res.content_2,
        });
        // console.log(srcListArr);
        WxParse.wxParse('content_1', 'html', this.data.content_1, this, 5);
        WxParse.wxParse('content_2', 'html', this.data.content_2, this, 5);
    }).catch((err) => {
        console.log(err);
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      wx.setNavigationBarTitle({
          title: '案例详情',
      })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})