<template>
  <div class="page">
    <van-list
      v-model="loadingMore"
      :finished="finished"
      :immediate-check="false"
      :finished-text="total ? '没有更多了' : ''"
      @load="onLoadMore"
    >
      <div class="page-top flex flex-col justify-center items-center">
        <!-- <img class="logo" :src="supplierInfo.logo" /> -->
        <div class="mt-2 name">
          <span v-text="supplierInfo.shopName"></span><span>官方授权设备</span>
        </div>
      </div>
      <div class="page-content">
        <div class="search-title">设备种类查询：</div>
        <div class="search-container">
          <el-select
            v-model="listQuery.productTypeId"
            slot="prepend"
            placeholder="设备种类"
            class="select-type"
          >
            <template v-for="product in productSelectList">
              <el-option
                :label="product.name"
                :value="product.productTypeId"
                :key="product.productTypeId"
              ></el-option>
            </template>
          </el-select>
          <el-input
            :placeholder="
              searchQuery.type === 1 ? '请输入SN码' : '请输入完整的机构名称'
            "
            v-model="searchQuery.keyword"
            class="input-with-select"
          >
            <el-select
              v-model="searchQuery.type"
              slot="prepend"
              placeholder="请选择"
            >
              <el-option label="SN码" :value="1"></el-option>
              <el-option label="机构名" :value="2"></el-option>
            </el-select>
            <i slot="prefix" class="el-input__icon el-icon-search"></i>
          </el-input>
          <el-button class="submit" type="warning" @click="onSearch"
            >查询</el-button
          >
        </div>
        <div class="area">
          <RossSelectGroup @change="onCityChange" ref="citySelect" />
        </div>
        <template v-if="list.length > 0 || searchFlag">
          <!-- 标题 -->
          <div class="title px-4 pt-12 pb-6 md:px-0">
            共<span v-text="total"></span>台设备
          </div>
          <!-- 列表 -->
          <div class="list">
            <div
              class="section flex justify-between mb-4"
              v-for="item in list"
              :key="item.productId"
              @click="toDetail(item)"
            >
              <img class="cover" :src="item.productImage" />
              <div class="info">
                <div class="name" v-text="item.productName"></div>
                <div class="code">SN码：{{ item.snCode | formatSnCode }}</div>
                <el-popover placement="right" title="机构列表" trigger="hover">
                  <template v-for="club in item.clubList">
                    <div
                      @click.stop="toClubDetail(club)"
                      :key="club.authId"
                      class="club-item"
                    >
                      {{ club.authParty }}
                    </div>
                  </template>
                  <div class="club-name" slot="reference">
                    所属机构：
                    <template v-for="(club, index) in item.clubList">
                      <span :key="club.authId"
                        ><i v-if="index !== 0">,</i>{{ club.authParty }}</span
                      >
                    </template>
                  </div>
                </el-popover>
              </div>
            </div>
          </div>
          <!-- 列表为空 -->
          <SimpleEmpty
            v-if="!total && !isRequest"
            name="icon-empty-device.png"
            description="未找到相关设备~"
          ></SimpleEmpty>
        </template>
      </div>
    </van-list>
  </div>
</template>

<script>
import deviceListMixin from '@/mixins/deviceList'
export default {
  layout: 'app-ph',
  mixins: [deviceListMixin],
}
</script>

<style scoped lang="scss">
.input-with-select {
  ::v-deep {
    .el-input-group__prepend {
      background-color: #fff;
    }
  }
}

// pc 端
@media screen and (min-width: 768px) {
  .el-popover {
    .club-item {
      line-height: 24px;
      cursor: pointer;
      &:hover {
        color: #bc1724;
      }
    }
  }

  .page {
    @include useTheme() {
      position: relative;
      min-height: calc(100vh - 80px - 80px);
      background-color: #fff;

      .page-top {
        height: 420px;
        background: fetch('pc-banner-device');
        background-size: auto 420px;

        .logo {
          display: block;
          width: 120px;
          height: 120px;
          border-radius: 50%;
          background: #fff;
        }
        .name {
          font-size: 30px;
          color: #fff;
        }
      }
      .page-content {
        width: 1000px;
        margin: 0 auto;

        .search-title {
          font-size: 16px;
          color: #404040;
          margin: 25px 0;
        }

        .search-container {
          display: flex;
          justify-content: space-between;
          .input-with-select {
            margin: 0 15px;
            .el-select {
              ::v-deep {
                .el-input {
                  width: 130px;
                }
              }
            }
          }

          .submit {
            width: 295px;
          }
        }

        .title {
          font-size: 16px;
          color: #404040;

          span {
            color: fetch('color');
          }
        }

        .list {
          display: flex;
          align-items: center;
          flex-wrap: wrap;
          justify-content: space-between;

          .empty {
            width: 390px;
          }

          .section {
            width: 490px;
            height: 136px;
            background-color: #f3f5f6;
            border-radius: 4px;
            box-sizing: border-box;
            padding: 16px;
            cursor: pointer;
            transition: all 0.4s;
            &:hover {
              box-shadow: 0 0 24px rgba(0, 0, 0, 0.2);
            }

            .cover {
              display: block;
              width: 104px;
              height: 104px;
            }
            .info {
              width: 336px;
              position: relative;

              .name {
                font-size: 18px;
                color: #101010;
                font-weight: bold;
                margin-bottom: 16px;
                margin-top: 4px;
                text-overflow: ellipsis;
                white-space: nowrap;
                overflow: hidden;
              }
              .code,
              .club-name {
                position: relative;
                font-size: 14px;
                color: #666;
                line-height: 24px;
                text-overflow: ellipsis;
                white-space: nowrap;
                overflow: hidden;
                margin-top: 6px;

                span {
                  color: #1890ff;
                }
              }
            }
          }
        }
      }
    }
  }
}

// 移动 端
@media screen and (max-width: 768px) {
  .page {
    @include useTheme() {
      .page-top {
        height: 46vw;
        background: fetch('h5-banner-device');
        background-size: auto 46vw;

        .logo {
          display: block;
          width: 14.8vw;
          height: 14.8vw;
          border-radius: 50%;
          background: #fff;
        }
        .name {
          font-size: 4vw;
          color: #fff;
        }
      }
      .page-content {
        position: relative;

        .search-title {
          font-size: 3.4vw;
          color: #404040;
          margin: 3.2vw;
        }

        .search-container {
          padding: 0 3.2vw;

          .select-type {
            width: 100%;
          }

          .input-with-select {
            margin: 3.2vw 0;
            .el-select {
              ::v-deep {
                .el-input {
                  width: 130px;
                }
              }
            }
          }

          .submit {
            width: 100%;
          }
        }

        .title {
          font-size: 3.4vw;
          color: #404040;

          span {
            color: fetch('color');
          }
        }

        .list {
          display: flex;
          align-items: center;
          flex-direction: column;

          .section {
            width: 93.6vw;
            height: 26vw;
            background-color: #f3f5f6;
            border-radius: 4px;
            box-sizing: border-box;
            padding: 3.2vw;

            .cover {
              display: block;
              width: 19.6vw;
              height: 19.6vw;
            }
            .info {
              width: 64vw;
              position: relative;
              margin-left: 3.2vw;
              .name {
                font-size: 4vw;
                color: #101010;
                font-weight: bold;
                margin-bottom: 4vw;
                text-overflow: ellipsis;
                white-space: nowrap;
                overflow: hidden;
              }
              .code,
              .club-name {
                width: 66vw;
                position: relative;
                font-size: 3vw;
                color: #404040;
                line-height: 5vw;
                text-overflow: ellipsis;
                white-space: nowrap;
                overflow: hidden;

                span {
                  color: #6d9eff;
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>
