Sanakey
2021-01-31 53cc6f817625897935fb10c3845ad7be400f3036
pages/detail/detail.js
@@ -12,7 +12,7 @@
};
import {Http} from "../../utils/http-p.js";
const Request = new Http();
// Object.assign({}, Quantity,
// Object.assign({}, Quantity,
Page({
  /**
@@ -44,7 +44,37 @@
    overflow: "auto",
    list: [],
    isPullTelephone: false,
    cltcode: ''
    cltcode: '',
    attrList:[
      {
        title: '颜色',
        list: [
          {
            name:'红',
            checked: true
          },
          {
            name:'黄',
            checked: false
          },
        ]
      },
      {
        title: '尺寸',
        list: [
          {
            name:'大',
            checked: false
          },
          {
            name:'小',
            checked: true
          },
        ]
      }
    ]
  },
@@ -54,7 +84,7 @@
  onLoad: function(options) {
    // homeLayoutStyle = options.homeLayoutStyle;
    imgDownloadSum = 0;
    // this.setData({
    //   homeLayoutStyle: homeLayoutStyle
    // })
@@ -121,6 +151,9 @@
        that.setData({
          goodsItem: res.data.list,
          CouponList:res.data.CouponList,
          groupBuyingList:res.data.groupBuyingList,
          SkuParameterList:res.data.SkuParameterList,
          SkuMatCodeList:res.data.SkuMatCodeList,
          title: res.data.list.MatName,
          num: 0,
          description: res.data.list.Description,
@@ -128,7 +161,7 @@
          ['Quantity.quantity']: res.data.list.Mininum||1
          // price: goodsItem.Price
        })
        let {
          Quantity,
          isRestrictQuantity,
@@ -164,6 +197,7 @@
        }
        // WxParse.wxParse('article', 'html', res.data.list.Description, that, 5);
        this.getPosterQrCode();
        this.handleCurrentGoods();
        wx.setNavigationBarTitle({
          title: res.data.list.MatName,
        })
@@ -244,7 +278,7 @@
  },
  getPosterQrCode(){
    wx.request({
      url: utils.getUrl('/shopping/poster/getQrCodeForPoster.do'),
      header: {
@@ -263,7 +297,7 @@
        this.setData({
          QrCode:res.data.QrCode
        })
      },
      fail: function (errmsg) {
@@ -395,7 +429,7 @@
    })
  },
    // downloadFile(){
    //   console.log(app.globalData.cardUserData)
    //   console.log('头像',app.globalData.cardUserData.Avatar)
@@ -458,23 +492,23 @@
    //         // } else if (res.cancel) {
    //         //   console.log('用户点击取消')
    //         // }
    //       }
    //     })
    //   })
    // },
    // createCanvas(e){
    //   wx.showToast({
    //     title: '生成中...',
    //     icon: 'loading',
    //     mask:true,
    //     duration: 10000
    //   });
    //   if (imgDownloadObj.isComplete) {
    //     // wx.hideToast()
    //     // let posterCreate =  this.selectComponent('#posterCreate');
@@ -493,11 +527,11 @@
    //       // wx.hideToast()
    //       // let posterCreate =  this.selectComponent('#posterCreate');
    //       // posterCreate.formSubmit(e);
    //     })
    //   }
    // },
    // sendCommand(e){
@@ -522,7 +556,7 @@
    // },
    //将canvas转换为图片保存到本地,然后将图片路径传给image图片的src
    // createPoster (e) {
    //   let posterCreate =  this.selectComponent('#posterCreate');
@@ -531,7 +565,7 @@
    //   // let context = canvas.getContext('2d');
    //   let context = e.detail.context;
    //   // let context = wx.createCanvasContext('mycanvas');
    //   // let path = "../../imgs/gobg.png";
    //   // //不知道是什么原因,手机环境能正常显示
    //   // context.drawImage(path, 0, 0, 375, 183);
@@ -562,7 +596,7 @@
    //   context.textAlign='left';
    //   context.fillText("我看上了这款商品", 140, 50);
    //   context.stroke();
    //   context.setFontSize(16);
    //   context.fillStyle='#333333';
    //   context.textAlign='left';
@@ -573,7 +607,7 @@
    //   context.beginPath();
    //   context.drawImage(goodsImg, 48, 125, 280, 280);
    //   // 商品文字
    //   context.setFontSize(16);
    //   context.fillStyle='#333333';
    //   context.textAlign='left';
@@ -585,7 +619,7 @@
    //       context.fillText(line, 50, lineHeight * index + 435);
    //       // context.fillText("商品描述", 50, 445);
    //   });
    //   context.stroke();
    //   context.setFontSize(32);
    //   context.fillStyle='#f23232';
@@ -593,7 +627,7 @@
    //   context.fillText("¥1999.00", 45, 505);
    //   context.stroke();
    //   context.closePath();
    //   // 绘制分割线
    //   context.beginPath()
    //   context.strokeStyle='#ddd'
@@ -610,7 +644,7 @@
    //   //绘制左下角文字背景图
    //   context.beginPath();
    //   context.drawImage(qrCodeImg, 20, 530, 120, 120);
    //   //绘制右下角扫码提示语
    //   // context.drawImage(path5, 248, 578, 90, 25);
    //   context.setFontSize(16);
@@ -631,7 +665,7 @@
    //   //将生成好的图片保存到本地,需要延迟一会,绘制期间耗时
    //   setTimeout( ()=> {
    //     posterCreate.createPoster(canvas);
    //     console.log('将生成好的图片保存到本地',avatarImg,goodsImg,qrCodeImg)
    //    }, 500);
@@ -690,7 +724,7 @@
    //       context.fillText(line, 50, lineHeight * index + 435);
    //       // context.fillText("商品描述", 50, 445);
    //   });
    //   context.stroke();
    //   context.setFontSize(32);
    //   context.setFillStyle('#f23232');
@@ -698,7 +732,7 @@
    //   context.fillText(goodsItem.CurrencySign+goodsItem.Price, 45, 495);
    //   context.stroke();
    //   context.closePath();
    //   // 绘制分割线
    //   context.beginPath()
    //   context.strokeStyle='#ddd'
@@ -714,7 +748,7 @@
    //   // context.stroke();
    //   //绘制左下角二维码
    //   context.drawImage(qrCodeImg, 20, 530, 120, 120);
    //   //绘制右下角扫码提示语
    //   // context.drawImage(path5, 248, 578, 90, 25);
    //   context.setFontSize(16);
@@ -737,8 +771,12 @@
  buyTap: function(event) {
    // 根据按钮不同区分“下一步”触发的事件
    var name = event.target.dataset.name;
    if (name == "order") {
    let name = event.target.dataset.name || event.detail.name;
    console.log(event);
    this.setData({
      groupCode:event.detail.groupCode||'',
    });
    if (name === "order") {
      this.setData({
        actionType: 'payOrder'
      })
@@ -751,11 +789,17 @@
      //     }
      //   }
      // })
    } else if (name == "cart") {
    } else if (name === "cart") {
      this.setData({
        actionType: 'addCart'
      })
    }
    else if (name === "group") {
      this.setData({
        actionType: 'groupBuying'
      })
    }
    if (this.data.isShow) {
        this.hideLayer();
@@ -764,12 +808,100 @@
      }
  },
  handleCurrentGoods(){
  /*
  *
  * 首先拿到当前商品的所有skuid [],同时也是选中的id
  * 处理所有商品的skuid为字符串
  * 用户点击sku[i],拼接为字符串与上面的对比
  * */
    let SkuParameterList = this.data.SkuParameterList;
    let SkuMatCodeList = this.data.SkuMatCodeList;
    let MatCode = this.data.goodsItem.MatCode;
    let selectedSkuId = [];
    let selectedSkuName = [];
    let skuIdStrings = [];
    SkuMatCodeList.forEach((item,index)=>{
      let skuIdString = '';
      for (let i = 1; i < 11; i++) {
        if (item.MatCode === MatCode && item[`skuId${i}`]){
          selectedSkuId.push(item[`skuId${i}`])
          selectedSkuName.push(item[`skuName${i}`])
        }
        if (item[`skuId${i}`]){
          skuIdString+=item[`skuId${i}`]
        }
      }
      skuIdStrings.push(skuIdString)
    })
    this.setData({
      selectedSkuId,
      selectedSkuName,
      skuIdStrings
    })
    console.log('selectedSkuId',selectedSkuId);
    console.log('selectedSkuName',selectedSkuName);
    console.log('skuIdStrings',skuIdStrings);
  },
  selectGoodsAttr(e){
    console.log(e);
    let attrIndex = e.currentTarget.dataset.i;
    let listIndex = e.currentTarget.dataset.index;
    let skuId = e.currentTarget.dataset.skuId;
    let selectedSkuId = this.data.selectedSkuId;
    selectedSkuId[attrIndex] =  skuId;
    let skuIdStrings = this.data.skuIdStrings;
    let hasSkuId = skuIdStrings.includes(selectedSkuId.join(''));
    console.log(skuIdStrings,selectedSkuId.join(''));
    if (skuIdStrings.includes(selectedSkuId.join(''))){
      this.setData({
        [`selectedSkuId[${attrIndex}]`]:skuId
      })
    } else{
    }
    /*
    * 遍历第一列,把没有的标记
    * 点击第一列可选的项后,遍历剩下所有列,把没有的标记
    * */
    // let list = this.data.attrList[attrIndex].list;
    // list.forEach((item,index)=>{
    //   item.checked = index === listIndex;
    // })
    // this.setData({
    //   [`attrList[${attrIndex}].list`]:list
    // })
  },
  quantityEdit(e){
    // console.log(e)
    this.setData({
      ['Quantity.quantity']:parseFloat(e.detail.quantity)
    })
    // console.log(this.data.Quantity)
  },
  groupBuying(e){
    console.log('准备团购');
    let quantity = this.data.Quantity.quantity;
    let matCode = this.data.goodsItem.MatCode;
    let groupCode = this.data.groupCode;
    let goodsItem = this.data.goodsItem;
    // let eventChannel = this.getOpenerEventChannel();
    //?quantity=${quantity}&matcode=${matcode}&groupCode=${groupCode}
    wx.navigateTo({
      url: `../order/order`,
      success(res){
        res.eventChannel.emit('getSelectedGoods', {
          quantity,
          matCode,
          groupCode,
          goodsItem
        });
      }
    })
  },
  // 加入购物车触发事件
  addCart: function(e) {
@@ -788,7 +920,7 @@
    var img = this.data.goodsItem.images[0];
    console.log(this.data.Quantity)
    wx.request({
      url: utils.getUrl('/shopping/cart.do?m=add'),
@@ -830,7 +962,7 @@
  payOrder: function(e) {
    // utils.subscribeMessage({
    //   callback:()=>{
    //   }
    // })
    //获取数量,价格,商品名称,id,封面图
@@ -863,7 +995,7 @@
        // }
        wx.navigateTo({
          url: '../order/order'
          url: '../order/order?selectedCartIds='+res.data.CartId
        })
        // if(isLogin){
        //   wx.navigateTo({
@@ -976,7 +1108,7 @@
    //   // 来自页面内转发按钮
    //   console.log(ops.target)
    // }
    // console.log('title',utils.getShareTitle())
    return {
      // title: '我在' + app.globalData.titleName +'发现' + this.data.title + ',赶快来看看吧',