videobox.js 4.0 KB
// pages/videobox/videobox.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    region: [],
    regionname: '全部',
    reginindex: 0,
    type_id:'',
    videolist:[],
    xieyi: false,
    money: "",
    type: 0,
    yu: false,
    wei: false,
    page:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getreginlist()
  },

  // 获取地区列表
  getreginlist() {
    let that = this;

    let url = 'user/type';
    app.post(url, '', 'post').then((res) => {
      console.log(res);
      this.setData({
        region: res,


      })




      // 获取视频列表
      that.getvideolist();


    }).catch((err) => {

    })
  },

  bindRegionChange: function(e) {
    console.log(e)

    this.setData({

      regionname: this.data.region[e.detail.value].area_name,
      type_id: this.data.region[e.detail.value].id
    })

    console.log(this.data.type_id)
    this.getvideolist()
    // this.getpiclist()
  },

  // 获取视频列表
  getvideolist() {
    let that = this;

    let url = 'user/video';
    let param={
      type_id: that.data.type_id,
      page:that.data.page,
      pageNum:10
    }
    app.post(url, param, 'post').then((res) => {
      console.log(res);
      this.setData({
        videolist: res,
      })


    }).catch((err) => {

    })
  },

  videodetail(e) {
    console.log(e)
    let id=e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/videodetail/videodetail?id='+id,
    })
  },

  pay() {
    let that = this;
    let url = 'user/orders';
    let param = {
      video_id: that.data.video_id.join(","),
      pic_id: that.data.pic_id.join(","),
      total: that.data.totalmoney
    }
    app.post(url, param, 'post').then((res) => {
      console.log(res);
      that.setData({
        order_id: res.order_id,
        tixian: true
      })


    }).catch((err) => {
      console.log(err);
      console.log(err.msg.msg)
      wx.showToast({
        title: err.msg.msg,
        icon: 'none'
      })

    })
  },

  payfinish() {
    let that = this;
    let url = 'user/orders';
    let param = {
      video_id: that.data.video_id.join(","),
      pic_id: that.data.pic_id.join(","),
      total: that.data.totalmoney
    }
    app.post(url, param, 'post').then((res) => {
      console.log(res);
      that.setData({
        order_id: res.order_id
      })


    }).catch((err) => {

    })
  },

  zhifuque() {
    let that = this;

    console.log(that.data.type)

    if (this.data.type == 0) {
      wx.showToast({
        title: '请选择支付方式',
        icon: 'none'
      })
    } else if (this.data.xieyi == false) {
      wx.showToast({
        title: '请勾选服务协议',
        icon: 'none'
      })
    } else {
      let url = 'pay/picpay';
      let param = {
        order_id: that.data.order_id,
        type: that.data.type
      }
      app.post(url, param, 'post').then((res) => {
        console.log(res);
        wx.showToast({
          title: res,
          icon: 'none'
        })

        setTimeout(function () {
          that.setData({
            tixian: false
          })
          wx.navigateTo({
            url: '/pages/orderbox/orderbox',
          })
        }, 1500)



      }).catch((err) => {
        console.log('9999', err);
        console.log(err.msg.msg)
        wx.showToast({
          title: err.msg.msg,
          icon: 'none'
        })

      })
    }

  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})