<!--  -->
<template>
  <div class="collection-type">
    <div class="wrapper">
      <div class="top">
        <img
          class="bg"
          :src="require('@/assets/images/survey-type-top-bg.png')"
          alt=""
        />
      </div>
      <div class="bottom">
        <img
          class="bg"
          :src="require('@/assets/images/survey-type-bottom-bg.png')"
          alt=""
        />

        <div class="content">
          <div class="nav">
            <img
              class="bg"
              :src="require('@/assets/images/survey-type-nav-bg.png')"
              alt=""
            />
            <div class="nav-con">
              <div class="nav-con-title">典藏</div>
              <div class="nav-con-type">
                <ul>
                  <li
                    :class="{ cur: collectionType === 'boutique' }"
                    @click="switchType('boutique')"
                  >
                    <a>精品典藏</a>
                    <div class="arrow" v-if="collectionType === 'boutique'">
                      <img :src="require('@/assets/images/arrow.png')" alt="" />
                    </div>
                  </li>
                  <li
                    :class="{ cur: collectionType === 'threeDimensional' }"
                    @click="switchType('threeDimensional')"
                  >
                    <a>三维藏品</a>
                    <div
                      class="arrow"
                      v-if="collectionType === 'threeDimensional'"
                    >
                      <img :src="require('@/assets/images/arrow.png')" alt="" />
                    </div>
                  </li>
                </ul>
              </div>
            </div>
          </div>
          <div class="con">
            <!-- <div class="back" @click="back">
              <img :src="require('@/assets/images/back.png')" alt="" />
            </div> -->
            <img
              class="bg"
              :src="require('@/assets/images/survey-type-con-bg.png')"
              alt=""
            />
            <div class="search">
              <div class="select">
                <select v-model="params.goodsAgeId">
                  <!-- <option value="" disabled selected style="display: none">
                    年代
                  </option> -->
                  <option value="">全部</option>
                  <option :value="item.id" v-for="(item,index) in getGoodAgeList" :key="index">{{item.name}}</option>
                </select>
              </div>
              <div class="select">
                <select v-model="params.goodsTypeId">
                  <!-- <option value="" disabled selected style="display: none">
                    分类
                  </option> -->
                  <option value="">全部</option>
                  <option :value="item.id" v-for="(item,index) in getGoodTypeList" :key="index">{{item.name}}</option>
                </select>
              </div>
              <div class="ipt">
                <input
                  type="text"
                  v-model="params.searchKey"
                  placeholder="输入名称"
                />
              </div>
              <div class="btn" @click="search()">
                <button>搜索</button>
              </div>
            </div>
            <ul class="list">
              <li
                v-for="(item, index) in dataList"
                :key="index"
                @click="toDetail(item)"
              >
                <div class="pic">
                  <img :src="$cdnUrl + item.thumb" alt="" />
                </div>
                <div class="cover">
                  <div class="txt">
                    <div class="txt-name">{{ item.name }}</div>
                  </div>
                </div>
              </li>
            </ul>
            <el-empty :image-size="200" v-if="dataList.length === 0"></el-empty>
            <div class="my-paging" v-if="dataList.length">
              <Paging
                v-if="paging.total"
                :paging="paging"
                @changeCurrent="pageChange"
              />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import Paging from '@/components/pagination'
export default {
  name: 'collection-type',
  // import引入的组件需要注入到对象中才能使用
  components: {
    Paging
  },
  data () {
    // 这里存放数据
    return {
      collectionType: 'boutique',
      dataList: [],
      paging: {
        pageSize: 12,
        pageNum: 1,
        total: 0,
        showSize: 12,
        current: 1
      },
      params: {
        pageNum: 1,
        pageSize: 12,
        type: '',
        goodsAgeId: '',
        goodsTypeId: '',
        searchKey: ''
      },
      typeChange: {
        boutique: 'img',
        threeDimensional: 'model'
      },
      getGoodAgeList: [],
      getGoodTypeList: []
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {
    paging: {
      deep: true,
      handler: function () {}
    }
  },
  // 方法集合
  methods: {
    async getList (reload = false) {
      if (reload) {
        this.dataList = []
        this.params.pageNum = 1
      }
      let result = await this.$http({
        method: 'post',
        url: '/api/web/goods/list',
        data: this.params
      })
      this.dataList = result.data.list
      this.paging.total = result.data.total
    },
    switchType (type) {
      this.collectionType = type
      this.params['type'] = this.typeChange[this.collectionType]
      this.params['pageNum'] = 1
      this.paging.current = 1
      this.getList()
    },
    back () {
      this.$router.push({ path: '/collection' })
    },
    pageChange (val) {
      console.log(val)
      this.paging.current = val
      this.params.pageNum = val
      this.getList()
    },
    toDetail (item) {
      let classify, myage
      this.getGoodAgeList.forEach(v => {
        if (v.id === item.goodsAgeId) myage = v.name
      })
      this.getGoodTypeList.forEach(v => {
        if (v.id === item.goodsTypeId) classify = v.name
      })

      this.$router.push({
        path: '/collection-detail',
        query: { ...item, navType: this.collectionType, classify, myage }
      })
    },
    search () {
      console.log(this.params)
      this.getList(true)
    },
    async getGoodAge () {
      let result = await this.$http({
        method: 'get',
        url: '/api/web/goods/age/list',
        data: this.params
      })
      this.getGoodAgeList = result && result['code'] === 0 && result['data']
      console.log('this.getGoodAgeList', this.getGoodAgeList)
    },
    async getGoodType () {
      let result = await this.$http({
        method: 'get',
        url: '/api/web/goods/type/list',
        data: this.params
      })
      this.getGoodTypeList = result && result['code'] === 0 && result['data']
    }
  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created () {
    this.collectionType =
      (this.$route.query && this.$route.query['type']) || 'boutique'
    this.params['type'] = this.typeChange[this.collectionType]
    this.getList()
    this.getGoodAge()
    this.getGoodType()
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted () {},
  beforeCreate () {}, // 生命周期 - 创建之前
  beforeMount () {}, // 生命周期 - 挂载之前
  beforeUpdate () {}, // 生命周期 - 更新之前
  updated () {}, // 生命周期 - 更新之后
  beforeDestroy () {}, // 生命周期 - 销毁之前
  destroyed () {}, // 生命周期 - 销毁完成
  activated () {} // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style lang='less' scoped>
.bg {
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  z-index: -1;
}
.collection-type {
  width: 100%;
  margin-bottom: 98px;
  .wrapper {
    width: 100%;
    .top {
      width: 100%;
      height: 278px;
      position: relative;
    }
    .bottom {
      width: 100%;
      position: relative;
      .content {
        min-width: 1090px;
        margin: 0 auto;
        width: 57%;
        display: flex;
        justify-content: center;
        .nav {
          flex: 1;
          margin-right: 1%;
          margin-top: -68px;
          position: relative;
          .nav-con {
            width: 85%;
            margin: 94px auto 0;
            .nav-con-title {
              background: #945335;
              padding: 14.5px 0 14.5px 46px;
              font-size: 20px;
              font-family: Microsoft YaHei;
              font-weight: bold;
              color: #ffffff;
              opacity: 1;
            }
            .nav-con-type {
              margin-top: 3px;
              background: rgba(148, 83, 53, .6);
              overflow: hidden;
              > ul {
                width: 100%;
                margin-top: 21px;
                margin-bottom: 105px;
                > li {
                  width: 100%;
                  padding: 8px 0 8px 51px;
                  font-size: 16px;
                  font-family: Microsoft YaHei;
                  font-weight: 400;
                  color: #000000;
                  position: relative;
                  cursor: pointer;
                  .arrow {
                    position: absolute;
                    top: 10px;
                    right: 11.5px;
                    width: 10.5px;
                    height: 18px;
                    > img {
                      width: 100%;
                      height: 100%;
                    }
                  }
                }
                .cur {
                  background: linear-gradient(180deg, #585a5a 0%, #949198 100%);
                  color: #ffffff;
                }
              }
            }
          }
        }
        .con {
          flex: 3;
          margin-top: -68px;
          position: relative;
          overflow: hidden;
          .back {
            width: 19px;
            position: absolute;
            left: 26px;
            top: 97px;
            cursor: pointer;
            > img {
              width: 100%;
            }
          }
          .search {
            margin: 0 19px;
            margin-top: 94px;
            display: flex;
            justify-content: flex-start;
            height: 38px;
            .select {
              width: 22%;
              height: 100%;
              margin-right: 8px;
              > select {
                border-radius: 5px;
                background: rgba(0, 0, 0, 0.4);
                width: 100%;
                height: 100%;
                border:none;
              }
            }
            .ipt {
              width: 35%;
              > input {
                border-radius: 5px 0 0 5px;
                width: 100%;
                height: 100%;
                padding-left: 16px;
                color: #ffffff;
                border: rgba(148, 83, 53, 0.4);
                background: rgba(148, 83, 53, 0.4);
                &::placeholder {
                  font-size: 16px;
                  font-family: Microsoft YaHei;
                  font-weight: 400;
                  line-height: 21px;
                  color: #ffffff;
                  opacity: 0.7;
                }
              }
            }
            .btn {
              width: 19%;
              > button {
                width: 100%;
                height: 100%;
                border: #945335;
                background: #945335;
                border-radius: 0 5px 5px 0;
                font-size: 16px;
                font-family: Microsoft YaHei;
                font-weight: bold;
                line-height: 21px;
                letter-spacing: 2px;
                color: #ffffff;
                opacity: 1;
              }
            }
          }
          > ul {
            margin: 30px 19px 62px;
            display: flex;
            align-items: center;
            justify-content: flex-start;
            flex-wrap: wrap;
            > li {
              display: flex;
              align-items: center;
              justify-content: center;
              margin-bottom: 2%;
              margin-right: 2%;
              width: 32%;
              height: 254px;
              cursor: pointer;
              position: relative;
              //-----------------------------------
              &:nth-of-type(3n) {
                margin-right: 0;
              }
              .pic {
                width: 100%;
                height: 254px;
                font-size: 0; // 消除img自带间距
                position: relative;
                overflow: hidden;
                > img {
                  width: 100%;
                  position: absolute;
                  top: 50%;
                  left: 50%;
                  transform: translate(-50%, -50%);
                }
              }
              .cover {
                width: 100%;
                height: 100%;
                background: rgba(148, 83, 53, 0.8);
                box-shadow: 0 0 15px rgba(0, 0, 0, 1);
                position: absolute;
                top: 0;
                left: 0;
                display: none;
                .txt {
                  position: absolute;
                  top: 50%;
                  left: 50%;
                  transform: translate(-50%, -50%);
                  text-align: center;
                  font-size: 24px;
                  font-family: Microsoft YaHei;
                  font-weight: 300;
                  color: #ffffff;
                  opacity: 1;
                  .txt-name {
                  }
                }
              }
              &:hover {
                .cover {
                  display: block;
                }
              }
            }
          }
          .my-paging {
            margin: 25px auto;
            text-align: right;
          }
        }
      }
    }
  }
}
</style>
