<template>
  <div class="ruleMaskDiv" v-if="show">
    <basicPop :pop="pop" @closeClick="closeClick">
      <div class="context1">
        <div class="context" v-html="ruleText"></div>
      </div>
    </basicPop>
  </div>
</template>

<script>
import basicPop from "./hdzxtbasicPop.vue";
import apis1 from "../../../util/apis1.js";
let { getRule } = apis1;
export default {
  props: [],
  components: {
    basicPop,
  },
  data() {
    return {
      pop:{
          title:'活动规则',
          titlepop:''
      },
      ruleText: "",
      // show:true
    };
  },
  created() {
    // console.log(this.ruleText);
    this.pop.titlepop = this.styleDataNew.titlepop
    this.pop.leftLineDiv = this.styleDataNew.leftLineDiv
    this.pop.rightLineDiv = this.styleDataNew.rightLineDiv
    // console.log(this.titlepop,"lplplplplp");
    document
      .querySelector("body")
      .setAttribute(
        "style",
        "position:#fixed;top:0;height:100%;overflow:hidden"
      );

    this.initData();
  },
  methods: {
    initData() {
      if (this.isTemplate == true) {
        console.log(this.templateData, "活动规则templateData");
        // this.ruleText = this.templateData;
        if (this.templateData) {
          var rules = this.templateData.activity.actRule;
          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 || 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/>");
          console.log(this.ruleText, "this.ruleText");
        } else {
          this.ruleText = "暂无规则";
        }
        return;
      } else {
        getRule((initDatas) => {
          console.log(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 = "暂无规则";
          }
        });
      }
    },
    closeClick() {
      document.querySelector("body").removeAttribute("style");
      this.submit();
      // this.$emit('closeClick');
    },
  },
};
</script>

<style lang="scss">
.ruleMaskDiv {
  .basicPopDiv {
    height: 9.13rem;
    .context1 {
      margin-top: 0.2rem;
      height: 100%;
      display: flex;
      // align-items: center;
      justify-content: center;
      font-size: 0.24rem;
      color: #333333;
    }
    .context {
      height: 7.5rem;
      overflow-y: scroll;
      padding: 0 0.3rem;
      word-break: break-all;
      line-height: 0.4rem;
    }
  }
}
</style>
