<template>
  <div :style="styleData.friendsHelpBox" ref="friendsHelpNew" @click="styleClick('click', 'friendsHelpNew')"
    @mousemove="styleClick('mousemove', 'friendsHelpNew')" @mouseout="styleClick('mouseout')">
    
    <div class="mainStyleDiv" :style="styleData.mainStyleDiv">
      <div class="recordListDiv" :style="styleData.recordListDiv">
        <div v-if="friendsHelpList.length > 0">
          <div class="item">
            <div
              v-for="(item, index) in friendsHelpList"
              :key="index"
              :style="styleData.recordItemDiv"
            >
              <div class="recordItemLeft" :style="styleData.recordItemLeft">
                <img
                  :style="styleData.avatarImg"
                  :src="
                    item.helpUserImg ||
                    'https://img10.360buyimg.com/imgzone/jfs/t1/8136/5/13801/2619/5c4ae5efE757a72c1/6639cb75e7f0762d.png'
                  "
                />
                <span :style="styleData.userName">{{
                  item.helpUserName | twostar
                }}</span>
              </div>
              <div
              :style="styleData.recordItemRightBox"
                style="
                  display: flex;
                  flex-direction: column;
                  justify-content: center;
                  align-items: end;
                "
              >
                <div :style="styleData.recordItemRight">
                  疯狂助攻，
                  <span v-if="item.status == 1"
                    >抽到“{{ item.cardName }}”字卡</span
                  >
                  <span v-else>很遗憾，未抽到卡片</span>
                </div>
                <div :style="styleData.recordItemRight1">
                  {{ item.createTime | dateTime }}
                </div>
              </div>
            </div>
          </div>
        </div>
        <div v-else :style="styleData.recordItemDiv1">暂无好友助力记录哦~</div>
      </div>
    </div>

    <div id="noPrizeDiv" v-if="isShow" @click="clickEmpty()"   >
      <div id="thanksjion" @click="stopClickEmpty">
        <div id="close" @click="closeFriendsHelp()"></div>
        <div id="bottom-content">
          <div class="friendAssistGroup" v-if="cardList.canAssist == 0">
            <div class="fAssistuser">
              <div class="userinfoleft">
                <img
                  class="userimg"
                  :src="
                    cardList.helpUserImg ||
                    'https://img10.360buyimg.com/imgzone/jfs/t1/8136/5/13801/2619/5c4ae5efE757a72c1/6639cb75e7f0762d.png'
                  "
                />
                {{ cardList.helpUserName }}
              </div>
            </div>
            <div
              style="
                height: 3.26rem;
                display: flex;
                flex-direction: column;
                justify-content: center;
              "
            >
              <img
                v-if="cardList.helpCardStatus == 1"
                :src="cardList.helpCardUrl"
                class="friendCardimg"
              />
              <div v-if="cardList.helpCardStatus == 1" class="thanksfalse2">
                谢谢您帮我抽中“{{ cardList.helpCardName }}”
              </div>
              <div v-else class="thanksfalse">很遗憾您没帮我抽中！</div>
              <div class="thanksfalse1">
                【感谢老铁助力，参与集卡可以赢大奖哦】
              </div>
            </div>

            <div class="mainbtn" @click="closeFriendsHelp()">
              参与活动，查看我的卡片
            </div>
            <div class="friendAssistTip">
              助人为乐的您也有机会获得一张卡，赶紧去看看吧
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import apis1 from "../../../util/apis1.js";
import dateUtil from "../../../util/dateUtil.js";
import store from "../../../store/store.js";
let { cardFriendHelpList, cardInfoList, cardFriendsHelpList } = apis1;

export default {
  components: {
    store,
  },
  props: ["isTemplate", "datas", "keyData", "styleData", "templateData","isWebClick","modifyContent"],
  data() {
    return {
      friendsHelpList: [],
      cardList: [],
      shareUserId: "",
      helpCount: 0,
      isShow: false,
      styleDataOld: {},
    };
  },

  created() {
       this.styleDataOld = JSON.parse(JSON.stringify(this.styleData));
    this.initData();
  },
  mounted() {
    this.friendsHelpList = [];
    this.cardList = [];
  },
  methods: {
    styleClick(type, refName) {
      if (this.isWebClick) {
        //传值给B端
        let byValue = {
          modifyContent: this.modifyContent,
          refName: refName,
          styleData: this.styleData,
          c_this: this,
          isCustomSwitching: this.isCustomSwitching,
          styleDataOld: this.styleDataOld,
        };
        this.$emit("opertaionCom", type, byValue);
      }
    },
    initData() {
      var datasAll = this.templateData;

      if (this.isTemplate == true) {
        // this.$toast("活动预览，仅供查看");
      } else {
        this.shareUserId = store.state.shareUserId;
        var shareUserId = this.shareUserId;
        cardFriendsHelpList(shareUserId, (data) => {
          this.cardList = data.data;
          this.friendsHelpBack();
          if (data.data.canAssist == 1) {
            this.$toast("您已为该好友助力过了");
            this.isShow = false;
            return;
          } else if (data.data.canAssist == 2) {
            this.$toast("您今日助力次数已达上限");
            this.isShow = false;
            return;
          } else if (data.data.canAssist == 4) {
            this.isShow = false;
            return;
          } else {
            this.isShow = true;
          }
        });
      }
    },
    closeFriendsHelp() {
      this.isShow = false;
    },
    friendsHelpBack() {
      cardFriendHelpList((data) => {
        this.friendsHelpList = data.data.collectHelpListDTOS;
        this.helpCount = data.data.helpCount;
      });
    },
    //点击空白处关闭弹框
    clickEmpty() {
      this.isShow = false;
    },
    //阻止冒泡
    stopClickEmpty(event) {
      event.stopPropagation();
    },
  },
  filters: {
    //时间转换
    dateTime(val) {
      if (val) {
        return dateUtil.formatTime(val, "yyyy-MM-dd hh:mm");
      }
      return val;
    },
    twostar: function (value) {
      if (!value) {
        return "";
      }
      return value.substr(0, 1) + "**" + value.substr(-1, 1);
    },
  },
};
</script>
<style lang="scss" scoped>
#noPrizeDiv {
  position: fixed;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  top: 0;
  z-index: 4999;
  display: flex;
  justify-content: center;
  align-items: center;
}

#thanksjion {
  width: 5.88rem;
  height: 6.3rem;
  position: relative;
  z-index: 2;
  border-radius: 0.3rem;
  background: #fff;
}

#close {
  height: 0.24rem;
  width: 0.24rem;
  position: absolute;
  right: 0.34rem;
  top: 0.34rem;
  background: url("//img10.360buyimg.com/imgzone/jfs/t1/143521/26/18654/387/5fd9e706E8f1594e3/ae5cc06440559585.png")
    no-repeat;
  background-size: 100% 100%;
}

#top-img {
  height: 0.35rem;
  width: 2.39rem;
  margin: auto;
  margin-top: 0.4rem;
  background-image: url("//img10.360buyimg.com/imgzone/jfs/t1/138090/24/18694/2054/5fd996ffE21debdd7/9495c2233cce85e2.png");
  background-repeat: no-repeat;
  background-size: 100%;
}

#bottom-content {
  background-color: white;
  margin: auto;
  border-radius: 0.2rem;
}
.friendsHelpNew {
  width: 100%;
  max-height: 6.1rem;
  background: #fff;
  top: 1rem;
  overflow-y: auto;
  position: absolute;
}
.friendAssistGroup {
  width: 100%;
  background: #fff;
  padding: 0.2rem;
  margin-top: 0.2rem;
}
.friendgivecardgroup {
  width: 100%;
  background: #fff;
  padding: 0.2rem 0.3rem;
  margin-top: 0.2rem;
}
.friendgivecardtitle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333333;
  font-size: 0.3rem;
  margin-bottom: 0.2rem;
}
.friendgiveitem {
  width: 100%;
  height: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px dashed #cccccc;
}

.friendgiveitem img {
  width: 0.72rem;
  height: 0.72rem;
  border-radius: 50%;
}
.fgcinfoleft {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}
.fgcname {
  color: #333333;
  font-size: 0.3rem;
  margin-left: 0.1rem;
}
.fgcinforight {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-end;
}
.fgccontext {
  font-size: 0.2rem;
  color: #333;
}

.fgcdate {
  font-size: 0.18rem;
  color: #f23c3c;
}
.fAssistuser {
  padding: 0 0.1rem;
}
.userinfoleft {
  display: flex;
  align-items: center;
  color: #333333;
  font-size: 0.2rem;
}
.userimg {
  border-radius: 50%;
  overflow: hidden;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.1rem;
}
.thankssuc {
  font-size: 0.24rem;
  color: #f23c3c;
  padding: 0.1rem 0.2rem;
  border: 1px solid #ffe5ea;
  border-radius: 0.22rem;
  margin-left: 0.1rem;
}

.thanksfalse {
  font-size: 0.3rem;
  color: #262626;
  font-weight: bold;
}
.thanksfalse2 {
  font-size: 0.3rem;
  color: #f2270c;
  font-weight: bold;
}
.thanksfalse1 {
  font-size: 0.24rem;
  color: #ff9900;
  font-weight: 500;
  margin-top: 0.14rem;
}
.friendCardimg {
  width: 1.13rem;
  height: 1.35rem;
  margin: 0 auto 0.35rem;
  display: block;
}
.mainbtn {
  width: 4rem;
  height: 0.76rem;
  background: linear-gradient(90deg, #f2270c 0%, #ff6420 100%);
  border-radius: 0.38rem;
  color: #fff;
  font-size: 0.3rem;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto 0.36rem;
}
.friendAssistTip {
  width: 100%;
  text-align: center;
  font-size: 0.2rem;
  color: #999999;
}
.redtext {
  color: #f23c3c;
}
</style>
