<template>
  <div>
    <div v-if="isData">
      <div class="tit">
        <span>首粒入球/最后一粒入球</span>
      </div>
      <div class="playCode">
        <div class="tbody">
          <div>最先进球</div>
          <div>最后进球</div>
          <div>没有进球</div>
        </div>
        <div class="info">
          <span class="before">
            <div
              class="team"
              v-for="(item,index) in data"
              v-if="item.odds_code == 'flbfh'"
            >
              <span class="teamName">{{home_team}}</span>
              <span v-if="item.odds <= 0"  class="odds">
                  <img style="vertical-align:middle;width:0.2rem" src="@/assets/st-imges/mima.png" alt="">
              </span>
              <span v-else
                class="odds"
                :class="{chooseStyle:item.isTrue,rising:item.change == 'rising',falling:item.change == 'falling'}"
                @click="betMethod(index,item.id,home_team,'最先进球')"
              >{{item.odds}}</span>
            </div>
            <div
              class="team"
              v-for="(item,index) in data"
              v-if="item.odds_code == 'flbfg'"
            >
              <span class="teamName">{{guest_team}}</span>
              <span v-if="item.odds <= 0"  class="odds">
                  <img style="vertical-align:middle;width:0.2rem" src="@/assets/st-imges/mima.png" alt="">
              </span>
              <span v-else
                class="odds"
                :class="{chooseStyle:item.isTrue,rising:item.change == 'rising',falling:item.change == 'falling'}"
                @click="betMethod(index,item.id,guest_team,'最先进球')"
              >{{item.odds}}</span>
            </div>
          </span>
          </div>
          <div class="after">
            <div
              class="team"
              v-for="(item,index) in data"
              v-if="item.odds_code == 'flblh'"
            >
              <span class="teamName">{{home_team}}</span>
              <span v-if="item.odds <= 0"  class="odds">
                  <img style="vertical-align:middle;width:0.2rem" src="@/assets/st-imges/mima.png" alt="">
              </span>
              <span v-else
                class="odds"
                :class="{chooseStyle:item.isTrue,rising:item.change == 'rising',falling:item.change == 'falling'}"
                @click="betMethod(index,item.id,home_team,'最后进球')"
              >{{item.odds}}</span>
            </div>
            <div
              class="team"
              v-for="(item,index) in data"
              v-if="item.odds_code == 'flblg'"
            >
              <span class="teamName">{{guest_team}}</span>
              <span v-if="item.odds <= 0"  class="odds">
                  <img style="vertical-align:middle;width:0.2rem" src="@/assets/st-imges/mima.png" alt="">
              </span>
              <span v-else
                class="odds"
                :class="{chooseStyle:item.isTrue,rising:item.change == 'rising',falling:item.change == 'falling'}"
                @click="betMethod(index,item.id,guest_team,'最后进球')"
              >{{item.odds}}</span>
            </div>
          </div>
          <div class="notHave row item-center">
            <div
              class="team"
              v-for="(item,index) in data"
              v-if="item.odds_code == 'flbn'"
            >
              <span class="teamName">没有进球</span>
              <span v-if="item.odds <= 0"  class="odds">
                  <img style="vertical-align:middle;width:0.2rem" src="@/assets/st-imges/mima.png" alt="">
              </span>
              <span v-else
                class="odds"
                :class="{chooseStyle:item.isTrue,rising:item.change == 'rising',falling:item.change == 'falling'}"
                @click="betMethod(index,item.id,'','没有进球')"
              >{{item.odds}}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
</template>
<script>
export default {
  data() {
    return {
      title: "FLB",
      data: [], //数据源
      isData: "", //是否有数据
      guest_team: "", //客队名
      home_team: "", //主队名
      // obj:'',//
      match_id: "",
      limit: "", //投注数量
      lg_id: "",
      match_inf:{},
    };
  },
  /***
   * 方法
   */
  methods: {
    //玩法分类
    playGrouping(data) {
      // let obj={};
      let betting = this.$store.getters.getBetting;
      data.forEach(e => {
         if(betting.length > 0){
          for(let i= 0; i< betting.length; i++){
            if(betting[i].title =="FLB" && betting[i].data.length >0){
              for(let j = 0 ; j < betting[i].data.length ; j++ ){
                if(betting[i].data[j].mark == e.mark){
                  this.$set(e,'isTrue',true);
                  //betting[i].data.splice(j,1);
                }
              }
              break;
            }
          }
        }
        
        e.lg_id = this.lg_id;
        // if(e.odds_code.startsWith('last_number')){
        // obj.a= true
        // }else if(e.odds_code.startsWith('half')){
        // obj.b= true;
        // }
      });
      // this.obj = obj;
    },
    /*---------------------------------- */
    //玩法投注
    betMethod(index, id, name, playName) {
      let betting;
      let _this = this;
      let ballId = this.$store.getters.getBallCode;
      let bettingType = this.$store.getters.getBettingType;

      if(bettingType == 2){
        betting = this.$store.getters.getPassBetting;
        betting = betting == null ? []:betting;
        for(let e in betting){
          if(betting[e].title == this.title){
            for(let i in betting[e].data ){
              for(let j in this.data){
                if(betting[e].data[i].mark  == this.data[j].mark ){
                  this.$set(this.data[j], "isTrue", false); 
                  break
                }
              }
            }
          }
        }
      }else if(bettingType == 1){
        betting = this.$store.getters.getBetting;
      }
      if (this.data[index].isTrue) {
        this.$set(this.data[index], "isTrue", false);
      } else {
        this.$set(this.data[index], "isTrue", true);
      }
      //调用投注公共方法
      let teamName = {
        home: this.home_team,
        guest: this.guest_team
      };
      this.$public.publicBetMethod(
        this.data,
        this.title,
        index,
        betting,
        teamName,
        playName,
        name,
        this.match_id,
        ballId,
        this.limit,
        bettigType,
        this.$store.getters.getActivity,
        this.match_inf,
        function(data, type) {
          if(bettingType == 2){
            _this.$store.dispatch("SET_PASSBETTING", []);
            _this.$store.dispatch("SET_PASSBETTING", data);
          }else{
            _this.$store.dispatch("SET_BETTING", []);
            _this.$store.dispatch("SET_BETTING", data);
          }
        }
      );
    }
  },
  /**
   * 计算属性
   */
  computed: {
    getGameRatio() {
      return this.$store.getters.getGameRatio;
    },
    //获取投注数据
    getBetting() {
      if(this.$store.getters.getBettingType == 2){
        return this.$store.getters.getPassBetting;
      }else{
        return this.$store.getters.getBetting;
      }
    },
    //获取投注数据数量
    getLimit() {
      return this.$store.getters.getLimit;
    }
  },
  /**
   * 监听器
   */
  watch: {
    getGameRatio(val) {
      this.lg_id = val.lg_id;
      this.match_id = val.match_id;
      this.guest_team = val.guest_team;
      this.home_team = val.home_team;
      this.match_inf={
        match_process:val.match_process,
        match_ptime:val.match_ptime,
        match_score:val.match_score,
      }
      val.oddsData.forEach(e => {
        if (e[0].p_code == this.title) {
          this.data = e;
          this.isData = true;
          this.playGrouping(this.data);
        }
      });
      //console.log(this.data);
    },
    //投注数据监听和处理
    getBetting(val) {
      if (val.length > 0) {
        let mark = this.$store.getters.getDeleteType;
        for (let i = 0; i < val.length; i++) {
          if (val[i].title == this.title) {
            for (let j = 0; j < this.data.length; j++) {
              if (this.data[j].mark == mark) {
                this.$set(this.data[j], "isTrue", false);
                break;
              }
            }
            break;
          }
        }
      } else {
        for (let j = 0; j < this.data.length; j++) {
          if (this.data[j].isTrue) {
            this.$set(this.data[j], "isTrue", false);
          }
        }
      }
    },
    //投注数量
    getLimit(val) {
      this.limit = val;
    }
  }
};
</script>
<style scoped>
.flex {
  display: flex;
  /* justify-content: space-between; */
  align-items: center;
  flex-direction: row;
  flex-wrap: wrap;
}
.rFlex {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.tit {
  background: #cdcdcd;
  font-size: 0.14rem;
  padding: 0 0.1rem;
  height: 0.4rem;
  line-height: 0.4rem;
  color: #333;
}
.playCode {
  background: #fff;
}
.tbody {
  height: 0.4rem;
  line-height: 0.4rem;
  background-color: #e5e5e5;
  color: rgb(90, 90, 90);
  text-align: left;
  display: flex;
}
.tbody div {
  font-size: 0.14rem;
  padding-left: 0.1rem;
  flex: 1 1 0%;
  display: flex;
  /* justify-content: center; */
}
.info {
  display: flex;
  flex-direction: row;
  align-items: center;
  height: 100%;
}
.info .before,
.after,
.notHave {
  flex: 1 1 0%;
  flex-direction: column;
}
.team {
  display: flex;
  justify-content: space-between;
  flex: 1 1 0%;
  height: 0.4rem;
  font-size: 0.14rem;
  padding: 0 0.1rem;
  align-items: center;
  border-bottom: 1px solid #d7d7d7;
  line-height: 0.4rem;
}
.odds {
  display: inline-block;
  width: 0.48rem;
  height: 0.3rem;
  border: 0.01rem solid #ccc;
  line-height: 0.3rem;
  text-align: center;
  border-radius: 0.05rem;
  cursor: pointer;
}
.odds:hover {
  background: #ddd;
  color: #f76649;
}
.after {
  border-left: 1px solid #d7d7d7;
  border-right: 1px solid #d7d7d7;
}
.notHave {
  height: 0.8rem;
}

.notHave .team {
  border: none;
  width: 100%;
}
.team:hover {
  background: #fff5e9;
}
.notHave .team:hover {
  background: #fff;
}
.after .team:nth-last-child(1),
.before .team:nth-last-child(1) {
  border-bottom: none;
}
</style>