<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-26 10:58:22
 * @LastEditTime: 2019-08-26 15:21:04
 * @LastEditors: Please set LastEditors
 -->
<template>
  <div>
    <div v-if="isDisplay">
      <div v-if="obj.a">
        <yd-accordion :accordion="true">
          <yd-accordion-item title="进球:大/小" open>
            <div style="padding:0 0.32rem;" class="odds">
              <div class="row allAlignment center">
                <div style="width:50% ;" class="column">
                  <div v-for="(item,index) in data" :accordion="true" :key="index">
                    <div v-if="item.odds_code.startsWith('gsb') && !item.odds_code.endsWith('h')">
                      <!-- && item.odds_code.endsWith('big') -->
                      <div
                        style="border-right: 1px solid #e4e4e4; padding-right:0.1rem; "
                        class="small row allAlignment center"
                      >
                        <div>大</div>
                        <div v-if="item.odds >0 "  class="ratio column center"
                          :class="{col:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'} "
                          @click="bettingBtn('大',item,'进球大小')"
                        >
                          <span class="score">{{item.condition}}</span>
                          <span>{{item.odds}}</span>
                        </div>
                        <div v-else  class="ratio column center">
                          <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div style="width:50% ;" class="column">
                  <div v-for="(item,index) in data" :accordion="true" :key="index">
                    <div v-if="item.odds_code.startsWith('gss') && !item.odds_code.endsWith('h')">
                       <!-- && item.odds_code.endsWith('small') -->
                      <div class="small row allAlignment center">
                        <div>小</div>
                        <div v-if="item.odds >0 "  class="ratio column center"
                          :class="{col:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'} "
                          @click="bettingBtn('小',item,'进球大小')"
                        >
                          <span class="score">{{item.condition}}</span>
                          <span>{{item.odds}}</span>
                        </div>
                        <div v-else  class="ratio column center">
                          <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </yd-accordion-item>
        </yd-accordion>
      </div>
     
      <div v-if="obj.b">
        <yd-accordion :accordion="true">
          <yd-accordion-item title="进球:大/小-上半场" open>
            <div style="padding:0 0.32rem;" class="odds">
              <div class="row allAlignment center">
                <div style="width:50% ;" class="column">
                  <div v-for="(item,index) in data" :accordion="true" :key="index">
                    <!-- gsb_h -->
                    <div v-if="item.odds_code.startsWith('gsb') && item.odds_code.endsWith('h')">
                      <div
                        style="border-right: 1px solid #e4e4e4; padding-right:0.1rem; "
                        class="small row allAlignment center"
                      >
                        <div>大</div>
                        <div v-if="item.odds >0 " class="ratio column center"
                          :class="{col:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'}"
                          @click="bettingBtn('大',item,'进球大小-上半场')"
                        >
                          <span class="score">{{item.condition}}</span>
                          <span>{{item.odds}}</span>
                        </div>
                        <div v-else  class="ratio column center">
                          <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div style="width:50% ;" class="column">
                  <!-- || item.odds_code == 'gss_h' -->
                  <div v-for="(item,index) in data" :accordion="true" :key="index">
                    <div v-if="item.odds_code.startsWith('gss') && item.odds_code.endsWith('h')">
                      <div class="small row allAlignment center">
                        <div>小</div>
                        <div v-if="item.odds >0" class="ratio column center"
                          :class="{col:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'}"
                          @click="bettingBtn('小',item,'进球大小-上半场')"
                        >
                          <span class="score">{{item.condition}}</span>
                          <span>{{item.odds}}</span>
                        </div>
                        <div v-else  class="ratio column center">
                          <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </yd-accordion-item>
        </yd-accordion>


      </div>
    </div>
    <!-- <div class="BettingWindow" v-if="isWindow">
       <BettingWindow />
    </div>-->
  </div>
</template>
<script>
// import BettingWindow from "@/components/StBettingWindow";
export default {
  data() {
    return {
      title: "GS",
      isDisplay: false,
      home_team: "",
      guest_team: "",
      data: [],
      lg_id:'',
      match_id: "",
      obj:'',
      betting: [], //已投注倍率id集合
      dataNum: 10000 ,//对应的数据的下标
      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) {
          //console.log(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;
          }
        });
      }
    },
    //获取检测玩法
    playGrouping(data) {
      let obj ={};
      data.forEach(res => {
          // console.log(res)
        if(res.odds_code.startsWith('gs')&& (res.odds_code.endsWith('d')||res.odds_code.endsWith('s') )){
          obj.a =true;
        }else if(res.odds_code.endsWith('h')){
          obj.b =true;
        }
      });
      this.obj =obj      
    }
  },

  /**
   * 计算属性
   */
  computed: {
    getUserIcons() {
      return this.$store.getters.getGameRatio;
    },
    getBetting() {
      return this.$store.getters.getBetting;
    },
    //获取投注框删除的投注信息
    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) {
          //console.log("更新数据", res);
          this.playGrouping(res);
          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.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);
          }
        }
      });
    }
  }
  // component:{BettingWindow},
};
</script>
<style scoped>
div /deep/ .yd-accordion-head {
  padding: 0 0.32rem;
  background: #a0a0a0;
}
div /deep/ .yd-accordion-title {
  color: #fefefe;
  font-size: 0.28rem;
}
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%;
}
.small {
  font-size: 0.26rem;
  border-bottom: 1px solid #e4e4e4;
  padding-left: 0.16rem;
}
.odds {
  background: #f4f4f4;
  text-align: left;
}
.ratio {
  width: 1.07rem;
  height: 0.76rem;
  border: 1px solid #cecece;
  margin-right: 0.14rem;
  border-radius: 0.1rem;
  margin: 0.06rem;
}
.score {
  color: #f76649;
}
.col {
  background: #f76649;
  border: 2px solid #f76649 !important;
}
.col span {
  color: #f4f4f4 !important;
}
</style>
