<template>
  <div class="page">
    <div class="page-top">
      <div class="swiper">
        <SimpleSwiper :imageList="clubInfo.bannerList"></SimpleSwiper>
      </div>
      <div class="club-info">
        <img class="logo" :src="clubInfo.logo" />
        <div class="name" v-text="clubInfo.authParty"></div>
        <div class="remark" v-if="clubInfo.remarks">
          认证设备：{{ clubInfo.remarks }}
        </div>
      </div>
    </div>
    <div class="page-content">
      <div class="club-info">
        <div class="address" v-text="address"></div>
        <div class="mobile">{{ clubInfo.mobile | formatEmpty }}</div>
        <div class="navigation" @click="onMapNav">导航过去</div>
      </div>
      <template v-if="clubInfo.doctorList && clubInfo.doctorList.length > 0">
        <!-- 列表标题 -->
        <div class="title">明星操作师</div>
        <!-- 列表 -->
        <div class="list">
          <div
            class="section flex items-center"
            v-for="(item, index) in clubInfo.doctorList"
            :key="index"
          >
            <img :src="item.doctorImage" class="cover" />
            <div class="info">
              <div class="name" v-text="item.doctorName"></div>
              <div class="tag" v-text="item.tagList.join(' | ')"></div>
              <div class="more" @click="toDetail(item)">点击查看</div>
            </div>
          </div>
        </div>
      </template>
    </div>
    <SimpleMapNav ref="mapNav" color="black" @click="navigation"></SimpleMapNav>
  </div>
</template>

<script>
import { drawLogo } from '@/utils'
import { mapNavigate } from '@/utils/map-utils'
import { mapGetters } from 'vuex'
export default {
  layout: 'app-ldm',
  filters: {
    formatEmpty(val) {
      return val || '暂无'
    },
  },
  data() {
    return {
      authId: '',
      clubInfo: {},
    }
  },
  computed: {
    ...mapGetters(['routePrefix']),
    address() {
      return this.clubInfo.area + this.clubInfo.address || '暂无'
    },
    isEmpty() {
      return this.clubInfo.productList
        ? this.clubInfo.productList.length === 0
        : true
    },
  },
  mounted() {
    this.initData()
  },
  beforeDestroy() {
    this.$removeStorage(this.routePrefix, 'clubInfo')
  },
  methods: {
    toDetail(row) {
      const url = `${this.routePrefix}/approve/personnel/operate/detail?id=${row.doctorId}`
      this.$router.push(url)
    },
    // 初始化
    initData() {
      this.authId = parseInt(this.$route.query.id)
      const clubInfo = this.$getStorage(this.routePrefix, 'clubInfo')
      if (clubInfo) {
        this.clubInfo = clubInfo
      }
      this.fetchDetail()
    },
    // 获取机构详细信息
    async fetchDetail() {
      try {
        const res = await this.$http.api.getAuthClubDetail({
          authId: this.authId,
        })
        this.clubInfo = { ...this.clubInfo, ...res.data } // 合并
      } catch (error) {
        console.log(error)
      }
      if (this.clubInfo.bannerList.length <= 0) {
        this.clubInfo.bannerList.push('/ldm-placeholder.png')
      }
      if (!this.clubInfo.logo) {
        this.clubInfo.logo = drawLogo(this.clubInfo.authParty)
      }
    },
    // 地图导航
    onMapNav() {
      this.$refs.mapNav.open()
    },
    // 导航
    navigation(type) {
      const point = this.clubInfo.lngAndLat.split(',')
      const lng = point[0]
      const lat = point[1]
      mapNavigate(
        { lat, lng, title: this.clubInfo.authParty, address: this.address },
        type
      )
      this.$refs.mapNav.close()
    },
  },
}
</script>

<style scoped lang="scss">
@media screen and (min-width: 768px) {
  .page {
    display: flex;
    justify-content: space-between;
    width: 1035px;
    margin: 0 auto;
    position: relative;
    padding-top: 500px;
    padding-bottom: 60px;
  }
  .page-top {
    .swiper {
      width: 452px;
      height: 452px;
      background: #f7f7f7;

      ::v-deep {
        img {
          width: 452px;
          height: 452px;
        }
      }
    }

    .club-info {
      width: 100%;
      position: absolute;
      top: 80px;
      text-align: center;
      .logo {
        display: block;
        width: 158px;
        height: 158px;
        margin: 0 auto;
        border-radius: 50%;
        box-shadow: 0 4px 66px rgb(131 131 131 / 40%);
        background: #fff;
      }
      .name {
        font-size: 50px;
        font-weight: bold;
        color: #000000;
        margin: 39px 0 26px;
      }
      .remark {
        font-size: 25px;
        font-weight: bold;
        color: #000000;
      }
    }
  }

  .page-content {
    width: 507px;
    // height: 452px;
    // overflow-y: auto;

    .club-info {
      position: relative;
      font-size: 19px;
      color: #000000;
      border-top: 1px solid rgba(0, 0, 0, 0.169);
      border-bottom: 1px solid rgba(0, 0, 0, 0.169);
      padding-top: 36px;
      padding-bottom: 36px;
      .address,
      .mobile {
        position: relative;
        padding-left: 26px;

        &::after {
          content: '';
          display: block;
          width: 20px;
          height: 20px;
          position: absolute;
          left: 0;
          top: 4px;
          background-size: auto 20px;
          background-repeat: no-repeat;
        }
      }

      .mobile {
        margin-top: 34px;
        &::after {
          background-image: url(https://static.caimei365.com/www/authentic/h5/ldm-icon-contact.png);
        }
      }

      .address {
        &::after {
          background-image: url(https://static.caimei365.com/www/authentic/h5/ldm-icon-address.png);
        }
      }

      .navigation {
        position: absolute;
        bottom: 36px;
        right: 0;
        font-size: 19px;
        color: #0080ed;
        cursor: pointer;
        &::after {
          content: '>';
          margin-left: 8px;
        }
      }
    }
  }

  .title {
    font-size: 21px;
    color: #000;
    font-weight: bold;
    padding: 40px 0;

    &::before {
      content: '';
      display: inline-block;
      width: 24px;
      height: 28px;
      background: url(https://static.caimei365.com/www/authentic/h5/ldm-icon-badge-black.png)
        no-repeat center;
      background-size: 24px;
      vertical-align: -7px;
      margin-right: 8px;
    }
  }

  .list {
    display: flex;
    flex-direction: column;
    align-items: center;
    border-bottom: 1px solid rgba(0, 0, 0, 0.169);
    .section {
      width: 100%;
      margin-bottom: 32px;
      .cover {
        display: block;
        width: 140px;
        height: 140px;
        border-radius: 1.7vw;
      }
      .info {
        position: relative;
        flex: 1;
        margin-left: 18px;
        .name {
          font-size: 26px;
          color: #000;
          font-weight: bold;
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
        }
        .tag {
          width: 206px;
          font-size: 14px;
          color: #000;
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
          margin-top: 15px;
        }
        .more {
          position: absolute;
          bottom: 0;
          right: 0;
          font-size: 19px;
          color: #0080ed;
          cursor: pointer;
          &::after {
            content: '>';
            margin-left: 8px;
          }
        }
      }
    }
  }
}

@media screen and (max-width: 768px) {
  .page-top {
    position: relative;
    height: 137vw;

    .swiper {
      height: 100vw;

      background: #f7f7f7;

      ::v-deep {
        img {
          height: 100vw;
        }
      }
    }

    .club-info {
      width: 100%;
      position: absolute;
      bottom: 0;
      z-index: 9;
      text-align: center;
      .logo {
        display: block;
        width: 29.5vw;
        height: 29.5vw;
        margin: 0 auto;
        border-radius: 50%;
        box-shadow: 0 0.4vw 0.9vw rgba(200, 200, 200, 0.4);
        background: #fff;
      }
      .name {
        font-size: 5vw;
        font-weight: bold;
        color: #000000;
        margin: 6vw 0;
      }
      .remark {
        font-size: 2.5vw;
        font-weight: bold;
        color: #000000;
      }
    }
  }

  .page-content {
    .club-info {
      position: relative;
      font-size: 3vw;
      color: #000000;
      padding: 6vw 3vw;
      .address,
      .mobile {
        position: relative;
        padding: 4vw 0;
        border-top: 0.1vw solid rgba(0, 0, 0, 0.169);
        padding-left: 8.6vw;

        &::after {
          content: '';
          display: block;
          width: 4vw;
          height: 4vw;
          position: absolute;
          left: 4.3vw;
          top: 4vw;
          background-size: 4vw;
          background-repeat: no-repeat;
        }
      }

      .mobile {
        border-bottom: 0.1vw solid rgba(0, 0, 0, 0.169);
        &::after {
          background-image: url(https://static.caimei365.com/www/authentic/h5/ldm-icon-contact.png);
        }
      }

      .address {
        &::after {
          background-image: url(https://static.caimei365.com/www/authentic/h5/ldm-icon-address.png);
        }
      }

      .navigation {
        position: absolute;
        bottom: 10vw;
        right: 5vw;
        font-size: 3vw;
        color: #0080ed;
        &::after {
          content: '>';
          margin-left: 1vw;
        }
      }
    }
  }

  .title {
    font-size: 3.4vw;
    color: #000;
    font-weight: bold;
    text-align: center;

    &::before {
      content: '';
      display: inline-block;
      width: 3.7vw;
      height: 4.4vw;
      background: url(https://static.caimei365.com/www/authentic/h5/ldm-icon-badge-black.png)
        no-repeat center;
      background-size: 3.7vw;
      vertical-align: -0.8vw;
      margin-right: 1vw;
    }
  }

  .list {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 6vw;
    .section {
      width: 95vw;
      padding: 5vw;
      background: #f1f1f1;
      border-radius: 2.4vw;
      box-sizing: border-box;
      margin-bottom: 2.4vw;
      .cover {
        display: block;
        width: 21.8vw;
        height: 21.8vw;
        border-radius: 1.7vw;
      }
      .info {
        position: relative;
        flex: 1;
        margin-left: 2.7vw;
        .name {
          font-size: 4.2vw;
          color: #000;
          font-weight: bold;
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
        }
        .tag {
          width: 30vw;
          font-size: 2.2vw;
          color: #000;
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
          margin-top: 2.5vw;
        }
        .more {
          position: absolute;
          bottom: 0;
          right: 0;
          font-size: 3vw;
          color: #0080ed;
          &::after {
            content: '>';
            margin-left: 1vw;
          }
        }
      }
    }
  }
}
</style>
