<template>
  <div class="head" :class="newIsShrink ?'hiddenbox':'bgcolor'">
    <div style="padding-top:2rem; height:100%;width:90%" class="baffleBox"  v-show="!newIsShrink">
      <div class="allBox">
        <div class="box">
          <div class="row allAlignment center">
            <span style="color:#f8f8f8;font-size:0.24rem;">余额:{{cash}}</span>
            <span style="font-size:0.28rem; color:#333333;font-weight:bold">投注单</span>
            <img style="width:.50rem;height:0.8rem" :src="img_size" alt @click="shrink()">
            <!-- style="color:#33333;font-size:0.24rem;" -->
          </div>
        </div>

        <!-- 数据列表 -->
        <div class="titleBox" v-for="(item,index) in dataList" :key="index" @click="activekey(index)" >
          <div class="tilteMatch">
            <div class="row center allAlignment" style="height:.5rem;padding-left:0.32rem">
              <span :style="item.repeat? 'background: #f76649;':'' ">{{item.play_name}}</span>
              <span class="cancel" @click.stop="delarr(item.p_code,item.mark)">
                <img style="width:.25rem;height:.25rem" :src="img" alt>
              </span>
            </div>
            <div class="tilteMatchDiv" style="min-height:1rem;padding:0 .32rem">
              <div class="row item-center" style="height:50%">
             
                <div v-if="item.p_code =='capot'">
                  <span>{{item.name}}</span>&emsp;
                  <span>{{item.condition == 1 ? item.home_team :item.condition == 'x'? '和局':item.condition == 2? item.guest_team:item.condition }}</span>@
                  <span>{{item.odds}}</span>
                </div>
                <div v-else>
                  <span>{{item.name}}</span>&emsp;
                  <span>{{item.condition}}</span>@
                  <span>{{item.odds}}</span>
                </div>
              </div>
              <div class="row item-center" style="height:50%;">
                <span>{{item.home_team}}</span>
                <span style="color:#F76649">vs</span>
                <span>{{item.guest_team}}</span>
              </div>
            </div>
          </div>
          <div class="bettingInput row item-center allAlignment">
            <div class="inputBox row allAlignment">
              <input
                class="input_text"
                type
                @click.stop="go()"
                v-model="bettingNumber[index]"
                placeholder="投注额"
                @click="activekey(index)"
              >
              <span style="padding:0 0.22rem;" @click.stop="ClearData(index)">
                <img style="width:.2rem;height:.2rem" :src="img" alt>
              </span>
            </div>
            <div class>
              <span v-if="bettingNumber[index]">{{(bettingNumber[index]*item.odds).toFixed(2)}}</span>
              <span v-else>可赢额</span>
            </div>
          </div>

          <div v-if="item.msg" class="promptStyle row center" >
              <img style="margin-right: 0.1rem;" src="../assets/st-imges/warning.png" /> {{item.msg}}
          </div>

          <div class="bottonBox row allAlignment" v-show="clickIndex==index">
            <div class="bottonBox-num  column allAlignment center">
              <div @click="additionFun(100,index) ">+100</div>
              <div @click="additionFun(1000,index) ">+1000</div>
              <div @click="additionFun(10000,index) ">+10000</div>
            </div>
            <div class="column allAlignment center" >
              <div class="row allAlignment center" style="width:3.8rem">
                <div v-for=" n in 3" @click="updateNumber(n,index)">
                  <button>{{n}}</button>
                </div>
              </div>
              <div class="row allAlignment center" style="width:3.8rem">
                <div v-for=" n in 3" @click="updateNumber(n+3,index)">
                  <button>{{n+3}}</button>
                </div>
              </div>
              <div class="row allAlignment center" style="width:3.8rem">
                <div v-for=" n in 3" @click="updateNumber(n+6,index)">
                  <button>{{n+6}}</button>
                </div>
              </div>
            </div>
            <div class="column allAlignment center" >
              <button class="btn-right"  @click="delNumder(index)" >x</button>
              <button class="btn-right"  style="margin:0.1rem 0;" @click="updateNumber('0',index)">0</button>
              <button class="btn-right" @click="updateNumber('00',index)">00</button>
            </div>
          </div>
        </div>

        <!-- 单注 -->
        <div class="showNumber" @click.stop="activekey('all')">
          <div v-if="dataList.length>1">
            <span v-if="dataList" style="font-size:.3rem">单注</span>
            <div class="bettingInput row item-center allAlignment">
              <div class="inputBox row allAlignment">
                <input type @click="go()" v-model="arrNumber" placeholder="投注额">
                <span class="cancel" @click.stop="ClearData('all')">
                  <img style="width:.2rem;height:.2rem" :src="img" alt>
                </span>
                <!-- <span @click.stop="ClearData('all')">x</span> -->
              </div>
              <div class>
                <span v-if="arrNumber">{{(datamMoney).toFixed(2)}}</span>
                <span v-else>可赢额</span>
              </div>
            </div>
            <!-- <div class="bottonBox" v-if="clickIndex=='all'">
              <div class="bottonBox-num row allAlignment" style="padding:0 .2rem">
                <div @click="additionFun(100,'all') ">+100</div>
                <div @click="additionFun(1000,'all')">+1000</div>
                <div @click="additionFun(10000,'all')">+10000</div>
              </div>
              <div style="margin-top:0.42rem;margin-bottom:0.42rem">
                <div class="row allAlignment center">
                  <div v-for=" n in 6" @click="updateNumber(n,'all')">
                    <button>{{n}}</button>
                  </div>
                </div>

                <div class="row allAlignment center" style="margin-top:0.17rem;">
                  <div v-for=" n in 3" @click="updateNumber(n+6,'all')">
                    <button>{{n+6}}</button>
                  </div>
                  <button @click="updateNumber('0','all')">0</button>
                  <button @click="updateNumber('00','all')">00</button>
                  <button
                    @click="delNumder('all')"
                    style="background:rgb(247, 102, 73);font-size:.4rem;line-height:.86rem;"
                  >x</button>
                </div>
              </div>
            </div> -->
            <div class="bottonBox row allAlignment" v-if="clickIndex=='all'">
              <div class="bottonBox-num  column allAlignment center">
                <div @click="additionFun(100,'all') ">+100</div>
                <div @click="additionFun(1000,'all') ">+1000</div>
                <div @click="additionFun(10000,'all') ">+10000</div>
              </div>
              <div class="column allAlignment center" >
                <div class="row allAlignment center" style="width:3.8rem">
                  <div v-for=" n in 3" @click="updateNumber(n,'all')">
                    <button>{{n}}</button>
                  </div>
                </div>
                <div class="row allAlignment center" style="width:3.8rem">
                  <div v-for=" n in 3" @click="updateNumber(n+3,'all')">
                    <button>{{n+3}}</button>
                  </div>
                </div>

                <div class="row allAlignment center" style="width:3.8rem">
                  <div v-for=" n in 3" @click="updateNumber(n+6,'all')">
                    <button>{{n+6}}</button>
                  </div>
              
                </div>
              </div>
              <div class="column allAlignment center" >
                <button class="btn-right"  @click="delNumder('all')" >x</button>
                <button class="btn-right"  style="margin:0.1rem 0;" @click="updateNumber('0','all')">0</button>
                <button class="btn-right" @click="updateNumber('00','all')">00</button>
              </div>
            </div>
          </div>
        </div>

        <!-- 过关投注  && compound.length > 0 -->
        <div v-if="!passThroughPlay && dataList.length > 2 ">
          <yd-accordion>
            <yd-accordion-item title="复式连串过关投注" open>
              <div
                class="showNumber"
                v-for="(item,index) in compound"
                @click.stop="activekey('through'+index)"
              >
                <span v-if="dataList" style="font-size:.3rem">{{item.title}}</span>
                <div class="bettingInput row item-center allAlignment">
                  <div class="row center">
                    <div class="inputBox row allAlignment">
                      <input type @click="go()" v-model="item.money " placeholder="投注额">
                      <!-- <span @click.stop="ClearData('through')">x</span> -->
                      <span class="cancel" @click.stop="ClearData('through',index)">
                        <img style="width:.2rem;height:.2rem" :src="img" alt>
                      </span>
                    </div>
                    <span style="font-size:0.26rem;margin-left: 0.1rem;">X{{item.index}}</span>
                  </div>
                  <div class>
                    <span v-if="item.money*1 > 0 ">{{(item.money * item.odds).toFixed(2)}}</span>
                    <span v-else>可赢额</span>
                  </div>
                </div>
                <!-- <div class="bottonBox" v-if="clickIndex=='through'+index">
                  <div class="bottonBox-num " style="padding:0 .2rem">
                    <div @click="additionFun(100,'through',index) ">+100</div>
                    <div @click="additionFun(1000,'through',index)">+1000</div>
                    <div @click="additionFun(10000,'through',index)">+10000</div>
                  </div>
                  <div style="margin-top:0.42rem;margin-bottom:0.42rem">
                    <div class="row allAlignment center">
                      <div v-for=" n in 6" @click="updateNumber(n,'through',index)">
                        <button>{{n}}</button>
                      </div>
                    </div>
                    <div class="row allAlignment center" style="margin-top:0.17rem;">
                      <div v-for=" n in 3" @click="updateNumber(n+6,'through',index)">
                        <button>{{n+6}}</button>
                      </div>
                      <button @click="updateNumber('0','through',index)">0</button>
                      <button @click="updateNumber('00','through',index)">00</button>
                      <button
                        @click="delNumder('through',index)"
                        style="background:rgb(247, 102, 73);font-size:.4rem;line-height:.86rem;"
                      >x</button>
                    </div>
                  </div>
                </div> -->
                <div class="bottonBox row allAlignment" v-if="clickIndex=='through'+index">
                  <div class="bottonBox-num  column allAlignment center">
                    <div @click="additionFun(100,'through',index) ">+100</div>
                    <div @click="additionFun(1000,'through',index) ">+1000</div>
                    <div @click="additionFun(10000,'through',index) ">+10000</div>
                  </div>
                  <div class="column allAlignment center" >
                    <div class="row allAlignment center" style="width:3.8rem">
                      <div v-for=" n in 3" @click="updateNumber(n,'through',index)">
                        <button>{{n}}</button>
                      </div>
                    </div>
                    <div class="row allAlignment center" style="width:3.8rem">
                      <div v-for=" n in 3" @click="updateNumber(n+3,'through',index)">
                        <button>{{n+3}}</button>
                      </div>
                    </div>

                    <div class="row allAlignment center" style="width:3.8rem">
                      <div v-for=" n in 3" @click="updateNumber(n+6,'through',index)">
                        <button>{{n+6}}</button>
                      </div>
                  
                    </div>
                  </div>
                  <div class="column allAlignment center" >
                    <button class="btn-right"  @click="delNumder('through',index)" >x</button>
                    <button class="btn-right"  style="margin:0.1rem 0;" @click="updateNumber('0','through',index)">0</button>
                    <button class="btn-right" @click="updateNumber('00','through',index)">00</button>
                  </div>
                </div>
              </div>
            </yd-accordion-item>
          </yd-accordion>

          <!-- <div class="row allAlignment center " style="height: 0.8rem;background: #ccc;padding: 0 0.2rem;">
          <span>复式连串过关投注</span>
          <img  style="width:.4rem;height:.4rem" src="../assets/st-imges/xiangxia.png" alt="">
          </div>-->
        </div>

        <div v-if="passThroughPlay" class="row center" style="background: #c3c0c0;height: 0.8rem;">
          <span style="color:red ">红色选项不可以结合进行过关投注</span>
        </div>

        <!-- 总数据展示 -->
        <div class="row allAlignment" style="padding:.1rem .2rem;background:#f8f8f8;">
          <span v-if="dataNum" class="showNumberSpan">所有投注({{dataNum}}):</span>
          <span v-else class="showNumberSpan">所有投注:</span>
          <span v-if="dataNumbe" style="font-size:0.24rem">{{(dataNumbe)}}</span>
          <span v-else style="font-size:0.24rem">0.00</span>
        </div>
        <div class="row allAlignment" style="padding:0 .2rem;background:#f8f8f8;">
          <span class="showNumberSpan">可赢金额:</span>
          <span
            v-if="datamMoney || compound_amount "
            style="font-size:0.24rem;color:#F76649;"
          >{{compound_amount *1 ?(compound_amount*1+datamMoney*1).toFixed(2):(datamMoney).toFixed(2)}}</span>
          <span v-else style="font-size:0.24rem;color:#F76649;">0.00</span>
        </div>
        <div style="background:#f8f8f8;padding:.1rem 0;border-radius: 0 0 .1rem .1rem; ">
          <div class="btn" style="background:#F76649;" @click="betOrder" v-if="isLogin">
            <span>确认投注</span>
          </div>
          <!-- <div class="btn" style="background:#F76649;" @click="betOrder" v-if="isLogin">
            <span>确认投注</span>
          </div> -->
          <div class="btn" style="background:#F76649;" @click="loginReg" v-else>
            <span>登陆/注册</span>
          </div>
          <div class="btn" style="background:#A1A1A1;" @click="shrink">
            <span>添加更多的选择</span>
          </div>
          <div class="btn" style="background:#333;margin-bottom:.1rem;" @click.stop="alldel()">
            <span>全删除</span>
          </div>
        </div>
      </div>

      <!-- <div class="loading_box row center" >
        <div class="weui-loading"></div>
      </div>-->
    </div>
    <div
      class="shrink"
      :style="newIsShrink?'':'display:none'"
      @click="show()"
    >
      投注单--选项
      <span class="num">{{dataList?dataList.length:'0'}}</span>
    </div>
    <!-- <div></div> -->
    <div v-if="isshow" class="login">
      <Login></Login>
    </div>
    <div v-else-if="rgShow" class="login">
      <register></register>
    </div>
  </div>
</template>
<script>
import "../css/index.css";
import Login from "@/pages/Login/index/StLogin";
import register from "@/pages/Login/index/register";
export default {
  data() {
    return {
      img: require("../assets/st-imges/del.png"),
      img_size: require("../assets/st-imges/narrow.png"),
      bettingNumber: [],
      balance: "", //余额
      bettingquantity: "", // 投注信息
      betting: "",
      dataList: [],
      arr: [], // 是否缩小
      isshrink: false, //小键盘显示位
      clickIndex: 0,
      // money:0,//可赢金额
      arrNumber: "", //单注数量
      dataNum: 0, //已投注数量
      dataNumbe: 0, //总投数
      datamMoney: 0, //可赢总金额
      isThrough: false, //触发过关玩法
      cash: 0.0, //余额
      compound: [], //复合玩法
      passThroughPlay: false, //判断比赛数据是否有相同赛事
      isLogin: false, //是否登陆
      isshow: false, //登陆显示/隐藏
      rgShow: false, //注册显示/隐藏
      compound_amount: "", //复合玩法可赢金额
      isSubmit: false ,//防止重复提交
      startEnd:true ,//玩法数据检测开关
      intervalId:'',
      banBets:2,//禁止投注,2=检测通过,3=检测未通过
    };
  },
  components: {
    Login,
    register
  },
  methods: {
    //
    /*---------------------------------- */
    //阻止input框获取焦点
    go: function() {
      document.activeElement.blur();
    },


    /**************检测玩法是否失效***************/
    checkFailure(data,type){
      this.$http.post(this.$ports.VerOddsScore, {
        data:JSON.stringify(data)
      }).then(res=>{
        if(res.status == 200){
          if(res.data.status == 1){
            if(res.data.data != 'ok' ){
              res.data.data.forEach(e=>{
                this.$set(this.dataList[e.sort],'msg',e.ver_mark);
                this.dataList[e.sort].status = e.status;
              })
            } 
          }
        }
      })
    },

    /*---------------------------------- */
    //小键盘数字字符串拼接
    updateNumber: function(val, index, num) {
      // console.log(index);
      let temporaryData = "";
      let isNumbers = true;
      if (index != "through" && index == "all") {
        temporaryData =
          this.arrNumber * 1 ? this.arrNumber + val + "" : val + "";
        if (temporaryData * 1 > 999999999) {
          temporaryData = 999999999 + "";
        }
        this.arrNumber = temporaryData;
      }
      if (index == "through") {
        isNumbers = false;
        let dataVal =
          this.compound[num].money * 1 > 0
            ? this.compound[num].money + (val + "")
            : val + "";
        if (dataVal * 1 > 999999999) {
          dataVal = 999999999 + "";
        }
        this.$set(this.compound[num], "money", dataVal);
      } else {
        this.dataList.forEach((e, i) => {
          if (index != "all" && index != "through") {
            if (index == i) {
              temporaryData =
                this.bettingNumber[index] * 1
                  ? this.bettingNumber[index] + (val + "")
                  : val + "";
              if (temporaryData * 1 > 999999999) {
                temporaryData = 999999999 + "";
              }
              this.bettingNumber.splice(index, 1, temporaryData);
              this.arrNumber = "";
            }
          } else if (index == "all") {
            this.bettingNumber.splice(i, 1, temporaryData);
          }
        });
      }
      this.profitFun();
    },

    /*---------------------------------------------*/
    //投注加法
    additionFun: function(val, index, num) {
      let data = "";
      let isNumbers = true;
      if (index != "through" && index == "all") {
        let dataAdd = 0;
        data =
          this.arrNumber * 1 ? this.arrNumber * 1 + val * 1 + "" : val + "";
        if (data * 1 > 999999999) {
          data = 999999999 + "";
        }
        this.arrNumber = data;
      }
      if (index == "through") {
        isNumbers = false;
        let dataVal =
          this.compound[num].money * 1 > 0
            ? this.compound[num].money * 1 + val * 1
            : val + "";
        if (dataVal * 1 > 999999999) {
          dataVal = 999999999 + "";
        }
        this.$set(this.compound[num], "money", dataVal);
      } else {
        this.dataList.forEach((e, i) => {
          if (index != "all" && index != "through") {
            if (index == i) {
              data =
                this.bettingNumber[index] * 1
                  ? this.bettingNumber[index] * 1 + val + ""
                  : val + "";
              if (data * 1 > 999999999) {
                data = 999999999 + "";
              }
              this.bettingNumber.splice(index, 1, data);
              this.arrNumber = "";
            }
          } else if (index == "all") {
            this.bettingNumber.splice(i, 1, data);
          }
        });
      }
      //if(!isNumbers) return false;
      this.profitFun();
    },

    /*---------------------------------- */
    //删除投注数的一位数
    delNumder: function(index, num) {
      //console.log(this.compound);
      let Str = this.bettingNumber;
      let strVal = "";
      let isNumbers = true;
      if (index == "through") {
        isNumbers = false;
        strVal = this.compound[num].money.substring(
          0,
          this.compound[num].money.length - 1
        );
        this.$set(this.compound[num], "money", strVal);
      } else {
        if (index != "all") {
          Str.forEach((e, i) => {
            if (i == index) {
              strVal = e;
              e = strVal.substring(0, strVal.length - 1);
              this.bettingNumber.splice(index, 1, e);
              this.arrNumber = "";
            }
          });
        } else {
          Str.forEach((e, i) => {
            strVal = e.substring(0, e.length - 1);
            // console.log(strVal);
            this.bettingNumber.splice(i, 1, strVal);
          });
          this.arrNumber = this.arrNumber.substring(
            0,
            this.arrNumber.length - 1
          );
        }
      }
      //if(!isNumbers) return false;
      this.profitFun();
    },

    /*---------------------------------- */
    //清空input框数据
    ClearData: function(index, num) {
      let isNumbers = true;
      if (index == "through") {
        //console.log(num);
        isNumbers = false;
        this.$set(this.compound[num], "money", "");
      } else {
        this.bettingNumber.forEach((e, i) => {
          if (index != "all") {
            if (i == index) {
              this.bettingNumber.splice(index, 1, "");
              this.arrNumber = "";
            }
          } else if (index == "all") {
            this.bettingNumber.splice(i, 1, "");
            this.arrNumber = "";
          }
        });
      }
      //if(!isNumbers) return false;
      this.profitFun();
    },

    /*---------------------------------- */
    // 删除所有投注
    alldel() {
      let betting = this.$store.getters.getBetting;
      betting.forEach(e => {
        e.data = [];
      });
      this.$store.dispatch("SET_NOROLL", false);
      this.bettingNumber = [];
      this.$store.dispatch("BETTING", []);
      this.$store.dispatch("BETTING", betting);
      this.$public.setItem("box_size", 2);
      this.$store.dispatch("ISBETTING", "-1");
      this.$store.dispatch("DEL_TYPE", "all");
      this.profitFun();
    },

    /*---------------------------------- */
    // 激活投注框的小键盘
    activekey(index) {
      this.clickIndex = index;
    },

    /*---------------------------------- */
    // 删除指定的投注数据
    delarr(name, mark) {
      let betting = this.$store.getters.getBetting;
      let state = true;
      betting.forEach(res => {
        if (res.title == name) {
          res.data.forEach((e, index) => {
            if (e.mark == mark) {
              res.data.splice(index, 1);
              //删除数据也要删除想对应的值
              this.bettingNumber.splice(index, 1);
            }
          });
        }
        this.$store.dispatch("BETTING", []);
        this.$store.dispatch("BETTING", betting);
      });
      this.$store.dispatch("DEL_TYPE", mark);
      this.profitFun();
    },

    /*---------------------------------- */
    //投注窗口放大
    shrink() {
      this.isshrink = true;
      this.$public.setItem("box_size", 1);
    },

    /*---------------------------------- */
    //计算可赢金额(总额)
    profitFun() {
      let dataNum = 0;
      let dataNumbe = 0;
      let datamMoney = 0;
      let compound_amount = 0;
      this.bettingNumber.forEach((e, i) => {
        if (e) {
          dataNum++;
          dataNumbe += e * 1;
          datamMoney += e * 1 * this.dataList[i].odds;
        }
      });
      this.compound.forEach(e => {
        //console.log(e);
        if (e.money * 1 > 0) {
          dataNum += e.index * 1;
          dataNumbe += e.money * 1 * e.index * 1;
          compound_amount += e.money * e.odds;
        }
      });
      this.dataNum = dataNum;
      this.dataNumbe = dataNumbe + "";
      this.datamMoney = datamMoney;
      this.compound_amount = compound_amount;
    },

    /*---------------------------------- */
    //投注窗口缩小
    show() {
      this.isshrink = false;
      this.$public.setItem("box_size", 2);
    },

    /*---------------------------------- */
    //登陆
    loginReg() {
      let isShow = true;
      this.isshow = true;
      this.$store.dispatch("GET_ISSHOW", isShow);
    },
    /*------------------------------- */
    //投注确认提交
    betOrder() {
      for(let i in this.dataList){
        if(this.dataList[i].status > 2 ){
          this.$dialog.alert({ mes: `赔率变法或盘口关闭不能投注` });
          return false;
        }
      }
      console.log('来不来');
      // 给数据原型添加一个判断字符是否存在于数组
      Array.prototype.in_array=function(e){
        var r=new RegExp(','+e+',');
        return (r.test(','+this.join(this.S)+','));
      };
      //error-5111' => '赔率唯一ID为空'
      //'error-7047' => '赔率条件不匹配',
      //'error-7048' => '赔率数据不匹配',
      //'error-7049' => '赔率数据过期',
      //'error 7050' => ' 赔率代码不匹配',
      //'error-7051' =>'未获取到赔率记录' ,
      //' error-7052' => '赔率玩法代码未获取' ,
      //' error-7053' => '赔率玩法代码无效"，
      //'error-7029' => '未获取到赔率数据',
      let code_array= [5111,7050,7052,7029,7053,7051,7047,7048,7049];
      

      if (this.isSubmit) return false;
      let limitingCond = JSON.parse(this.$public.getItem('limitingCond'));
      this.isSubmit = true;
      let list = [],obj = {},obj1 = {};

      for (let i = 0; i < this.bettingNumber.length; i++) {
        // console.log();  
        if(this.bettingNumber[i]*1 < limitingCond.lower_limit*1  &&  this.bettingNumber[i] != ''){
          this.$dialog.alert({ mes: `亲！你输入的投注额,小于最低投注限制${limitingCond.lower_limit}元` });
          this.isSubmit = false;
          return false;
        }
        if(this.bettingNumber[i]*1 > limitingCond.upper_limit*1){
          this.$dialog.alert({ mes: `亲！你输入的投注额,大于最高投注限制${limitingCond.upper_limit}元` });
          this.isSubmit = false;
          return false;
        }
      }

      this.dataList.forEach((res, index) => {
        //单式数据组合
        if (this.bettingNumber[index]) {
          obj = {
            type: "1",
            index: index,
            bet_amount: this.bettingNumber[index]
          };
          list.push(obj);
        }
      });
        //串式数据组合
      for (let index = 0; index <  this.compound.length; index++) {
        if ( this.compound[index].money) {

          if(this.compound[index].money * 1 < limitingCond.lower_limit*1){
            this.$dialog.alert({ mes: `亲！你输入的投注额,小于最低投注限制${limitingCond.lower_limit}元` });
            this.isSubmit = false;
            return false;
          }
          if(this.compound[index].money * 1 > limitingCond.upper_limit*1){
            this.$dialog.alert({ mes: `亲！你输入的投注额,大于最高投注限制${limitingCond.upper_limit}元` });
            this.isSubmit = false;
            return false;
          }

          obj = {
            type: this.compound[index].title,
            // odds:e.odds,
            bet_amount: this.compound[index].money //e.amount
          };
          list.push(obj);
          
        }
      };
      list.push(this.dataList);
      // console.log(this.dataNumbe);

      if (list.length > 1 && this.dataNumbe *1 >0 ) {
        //if(limitingCond.lower_limit * 1 <= this.dataNumbe  && limitingCond.upper_limit * 1 >= this.dataNumbe){
          let token = this.$public.getItem("token");
          this.$http.post(this.$ports.betOrder.Bet, {
            data: list,
            token,
            bet_money: this.dataNumbe
          }).then(res => {
            if (res.data.status == 1) {
              this.alldel();
              this.cash = (this.cash - this.dataNumbe * 1).toFixed(2);
              this.$dialog.alert({ mes: "亲！你已经投注成功啦。" });
            } else if (res.data.status == "-4001") {
              this.isLogin = false;
              this.$dialog.alert({ mes: "亲！你的登陆已过期。" });
            } else if (res.data.status == "4204") {
              this.$dialog.alert({ mes: "亲！你的余额不足。" });
            }else if(code_array.in_array(res.data.status)){
              this.$dialog.alert({ mes: "亲！赔率发生变法，请重新选择。" });
              this.alldel();
            }else{
              this.$dialog.alert({ mes: "错误代码:"+res.data.status});
            }
            this.isSubmit = false;
          });
        //}
      } else {
        this.$dialog.alert({ mes: "亲！你还未输入投注金额啦。" });
        this.isSubmit = false;
      }
    },

    /*---------------------------------- */
    //投注页面数据处理
    getDataList: function(val) {
      let arrays = [];
      this.dataList = [];
      let isRepeat = false;
      if (val) {
        val.forEach(e => {
          if (e.data.length > 0) {
            e.data.forEach((res, index) => {
              if (this.bettingNumber.length < e.data.length) {
                this.bettingNumber.push("");
              }
              res.repeat = false;
              this.passThroughPlay = false;
              if(res.oddsType == 'StRollBall'){
                res.repeat = true;
                isRepeat = true;
              }else{
                res.repeat = false;
              }
              arrays.push(res);
              //console.log('什么数据',arrays);
            });
          }
        });
        this.dataList = arrays;
        if(isRepeat){
          this.passThroughPlay = true;
        }
        //判断比赛数据是否相同赛事
        if (this.dataList.length > 1) {
          this.dataList.forEach((res, i) => {
            if(res.match_id == 0){
              res.repeat = true;
              this.passThroughPlay = true;
            }
            this.dataList.forEach((e, index) => {
              if (res.match_id == e.match_id && i != index) {
                e.repeat = true;
                this.passThroughPlay = true;
              }
            });
          });
        }

        // 查看是否还有数据确定是否要关闭窗口
      }
      if (this.dataList.length == 0) {
        this.$public.setItem("box_size", 2);
        this.$store.dispatch("ISBETTING", "-1");
      }
      //console.log('处理完成的数据',this.dataList);

      //判断是否有过关玩法
      if (this.dataList.length >= 3) {
        this.compound.splice(0, this.compound.length);
        this.isThrough = true;
        this.dataList.forEach((res, index) => {
          if (index >= 2) {
            //this.$public.betPlay(index+1,this.dataList)
            this.compound.push(this.$public.betPlay(index + 1, this.dataList));
          }
        });
      } else {
        this.compound.splice(0, this.compound.length);
      }
      this.$store.dispatch("DEL_TYPE", "");
    },

    /*---------------------------------- */
    //获取用户个人信息
    getUserInfo() {
      let token = this.$public.getItem("token");
      this.$http.post(this.$ports.login.getAgent, { token }).then(res => {
        //console.log('检测',res);
        if (res.data.status == 1 && res.data.data != null) {
          this.cash = res.data.data.cash;
          this.isLogin = true;
        } else {
          this.isLogin = false;
        }
      });
    }
  },

  /**
   *
   */
  computed: {
    //获取vuex投注数据
    getBetting: function() {
      return this.$store.getters.getBetting;
    },
    /*------------------------------*/
    //获取投注框放大缩小状态
    newIsShrink() {
      // 改变背景滑动
      this.$store.dispatch("SET_NOROLL", !this.isshrink);
      return this.isshrink;
    },
    //获取注册页面状态
    getRgShow() {
      return this.$store.getters.getRgShow;
    },
    //获取登陆页面状态
    getIsShow() {
      return this.$store.getters.getIsShow;
    },
    //获取用户token
    getToken() {
      return this.$store.getters.getToken;
    }
  },

  /**
   *
   */
  watch: {
    getIsShow(val) {
      this.isshow = val;
    },
    getBetting(val) {
      this.getDataList(val);
    },
    //显示注册页面
    getRgShow(val) {
      this.rgShow = val;
      this.isshow = val ? false : true;
      //console.log(this.rgShow);
    },
    getToken(val) {
      //this.getUserInfo();
      this.isLogin = true;
    }
  },

  /**
   * 页面初始化完成进行挂载
   */
  mounted() {
    if (this.$public.getItem("box_size") == 1) {
      this.isshrink = true;
    }
    this.getDataList(this.$store.getters.getBetting);
    this.getUserInfo();
    if (this.$public.getItem("token")) {
      this.isLogin = true;
    }
    this.intervalId = setInterval(e=> {
      //console.log('我是投注数据',new Date())
      //console.log(this.dataList);
      let newArray=[];
      this.dataList.forEach(res=>{
        newArray.push({
          game_code:res.ballId,
          match_id:res.match_id,
          home_score:0,
          guest_score:0,
          odds_only:res.odds_only,

        })
      })
      this.checkFailure(newArray);
    }, 1000*3);
    
    //
    // if(this.dataList){
    //   this.dataList.forEach(res=>{
    //     newArray.push({
    //       game_code:res.ballId,
    //       match_id:res.match_id,
    //       home_score:0,
    //       guest_score:0,
    //       odds_only:res.odds_only,
  
    //     })
    //   })
    //   this.checkFailure(newArray);
    // }
  },

  /**********组件销毁前**********/
  beforeDestroy() { 
    console.log('销毁组件')
    clearTimeout(this.intervalId);
  }
};
</script>
<style scoped>
div /deep/ .yd-accordion-head {
  padding: 0 0.32rem;
  height: 0.88rem;
  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%;
}
.login {
  z-index: 999999;
  position: fixed;
  top: 0;
}
.num {
  display: inline-block;
  width: 0.46rem;
  height: 0.46rem;
  background: #dcdcdc;
  border-radius: 50%;
  line-height: 0.46rem;
  text-align: center;
  color: #f76649;
}
.bgcolor {
  background: rgba(40, 40, 40, 0.75);
  height: 55rem;
}
.hiddenbox {
  height: 1rem;
}
.head {
  display: flex;
  justify-content: center;
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  z-index: 1000000;
}
.baffleBox {
  position: fixed;
  overflow-y: scroll;
  top: 0;
  left: 0.4rem;
  width: 100%;
  height: 100%;
  -webkit-overflow-scrolling: touch;
  z-index: 29;
  box-sizing: border-box;
}
.baffleBox::-webkit-scrollbar {
  width: 0;
  height: 0;
  background: transparent;
}
.allBox {
  width: 100%;
  height: 100%;
  border-radius: 0.1rem 0.1rem;
}
.box {
  background: #f76649;
  border-radius: 0.1rem 0.1rem 0 0;
  height: 1rem;
  line-height: 1rem;
  padding: 0 0.32rem 0 0.22rem;
}
.bottonBox {
  /* margin-top: 0.1rem;*/
  padding: 0.22rem 0; 
  background: #CFD3D9;
}
.titleBox {
  padding: 0.21rem 0.07rem;
  border-bottom: 1px solid #ebebeb;
  background: #f8f8f8;
}
.bettingInput {
  padding-right: 0.32rem;
  padding-left: 0.45rem;
  height: 0.9rem;
  margin: 0.1rem 0;
}
.inputBox {
  width: 2.6rem;
  height: 0.8rem;
  border: 1px solid #CFD3D9;
  border-radius: 0.1rem;
  line-height: 0.8rem;
  padding-left: 0.22rem;
}
input {
  border: 0;
  width: 1.7rem;
}
.tilteMatch {
  height: 1.52rem;
  background: #ebebeb;
}
.tilteMatchDiv {
  margin-left: 0.13rem;
}
.cancel {
  padding: 0 0.15rem;
}
.btn-right{
  color: #FFFFFF;
  background: #A7AFBC;
}
button {
  width: 1.2rem;
  height: 0.8rem;
  border: 0;
  background: #FFFFFF;
  border-radius: 0.1rem;
  color: #000000;
}
.bottonBox-num > div {
  text-align: center;
  width: 1.2rem;
  height: 0.8rem;
  line-height: 0.8rem;
  border-radius: 0.1rem;
  color: #FFFFFF;
  background: #A7AFBC;
}
.showNumber {
  /* margin-top: 0.36rem; */
  border-bottom: 1px solid #ebebeb;
  background: #f8f8f8;
  padding-top: 0.2rem;
  padding: 0.21rem 0.2rem;
}
.btn {
  width: 100%;
  height: 0.94rem;
  border-radius: 0.1rem;
  line-height: 0.94rem;
  color: #f8f8f8;
  text-align: center;
  margin-top: 0.1rem;
}
.showNumberSpan {
  color: #363636;
  font-size: 0.28rem;
}
.shrink {
  height: 1rem;
  width: 100%;
  background: #f76649;
  color: #dcdcdc;
  position: fixed;
  left: 0;
  bottom: 0rem;
  line-height: 1rem;
  text-align: center;
  font-size: 0.3rem;
}
.loading_box {
  width: 3rem;
  height: 3rem;
  background: #ebebeb;
}
.promptStyle{
  height:0.6rem;
  line-height:0.6rem;
  text-align: center;
  /* background: #f76649; */
  background:#de9549;
  color: #FFFFFF;
  font-weight: bold;
  
}
</style>


