<template>
  <div class="bargainTeamRule" v-if="helpStatus == 2 || helpStatus == 4 || ruleFlag == false" :style="styleData.bargainTeamRule">
    <div class="name-bt">
      <span class="name-left-bt" :style="styleData.bargainTeamRuleLeft"></span>
      <span>活动规则</span>
      <span class="name-right-bt" :style="styleData.bargainTeamRuleRight"></span>
    </div>
    <div class="context-bargainTeam" :style="styleData.contextBargainTeam">
      <div
        class="context1-bargainTeam"
        v-html="ruleText"
        :style="styleData.contextBargainTeam1"
      ></div>
    </div>
  </div>
</template>

<script>
import apis1 from "../../../util/apis1.js";
let { getRule } = apis1;
export default {
  props:["isTemplate", "datas", "keyData", "styleData", "templateData"],
  components: {
  },
  data() {
    return {
      title: "活动规则",
      ruleText: "",
      show:true,
      helpStatus: null,
      ruleFlag:true,
    };
  },
  created() {
    this.publicData.$on('bargainTeamHelpStatus', res => {
      this.helpStatus = res;
    });
    this.publicData.$on('bargainTeamJoin', res => {
      this.ruleFlag = false;
    });
    this.initData();
  },
  methods: {
    initData() {
      if (this.isTemplate == true) {
        if (this.templateData) {
          var rules = this.templateData.activity.actRule
            .trim()
            .toLowerCase()
            .split("\n");
          var rules1 = this.templateData.activity.actRule.trim().toLowerCase();
          var ua = navigator.userAgent.toLowerCase();
          var prompt1 = "本次活动为商家自发举办，与苹果公司及app store无关";
          var prompt2 = "本次活动为商家自发举办,与苹果公司及app store无关";
          var prompt3 = "本次活动为商家自发举办,与苹果公司及app store无关。";
          var prompt4 = "本次活动为商家自发举办，与苹果公司及app store无关。";

          if (rules1.indexOf(prompt1 || prompt2 || prompt3 || prompt4) != -1) {
            var a = rules.indexOf(prompt1);
            var b = rules.indexOf(prompt2);
            var c = rules.indexOf(prompt3);
            var e = rules.indexOf(prompt4);

            if (a != -1) {
              rules.splice(a, prompt1.length);
            }
            if (b != -1) {
              rules.splice(b, prompt2.length);
            }
            if (c != -1) {
              rules.splice(c, prompt3.length);
            }
            if (e != -1) {
              rules.splice(e, prompt4.length);
            }
          }
          if (/iphone|ipad|ipod/.test(ua)) {
            rules.push("本次活动为商家自发举办，与苹果公司及App Store无关。");
          }
          this.ruleText = rules.join("<br/>");
        } else {
          this.ruleText = "暂无规则";
        }
        return;
      } else {
        getRule((initDatas) => {
          var data = initDatas.data.trim();
          //渲染规则
          if (data) {
            if (data.trim() == "") {
              this.ruleText = "暂无规则";
            } else {
              var rules = data;
              rules = rules.replace(/app store/gi, "app store").split("\n");

              var rules1 = rules;

              var ua = navigator.userAgent;

              var prompt1 = "本次活动为商家自发举办，与苹果公司及app store无关";
              var prompt2 = "本次活动为商家自发举办,与苹果公司及app store无关";
              var prompt3 =
                "本次活动为商家自发举办,与苹果公司及app store无关。";
              var prompt4 =
                "本次活动为商家自发举办，与苹果公司及app store无关。";

              if (
                rules1.indexOf(prompt1) != -1 ||
                rules1.indexOf(prompt2) != -1 ||
                rules1.indexOf(prompt3) != -1 ||
                rules1.indexOf(prompt4) != -1
              ) {
                var a = rules.indexOf(prompt1);
                var b = rules.indexOf(prompt2);
                var c = rules.indexOf(prompt3);
                var e = rules.indexOf(prompt4);

                if (a != -1) {
                  rules.splice(a, prompt1.length);
                }
                if (b != -1) {
                  rules.splice(b, prompt2.length);
                }
                if (c != -1) {
                  rules.splice(c, prompt3.length);
                }
                if (e != -1) {
                  rules.splice(e, prompt4.length);
                }
              }

              if (/iphone|iPhone|ipad|iPad|ipod|iPod/.test(ua)) {
                rules.push(
                  "本次活动为商家自发举办，与苹果公司及App Store无关。"
                );
              }
              this.ruleText = rules.join("<br/>");
            }
          } else {
            this.ruleText = "暂无规则";
          }
        });
      }
    },
  },
};
</script>

<style lang="scss">

.context {

}

</style>
