<template>
  <div>
    <div v-if="isDisplay">
      <yd-accordion>
        <yd-accordion-item class="Match-game" title="独赢" open>
          <div v-for="(item ,index) in data" :key="index">
            <div class="box" style="background: #F4F4F4;">
              <div v-if="item.odds_code == 'capot_home'">
                <div class="row allAlignment center row-box">
                  <span>{{home_team}}</span>
                  <div
                    class="The-club-box row center"
                    :class="item.isTrue== true ? 'active' : ''"
                    @click="bettingBtn(item.id,home_team,item.odds,item.odds_only,item.p_code,match_id,item.condition)"
                  >
                    <span>{{item.odds}}</span>
                  </div>
                </div>
              </div>
              <div v-if="item.odds_code == 'capot_guest'">
                <div class="row allAlignment center row-box">
                  <span>{{guest_team}}</span>
                  <div
                    class="The-club-box row center"
                    :class="item.isTrue== true ? 'active ' : ''"
                    @click="bettingBtn(item.id,guest_team,item.odds,item.odds_only,item.p_code,match_id,item.condition)"
                  >
                    <span>{{item.odds}}</span>
                  </div>
                </div>
              </div>
              <div v-if="item.odds_code == 'capot_dogfall'">
                <div class="row allAlignment center row-box" style=" border-bottom:0;">
                  <span>和局</span>
                  <div
                    class="The-club-box row center"
                    :class="item.isTrue== true ? 'active' : ''"
                    @click="bettingBtn(item.id,'和局',item.odds,item.odds_only,item.p_code,match_id,item.condition)"
                  >
                    <span>{{item.odds}}</span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </yd-accordion-item>
      </yd-accordion>

      <yd-accordion>
        <yd-accordion-item class="Match-game" title="独赢-上半场" open>
          <div v-for="(item ,index) in data" :key="index">
            <div class="box" style="background: #F4F4F4;">
              <div v-if="item.odds_code == 'half_capot_home'">
                <div class="row allAlignment center row-box">
                  <span>{{home_team}}</span>
                  <div
                    class="The-club-box row center"
                    :class="item.isTrue== true ? 'active' : ''"
                    @click="bettingBtn(item.id,home_team,item.odds,item.odds_only,item.p_code,match_id,item.condition)"
                  >
                    <span>{{item.odds}}</span>
                  </div>
                </div>
              </div>
              <div v-if="item.odds_code == 'half_capot_guest'">
                <div class="row allAlignment center row-box">
                  <span>{{guest_team}}</span>
                  <div
                    class="The-club-box row center"
                    :class="item.isTrue== true ? 'active ' : ''"
                    @click="bettingBtn(item.id,guest_team,item.odds,item.odds_only,item.p_code,match_id,item.condition)"
                  >
                    <span>{{item.odds}}</span>
                  </div>
                </div>
              </div>
              <div v-if="item.odds_code == 'half_capot_dogfall'">
                <div class="row allAlignment center row-box" style=" border-bottom:0;">
                  <span>和局</span>
                  <div
                    class="The-club-box row center"
                    :class="item.isTrue== true ? 'active' : ''"
                    @click="bettingBtn(item.id,'和局',item.odds,item.odds_only,item.p_code,match_id,item.condition)"
                  >
                    <span>{{item.odds}}</span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </yd-accordion-item>
      </yd-accordion>
    </div>
  </div>
</template>

<script>
export default {
  // 独赢
  data() {
    return {
      title: "capot",
      home_team: " ",
      match_id:'',
      guest_team: " ",
      data: [],
      isDisplay: "", //是否显示
      betting: [], //已投注倍率id集合
      dataNum: 10000 //对应的数据的下标
    };
  },
  methods: {
    //玩法投注
    bettingBtn(id, name, odds,odds_only,p_code,match_id,condition = "", bettingTime = "") {
      console.log(this.data)
      let _this = this;
      let bettingInfo = {
        id,
        home_team: this.home_team,
        guest_team: this.guest_team,
        name,
        odds,
         ballId:this.$store.getters.getBallId,
        condition,
        ganame: this.title,
        score: this.score,
        bettingTime,
        odds_only,
        p_code,
        match_id,
      };
      //调用玩法投注公共方法
      this.$public.bettingFunction(
        this.betting,
        bettingInfo,
        this.data,
        this.$store.getters.getBetting,
        this.title,
        this.dataNum,
        function(res, type) {
          _this.$set(res, "isTrue", type);
        },
        function(data, val) {
          _this.$store.dispatch("BETTING", []);
          _this.$store.dispatch("BETTING", data ? data : val);
          if (_this.$store.getters.getIsBetting) return false;
          _this.$store.dispatch("ISBETTING", true);
        }
      );
    },
    //获取玩法id
    getBettingId(data) {
      if (data) {
        data.forEach((res, index) => {
          if (res.title == this.title) {
            this.betting = res.data;
            this.dataNum = index;
          }
        });
      }
    }
  },
  computed: {
    getUserIcons() {
      return this.$store.getters.getGameRatio;
    },
    getBetting() {
      return this.$store.getters.getBetting;
    },
    // 获取投注删除状态
    deleteType() {
      return this.$store.getters.getDeleteType;
    }
  },
  watch: {
    getUserIcons(val) {
      this.match_id=val.match_id
       console.log(val,'val')
      if (!val) return false;
     
      this.home_team = val.home_team;
      this.guest_team = val.guest_team;
      val.oddsData.forEach(res => {
        if (res[0].p_code == this.title) {
          this.isDisplay = true;
          this.data = res;
        }
      });
      this.getBettingId(this.$store.getters.getBetting);
      if (this.dataNum != 10000) {
        this.betting.forEach(res => {
          this.data.forEach((e, index) => {
            if (res.id == e.id) {
              this.$set(e, "isTrue", true);
            }
          });
        });
      }
    },
    //获取已投注信息
    getBetting(val) {
      let _this = this;
      this.$public.getBettingId(val, this.title, function(data, index) {
        _this.betting = data;
        _this.dataNum = index;
      });
    },
     //监听投注框删除处理
  deleteType(val) {
    console.log("我要的数据B",val);
    this.data.forEach(e => {
      if (val == "all") {
        this.$set(e, "isTrue", false);
      } else {
        if (e.id == val) {
          this.$set(e, "isTrue", false);
        }
      }
    });
  },
  },
  mounted() {
    
  }
};
</script>

<style scoped>
div /deep/ .yd-accordion-head-arrow:after {
  border: none;
  width: 0.5rem;
  height: 0.5rem;
  background: url(../../assets/st-imges/xiangxia.png) no-repeat;
  background-size: 100% 100%;
}
div /deep/ .yd-accordion-head,
div /deep/ .yd-accordion-head-content,
div /deep/ .yd-accordion-title {
  height: 0.88rem;
  font-size: 0.28rem;
  color: #fefefe;
  background: #a0a0a0;
}
div /deep/ .yd-accordion-head {
  padding: 0 0.32rem;
}
.box {
  padding: 0 0.32rem;
}
.row-box {
  height: 0.9rem;
  font-size: 0.26rem;
  border-bottom: 1px solid #e4e4e4;
}
.The-club-box {
  width: 1.07rem;
  height: 0.76rem;
  font-size: 0.24rem;
  padding: 0.1rem;
  border: 2px solid #cecece;
  border-radius: 0.1rem;
  margin-right: 0.1rem;
}
.active {
  background: #f76649;
  color: #f4f4f4;
  padding: 0.1rem;
  border: 2px solid #f76649;
}
.active i {
  color: #f4f4f4 !important;
}
</style>
