goodtail.js 6.7 KB
// pages/shop/goodtail/goodtail.js
var WxParse = require('../../../wxParse/wxParse.js');
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // imgUrls: [
    //   {
    //     url: '../../../img/chairfour.png',
    //     color: '#E7D3A8',
    //     colorname:'卡其色',
    //     idx:0
    //   },
    //   {
    //     url: '../../../img/chairfour.png',
    //     color: '#D4D4D4',
    //     colorname: '灰色',
    //     idx: 1
    //   },
    //   {
    //     url: '../../../img/chairfour.png',
    //     color: '#15276D',
    //     colorname: '深蓝',
    //     idx: 2
    //   }
      
    // ],
    indicatorDots: false,
    autoplay: false,
    interval: 2000,
    duration: 1000,
    currentSwiper: 0,

    // 字轮播
    currentSwipername:0,
    goodnum:1,
    buywrap:false,
    number:2,
    type:'',
    canshu:true,
    goodid:'',
    //商品详情
    goodsdetail:[],
    parameters: [],
    leatherPrice: [],
    title:"",
    describe:'',
    originalPrice:'',
    price:'',
    imgUrl:'',
    goodname: '',
    originalPrice: '',
    price: '',
    color:'',
    inventorynum:'',
    goodsLeatherid:'',
    suid:'',
    goodpic:""
   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      goodid:options.id,
      suid: wx.getStorageSync("Suid")
    })

    this.getgoodtail()
  },

  //获取商品详情页
  getgoodtail(){
    let that = this;
    let url = '/Product/SelectProductDetailsById', params = {
      id: that.data.goodid,

    }
    app.post(url, params).then((res) => {
      console.log(res)

      console.log(res.GoodsDetail);
      that.setData({
        goodsdetail: res.GoodsDetail[0],
        parameters: res.Parameters[0],
        leatherPrice: res.LeatherPrice,
        originalPrice: res.LeatherPrice[0].originalPrice,

        price: res.LeatherPrice[0].originalPrice,
        imgUrl: res.LeatherPrice[0].imgUrl,
        title: res.GoodsDetail[0].title.split(","),
    
        describe: res.GoodsDetail[0].describe.split(","),
        goodname: res.LeatherPrice[0].name,
        originalPrice: res.LeatherPrice[0].originalPrice,
        price: res.LeatherPrice[0].price,
        color: res.LeatherPrice[0].colorName,
        inventorynum: res.LeatherPrice[0].inventoryNum,
        goodsLeatherid: res.LeatherPrice[0].id,
        goodpic: res.LeatherPrice[0].imgUrl
      })

      WxParse.wxParse('article', 'html', res.GoodsDetail[0].introduction, that, 5)

      consoe.log(that.data.parameters)



    }).catch((err) => {

    }) 
  },
  shopintro(){
    this.setData({
      canshu:!this.data.canshu
    })
  },
  //进入首页
  goindex(){
    console.log(9090)
    wx.switchTab({
   
      url: "/pages/homeindex/homeindex",
    })
    
  },
  swiperChange: function (e) {
    console.log(e)
    this.setData({
      currentSwiper: e.detail.current,
      currentSwipername:e.detail.current
    })

    let newleatherPrice = this.data.leatherPrice;
    for (var i = 0; i <newleatherPrice.length;i++){
      if (i == e.detail.current){
          this.setData({
            goodname: newleatherPrice[i].name,
            originalPrice: newleatherPrice[i].originalPrice,
            price: newleatherPrice[i].price,
            color: newleatherPrice[i].colorName,
            inventorynum: newleatherPrice[i].inventoryNum,
            goodsLeatherid: newleatherPrice[i].id,
            goodpic: newleatherPrice[i].imgUrl,
          })
        }
    }
  },

  //加入购物车
  addcar(){
    console.log(99)
    this.setData({
      buywrap:true,
      type:1
    })

    

  },
  //立即购买
  buynow(){
      // wx.navigateTo({
      //   url: '/pages/ordercontainer/sureorderone/sureorderone',
      // })

    this.setData({
      buywrap: true,
      type: 2
    })

  },
  sure(){
    let that=this;
    if(this.data.type==1){
      
      let that = this;
      let url = '/ShoppingCart/AddProductToShoppingCart', params = {
        numbers: that.data.goodnum,
        goodsLeatherId: that.data.goodsLeatherid,
        suid: that.data.suid


      }
      app.post(url, params).then((res) => {
        console.log(res);
        if(res==null){
          wx.showToast({
            title: '加入购物车成功',
            icon:'none'
          })
          wx.setStorageSync("listgood", '')
          setTimeout(function(){
            that.setData({
              buywrap: false
            })
          },1500)
        }



      }).catch((err) => {

      })


    }else{
      let enterarr = []
      console.log(that.data.goodpic)
      let enterobj={
        "numbers": that.data.goodnum,
        "goodsLeatherId": that.data.goodsLeatherid
      }
      enterarr.push(enterobj)
      

      let goodinfo={
        goodname: that.data.goodname,
        goodcolor: that.data.color,
        goodprice: that.data.price,
        goodnum: that.data.goodnum,
       
      }
      goodinfo = JSON.stringify(goodinfo)
      

      console.log(goodinfo)
      wx.setStorageSync('enterobj', enterarr)
      wx.setStorageSync("invoiceId", 0);
      let usertype = wx.getStorageSync('UserType')
      wx.setStorageSync("listgood", '');
      wx.setStorageSync("goodarr", '');
      wx.setStorageSync("drawbill", '')
      wx.setStorageSync('goodpic', that.data.goodpic)
      wx.setStorageSync('addressinfo', '')
      if (usertype==3){

        wx.navigateTo({
          url:"/pages/ordercontainer/shopsureorder/shopsureorder?goodinfo="+goodinfo
          
        })
      }else{
        wx.navigateTo({

          url: '/pages/ordercontainer/sureorderone/sureorderone?goodinfo=' + goodinfo 
        })
      }
      
    }
  },
  //购物车增加
  add(){
    let newgoodnum=this.data.goodnum;
    newgoodnum++;
    this.setData({
      goodnum:newgoodnum
    })
  },
  hidebuywrap(){
      this.setData({
        buywrap:false
      })
  },

  reduce(){
    let newgoodnum = this.data.goodnum;
    if(newgoodnum<=1){
      this.setData({
        goodnum: 1
      })
    }else{
      newgoodnum=newgoodnum-1;
      this.setData({
        goodnum: newgoodnum
      })
    }
   
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})