<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-26 10:58:22
 * @LastEditTime: 2019-08-27 15:58:41
 * @LastEditors: Please set LastEditors
 -->
<template>
  <div>
    <div v-if="isDisplay">
      <yd-accordion>
        <!-- 组件标题 -->
        <yd-accordion-item class="Match-game" title="半场/全场" open>
          <div style="background: #F0F0F0;">
            <div v-for="(item, index) in data" class="list-row" :key="index">
              <div v-for="(items,i) in titleKey" :key="i" v-if="item.odds_code == items ">
                <span class="The-club">{{ titleData[i]}}</span>
              </div>
              <span v-if="item.odds > 0" class="The-club-box"
                :class="{active:item.isTrue,increased_color:item.change == 'add',reduce_color:item.change == 'red'}"
                @click="bettingBtn(item.condition,item,'半场/全场')"
              >
                <!-- <i style="color: #FD8F26;" v-if="item.num">{{ item.num.num1 }}</i> -->
                <i>{{ item.odds}}</i>
              </span>
              <div v-else  class="The-club-box column center">
                <img style="width: 0.7rem;height: 0.5rem;" src="@/assets/st-imges/mima.png"><img>
              </div>
            </div>
          </div>
        </yd-accordion-item>
      </yd-accordion>
    </div>
  </div>
</template>

<script>
export default {
  // 让球
  data() {
    return {
      title: "HF",
      data: [], //数据源
      home_team: "", //主队名
      guest_team: "", //客队名
      isDisplay: false, //是否显示
      titleKey: [], //
      match_id:'',
      lg_id:'',
      titleData: [], //
      betting: [], //已投注倍率id集合
      dataNum: 10000 //对应的数据的下标
    };
  },
  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')
        }
      );
    },
    //获取玩法id
    getBettingId(data) {
      if (data) {
        data.forEach((res, index) => {
          if (res.title == this.title) {
            this.betting = res.data;
            this.dataNum = index;
          }
        });
      }
    }
  },
  computed: {
    //从Vuex获取数据
    getUserIcons() {
      return this.$store.getters.getGameRatio;
    },
    getBetting() {
      return this.$store.getters.getBetting;
    },
    //获取投注框删除的投注信息
    getDeleteType(){
      return this.$store.getters.getDeleteType;
    },
  },
  watch: {
    //监听vuex里面数据
    getUserIcons(val) {
      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;
          // console.log("获取数据", res);
        }
      });
      let objs = {
        hfhh: this.home_team + "/" + this.home_team,
        hfhd: this.home_team + "/和局",
        hfhg: this.home_team + "/" + this.guest_team,
        hfdh: "和局/" + this.home_team,
        hfdd: "和局/和局",
        hfdg: "和局/" + this.guest_team,
        hfgh: this.guest_team + "/" + this.home_team,
        hfgd: this.guest_team + "/和局",
        hfgg: this.guest_team + "/" + this.guest_team
      };
      this.titleKey = Object.keys(objs);
      this.titleData = Object.values(objs);

      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-head,
div /deep/ .yd-accordion-head-content,
div /deep/ .yd-accordion-title {
  font-size: 0.28rem;
  color: #fefefe;
  background: #a0a0a0;
}
div /deep/ .yd-accordion-head {
  padding: 0 0.32rem;
}
.Match-game {
  position: relative;
}
.Match-game-stat {
  position: absolute;
  right: 1.35rem;
  color: #fd8f26;
  font-size: 0.23rem;
}
.list-row {
  display: flex;
  justify-content: space-between;
  height: 0.87rem;
  background: #f4f4f4;
  border-bottom: 1px solid #e4e4e4;
  align-items: center;
  padding: 0 0.32rem;
}
.The-club {
  font-size: 0.24rem;
}
.The-club-box {
  display: inline-block;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  width: 1.07rem;
  height: 0.76rem;
  font-size: 0.24rem;
  padding: 0.1rem;
  border: 1px solid #cecece;
  border-radius: 0.1rem;
  margin-right: 0.1rem;
}
.active {
  background: #f76649;
  padding: 0.1rem;
  border: 2px solid #f76649;
}
.active i {
  color: #f4f4f4 !important;
}
</style>
