barCodeBank.js 6.32 KB
var t = require("../../../utils/util.js"),
  ut = t,
  e = require("../../../utils/common.js"),
  a = require("../../../utils/wxParse/wxParse.js"),
  s = getApp(),
  o = s.globalData.setting,
  os = o;

Page({
  data: {
    start_stop: 2, //秒杀开始 结束 的控制(1正在进行,2即将开始)
    color_type: 0, //线条控制
    color_type_one: 0,
    color_type_two: 1,
    is_no_plus: 1,
    gid: "",
    stoid: o.stoid,
    url: o.url,
    resourceUrl: o.h5_url, //公众号那边的图片文件域名
    iurl: o.imghost,
    defaultAvatar: o.resourceUrl + "/static/images/user68.jpg",
    userbuynum:0,//用户组合购购买的次数
    data: null,
    content: "", //商品详情
    comments: null, //商品评论
    c_curr_p: 1, //评论分页
    com_num: 0, //评论人数
    gallery: null, //图片滚动
    is_collect: 0,
    collect_id: 0,
    cartGoodsNum: 0,

    activeCategoryId: 0,
    supportPageScroll: !1,
    address: {
      address: "",
      district: 0
    },
    shipping: "",
    shippingCost: 0,
    enterAddressPage: !1,
    categories: [{
      name: "商品",
      id: 0
    }, {
      name: "详情",
      id: 1
    }],

    //---计时器开关----
    is_timer: 1,
    isshow: 0,
    bconfig: null, //基础配置
    coupon: 0,

    //----------视频图片data参数---------
    current: 0, //图片计数
    swiperCurrent: 0, //轮播的下标
    hiddenn: 0, //控制轮播计数显示
    currentTab: 0, // 选择器控制参数
    mapurl: "",
    mapurl_f_img: "",
    videopicture: 0, //视频图片的控制
    video: 0, //视频图片切换器
    index: 0,
    noon: 0, //开始视频的隐藏
    screenWidth: 0,
    canvasHidden: 1,
    
  },

  //------初始化加载----------
  onLoad: function (t) {
    var ee = this,
      that = ee

    if(t.goods_id!=null&&t.goods_id!=undefined && t.goods_id!=""){
       var gid = t.goods_id
    }else{
      var gid_str = decodeURIComponent(t.scene);
      var gid_str = gid_str.split("_");
      var gid = gid_str[0];
    }

    ee.setData({
      gid: gid
    });
    ee.init(gid);
    //获取用户设备信息,屏幕宽度
    wx.getSystemInfo({
      success: res => {
        that.setData({
          screenWidth: res.screenWidth
        })
      }
    });
  },

  //------------程序初始化入口-------------
  async init(gid) {
    var ee = this,
      gallery = null,
      is_collect = 0,
      fir_com = null,
      mapurl = null,
      mapurl_f_img = null;


    //------图片滚动----------
    await getApp().request.promiseGet("/api/weshop/barcodegoods/page", {
      data: {
        store_id: os.stoid,
        goods_id: gid,
      },
    }).then(res => {
      console.log('5555555555')
      var t = res;
      var g = t.data.data.pageData;

      for (var i = 0; i < g.length; i++) {

        if (g[i].goods_content == null) g[i].goods_content = "";
        //-----商品详情---
        if (!g[i].goods_content) g[i].goods_content = "  ";
        a.wxParse("content", "html", ut.format_content(g[i].goods_content), ee, 6);
        e.wxParseAddFullImageUrl(ee, "content");
        if(g[0].listvideo.length>0){
          var mapurl =g[0].listvideo[0].video_url
        }else{
         var mapurl=""
        }

        ee.setData({
          gallery: gallery,
          is_collect: is_collect,
          supportPageScroll: !0,
          mapurl_f_img: g[0].spec_img,
          mapurl: mapurl,
          data:g[0]
        });
      }
    })

    //--------获取视频图片---------
    // await getApp().request.promiseGet("/api/weshop/goodsVideos/get/" + os.stoid + "/" + ee.data.gid, {
    //   1: 1
    // }).then(res1 => {
    //   if (res1.data.code == 0) {
    //     mapurl = res1.data.data.video_url;
    //     mapurl_f_img = res1.data.data.video_img;
    //   }
    // })
 


  },

  //---展示---
  onShow: function () {
  },

  onReady() {
  },

  onUnload: function () {

  },
  onHide: function () {

  },

  //----------三个选项按钮-----------
  tabClick: function (t) {
    var e = t.currentTarget.id;
    this.setData({
      activeCategoryId: e
    }), 1 == e ? this.tabGoodsContent() : 2 == e && this.tabComment();
  },

  doScrollTop: function () {
    wx.pageScrollTo({
      scrollTop: 0
    });
  },

  tabComment: function () {
    this.setData({
      activeCategoryId: 2,
      comments_no_more: 0,
      get_c: 0
    }), this.data.comments || this.requestComments_new();
  },

  //--点击分享事件---
  onShareAppMessage: function (t) {
  },

  //加载更多是靠这个函数
  onReachBottom: function () {
  },

  // ----视频图片----
  // 图片计数器
  swiperChange: function (e) {
    var that = this;
    if (e.detail.current > 0) {
      that.setData({
        hiddenn: 1,
        videopicture: 1,
      })
    } else {
      that.setData({
        hiddenn: 0,
        videopicture: 0,
      })
    }
    if (e.detail.source == 'touch') {
      that.setData({
        current: e.detail.current
      })
    }
  },

  /*---视频相关--*/
  videopicture: function (e) {
    var vipi = e.currentTarget.dataset.vipi;
    this.setData({
      videopicture: vipi,
      swiperCurrent: vipi,
      noon: 0,
      current: 1
    });
  },

  videoPlay: function (e) {
    var _index = e.currentTarget.id
    this.setData({
      _index: _index,
      noon: 1
    })
    setTimeout(function () {
      //将点击视频进行播放
      var videoContext = wx.createVideoContext(_index)
      videoContext.play();
    }, 500)

  },

  //-- 检验商品的活动情况 --
  check_gd_prom_new: function (func) {
    func();
  },

  screenChange: function (e) {
    let fullScreen = e.detail.fullScreen //值true为进入全屏,false为退出全屏
    if (fullScreen) { //退出全屏
      getApp().globalData.no_clear = 1;
      this.data.show_video = 1;
    }
  },

  click_contact: function () {
    getApp().globalData.no_clear = 1;
  },

  pre_gallery_img(e) {

    this.data.show_prew_img = 1;

    var index = e.currentTarget.dataset.index;
    getApp().globalData.no_clear = 1;

    var url =this.data.iurl + this.data.data.listimages[index].imageUrl;
    var url_arr = [];

    for (var i in this.data.data.listimages) {
      url_arr.push(this.data.iurl + this.data.data.listimages[i].imageUrl)
    }


    wx.previewImage({
      current: url, // 当前显示图片的http链接
      urls: url_arr, // 需要预览的图片http链接列表
    });
  }


})