<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-26 10:58:22
 * @LastEditTime: 2019-08-27 16:35:56
 * @LastEditors: Please set LastEditors
 -->
<template>
  <div>
    <div v-if="isDisplay">
      <!-- 主队 -->
      <div v-if="obj.a">
        <yd-accordion> 
          <yd-accordion-item class="Match-game" :title="home_team+'进球:大小'" open>
            <div class="row allAlignment center rowBox" >
              <div class="width-box">
                <!-- item.odds_code.endsWith('big')&&  -->
                <div v-if="item.odds_code == 'tbhb'"  v-for=" (item,index) in data" class="row allAlignment center " style="border-right: 1px solid #e4e4e4">
                  <span>大</span>
                  <div v-if="item.odds >0" class="column center btn-box"
                    :class="{active:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'}"
                    @click="bettingBtn('大',item,'进球:大小')"
                  >
                    <span class="spanCol" v-if="item.condition">{{ item.condition }}</span>
                    <span>{{ item.odds }}</span>
                  </div>
                  <div v-else  class="btn-box column center">
                    <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
                  </div>
                </div>
              </div>
              <div class="width-box">
                <!-- item.odds_code.endsWith('small') &&  -->
                <div v-if="item.odds_code == 'tbhs'"  v-for=" (item,index) in data"   class="row allAlignment center">
                  <span style="padding-left: 0.2rem;">小</span>
                  <div v-if="item.odds >0" class="column center btn-box"
                    :class="{active:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'}"
                    @click="bettingBtn('小',item,'进球:大小')"
                  >
                    <span class="spanCol" v-if="item.condition">{{ item.condition }}</span>
                    <span>{{ item.odds }}</span>
                  </div>
                  <div v-else  class="btn-box column center">
                    <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
                  </div>
                </div>
              </div>
            </div>
          </yd-accordion-item>
        </yd-accordion>
      </div>
      <div v-if="obj.b">
        <!-- 主队上半场 -->
        <yd-accordion> 
          <yd-accordion-item class="Match-game" :title="home_team+'进球:大小-上半场'" open>
            <div class="row allAlignment center rowBox" >
              <div class="width-box">
                <!-- && item.odds_code.startsWith('half_home') -->
                <div v-if="item.odds_code.startsWith('tbhb_h')"  v-for=" (item,index) in data" class="row allAlignment center " style="border-right: 1px solid #e4e4e4">
                  <span>大</span>
                  <div v-if="item.odds >0" class="column center btn-box"
                    :class="{active:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'}"
                    @click="bettingBtn('大',item,'进球:大小-上半场')"
                  >
                    <span class="spanCol" v-if="item.condition">{{ item.condition }}</span>
                    <span>{{ item.odds }}</span>
                  </div>
                  <div v-else  class="btn-box column center">
                    <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
                  </div>
                </div>
              </div>
              <div class="width-box">
                <!-- && item.odds_code.startsWith('half_home') -->
                <div v-if="item.odds_code.startsWith('tbhs_h')"  v-for=" (item,index) in data"   class="row allAlignment center ">
                  <span style="padding-left: 0.2rem;">小</span>
                  <div v-if="item.odds >0" class="column center btn-box"
                    :class="{active:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'}"
                    @click="bettingBtn('小',item,'进球:大小-上半场')"
                  >
                    <span class="spanCol" v-if="item.condition">{{ item.condition }}</span>
                    <span>{{ item.odds }}</span>
                  </div>
                  <div v-else  class="btn-box column center">
                    <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
                  </div>
                </div>
              </div>
            </div>
          </yd-accordion-item>
        </yd-accordion>
      </div>

      <div v-if="obj.c">
        <!-- 客队 -->
        <yd-accordion> 
          <yd-accordion-item class="Match-game" :title="guest_team +'进球:大小'" open>
            <div class="row allAlignment center rowBox" >
              <div class="width-box">
                <!-- item.odds_code.endsWith('tbgb')&&  -->
                <div v-if="item.odds_code == 'tbgb'"  v-for=" (item,index) in data" class="row allAlignment center " style="border-right: 1px solid #e4e4e4">
                  <span>大</span>
                  <div v-if="item.odds >0" class="column center btn-box"
                    :class="{active:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'}"
                    @click="bettingBtn('大',item,'进球:大小')"
                  >
                    <span class="spanCol" v-if="item.condition">{{ item.condition }}</span>
                    <span>{{ item.odds }}</span>
                  </div>
                  <div v-else  class="btn-box column center">
                    <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
                  </div>
                </div>
              </div>
              <div class="width-box">
                <!-- item.odds_code.endsWith('small') &&  -->
                <div v-if="item.odds_code == 'tbgs'"  v-for=" (item,index) in data"   class="row allAlignment center ">
                  <span style="padding-left: 0.2rem;">小</span>
                  <div v-if="item.odds >0" class="column center btn-box"
                    :class="{active:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'}"
                    @click="bettingBtn('小',item,'进球:大小')"
                  >
                    <span class="spanCol" v-if="item.condition">{{ item.condition }}</span>
                    <span>{{ item.odds }}</span>
                  </div>
                  <div v-else  class="btn-box column center">
                    <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
                  </div>
                </div>
              </div>
            </div>
          </yd-accordion-item>
        </yd-accordion>
      </div>

      <div v-if="obj.d">
        <!-- 客队上半场 -->
        <yd-accordion> 
          <yd-accordion-item class="Match-game" :title="guest_team+'进球:大小-上半场'" open>
            <div class="row allAlignment center rowBox" >
              <div class="width-box">
                <!-- item.odds_code.endsWith('big')&&  -->
                <div v-if="item.odds_code.startsWith('tbgb_h')"  v-for=" (item,index) in data" class="row allAlignment center" style="border-right: 1px solid #e4e4e4">
                  <span>大</span>
                  <div v-if="item.odds >0" class="column center btn-box"
                    :class="{active:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'}"
                    @click="bettingBtn('大',item,'进球:大小-上半场')"
                  >
                    <span class="spanCol" v-if="item.condition">{{ item.condition }}</span>
                    <span>{{ item.odds }}</span>
                  </div>
                  <div v-else  class="btn-box column center">
                    <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
                  </div>
                </div>
              </div>
              <div class="width-box">
                <!-- item.odds_code.endsWith('small') &&  -->
                <div v-if="item.odds_code.startsWith('tbgs_h')"  v-for=" (item,index) in data"   class="row allAlignment center">
                  <span style="padding-left: 0.2rem;">小</span>
                  <div v-if="item.odds >0" class="column center btn-box"
                    :class="{active:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'}"
                    @click="bettingBtn('小',item,'进球:大小-上半场')"
                  >
                    <span class="spanCol" v-if="item.condition">{{ item.condition }}</span>
                    <span>{{ item.odds }}</span>
                  </div>
                  <div v-else  class="btn-box column center">
                    <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
                  </div>
                </div>
              </div>
            </div>
          </yd-accordion-item>
        </yd-accordion>
      </div>

    </div>
  </div>
</template>
<script>
export default {
  //总进球数
  data() {
    return {
      title: "TB",
      isDisplay: false,
      home_team: "",
      guest_team: "",
      data: [],
      lg_id: "",
      match_id: "",
      betting: [], //已投注倍率id集合
      dataNum: 10000, //对应的数据的下标
      obj:'',
      match_score:[],//比分
      match_process:'',//比赛进程
    };
  },
  methods: {
    bettingBtn(name,item,play_name) {
      let _this = this;
      let bettingInfo = item;
      bettingInfo.lg_id = this.lg_id;
      bettingInfo.match_id = this.match_id;
      bettingInfo.name = name;
      bettingInfo.home_team = this.home_team;
      bettingInfo.guest_team = this.guest_team;
      bettingInfo.ballId = this.$store.getters.getBallId,
      bettingInfo.oddsType = this.$store.getters.getActivity;
      bettingInfo.play_name = play_name;
      if( this.$store.getters.getActivity =='StRollBall'){
        bettingInfo.home_score = this.match_score[0];
        bettingInfo.guest_score = this.match_score[1];
        bettingInfo.roll_time = this.match_process;
      }
      //调用玩法投注公共方法
      this.$public.bettingFunction(
        this.betting,
        bettingInfo,
        this.data,
        this.$store.getters.getBetting,
        this.title,
        this.dataNum,
        this.$store.getters.getLimit,
        function(res, type) {
          _this.$set(res, "isTrue", type);
        },
        function(data, val,type) {
          if(type) {
            _this.$dialog.alert({mes: '你的注单已达到上限啦!'});
          }
          _this.$store.dispatch("BETTING", []);
          _this.$store.dispatch("BETTING", data ? data : val);
          if(_this.$store.getters.getIsBetting == '100') return false
          _this.$store.dispatch("ISBETTING",'100')
        }
      );
      if (this.$store.getters.getLimit * 1 >= 10) return false;
    },
    //获取玩法id
    getBettingId(data) {
      if (data) {
        data.forEach((res, index) => {
          if (res.title == this.title) {
            this.betting = res.data;
            this.dataNum = index;
          }
        });
      }
    },
    getGrouping(data){
      let obj ={}
      data.forEach(e => {
        if(e.odds_code.startsWith('tbh')&& !e.odds_code.endsWith('_h')){
          obj.a = true
        }else if(e.odds_code.startsWith('tbg')&& !e.odds_code.endsWith('_h')){
          obj.b = true
        }else if(e.odds_code.startsWith('tbh')&& e.odds_code.endsWith('_h')){
          obj.c = true
        }else if(e.odds_code.startsWith('tbg')&& e.odds_code.endsWith('_h')){
          obj.d = true
        }
      })
      this.obj = obj;
    }
  },
  computed: {
    getUserIcons() {
      return this.$store.getters.getGameRatio;
    },
    getBetting() {
      return this.$store.getters.getBetting;
    },
    //获取投注框删除的投注信息
    getDeleteType() {
      // console.log(this.$store.getters.getDeleteType)
      return this.$store.getters.getDeleteType;
    }
  },
  watch: {
    getUserIcons(val) {
      if (!val) return false;
      this.match_id = val.match_id;
      this.home_team = val.home_team;
      this.guest_team = val.guest_team;
      this.lg_id=val.lg_id;
      //获取滚球进程和比分数据
      if(this.$store.getters.getActivity == 'StRollBall'){
        let ball = this.$store.getters.getBallId;
        if(ball == 'zq'){
          this.match_process = `${val.match_process}-${val.match_ptime}`
        }else if(ball == 'lq'){
          this.match_process = `${val.match_process}-${val.match_ptime}`;
        }else if(ball == 'wq' && val.match_process){
          this.match_process = val.match_process.substr(val.match_process.length-1,1)
        }else if(ball == 'bq' && val.match_process){
          this.match_process = val.match_process.substr(val.match_process.length-1,1)
        }
        this.match_score = val.match_score.split('-');
      }
      val.oddsData.forEach(res => {
        if (res[0].p_code == this.title) {
          this.isDisplay = true;
          this.data = res;
          this.getGrouping(res)
          //console.log(res);
        }
      });
      this.getBettingId(this.$store.getters.getBetting);
      if (this.dataNum != 10000) {
        this.betting.forEach(res => {
          this.data.forEach((e, index) => {
            if (res.mark == e.mark) {
              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;
      });
    },
    //监听投注框删除处理
    getDeleteType(val) {
      this.data.forEach(e => {
        if (val == "all") {
          this.$set(e, "isTrue", false);
        } else {
          if (e.mark == val) {
            this.$set(e, "isTrue", false);
          }
        }
      });
    }
  }
};
</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-title {
  height: 0.88rem;
  font-size: 0.28rem;
  color: #fefefe;
}
div /deep/ .yd-accordion-head {
  padding: 0 0.32rem;
  background: #a0a0a0;
}
.rowBox {
  padding: 0 0.32rem;
  background: #f4f4f4;
  border-bottom: 1px solid #e4e4e4;
}
.width-box {
  width: 50%;
}
.right-box {
  padding-right: 0.32rem;
  padding-left: 0.2rem;
  border-bottom: 1px solid #e4e4e4;
}
.left-box {
  padding-left: 0.32rem;
  border-bottom: 1px solid #e4e4e4;
}
.btn-box {
  width: 1.07rem;
  height: 0.76rem;
  font-size: 0.24rem;
  padding: 0.1rem;
  border: 1px solid #cecece;
  border-radius: 0.1rem;
  margin: 0.1rem;
}

.active {
  background: #f76649;
  padding: 0.1rem;
  border: 1px solid #f76649;
}
.active span{
  color: #f4f4f4 !important;
}
.spanCol{
  color: #f76649;
}
</style>
