<template>
  <div class="club-detail page">
    <div class="page-top"></div>
    <div class="page-content">
      <div class="title">机构认证信息</div>
      <div class="updated" v-if="isAuth">
        <el-button type="warning" size="default" plain @click="editData">{{ status ? '修改' : '保存' }}</el-button>
      </div>
      <template v-if="!isAuth">
        <div class="tip">抱歉，您暂未认证机构</div>
        <div class="btn" @click="toAuth">去认证</div>
      </template>
      <template v-else>
        <div v-if="status">
          <div class="row">
          <div class="col label">机构名称：</div>
          <div class="col content">{{ clubInfo.authParty }}</div>
        </div>
        <div class="row">
          <div class="col label">联系电话：</div>
          <div class="col content">{{ clubInfo.mobile }}</div>
        </div>
        <div class="row">
          <div class="col label">运营联系人：</div>
          <div class="col content">{{ clubInfo.linkMan }}</div>
        </div>
        <div class="row">
          <div class="col label">运营联系人手机号：</div>
          <div class="col content">{{ clubInfo.linkMobile }}</div>
        </div>
        <div class="row">
          <div class="col label">所在地区：</div>
          <div class="col content">{{ clubInfo.area }}</div>
        </div>
        <div class="row">
          <div class="col label">详细地址：</div>
          <div class="col content">{{ clubInfo.address }}</div>
        </div>
        <div class="row">
          <div class="col label">所在位置：</div>
          <div class="col content">
            <div class="postion-btn" @click="initMap">查看定位</div>
          </div>
        </div>
        <div class="row block">
          <div class="col label">logo：</div>
          <div class="col content">
            <el-image :src="clubInfo.logo" v-if="clubInfo.logo"></el-image>
          </div>
        </div>
        <div class="row block">
          <div class="col label">门头照：</div>
          <div class="col content">
            <template v-for="(image, index) in clubInfo.bannerList">
              <el-image :src="image" :key="index"></el-image>
            </template>
          </div>
        </div>
        <div class="row">
          <div class="col label">机构类型：</div>
          <div class="col content">{{ firstClubTypeName }}</div>
        </div>
        <div class="row">
          <div class="col label">医美类型：</div>
          <div class="col content">{{ secondClubTypeName }}</div>
        </div>
        <div class="row block">
          <div class="col label">医疗许可证：</div>
          <div class="col content">
            <el-image :src="clubInfo.medicalLicenseImage" v-if="clubInfo.medicalLicenseImage"></el-image>
          </div>
        </div>
        <div class="row">
          <div class="col label">员工人数：</div>
          <div class="col content">{{ clubInfo.empNum }}</div>
        </div></div>
        <div v-else>
          <FormClubInfo ref="clubInfoForm" @step="onClubInfoFormStep" :clubInfo="clubInfo" /></div>
        <!-- <div class="row">
          <div class="col label">机构名称：</div>
          <div class="col content">{{ clubInfo.authParty }}</div>
        </div>
        <div class="row">
          <div class="col label">联系电话：</div>
          <div class="col content">{{ clubInfo.mobile }}</div>
        </div>
        <div class="row">
          <div class="col label">运营联系人：</div>
          <div class="col content">{{ clubInfo.linkMan }}</div>
        </div>
        <div class="row">
          <div class="col label">运营联系人手机号：</div>
          <div class="col content">{{ clubInfo.linkMobile }}</div>
        </div>
        <div class="row">
          <div class="col label">所在地区：</div>
          <div class="col content">{{ clubInfo.area }}</div>
        </div>
        <div class="row">
          <div class="col label">详细地址：</div>
          <div class="col content">{{ clubInfo.address }}</div>
        </div>
        <div class="row">
          <div class="col label">所在位置：</div>
          <div class="col content">
            <div class="postion-btn" @click="initMap">查看定位</div>
          </div>
        </div>
        <div class="row block">
          <div class="col label">logo：</div>
          <div class="col content">
            <el-image :src="clubInfo.logo" v-if="clubInfo.logo"></el-image>
          </div>
        </div>
        <div class="row block">
          <div class="col label">门头照：</div>
          <div class="col content">
            <template v-for="(image, index) in clubInfo.bannerList">
              <el-image :src="image" :key="index"></el-image>
            </template>
          </div>
        </div>
        <div class="row">
          <div class="col label">机构类型：</div>
          <div class="col content">{{ firstClubTypeName }}</div>
        </div>
        <div class="row">
          <div class="col label">医美类型：</div>
          <div class="col content">{{ secondClubTypeName }}</div>
        </div>
        <div class="row block">
          <div class="col label">医疗许可证：</div>
          <div class="col content">
            <el-image :src="clubInfo.medicalLicenseImage" v-if="clubInfo.medicalLicenseImage"></el-image>
          </div>
        </div>
        <div class="row">
          <div class="col label">员工人数：</div>
          <div class="col content">{{ clubInfo.empNum }}</div>
        </div> -->
      </template>
    </div>

    <div class="position-select" v-if="mapVisiable">
      <div class="position-select-container">
        <SimpleAMap ref="aMap" :lnglat="lnglat" />
        <div class="position-select-footer">
          <div class="lnglat">当前经纬度：{{ clubInfo.lngAndLat }}</div>
          <div class="position-confirm postion-control" @click="mapVisiable = false">确定</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import FormClubInfo from '../form/components/form-club-edit.vue'
export default {
  layout: 'app-hyt',
  data() {
    return {
      mapVisiable: false,
      clubInfo: {},
      status: true,
      clubData: {},
    }
  },
  components: { FormClubInfo },
  computed: {
    ...mapGetters(['userInfo', 'routePrefix']),
    isAuth() {
      return this.clubInfo.auditStatus === 1
    },
    firstClubTypeName() {
      if (!this.clubInfo.firstClubType) return '其他'
      return ['医美', '生美', '项目公司', '个人', '其他'][this.clubInfo.firstClubType - 1]
    },
    secondClubTypeName() {
      if (!this.clubInfo.secondClubType) return '其他'
      return ['诊所', '门诊', '医院', '其他', '美容院', '养生馆', '其他'][this.clubInfo.secondClubType - 1]
    },
    lnglat() {
      return this.clubInfo.lngAndLat ? this.clubInfo.lngAndLat.split(',') : null
    },
  },
  created() {
    this.fetchClubDetail()
  },
  methods: {
    // 获取机构详情
    async fetchClubDetail() {
      try {
        const authId = this.userInfo.authId
        if (!authId) return
        const res = await this.$http.api.fetchClubAuthInfoData({ authId })
        this.clubInfo = res.data
      } catch (error) {
        console.log(error)
      }
    },
    // 去认证
    toAuth() {
      this.$router.push(`${this.routePrefix}/form/club-register`)
    },
    // 地图定位
    initMap() {
      this.mapVisiable = true
      this.$nextTick(() => {
        this.$refs.aMap.init()
      })
    },
    // 修该数据
    editData() {
      if (!this.status) {
        this.$refs.clubInfoForm.validate().then(() => {
          return this.status = true
        }).catch(() => {
          return this.status = false
        })
      }
      this.status = false
    },
    async onClubInfoFormStep(authdata) {
      console.log(authdata)
      this.$toast.loading({
        message: '正在保存请稍后...',
        duration: 0,
      })

      try {
        await this.$http.api.authClubSave1(authdata)
        await this.fetchClubDetail()
        this.$toast.loading({
          message: '保存成功',
          duration: 1000,
        })
      } catch (e) {
        console.log(e)
      }
    },
  },
}
</script>

<style lang="scss" scoped>
@media screen and (min-width: 768px) {
  .page {
    display: flex;
    justify-content: center;
    background: #fff;
    position: relative;
  }

  .position-select {
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.39);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 999;

    display: flex;
    justify-content: center;
    align-items: center;

    .position-select-container {
      background: #fff;
      width: 60%;
      box-sizing: border-box;
      padding: 24px;

      .position-select-footer {
        position: relative;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        padding-top: 24px;

        .lnglat {
          position: absolute;
          font-size: 14px;
          color: #666;

          left: 0;
          top: 50%;
          transform: translateY(-50%);
        }
      }

      .postion-control {
        width: 120px;
        height: 40px;
        font-size: 14px;
        border-radius: 4px;
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
        margin-left: 16px;

        &.position-confirm {
          background: #f56c6c;
          color: #fff;
        }

        &.position-cancel {
          background: #b1b1b1;
          color: #fff;
        }
      }
    }
  }

  .page-content {
    max-width: 800px;
    padding-bottom: 120px;
    .updated {
      position: absolute;
      top: 50px;
      right: 200px;
      display: flex;
      justify-content: center;
      align-items: center;
      ::v-deep .el-button {
        font-size: 24px;
      }
      ::v-deep .el-button--warning {
        color: #f3920d;
        background: #fff;
        border-color: #f3920d;
      }
    }
    .title {
      font-size: 24px;
      color: #282828;
      font-weight: bold;
      text-align: center;
      padding: 60px 0;
    }

    .tip {
      font-size: 16px;
      color: #b2b2b2;
      margin-top: 200px;
      margin-bottom: 24px;
      text-align: center;
    }

    .btn {
      width: 98px;
      height: 36px;
      background: #bc1724;
      border-radius: 4px;
      text-align: center;
      line-height: 36px;
      color: #fff;
      font-size: 16px;
      margin: 0 auto;
      cursor: pointer;
    }

    .row {
      display: flex;
      align-items: flex-start;
      margin: 32px 0;

      .col {
        font-size: 16px;
      }
      .label {
        color: #666666;
        min-width: 100px;
      }
      .content {
        color: #282828;

        .el-image {
          width: 106px;
          height: 106px;
          border: 1px solid #dcdcdc;
          margin-right: 4px;

          &:last-child {
            margin-right: 0;
          }
        }

        .postion-btn {
          height: 28px;
          line-height: 28px;
          font-size: 14px;
          color: #fff;
          background: #1890ff;
          display: flex;
          justify-content: center;
          align-items: center;
          cursor: pointer;
          border-radius: 4px;
          padding: 0 8px;

          &::before {
            content: '';
            display: inline-block;
            width: 16px;
            height: 16px;
            background: url(~assets/theme-images/common/icon-position.png) no-repeat center;
            background-size: 16px 16px;
          }
        }
      }
    }
  }
}

@media screen and (max-width: 768px) {
  .page {
    display: flex;
    justify-content: center;
    position: relative;
    background: #fff;
  }

  .position-select {
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.39);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 999;

    display: flex;
    justify-content: center;
    align-items: center;

    .position-select-container {
      background: #fff;
      width: 80%;
      box-sizing: border-box;
      padding: 3.2vw;

      .position-select-footer {
        padding-top: 10vw;
        position: relative;
        display: flex;
        justify-content: flex-end;
        align-items: center;

        .lnglat {
          position: absolute;
          font-size: 3.2vw;
          color: #666;

          left: 0;
          top: 5vw;
          transform: translateY(-50%);
        }
      }

      .postion-control {
        width: 16vw;
        height: 7vw;
        font-size: 3.4vw;
        border-radius: 0.4vw;
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
        margin-left: 3.6vw;

        &.position-confirm {
          background: #f56c6c;
          color: #fff;
        }

        &.position-cancel {
          background: #b1b1b1;
          color: #fff;
        }
      }
    }
  }

  .page-content {
    padding: 0 4vw;
    .updated {
      position: absolute;
      top: 6.5vw;
      right: 4vw;
      display: flex;
      justify-content: center;
      align-items: center;
      ::v-deep .el-button {
        font-size: 3.4vw;
      }
      ::v-deep .el-button--warning {
        color: #f3920d;
        background: #fff;
        border-color: #f3920d;
      }
    }
    .title {
      font-size: 4.2vw;
      color: #282828;
      font-weight: bold;
      text-align: center;
      padding: 8vw 0;
    }

    .tip {
      font-size: 3vw;
      color: #b2b2b2;
      margin-top: 60vw;
      margin-bottom: 4.8vw;
      text-align: center;
    }

    .btn {
      width: 36vw;
      height: 8.8vw;
      background: #bc1724;
      border-radius: 0.4vw;
      text-align: center;
      line-height: 8.8vw;
      color: #fff;
      font-size: 3.4vw;
      margin: 0 auto;
    }

    .row {
      display: flex;
      align-items: flex-start;
      margin: 5.6vw 0;

      &.block {
        display: block;
        .label {
          margin-bottom: 2.4vw;
        }
      }

      .col {
        font-size: 3.4vw;
      }
      .label {
        color: #666666;
        min-width: 20.4vw;
      }
      .content {
        color: #282828;
        .el-image {
          width: 26vw;
          height: 26vw;
          border: 0.1vw solid #dcdcdc;
          margin-right: 0.6vw;

          &:last-child {
            margin-right: 0;
          }
        }

        .postion-btn {
          height: 6.8vw;
          line-height: 6.8vw;
          font-size: 3.2vw;
          color: #fff;
          background: #1890ff;
          display: flex;
          justify-content: center;
          align-items: center;
          cursor: pointer;
          border-radius: 0.4vw;
          padding: 0 1.2vw;

          &::before {
            content: '';
            display: inline-block;
            width: 3.58vw;
            height: 3.58vw;
            background: url(~assets/theme-images/common/icon-position.png) no-repeat center;
            background-size: 3.58vw;
          }
        }
      }
    }
  }
}
</style>
