<!--  -->
<template>
  <div class="Big-Book-prev-Textdes Sudoku" v-if="curQue">
      <div class="sodu-inner">
          <div class="item-box">
            <div :class="['item']" v-for="(item,index) in curQue.option" :key="index">
                <div v-for="(items,indexs) in item" :key="indexs" 
                    :class="[indexs%3==2?'noBorder':'',indexs>5?'noBorder-bottom':'',index==seletcItem[0]&&indexs==seletcItem[1]?'active':'',styleList[index][indexs],items.isHint?'notClick':'canClick']">
                    <span v-if="items.isHint">
                        {{items.value}}
                    </span>
                    <p v-else @click="handleCheck(index,indexs)">{{soduko[index][indexs]}}</p>
                    <!-- <input v-else v-model="soduko[index][indexs]" maxlength="1" readonly> -->
                </div>
            </div>
          </div>
          <div class="item-right">
              <ul>
                  <li v-for="(item,index) in selectList" :key="index" :class="[]" @click="handleClick(item)">
                      {{item}}
                  </li>
              </ul>
              <a class="resetBtn" @click="handleData">重做</a>
              <a class="submitBtn" @click="handleSubmit">提交</a>
          </div>
      </div>
      
  </div>
</template>

<script>
export default {
  components: {},
  props: ["curQue"],
  data() {
    return {
        soduko:[],
        selectList:['1','6','2','7','3','8','4','9','5','?'],
        seletcItem:[],
        styleList:[]
    };
  },
  computed: {},
  watch: {},
  //方法集合
  methods: {
      // 处理数据
      handleData(){
          let _this = this
          _this.soduko = []
          _this.seletcItem = []
          _this.styleList = []
          _this.curQue.option.forEach(item => {
              let arr = []
              item.forEach(items=>{
                  if(items.isHint){
                      arr.push(items.value)
                  }else{
                      arr.push('')
                  }
              })
              _this.soduko.push(arr)
              _this.styleList.push(JSON.parse(JSON.stringify(arr)))
          });
      },
      changeNumber(item,index,indexs) {
          let value = item.replace(/[^\d]/g, "")
          this.$set(this.soduko[index],indexs,value)
      },
      // 点击九宫格元素
      handleCheck(index,indexs){
          this.seletcItem = []
          this.seletcItem.push(index)
          this.seletcItem.push(indexs)
      },
      // 点击右侧数字
      handleClick(item){
          if(this.seletcItem.length>0){
              this.$set(this.soduko[this.seletcItem[0]],this.seletcItem[1],item)
          }
      },
      // 提交
      handleSubmit(){
          let _this = this
          _this.curQue.option.forEach((item,index) => {
              item.forEach((items,indexs)=>{
                  if(!items.isHint){
                      if(items.value &&_this.soduko[index][indexs] && _this.soduko[index][indexs] == items.value){
                          this.$set(this.styleList[index],indexs,'right')
                      }else if(items.value &&_this.soduko[index][indexs] && _this.soduko[index][indexs] != items.value){
                          this.$set(this.styleList[index],indexs,'error')
                      }
                  }
              })
          });
          this.seletcItem = []
      }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
      this.handleData()
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
.Big-Book-prev-Textdes{
    .sodu-inner{
        display: flex;
        border: 1px solid rgba(0, 0, 0, 0.1);
        border-radius: 8px;
    }
    .item-box{
        display: flex;
        flex-flow: wrap;
        width: 550px;
        border-bottom: 1px solid #000000;
        border-right: 1px solid #000000;
        margin: 24px;
        background: #E6E6E6;
        .item{
            display: flex;
            flex-flow: wrap;
            width: 183px;
            height: 183px;
            border-top: 1px solid #000000;
            border-left: 1px solid #000000;
            box-sizing: border-box;
            div{
                width: 60px;
                height: 60px;
                display: flex;
                justify-content: center;
                align-items: center;
                border: 1px solid #FFFFFF;
                background: #FFFFFF;
                // border-bottom: 1px solid #E6E6E6;
                // border-right: 1px solid #E6E6E6;
                margin-bottom: 1px;
                margin-right: 1px;
                box-sizing: border-box;
                &.noBorder{
                    // border-right: none;
                    margin-right: 0px;
                }
                &.noBorder-bottom{
                    // border-bottom: none;
                    margin-bottom: 0px;
                }
                &.canClick:hover{
                    border-color: #737373;
                }
                &.canClick.active{
                    border-color: #0086FF;
                }
                &.right{
                    background: #F5FFF9;
                    border-color: #F5FFF9;
                    p{
                        color: #00BC4B;
                    }
                }
                &.error{
                    background: #FFF8F8;
                    border-color: #FFF8F8;
                    p{
                        color: #DE4444;
                    }
                }
                span{
                    font-size: 16px;
                    line-height: 150%;
                    color: rgba(0, 0, 0, 0.85);
                    font-family: 'robot';
                    font-weight: 700;
                }
                p{
                    width: 100%;
                    height: 100%;
                    text-align: center;
                    color: #1890FF;
                    font-size: 16px;
                    font-weight: 700;
                    font-family: 'robot';
                    background: initial;
                    line-height: 58px;
                    margin: 0;
                    cursor: pointer;
                }
            }
        }
    }
    .item-right{
        background: rgba(0, 0, 0, 0.04);
        width: 164px;
        padding: 12px 10px;
        ul{
            display: flex;
            flex-flow: wrap;
            li{
                width: 60px;
                height: 60px;
                background: #FFFFFF;
                border: 1px solid #E6E6E6;
                margin: 12px 6px;
                font-size: 20px;
                font-weight: bold;
                color: rgba(0, 0, 0, 0.85);
                font-family: 'robot';
                text-align: center;
                line-height: 60px;
                cursor: pointer;
                &:hover {
                    border: 1px solid #0086FF;
                    box-shadow: 0px 0px 0px 2px rgba(24, 144, 255, 0.5);
                }
            }
        }
        .resetBtn,.submitBtn{
            width: 132px;
            height: 40px;
            background: #DE4444;
            border: 1px solid rgba(0, 0, 0, 0.1);
            box-sizing: border-box;
            border-radius: 8px;
            color: #FFFFFF;
            text-align: center;
            line-height: 38px;
            font-size: 16px;
            display: block;
            margin: 0 auto;
            margin-top: 54px;
        }
        .submitBtn{
            background: #00BC4B;
            margin-top: 8px;
        }
    }
}
</style>