<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-26 10:58:22
 * @LastEditTime: 2019-08-27 15:30:40
 * @LastEditors: Please set LastEditors
 -->
<template>
  <div>
    <!-- //v-for="(item,index) in data" -->
    <div v-if="isDisplay">
      <div v-if="obj.a">
        <yd-accordion>
          <yd-accordion-item title="波胆" open>
            <div>
              <div class="rulesName row average">
                <div class="row item-center">{{home_team}}</div>
                <div class="row item-center">和局</div>
                <div class="row item-center">{{guest_team}}</div>
              </div>
              <div class="row grids average">
                <div class="column">
                  <div class="gridsDiv row center" v-for="(item,index) in data.home " :key="item.id" v-if="data.home" >
                    <div  v-if="item.odds >0"  class="column average minGrid" 
                      :class=" {trueSelected:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'}"
                      @click="btnChoose(home_team,item,'波胆',data.home)" >
                      <span style="color:#f76649 ">{{item.condition}}</span>
                      <span>{{item.odds}}</span>
                    </div>
                    <div v-else  class="minGrid column center">
                      <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
                    </div>
                  </div>
                </div>
                <div class="column middle">
                  <div class="gridsDiv row center" v-for="(item,index) in data.arr " :key="item.id" v-if="data.arr" >
                    <div v-if="item.odds >0" class="column average minGrid" 
                      :class="{trueSelected:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'}"  
                      @click="btnChoose('和局',item,'波胆',data.arr)" >
                      <span style="color:#f76649 ">{{item.condition}}</span>
                      <span>{{item.odds}}</span>
                    </div>
                    <div v-else  class="minGrid column center">
                      <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
                    </div>
                  </div>
                </div>
                <div class="column">
                  <div class="gridsDiv row center"  v-for="(item,index) in data.goust " :key="item.id" v-if="data.goust" >
                    <div v-if="item.odds >0" class="column average minGrid" 
                      :class="{trueSelected:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'}" 
                      @click="btnChoose(guest_team,item,'波胆',data.goust)" >
                      <span style="color:#f76649 ">{{item.condition}}</span>
                      <span>{{item.odds}}</span>
                    </div>
                    <div v-else  class="minGrid column center">
                      <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
                    </div>
                  </div>
                </div>
              </div>
              <div style="background:#f8f8f8;">
                <div class="row rightAlignment center"  style="height: 0.88rem;" v-for="(item,index) in data.other" :key="item.id" v-if="item.odds_code == 'bo'">
                  <span>其他比分:</span>
                  <div v-if="item.odds >0" class="minGrid minGridAll"  :class=" item.isTrue ? 'trueSelected' :''"  @click="btnChoose('其他比分',item,'波胆',data.other)" >
                    {{item.odds}}
                  </div>
                  <div v-else  class="minGrid minGridAll">
                    <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 title="波胆-上半场" open>
            <div>
              <div class="rulesName row average">
                <div class="row item-center">{{home_team}}</div>
                <div class="row item-center">和局</div>
                <div class="row item-center">{{guest_team}}</div>
              </div>
              <div class="row grids average">
                <div class="column">
                  <div class="gridsDiv row center" v-for="(item,index) in data.home_h " :key="item.id" v-if="data.home_h" >
                    <div v-if="item.odds >0" class="column average minGrid" :class="{trueSelected:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'}" 
                      @click="btnChoose(home_team,item,'波胆-上半场',data.home_h)">
                      <span style="color:#f76649 ">{{item.condition}}</span>
                      <span>{{item.odds}}</span>
                    </div>
                    <div v-else  class="minGrid column center">
                      <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
                    </div>
                  </div>
                </div>
                <div class="column middle">
                  <div class="gridsDiv row center" v-for="(item,index) in data.arr_h " :key="item.id" v-if="data.arr_h" >
                    <div v-if="item.odds >0" class="column average minGrid" :class="{trueSelected:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'} " 
                      @click="btnChoose('和局',item,'波胆-上半场',data.arr_h)">
                      <span style="color:#f76649">{{item.condition}}</span>
                      <span>{{item.odds}}</span>
                    </div>
                    <div v-else  class="minGrid column center">
                      <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
                    </div>
                  </div>
                </div>
                <div class="column">
                  <div class="gridsDiv row center" v-for="(item,index) in data.goust_h " :key="item.id" v-if="data.goust_h">
                    <div  v-if="item.odds >0" class="column average minGrid" 
                      :class="{trueSelected:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'}" 
                      @click="btnChoose(guest_team,item,'波胆-上半场',data.goust_h)" >
                      <span style="color:#f76649">{{item.condition}}</span>
                      <span>{{item.odds}}</span>
                    </div>
                    <div v-else  class="minGrid column center">
                      <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
                    </div>
                  </div>
                </div>
              </div>
              <div style="background:#f8f8f8;">
                <div class="row rightAlignment center" style="height: 0.88rem;" v-for="(item,index) in data.other " :key="item.id" v-if="item.odds_code.startsWith('bo_h')" >
                  <span>其他比分:</span>
                  <div v-if="item.odds >0" class="minGrid minGridAll"  :class="item.isTrue ? 'trueSelected' :'' "   @click="btnChoose('其他比分',item,'波胆-上半场',data.other)"
                  >{{item.odds}}</div>
                  <div v-else  class="minGrid minGridAll">
                    <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>
import "../css/index.css";
import Vue from "vue";
import { Accordion, AccordionItem } from "vue-ydui/dist/lib.rem/accordion";
Vue.component(Accordion.name, Accordion);
Vue.component(AccordionItem.name, AccordionItem);
export default {
  name: "WaveBladder",
  data() {
    return {
      title: "B",
      home_team: "",
      guest_team: "",
      isDisplay: false,
      data:{},
      match_id:'',
      lg_id:'',
      betting: [], //已投注倍率id集合
      dataNum: 10000, //对应的数据的下标
      obj:{},//
      match_score:[],//比分
      match_process:'',//比赛进程
    };
  },
  methods: {
    /****************玩法投注*****************/
    btnChoose: function(name,item,play_name,data) {
      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,
        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')
        }
      );
    },

    //数据排序处理
    dataSorting(data){
      let arr = [],home = [],goust = [],other = [],arr_h = [],home_h = [],goust_h = [];
      let obj ={};
      data.forEach((res, i) => {
        let odds_code = res.odds_code;
        if(!res.odds_code.endsWith("h")){
          obj.a = true
        }else if(res.odds_code.endsWith("h")){
          obj.b = true
        }
        this.obj = obj;
        if (odds_code.startsWith("bo") == true || odds_code.startsWith("bo_h") == true) {
          other.push(res);
        
        }else{
          if (odds_code[1] - odds_code[2] < 0 && res.odds_code.endsWith("h") != true) {
            //客队排序
            goust.push(res);
            goust.sort((a, z) => {
              let str1 = a.condition.split("-");
              let str2 = z.condition.split("-");
              if (str1[1] - str2[1] != 0) {
                return str1[1] - str2[1];
              } else {
                return str1[0] - str2[0];
              }
            });
          } else if(odds_code[1] - odds_code[2] < 0 == true && res.odds_code.endsWith("h") == true){
            goust_h.push(res);
            //客队排序半场
            goust_h.sort((a, z) => {
              let str1 = a.condition.split("-");
              let str2 = z.condition.split("-");
              if (str1[1] - str2[1] != 0) {
                return str1[1] - str2[1];
              } else {
                return str1[0] - str2[0];
              }
            });
          }else if (odds_code[1] - odds_code[2] > 0 && res.odds_code.endsWith("h") != true ) {
            home.push(res);
            // 主队排序
            home.sort((a, z) => {
              let str1 = a.condition.split("-");
              let str2 = z.condition.split("-");
              if (str1[0] - str2[0] != 0) {
                return str1[0] - str2[0];
              } else {
                return str1[1] - str2[1];
              }
            });
          }else if(odds_code[1] - odds_code[2] > 0 && res.odds_code.endsWith("h") == true){
            home_h.push(res);
            // 主队排序半场
            home_h.sort((a, z) => {
              let str1 = a.condition.split("-");
              let str2 = z.condition.split("-");
              if (str1[0] - str2[0] != 0) {
                return str1[0] - str2[0];
              } else {
                return str1[1] - str2[1];
              }
            });
          }else if (odds_code[1] - odds_code[2] == 0 && res.odds_code.endsWith("h") != true) {
            arr.push(res);
            // 和排序
            arr.sort((a, z) => {
              let str1 = a.condition.split("-");
              let str2 = z.condition.split("-");
              return str1[0] - str2[0];
            });
          }else if (odds_code[1] - odds_code[2] == 0 && res.odds_code.endsWith("h") == true) {
            arr_h.push(res);
            // 和排序半场
            arr_h.sort((a, z) => {
              let str1 = a.condition.split("-");
              let str2 = z.condition.split("-");
              return str1[0] - str2[0];
            });
          }

        }
      });
      this.data= {home_h,home, goust,goust_h,arr,arr_h,other} //[...home, ...goust, ...arr, ...other];
    },
    //编辑数据
    loopEditor(data,val){
      if(data){
        data.forEach(e =>{
          if(val =='all'){
            this.$set(e, "isTrue", false);
          }else{
            if(e.mark == val){
              this.$set(e, "isTrue", false);
            }
          }
        })
      }
    },
    //for编辑处理
    getisTrue(mark){
      for(let i = 0 ;i < this.data.home.length ; i++){
        if (this.data.home[i].mark == mark) {
          this.$set(this.data.home[i], "isTrue", true);
          return false
        }
      }
      for(let i = 0 ;i < this.data.home_h.length ; i++){
        if (this.data.home_h[i].mark == mark) {
          this.$set(this.data.home_h[i], "isTrue", true);
          return false
        }
      }
      for(let i = 0 ;i < this.data.goust.length ; i++){
        if (this.data.goust[i].mark == mark) {
          this.$set(this.data.goust[i], "isTrue", true);
          return false
        }
      }
      for(let i = 0 ;i < this.data.goust_h.length ; i++){
        if (this.data.goust_h[i].mark == mark) {
          this.$set(this.data.goust_h[i], "isTrue", true);
          return false
        }
      }
      for(let i = 0 ;i < this.data.arr.length ; i++){
        if (this.data.arr[i].mark == mark) {
          this.$set(this.data.arr[i], "isTrue", true);
          return false
        }
      }
      for(let i = 0 ;i < this.data.arr_h.length ; i++){
        if (this.data.arr_h[i].mark == mark) {
          this.$set(this.data.arr_h[i], "isTrue", true);
          return false
        }
      }
      for(let i = 0 ;i < this.data.other.length ; i++){
        if (this.data.other[i].mark == mark) {
          this.$set(this.data.other[i], "isTrue", true);
          return false
        }
      }
    }


  },
  computed: {
    getUserIcons() {
      return this.$store.getters.getGameRatio;
    },
    getBetting() {
      return this.$store.getters.getBetting;
    },
    //获取投注框删除的投注信息
    getDeleteType(){
      return this.$store.getters.getDeleteType;
    },
  },
  watch: {
    getUserIcons(val) {
      this.match_id=val.match_id
      if (!val) return false;
      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;
          //console.log(res);
          this.dataSorting(res);
          //this.data = res;
        }
      });
      let _this =this;
      this.$public.getBettingId(this.$store.getters.getBetting,this.title,function(data,index){
        _this.betting = data;
        _this.dataNum = index;
      });  
      if (this.dataNum != 10000) {
        this.betting.forEach(res => {
          this.getisTrue(res.mark)
        });
      }
    },
    //获取已投注信息
    getBetting(val) {
      let _this =this;
      this.$public.getBettingId(this.$store.getters.getBetting,this.title,function(data,index){
        _this.betting = data;
        _this.dataNum = index;
      });  
    },
    //监听投注框删除处理
    getDeleteType(val){      
      this.loopEditor(this.data.home,val);
      this.loopEditor(this.data.goust,val);
      this.loopEditor(this.data.other,val);
      this.loopEditor(this.data.arr,val);
      this.loopEditor(this.data.arr_h,val);
      this.loopEditor(this.data.home_h,val);
      this.loopEditor(this.data.goust_h,val);
    }
  }
};
</script>
<style scoped>
div /deep/ .yd-accordion-head {
  padding: 0 0.32rem;
  background: #a0a0a0;
  
  
}
div /deep/ .yd-accordion-head:after{
  height: 0;
}
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%;
}
.grids{
  width: 100%;
}
.grids div {
  background: #f4f4f4;
}
.trueSelected{
  color: #f4f4f4 !important
}
.middle {
  border-left: 1px solid #e4e4e4;
  border-right: 1px solid #e4e4e4;
}
.rulesName {
  font-size: 0.26rem;
  background: #bcbcbc;
  color: #333;
}
div /deep/ .yd-accordion-content:after{
  height: 0;
}
.gridsDiv,
.rulesName div {
  border-bottom: 1px solid #e4e4e4;
  height: 0.88rem;
  justify-content: center;
  width: 2.49rem;
}
.minGrid {
  width: 1.07rem;
  height: 0.76rem;
  font-size: 0.24rem;
  text-align: center;
  border: 1px solid #cecece;
  border-radius: 0.1rem;
}
.minGrid span {
  font-size: 0.24rem;
  padding: 0.08rem 0;
  line-height: 0;
  
}
.minGridAll {
  margin-right: 0.69rem;
  line-height: 0.76rem;
  text-align: center;
}
.trueSelected {
  background: #f76649 !important;
  border: 2px solid #f76649;
}
.trueSelected span {
  color: #f4f4f4 !important;
}
</style>

