<template>
  <div v-if="show">
    <div class="activePrizeDiv">
      <!-- <div class="userHeader">
        <img :src="datalist.userImg" alt class="userHeaderimg" />
      </div> -->
      <div class="revivediv">
        <!-- <img
          class="reviveimg"
          :src="fuhuka == 0 ? 'https://img10.360buyimg.com/imgzone/jfs/t14536/268/2427872060/2017/109547aa/5a9eb4d8N918fa182.png' : '//img10.360buyimg.com/imgzone/jfs/t16684/140/682620380/2186/c3880f9/5a9eb4d8N76ae8c73.png'"
          alt
        /> -->
        <!-- <span class="revivespan">复活卡：{{fuhuka}}</span> -->
      </div>
      <div class="activeDiv">
        <div id="close" @click="closeClick()"></div>
        <div id="bottom-content">
          <div class="win-modal-footer win-modal-body">
            <!-- ======================================= 答题 ============================= -->
            <div
              class="win-modal-body"
              v-for="(item,index) in list"
              :key="index"
              v-if="selectNum == index"
            >
              <!--盒子-->
              <div class="question-num">第{{index + 1}}题</div>
              <!--第几题-->
              <div class="question-title">
                {{item.questionName}}
                <span
                  style="font-size:.24rem;color:red;"
                >{{item.questionType == 1 ? '(单选)' : "(多选)"}}</span>
              </div>
              <!--问题-->
              <div
                id="choice1"
                class="question-option"
                v-lz-click="'15'"
                @click="boom(index , item)"
                v-for="(data,index) in item.qaAnswerList"
                :key="data.id"
                :style="iconList[index] == true ? `background:${data.rightFlag == 1 ?selectColor:selectColorRed};` :`` "
                ref="gaise"
              >
                <!--A点击判断状态 --    ABCD选项卡-->
                <span class="num">
                  <van-icon
                    v-if="selectvote && (iconList[index] == true)"
                    :name="tutuList[data.rightFlag == 1 ?0:1].name"
                    :class="tutuList[data.rightFlag == 1 ?0:1].tutu"
                  />
                  <span class="no" v-else>{{ammolist[index]}}</span>
                </span>
                <!--图标-->
                <span class="choice">{{data.answerName}}</span>
                <!--答案-->
              </div>
            </div>
            <!-- ======================================================== 另 ========================== -->
            <!-- - 题目表单 -->
            <!-- <div class="win-modal-body" v-for="(item,index) in list" :key="index.id">
              <div class="question-num">第几题</div>
              <div class="question-title">问题</div>
            <div id="choice1" class="question-option " v-for="abc in item.answer" :key="abc.id" >      选项卡盒子-->
            <!-- <span class="choice">{{abc.xuanA}}--{{abc.daan}}--答案 </span>            选项卡内容 
              </div>
            </div>-->
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Vue from "vue";
import { Icon, Toast } from "vant";
Vue.use(Icon);
import {
  qasharePopComService,
  PrizeResultPopComService,
  qajoinPopComService,
} from "../../../util/comCreate.js";
import apis1 from "../../../util/apis1.js";
import bus from "../../../util/bus.js";
import store from "../../../store/store";
let { knowAnswer } = apis1;
import { goToShopPage } from "../../../util/tools.js";
import { allShare } from "../../../js/share.js";
export default {
  props: ["isTemplate", "datas", "styleData", "keyData", "templateData"],
  data() {
    return {
      aaaaaaa: "",
      nowclick: 0,
      isAnswer: 0,
      selectvote: false, //判定选项对错
      iconNum: 0, //判定显示的图标
      selectNum: 0, //控制当前第几题
      selectColor: "#d2e6f8", //控制当前选项的背景色
      selectColorRed: "", //控制当前选项的背景色
      checkNum: [], //当前点击的选项
      diandian: true,
      prizeResultData: {
        styleData: {},
        datas: {},
        keyData: {
          prizeUrl: "showImg",
          prizeName: "prizeName",
          prizeType: "prizeType",
          priceInfo: "priceInfo",
          discountType: "discountType",
          couponType: "couponType",
        },
      },
      list: [],
      ammolist: [],
      yesList: [],
      sukaList: [],
      iconList: [],
      tutuList: [
        {
          id: 1,
          name: "success",
          tutu: "rightNo",
        },
        {
          id: 2,
          name: "cross",
          tutu: "passNo",
        },
        {
          id: 3,
          name: "like",
          tutu: "wrongNo",
        },
      ],
      answerIdList: [],
    };
  },
  computed: {},
  created() {
    this.initdatas();
  },
  mounted() {},
  methods: {
    initdatas() {
      if (this.isTemplate) {
        this.$toast("活动预览，仅供查看");
        return;
      }
      let actStatus = sessionStorage.getItem("actStatus");
      if (actStatus == 2) {
        Toast("活动已结束");
        return;
      }
      if (actStatus == 1) {
        Toast("活动尚未开始");
        return;
      }
      this.list = this.datalist.activityQaBankByIds;
      for (var i = 0; i < 26; i++) {
        this.ammolist.push(String.fromCharCode(65 + i));
      }
    },
    boom(index, item) {
      if (this.isTemplate) {
        this.$toast("活动预览，仅供查看");
        return;
      }
      let actStatus = sessionStorage.getItem("actStatus");
      if (actStatus == 2) {
        Toast("活动已结束");
        return;
      }
      if (actStatus == 1) {
        Toast("活动尚未开始");
        return;
      }
      //isTrue 为点击选项的字母 select 为正确选项的字母
      if (this.nowclick == 0) {
        item.qaAnswerList.forEach((v, i) => {
          this.iconList.splice(i, 1, null);
        });
      }
      // let isAnswer = 0;
      var answerIdFlag = false;
      this.answerIdList.forEach((v) => {
        if (v == item.qaAnswerList[index].answerId) {
          answerIdFlag = true;
          return;
        }
      });
      if (answerIdFlag) {
        return;
      }
      if (this.isAnswer == 0) {
        this.isAnswer = 1;
        knowAnswer(
          this.dataId,
          item.questionId,
          item.qaAnswerList[index].answerId,
          (data) => {
            this.nowclick++;
            this.checkNum = index;
            if (item.questionType == 1) {
              if (data.data != "2") {
                this.iconList.splice(index, 1, true);
                this.selectColor = "green";
                this.iconNum = 0;
                this.selectvote = true;
                item.qaAnswerList[index].rightFlag = 1;
                setTimeout(() => {
                  if (this.selectNum >= this.list.length - 1) {
                    if (
                      data.data &&
                      data.data.prizeInfoId != null &&
                      data.data.prizeInfoId != ""
                    ) {
                      setTimeout(() => {
                        this.prizeResultData.datas = data.data;

                        PrizeResultPopComService.create(
                          this.prizeResultData,
                          data.data,
                          (submit) => {
                            qajoinPopComService.close();
                            PrizeResultPopComService.close();
                          }
                        );
                      }, 400);
                    } else {
                      if (data.data == "1") {
                        Toast("您来晚了，奖品已经发完了");
                      }
                      qajoinPopComService.close();
                    }
                  } else {
                    this.selectColor = "";
                    this.checkNum = null;
                    this.selectNum++;
                    this.nowclick = 0;
                    this.iconList = [];
                  }
                }, 300);
              } else {
                this.selectColorRed = "red";
                this.iconNum = 1;
                this.selectvote = true;
                this.iconList.splice(index, 1, true);
                setTimeout(() => {
                  qasharePopComService.create(this.datalist, (submit) => {
                    qasharePopComService.close();
                    this.selectColorRed = "";
                    if (submit == 1) {
                      qajoinPopComService.close();
                    } else if (submit == 2) {
                      this.submit(2);
                    } else if (submit == 3) {
                      this.submit(3);
                    }
                  });
                }, 300);
              }
            } else {
              this.answerIdList.push(item.qaAnswerList[index].answerId);
              if (data.data != "2") {
                this.selectColor = "green";
                this.iconList.splice(index, 1, true);
                this.iconNum = 0;
                this.selectvote = true;
                this.yesList.push(item.qaAnswerList[index].rightFlag);
                item.qaAnswerList[index].rightFlag = 1;
                if (item.rightCount == this.yesList.length) {
                  setTimeout(() => {
                    if (this.selectNum >= this.list.length - 1) {
                      if (
                        data.data &&
                        data.data.prizeInfoId != null &&
                        data.data.prizeInfoId != ""
                      ) {
                        setTimeout(() => {
                          this.prizeResultData.datas = data.data;

                          PrizeResultPopComService.create(
                            this.prizeResultData,
                            data.data,
                            (submit) => {
                              qajoinPopComService.close();
                              PrizeResultPopComService.close();
                            }
                          );
                        }, 400);
                      } else {
                        if (data.data == "1") {
                          Toast("您来晚了，奖品已经发完了");
                        }
                        qajoinPopComService.close();
                      }
                    } else {
                      this.iconList = [];
                      this.selectNum++;
                      this.nowclick = 0;
                      this.yesList = [];
                      this.sukaList = [];
                    }
                  }, 300);
                }
              } else {
                this.answerIdList = [];
                this.selectColorRed = "red";
                this.iconList.splice(index, 1, true);
                this.iconNum = 1;
                this.selectvote = true;
                setTimeout(() => {
                  qasharePopComService.create(this.datalist, (submit) => {
                    qasharePopComService.close();
                    this.selectColorRed = "";
                    if (submit == 1) {
                      this.submit(1);
                    } else if (submit == 2) {
                      this.submit(2);
                    } else if (submit == 3) {
                      this.submit(3);
                    }
                  });
                }, 300);
              }
            }
            setTimeout(() => {
              this.isAnswer = 0;
            }, 500);
          }
        );
      }
    },
    closeClick() {
      this.submit(1);
    },
    enterstore() {
      let shopId = store.state.shopId;
      goToShopPage(shopId);
    }, //邀请好友
    shareButton() {
      let actStatus = sessionStorage.getItem("actStatus");
      if (this.isTemplate) {
        this.$toast("活动预览，仅供查看");
        return;
      }
      if (actStatus == 2) {
        // Toast
        this.$toast("活动已结束");
        return;
      }
      if (actStatus == 1) {
        this.$toast("活动尚未开始");
        // Toast('活动尚未开始');
        return;
      }

      // Toast('活动正在惊醒中');
      // this.share = 1
      allShare(false, this, (callBackData) => {
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.userHeaderimg {
  width: 100%;
  height: 100%;
  border-radius: 100%;
}
.revivediv {
  position: absolute;
  top: 0.2rem;
  right: 0.4rem;
  float: right;
  width: 2rem;
  height: 0.8rem;
}
.reviveimg {
  width: 0.55rem;
}
.revivespan {
  font-size: 0.25rem;
  color: #fff;
  position: absolute;
  top: 0.5rem;
  left: 0.6rem;
}
.question-num {
  text-align: center;
  font-size: 0.3rem;
  color: #ffa033;
}
.question-title {
  padding: 0.2rem 0.2rem 0.4rem 0.2rem;
  position: relative;
  text-align: center;
  font-size: 0.35rem;
}
.question-option {
  padding: 0.15rem;
  height: 1rem;
  text-align: left;
  font-size: 0.3rem;
  border-radius: 30px;
  color: #333;
  margin-bottom: 0.15rem;
  position: relative;
  background-color: #d2e6f8;
}
.num {
  width: 0.5rem;
  height: 0.5rem;
  line-height: 0.5rem;
  background-color: #fff;
  border-radius: 100%;
  text-align: center;
  display: inline-block;
  vertical-align: middle;
  margin-top: 0.1rem;
}
.question-option .choice {
  line-height: 0.51rem;
  padding-top: 0.1rem;
  text-align: center;
  display: inline-block;
  width: 3.4rem;
  position: absolute;
  left: 0.9rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  right: 0;
}

.wrong {
  color: #fff;
  background-color: #f23c3c;
  border: none;
}

.rightNo {
  // display: none;
  color: #1dc11d;
}

.wrongNo {
  // display: none;
  color: #f23c3c;
}
.passNo {
  // display: none;
  color: red;
}

.van-icon {
  margin-top: 0.1rem;
  font-weight: bolder;
}
.userHeader {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 100%;
  position: absolute;
  top: 0.2rem;
  left: 0.4rem;
}
// ------------------------------------------------------------
.activePrizeDiv {
  position: fixed;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  top: 0;
  z-index: 200;
}

.activeDiv {
  height: 6.6rem;
  width: 5.27rem;
  position: absolute;
  z-index: 2;
  margin: auto;
  top: 2rem;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 0.2rem;
}

#close {
  width: 0.5rem;
  height: 0.5rem;
  position: absolute;
  right: -0.8rem;
  top: -2.2rem;
  background: url("//img10.360buyimg.com/imgzone/jfs/t21163/95/459418051/517/e07be561/5b0e40b3Nbd093241.png")
    no-repeat;
  background-size: 100% 100%;
  z-index: 1;
}

#bottom-content {
  background-color: white;
  margin: 0 auto;
  border-radius: 0.2rem;
  width: 6.4rem;
  padding: 0.36rem;
  text-align: center;
  position: absolute;
  top: -2rem;
  left: -0.5rem;
}
#bottom-content img {
  display: block;
  margin: auto;
}

#bottom-content p {
  /* padding-top: 0.2rem; */
  font-size: 0.36rem;
  color: #f23c3c;
  display: block;
  margin-top: 0.38rem;
  text-align: center;
  /* margin-top: 0.3rem; */
}

#bottom-content button {
  display: block;
  margin: 0 auto;
  margin-top: 1.06rem;
  width: 5rem;
  background-color: #e2231a;
  color: white;
  font-size: 0.28rem;
  border-radius: 0.1rem;
  border: 1px solid #e2231a;
  padding: 0.26rem 0;
}
.win-modal-footer {
  padding: 0 0.36rem 0.36rem 0.36rem;
  border-radius: 0 0 10px 10px;
  text-align: center;
  background: #fff;
  margin-top: -2px;
}
.showbtn {
  width: 50%;
  color: #666;
  font-size: 0.3rem;
  text-decoration: none;
}
</style>
