let url2 = getApiUrl().urlJava
let shoppData = [];
getShppingList()
function getShppingList() { // 获取用户剩余抽奖次数
    $.ajax({
      type: "POST",
      url: `${url2}/api/mactivity/getActivityGoods`,
      contentType: "application/json",
      data: getJavaData({ activityId: activityId }),
      async: false,//使用同步的方式,true为异步方式
      success: function (res) {
        if (res.resultCode === 1) {
            //console.log(res,'resss');
            shoppData = res.data;
            let str = '';
            for(var i=0;i<shoppData.length;i++){
                str+=`<div class="shop_List" onclick="setExchangeGoods(${shoppData[i].id})">
                        <div class="Splist_Top">
                            <img src="${shoppData[i].imgs[0]}" alt="">
                            <div class="Splist_Top_cishu">可兑换：${shoppData[i].limited}次</div>
                            <div class="Split_Top_title">${shoppData[i].name}</div>
                        </div>
                        <div class="Splist_btm">
                            <div class="Sp_money">市场价：¥${shoppData[i].marketPrice}</div><div class="hplistCont">
                            `;
                            for(var j=0;j<shoppData[i].rules.length;j++){
                                str+= `
                                <div class="sp_cailiao">
                                    <img src="${getImgSrc(shoppData[i].rules[j])}" alt="">
                                    <span>${shoppData[i].rules[j].amount}</span>
                                </div>
                                <i class="shopCheng">×</i>
                                `
                            }
                        str+= `</div></div>
                    </div>` 
            }
            $(".shop_ContentMain").html(str);
        }
      },
      error: function (res) {
      }
    });
  }
  function getImgSrc(obj){
      if (obj.mName === '蒙牛冰淇淋') {
        return `../../images/task/ice/c_ice_4.png`
      } else if (obj.mName === 'DQ冰淇淋') {
        return `../../images/task/ice/c_ice_3.png`
      } else if (obj.mName === '明治冰淇淋') {
        return `../../images/task/ice/c_ice_2.png`
      } else if (obj.mName === '和路雪冰淇淋') {
        return `../../images/task/ice/c_ice_1.png`
      } else if (obj.mName === '哈根达斯冰淇淋') {
        return `../../images/task/ice/c_ice_5.png`
      } else if (obj.mName === '冰淇淋全家桶') {
        return `../../images/task/ice/c_ice_quan.png`
      }
  }
  //点击兑换
  function setExchangeGoods(goodsId){
    let msg = {
        activityId: activityId,
        goodsId: goodsId 
    }
    $.ajax({
        type: "POST",
        url: `${url2}/api/mactivity/setExchangeGoods`,
        contentType: "application/json",
        data: getJavaData(msg),
        async: false,//使用同步的方式,true为异步方式
        success: function (res) {
          if (res.resultCode === 1) {
            showTips("兑换成功")
          }else{              
            showTips(res.message)
          }
        },
        error: function (res) {
            showTips(res.message);
        }
      });    
  }
  
  