<template>
  <div class="products bg-F5">
    <div class="banner">
      <img src="@assets/cjxq-banner.png" alt="" />
    </div>
    <div class="container" v-if="params">
      <el-row :gutter="20">
        <el-col :span="4">
          <category
            showHeader
            :currId="params.typeId"
            @change="id => (params.typeId = id)"
          />
        </el-col>
        <el-col :span="20">
          <div class="items">
            <load-more
              url="/goods/info/page"
              :params="params"
              :rows="16"
              v-slot="{
                item: { id, name, companyId, price, cover, companyName }
              }"
            >
              <router-link class="item" :to="`/shop/${companyId}/${id}`">
                <div class="img">
                  <img :src="`${$basePath}${cover}`" />
                </div>
                <span>{{ name }}</span>
                <div class="pay">
                  <span>¥ {{ price }}</span>
                  <router-link :to="`${id}`">
                    {{ $t("page.views.shops.details.products.buyNow") }}
                  </router-link>
                </div>
              </router-link>
            </load-more>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<script lang="ts">
import { Component, Vue, Prop, Watch } from "vue-property-decorator";
@Component
export default class extends Vue {
  private params: IAny | null = null;
  @Prop() private shopInfo!: IAny;
  @Prop(String) private keyWord!: string;
  @Watch("shopInfo", { immediate: true })
  shopChange({ id: companyId }: IAny) {
    if (!companyId) return;
    this.params = { companyId, typeId: 0, name: this.keyWord };
  }
  @Watch("keyWord")
  search(name: string) {
    this.params = { ...this.params, name };
  }
}
</script>
<style lang="scss" scoped>
.products {
  .banner {
    width: 100%;
    height: 240px;
    line-height: 240px;
    color: #fff;
    font-size: 2rem;
    font-weight: bold;
    text-align: center;
    background: rgb(220, 220, 220);
    img {
      width: 100%;
      height: 100%;
    }
  }
  .container {
    padding: 20px 0;
    .menu {
      width: 190px;
      // background: #fff;
      display: inline-block;
      // vertical-align: top;
      // margin-right: 20px;
      // border-radius: 4px;

      // position: relative;
      h3 {
        background: #fd5522;
        color: #fff;
        height: 35px;
        line-height: 35px;
        padding-left: 20px;
      }
    }
    .items {
      overflow: hidden;
      display: inline-block;
      width: 940px;
      .item {
        width: 215px;
        height: 327px;
        background: #fff;
        box-sizing: border-box;
        float: left;
        margin: 0 20px 20px 0;
        padding: 20px;
        .img {
          width: 100%;
          height: 200px;
          border: 1px #e5e5e5 solid;
          position: relative;
          img {
            width: 80%;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
          }
        }
        > span {
          display: inline-block;
          margin: 20px 0;
          color: rgb(51, 51, 52);
          white-space: nowrap;
          overflow: hidden;
          width: 100%;
          text-overflow: ellipsis;
          text-align: center;
        }
        .pay {
          border: 1px solid #fd5522;
          border-radius: 4px;
          height: 30px;
          line-height: 30px;
          > span {
            color: #fd5522;
            display: inline-block;
            width: 50%;
            text-align: center;
          }
          > a {
            color: #fff;
            background: #fd5522;
            width: 50%;
            text-align: center;
            display: inline-block;
          }
        }
      }
    }
  }
}
</style>
