<template>
  <div>
    <div class="serch row item-center allAlignment">
      <div class="row item-center">
        <div class="row item-center">
          <input
            class="fz14"
            type="text"
            placeholder="请输入球队名称"
            v-model="serchTxt"
            onkeyup="this.value=this.value.replace(/\s+/g,'')"
            color="#AAA"
          />
          <div class="row center serch-img pointer hover" @click="Serch()">
            <img src="@/assets/st-imges/serch.png" alt />
          </div>
        </div>
        <div class="row item-center">
          <div class="row center clear pointer hover br05 fz14" @click="clearSerchTxt()">清除</div>
        </div>
      </div>
      <div class="row center redraw pointer hover br05" @click="red()">
        <img src="@/assets/st-imges/redraw.png" alt />
      </div>
    </div>
    <!-- 标题 -->
    <div style="height:.5rem;background:#888;" class="pdg20 row allAlignment">
      <div
        class="row item-center"
        style="height:100%;color:#FFF;font-size:.16rem;font-weight:bold;"
      >篮球滚球</div>
      <div class="row item-center">
        <!-- <p style="font-size:.14rem;">显示</p>
        <div
          style="width:.5rem;height:.3rem;background:#AAA;color:#FFF;margin-left:.13rem;font-size:.14rem;"
          class="row center br05"
        >半场</div>
        <div
          style="width:.5rem;height:.3rem;background:#AAA;color:#FFF;margin-left:.13rem;font-size:.14rem;"
          class="row center br05"
        >单节</div> -->
      </div>
    </div>
    <div class="tennisRollBall" v-for="(item,index) in data" :key="item.id">
      <!-- 联赛名 -->
      <div class="tennisRollBall-title row item-center pdg20">{{item.leagueName}}</div>
      <div class="tennisRollBall-title-list" v-for="(items,i) in item.matchData" :key="items.id">
        <div class="tennisRollBall-title-list-title pdg20 row">
          <div style="width:24%;height:100%" class="row allAlignment item-center">
            <span>{{items.match_process}}</span>
            <span>
              <i style="color:#F76649" v-if="items.a_time != null">{{items.a_time}}</i>
              <i style="color:#F76649" v-else>00:00</i>
            </span>
            <div
              class="row center triangle tennisRollBall-title-list-title-num"
              style="background:#BBB;width:.5rem;height:.5rem;color:#fff;cursor: pointer;"
              @click="getTournamentPlay(items.match_id)"
            >{{items.tag}} ></div>
          </div>
          <div style="color:#666;width:70%;margin: 0 0.2rem;" class="row average item-center">
            <p style="width:30%;text-align: center;">独赢盘</p>
            <p style="width:30%;text-align: center;">让分</p>
            <p style="width:30%;text-align: center;">大/小</p>
            <!-- <p style="width:2rem;" class="row vertical-center">球队 大/小</p> -->
          </div>
        </div>
        <div class="row list-box pdg20" style="border-bottom:.01rem solid #EDEDED">
          <div class="list-box-name row item-center" style="line-height:.4rem;">
            <div style="width:.3rem;">
              <p style="color:#f76649">{{items.home_score}}</p>
              <p style="color:#f76649">{{items.guest_score}}</p>
            </div>
            <div>
              <p>{{items.home_team}}</p>
              <p>{{items.guest_team}}</p>
            </div>
          </div>
          <div class="row allAlignment" style="width:70%;margin: 0 0.2rem;">
            
              <!-- 独赢 -->
              <div style="width:30%;" class="column item-center">
                <div v-for="(itemList,idx) in items.oddsData" :key="itemList.id" >
                  <div style="padding:.01rem 0 ;" v-if="itemList.odds_code == 'ch'"class="capot home" >
                    <p v-if="itemList.odds <=0" class="singleAndDouble-list-btn">
                        <img style="vertical-align:middle" src="@/assets/st-imges/mima.png" alt="">
                    </p>
                    <p v-else class="singleAndDouble-list-btn hover"
                      :class="{col:itemList.isTrue,rising:itemList.change == 'rising',falling:itemList.change == 'falling'}"
                      @click="selection(index,i,idx,itemList.id,itemList.p_code,items.match_id,items.home_team,items.guest_team,items.home_team,'滚球')"
                    >{{itemList.odds}}</p>
                  </div>
                  <div v-if="itemList.odds_code == 'cg'" class="capot guest">
                    <p v-if="itemList.odds <=0" class="singleAndDouble-list-btn">
                        <img style="vertical-align:middle" src="@/assets/st-imges/mima.png" alt="">
                    </p>
                    <p v-else
                      class="singleAndDouble-list-btn hover"
                      :class="{col:itemList.isTrue,rising:itemList.change == 'rising',falling:itemList.change == 'falling'}"
                      @click="selection(index,i,idx,itemList.id,itemList.p_code,items.match_id,items.home_team,items.guest_team,items.guest_team,'滚球')"
                    >{{itemList.odds}}</p>
                  </div>
                </div>
              </div>

              <!-- 让球 -->
              <div style="width:30%;" class="column item-center">
                <div v-for="(itemList,idx) in items.oddsData" :key="itemList.id">
                  <div class="row item-center concede home" v-if="itemList.odds_code == 'coh'">
                    <span style="color:#f76649">{{itemList.condition}}</span>
                    <p v-if="itemList.odds <=0" class="singleAndDouble-list-btn">
                        <img style="vertical-align:middle" src="@/assets/st-imges/mima.png" alt="">
                    </p>
                    <p v-else
                      class="singleAndDouble-list-btn hover"
                      :class="{col:itemList.isTrue,rising:itemList.change == 'rising',falling:itemList.change == 'falling'}"
                      @click="selection(index,i,idx,itemList.id,itemList.p_code,items.match_id,items.home_team,items.guest_team,items.home_team,'滚球')"
                    >{{itemList.odds}}</p>
                  </div>
                  <div class="row item-center concede guest" v-if="itemList.odds_code == 'cog'">
                    <span style="color:#f76649">{{itemList.condition}}</span>
                    <p v-if="itemList.odds <=0" class="singleAndDouble-list-btn">
                        <img style="vertical-align:middle" src="@/assets/st-imges/mima.png" alt="">
                    </p>
                    <p v-else
                      class="singleAndDouble-list-btn hover"
                      :class="{col:itemList.isTrue,rising:itemList.change == 'rising',falling:itemList.change == 'falling'}"
                      @click="selection(index,i,idx,itemList.id,itemList.p_code,items.match_id,items.home_team,items.guest_team,items.guest_team,'滚球')"
                    >{{itemList.odds}}</p>
                  </div>
                </div>
              </div>

              <!-- 总分大小 -->
              <div style="width:30%;" class="column item-center">
                <div v-for="(itemList,idx) in items.oddsData" :key="itemList.id">
                  <div class="row item-center total home" v-if="itemList.odds_code == 'tnb'">
                    <span style="color:#f76649">大{{itemList.condition}}</span>
                    <p v-if="itemList.odds <=0" class="singleAndDouble-list-btn">
                        <img style="vertical-align:middle" src="@/assets/st-imges/mima.png" alt="">
                    </p>
                    <p v-else
                      class="singleAndDouble-list-btn hover"
                      :class="{col:itemList.isTrue,rising:itemList.change == 'rising',falling:itemList.change == 'falling'}"
                      @click="selection(index,i,idx,itemList.id,itemList.p_code,items.match_id,items.home_team,items.guest_team,'大','滚球')"
                    >{{itemList.odds}}</p>
                  </div>
                  <div class="row item-center total guest" v-if="itemList.odds_code == 'tns'">
                    <span style="color:#f76649">小{{itemList.condition}}</span>
                    <p v-if="itemList.odds <=0" class="singleAndDouble-list-btn">
                        <img style="vertical-align:middle" src="@/assets/st-imges/mima.png" alt="">
                    </p>
                    <p v-else
                      class="singleAndDouble-list-btn hover"
                      :class="{col:itemList.isTrue,rising:itemList.change == 'rising',falling:itemList.change == 'falling'}"
                      @click="selection(index,i,idx,itemList.id,itemList.p_code,items.match_id,items.home_team,items.guest_team,'小','滚球')"
                    >{{itemList.odds}}</p>
                  </div>
                </div>
              </div>

              <!-- 球队得分大小 -->
              <!-- <div
                style="width:2rem;flex-wrap: wrap;"
                class="row"
                v-if="itemList.odds_code.startsWith('tb')"
              >
                <div class="row item-center" v-if="itemList.odds_code == 'tbhb'">
                  <span style="color:#f76649">大{{itemList.condition}}</span>
                  <p
                    class="singleAndDouble-list-btn hover"
                    :class="{col:itemList.isTrue,rising:itemList.change == 'rising',falling:itemList.change == 'falling'}"
                    @click="selection(index,i,idx,itemList.id,itemList.p_code,items.match_id,items.home_team,items.guest_team,'大','滚球')"
                  >{{itemList.odds}}</p>
                </div>
                <div class="row item-center" v-if="itemList.odds_code == 'tbhs'">
                  <span style="color:#f76649">小{{itemList.condition}}</span>
                  <p
                    class="singleAndDouble-list-btn hover"
                    :class="{col:itemList.isTrue,rising:itemList.change == 'rising',falling:itemList.change == 'falling'}"
                    @click="selection(index,i,idx,itemList.id,itemList.p_code,items.match_id,items.home_team,items.guest_team,'小','滚球')"
                  >{{itemList.odds}}</p>
                </div>
              </div> -->
          </div>
          <div @click="promptInfo()" class="right-img column center ">
            <img style="margin-bottom:.1rem" src="@/assets/st-imges/TheGame.png" />
            <br />
            <img src="@/assets/st-imges/TheScore.png" />
          </div>
        </div>
      </div>
    </div>
    <div v-if="noData">
      <noData />
    </div>
  </div>
</template>

<script>
import noData from "@/components/noData";
export default {
  name: "BasketballRollBall",
  components: {
    noData
  },
  data() {
    return {
      serchTxt: "",
      lg_id: "", //联赛
      noData: false,
      noShow: true,
      data: [], //数据
      dataList:'',//临时数据
      limit: "", //投注长度
      timers: true
    };
  },
  /**
   * 组件内函数方法
   */
  methods: {
    /*******************直播比赛数据提示*******************/
    promptInfo() {
      this.$dialog.alert({ mes: "此功能暂未开放" });
    },

    getTournamentPlay(match_id) {
      this.$store.dispatch("MACTH_ID", match_id);
      this.$store.dispatch("SET_CONTROLROUTING", 10012);
    },
    // 获取数据
    getAjax(lg_id, search) {
      this.$http
        .get(this.$ports.home.gameList, {
          type: this.$store.getters.getActivity,
          game_code: this.$store.getters.getBallCode,
          lg_id, //需要拷贝
          search
        })
        .then(res => {
          if (res.data.data.length > 0 && res.data.status == 1) {
            this.noData = false;
            //数据匹配判断是否上一次有数据
            if(this.dataList.length){
              this.$public.oddsDataUpdate(res.data.data[0],this.dataList,1)
            }
            this.data = res.data.data[0];
            //临时储存数据
            this.dataList = JSON.stringify(res.data.data[0]);
          //  console.log('data', this.data)
            this.dataGroup(this.data);
          } else {
            this.noData = true;
            this.noShow = false;
          }
          this.$store.dispatch("GETLOADING", false);
        });
    },
    // 进入添加选中效果
    dataGroup(data) {
      let betting = this.$store.getters.getBetting;
      if (betting != null && betting.length > 0) {
        // console.log('bet',betting)
        data.forEach(e => {
          e.matchData.forEach(k => {
            k.oddsData.forEach(item => {
              betting.forEach(i => {
                i.data.forEach(j => {
                  if (j.mark == item.mark) {
                    item.isTrue = true;
                  }
                });
              });
            });
          });
        });
      }
    },
    //搜索按钮被点击
    Serch() {
        this.data = [];
        this.$store.dispatch("SET_LEAGUEDATA", []); //需要拷贝
        this.getAjax("", this.serchTxt);
    },
    // 删除搜索框内容
    clearSerchTxt() {
      if (this.serchTxt != "") {
        this.data = [];
        this.serchTxt = "";
        this.$store.dispatch("SET_LEAGUEDATA", []); //需要拷贝
        this.getAjax();
      }
    },
    // 刷新
    red() {
      this.$store.dispatch("SET_LEAGUEDATA", []); //需要拷贝
      if (this.serchTxt.length > 0) {
        this.Serch();
      } else {
        this.data = "";
        this.getAjax();
      }
    },
    // 选中添加数据与样式
    selection(
      index,
      i,
      idx,
      id,
      p_code,
      match_id,
      homeName,
      guestName,
      name,
      playName
    ) {
      // console.log(index,i,idx,id,p_code,match_id,homeName,guestName,name,playName)
      let ballId = this.$store.getters.getBallCode;
      let acty = this.$store.getters.getActivity;
      let _this = this;
      let betting = this.$store.getters.getBetting;
      let teamName = {
        home: homeName,
        guest: guestName
      };
      this.$public.publicBetting(
        this.data,
        p_code,
        id,
        index,
        i,
        idx,
        betting,
        acty,
        match_id,
        teamName,
        playName,
        name,
        ballId,
        this.limit,
        (data, type,mark)=> {
          if (type) {
            _this.$dialog.toast({ mes: "亲，超出表格上限啦。", timeout: 2000 });
          }
          _this.$store.dispatch("SET_BETTING", []);
          _this.$store.dispatch("SET_BETTING", data);
          //页面样式处理
          if (this.limit < 10) {
            this.data[index].matchData.forEach((val, i) => {
              val.oddsData.forEach(item => {
                if (item.mark == mark) {
                  this.$forceUpdate();
                  this.$set(item, "isTrue", item.isTrue ? false : true);
                }
              });
            });
          } else {
            this.data[index].matchData.forEach(val => {
              val.oddsData.forEach(item => {
                if (item.mark == mark) {
                  this.$set(item, "isTrue", false);
                }
              });
            });
          }
        }
      );
    }
  },
  mounted() {
    //获取选择的联赛id
    if (this.$store.getters.getLeagueData.length > 0) {
      if (this.$store.getters.getLeagueData.length == 1) {
        this.lg_id = this.$store.getters.getLeagueData[0];
      } else {
        this.lg_id = this.$store.getters.getLeagueData.join(",");
      }
    }
    this.$store.dispatch("SET_BETTING", []);
    this.getAjax(this.lg_id);
    let _this = this;
    this.$public.ajaxTimerFun(timing => {
      if (_this.timers) {
        _this.getAjax(_this.lg_id, _this.serchTxt);
      } else {
        clearInterval(timing);
      }
    });
  },
  computed: {
    getActy() {
      return this.$store.getters.getActivity;
    },
    getDeleteType() {
      return this.$store.getters.getDeleteType;
    },
    // 获取投注数量
    getLimit() {
      return this.$store.getters.getLimit;
    }
  },
  watch: {
    getActy(val) {
      // this.activity = val;
      this.getAJAX();
      this.$store.dispatch("SET_BETTING", []);
    },
    // 删除选中数据
    getDeleteType(val) {
      let jumpOut = false;
      for (var i = 0; i < this.data.length; i++) {
        for (var k = 0; k < this.data[i].matchData.length; k++) {
          for (var j = 0; j < this.data[i].matchData[k].oddsData.length; j++) {
            if (this.data[i].matchData[k].oddsData[j].id == val) {
              this.$forceUpdate();
              this.data[i].matchData[k].oddsData[j].isTrue = false;
              jumpOut = true;
              break;
            }
          }
          if (jumpOut == true) {
            break;
          }
        }
        if (jumpOut == true) {
          break;
        }
      }
    },
    getLimit(val) {
      this.limit = val;
      if (val == 0) {
        this.data.forEach(e => {
          e.matchData.forEach(k => {
            k.oddsData.forEach(item => {
              if (item.isTrue) {
                item.isTrue = false;
              }
            });
          });
        });
      }
    }
  },
  beforeDestroy() {
    this.timers = false;
  }
};
</script>

<style scoped>
.pdg20 {
  padding: 0 0.2rem;
}
.tennisRollBall-title {
  height: 0.5rem;
  color: #fff;
  background: #aaa;
}
.tennisRollBall-title-list {
  background: #fff;
  font-size: 0.14rem;
}
.tennisRollBall-title-list-title {
  height: 0.5rem;
  background: #e5e5e5;
  color: #666;
}
.tennisRollBall-title-list-title-num::after {
  border-width: 0.05rem;
  border-left-color: #e5e5e5;
  border-top-color: #e5e5e5;
  left: 0.2rem;
  bottom: -0.05rem;
  transform: rotate(45deg);
}

.serch {
  width: 100%;
  height: 0.5rem;
  background: #aaa;
  padding: 0 0.2rem;
}
input {
  border: none;
  background: #efefef;
  padding-left: 0.2rem;
  width: 4.6rem;
  height: 0.3rem;
  border-radius: 0.05rem 0 0 0.05rem;
}
.serch-img {
  width: 0.5rem;
  height: 0.3rem;
  background: #666;
  border-radius: 0 0.05rem 0.05rem 0;
  margin-right: 0.3rem;
}
.all {
  width: rem;
  height: 0.3rem;
  background: #ddd;
  color: #333;
}
.clear {
  width: 0.6rem;
  height: 0.3rem;
  background: #666;
  color: #ccc;
  margin-right: 0.1rem;
}
.redraw {
  width: 0.3rem;
  height: 0.3rem;
  background: #666;
}
img {
  width: 0.2rem;
  height: 0.2rem;
}
.br05 {
  border-radius: 0.05rem;
}
.fz14 {
  font-size: 0.14rem;
}
.hover:hover {
  background: #bbb;
  color: #fff;
}
.pointer {
  cursor: pointer;
}
.tennisRollBall-list-name p {
  width: 100%;
}
.tennisRollBall-list-name p span {
  display: inline-block;
  width: 0.08rem;
  height: 0.08rem;
  border-radius: 50%;
}
.right-img {
  width: 0.15rem;
  /* position: absolute; */
  right: -0.3rem;
  bottom: 0.1rem;
}
.right-img img {
  width: 0.22rem;
  height: 0.2rem;
}
.singleAndDouble-list-btn {
  width: 0.48rem;
  height: 0.3rem;
  border: 0.01rem solid #ccc;
  line-height: 0.3rem;
  text-align: center;
  border-radius: 0.05rem;
  cursor: pointer;
  margin: 0.05rem;
}
.tennisRollBall-list-footer-num span {
  margin-right: 0.1rem;
}
.list-box-name {
  width: 24%;
}
.hover:hover {
  background: #bbb;
  color: #fff;
}
.col {
  border-radius: 2px;
  background: #f76649;
  color: #fff;
}
.guest {
  /* position: absolute;
  top: 50%; */
  display: flex;
  justify-content: flex-end;
  /* width: 1.2rem; */
}
.home {
  /* position: absolute;
  top: 5%; */
  display: flex;
  justify-content: flex-end;
  /* width: 1.2rem; */
}
.capot {
  left: -8%;
}
.concede {
  left: 16%;
}
.total {
  left: 36%;
}
</style>