<template>
  <div class="select-commodity">
    <a class="close" @click="$emit('cancle')">+</a>
    <h3 class="title">{{title}}</h3>
    <div class="filter">
      <div>
        <input
          type="text"
          placeholder="输入关键词"
          v-model="key"
          @keyup.enter="(paging.current = 1) && $emit('updateList',key)">
          <i class="iconfont iconsearch" @click="(paging.current = 1) && $emit('updateList',key)"></i>
      </div>
    </div>

   <div class="scene-layer" v-if="name=='scene'">
     <ul>
       <li v-for="(item,i) in panos" :key="i">
         <slot name="list" :data="item"></slot>
       </li>
     </ul>
      <div class="nodata" v-if="panos.length==0">暂无数据</div>
     
   </div>

   <template v-if="name=='table'">
      <div class="table-layer">
      <table class="list">
        <tr>
          <th>
            <div class="checkbox">
              <!-- <input
                type="checkbox"
                v-model="allSelect"
                @click="e => selectGoodAll(e.target.checked)">
              <span></span> -->
            </div>
          </th>
          <th>封面</th>
          <th>房源名称</th>
        </tr>
        <tr v-for="item in houseList" :key="item.goodsId">
          <td>
            <div class="checkbox">
              <input
                :disabled="item.isUse == '1'"
                type="checkbox"
                @change="e => selectGood(item, e.target.checked)"
                :checked="item.id == houseSelect.id"
              >
              <span></span>
            </div>
          </td>
          <td width="500px">
            <div class="list-img">
              <img :key="item.goodsId" :src="`${item.thumb}?rnd=${Math.random()}`" alt="">
            </div>
          </td>
          <td>{{item.sceneName}}</td>
        </tr>
        <tr v-if="houseList.length === 0">
          <td colspan="4">暂无数据</td>
        </tr>
      </table>
    </div>

    <div class="paging">
      <p></p>
      <Paging
        v-if="paging.total>0"
        style="float: right"
        :paging="paging"
        @changeCurrent="changeCurrent"
        />
    </div>
   </template>

    <div class="btns" :class="{disable:disable}">
      <a @click="$emit('submit', houseSelect)" >确定</a>
      <a v-if="showCancle" @click="$emit('cancle')">取消</a>
    </div>
  </div>
</template>

<script>
import Paging from './paging'

export default {
props:{
  panos:{
    default(){
      return []
    },
    type:Array
  },
  houseList:{
    default(){
      return []
    },
    type:Array
  },
  paging: {
    default:function () {
      return {}
    },
    type: Object
  },
  showCancle:{
    default:'',
    type:String
  },
  title:{
    default:'',
    type:String
  },
  name:{
    default:'',
    type:String
  },
  current: {
    default:''
  }
},
  components:{
    Paging
  },
  watch:{
    houseSelect(newVal){
      console.log(newVal);
    }
  },
  computed:{
    disable(){
      let tmp =''
      this.panos.forEach(item=>{
         if (!tmp) {
          tmp = item.arr.find(i=>{
            return i.id == this.current.id
          })
         }
      })
      return !tmp&&!this.houseSelect
    }
  },
  data () {
    return {
      categs: [],
      houseSelect:'',
      allSelect: false,
      key:'',
      tmppaging:{...this.paging}
    }
  },

  methods: {
    changeCurrent(data){
      this.$emit('changeCurrent',data)
    },
    selectGood(item, isSelect){
      this.houseSelect = isSelect?item:''
    }
  },
  mounted() {
    this.key = ''
  }
}
</script>

<style lang="less" scoped>
.select-commodity {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 50%;
  transform: translateX(-50%) translateY(-50%);
  background: #252828;
  color: #fff;
  max-width: 960px;
  width: 100%;
}

.select-commodity > * {
  padding: 15px;
}

.title {
  font-size: 16px;
  line-height: 20px;
  font-weight: 400;
  margin: 0;
  font-weight: bold;
  border-bottom: 1px solid rgba(255,255,255,0.3);
}

.close {
  position: absolute;
  right: -8px;
  top: -15px;
  font-size: 25px;
  color: rgba(255,255,255,0.5);
  transform: rotate(45deg);
  cursor: pointer;
}

.filter {
  padding: 15px;
}

.filter > div {
  width: 210px;
  height: 34px;
  background: rgba(22,26,26,1);
  border: 1px solid rgba(85,85,85,1);
  border-radius: 2px;
  display: inline-block;
  margin-right: 10px;
  position: relative;
  vertical-align: middle;
}

.filter > div > select,
.filter > div > input {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  border: none;
  background: none;
  color: #fff;
  padding: 8px 10px;
  outline: none;
  background: rgba(22,26,26,1);
  color: #fff;
}

.filter > div > input {
  padding-right: 40px;
}

.filter > div > i {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 10px;
  cursor: pointer;
  color:@color;
}

.scene-layer {
  min-height: 400px;
  max-height: 60vh;
  overflow-y: auto;
  position: relative;
  .nodata{
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
  }
}

.table-layer {
  min-height: 400px;
  max-height: 60vh;
  overflow-y: auto;
}


.list {
  border-collapse: collapse;
  width: 100%;
}

.list td,
.list th {
  font-size:14px;
  line-height:20px;
  text-align: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.list th {
  color:rgba(255,255,255,0.60);
  font-weight: normal;
}


.list-img {
  height: 40px;
  line-height: 40px;
  position: relative;
}

.list-img > img {
  width: 40px;
  height: 40px;
}

.checkbox {
  position: relative;
  width:14px;
  height:14px;
  border-radius:2px;
}

.checkbox > input,
.checkbox > span {
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
}

.checkbox > input {
  z-index: 1;
  opacity: 0;
  cursor: pointer;
}

.checkbox > span {
  z-index: 2;
  background:rgba(37,40,40,1);
  border:1px solid rgba(85,85,85,1);
  pointer-events: none;
}

.checkbox > input:checked + span {
  background:rgba(37,40,40,1);
  border:1px solid rgba(0,200,175,1);
  background:rgba(0,200,175,0.3) url(/static/img/g.png) no-repeat center center;
}

.checkbox > input:disabled {
  cursor: not-allowed;
}

.checkbox > input:disabled + span {
  background:rgba(37,40,40,1);
  background:rgba(0,200,175,0.3) no-repeat center center;
}

.paging {
  display: flex;
  align-items: center;
  justify-content: space-between;
  p {
    font-size: 12px;
  }
}

.btns {
  text-align: center;

  > a {
    width:120px;
    height:40px;
    text-align: center;
    line-height: 40px;
    opacity:1;
    border-radius:20px;
    font-size:12px;
    cursor: pointer;
    color: #fff;
    display: inline-block;
    &:nth-child(1) {
      background-color: #00C8AF;
    }
    &:nth-child(2) {
      margin-left: 20px;
      border:1px solid rgba(112,112,112,1);
    }
  }
}
</style>