<template>
  <div class="page">
    <div class="page-top flex flex-col justify-center items-center">
      <!-- <img class="logo" :src="supplierInfo.logo" /> -->
      <!-- <div class="name mt-2" v-text="supplierInfo.shopName + '认证记录'"></div> -->
      <div class="name mt-2">认证记录</div>
    </div>
    <div class="page-content">
      <div class="page-title">设备认证</div>
      <div class="row">
        <div class="col">认证方式：</div>
        <div class="col">新设备认证</div>
      </div>
      <div class="row">
        <div class="col">设备名称：</div>
        <div class="col">{{ productInfo.productName }}</div>
      </div>
      <div class="row">
        <div class="col">设备图片：</div>
        <div class="col">
          <el-image
            v-if="productInfo.productImage"
            :src="productInfo.productImage"
            :preview-src-list="[productInfo.productImage]"
          ></el-image>
          <span v-else>暂无图片</span>
        </div>
      </div>
      <div class="row">
        <div class="col">所属品牌：</div>
        <div class="col">{{ productInfo.brandName }}</div>
      </div>
      <div class="row">
        <div class="col">购买渠道：</div>
        <div class="col">{{ productInfo.purchaseWay || '暂无' }}</div>
      </div>
      <div class="row">
        <div class="col">发票：</div>
        <div class="col">
          <el-image
            v-if="productInfo.invoiceImage"
            :src="productInfo.invoiceImage"
            :preview-src-list="[productInfo.invoiceImage]"
          ></el-image>
          <span v-else>暂无图片</span>
        </div>
      </div>
      <div class="row">
        <div class="col">设备SN码：</div>
        <div class="col">{{ productInfo.snCode }}</div>
      </div>
      <div class="row">
        <div class="col">设备参数：</div>
        <div class="col">
          <div class="params-list">
            <div
              class="param"
              v-for="param in productInfo.paramList"
              :key="param.productName"
            >
              <div class="param-name">{{ param.paramName }}：</div>
              <div class="param-content">{{ param.paramContent }}</div>
            </div>
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col">状态：</div>
        <div class="col" :class="auditStatusColor(productInfo.auditStatus)">
          {{ productInfo.auditStatus | auditStatusFilter }}
        </div>
      </div>

      <div class="row" v-if="productInfo.auditStatus === 0">
        <div class="col">原因：</div>
        <div class="col">
          {{ productInfo.invalidReason ? productInfo.invalidReason : '暂无' }}
        </div>
      </div>

      <div
        class="control flex flex-col items-center"
        v-if="productInfo.auditStatus === 0"
      >
        <div
          class="button edit flex justify-center items-center"
          @click="onEdit"
        >
          编辑
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  layout: 'app-ross',
  data() {
    return {
      relationId: '',
      productId: '',
      productInfo: {},
    }
  },
  filters: {
    auditStatusFilter(value) {
      // 认证状态：0审核未通过，1审核通过，2待审核
      const map = {
        0: '审核未通过',
        1: '审核通过',
        2: '待审核',
      }
      return map[value]
    },
  },
  computed: {
    ...mapGetters(['supplierInfo', 'authUserId', 'routePrefix']),
  },
  mounted() {
    this.initData()
  },
  methods: {
    initData() {
      this.productId = this.$route.query.id
      this.relationId = this.$route.query.relationId
      this.getProductDetails()
    },
    // 获取认证机构信息
    async getProductDetails() {
      try {
        const res = await this.$http.api.getProductDetails({
          productId: this.productId,
          relationId: this.relationId,
        })
        this.productInfo = { ...this.productInfo, ...res.data }
        console.log('res', this.productInfo)
      } catch (error) {
        console.log(error)
      }
    },
    auditStatusColor(value) {
      // 认证状态：0 danger，1 success，2 warning
      const map = {
        0: 'danger',
        1: 'success',
        2: 'warning',
      }
      return map[value]
    },
    onEdit() {
      this.$router.push(
        `${this.routePrefix}/record/device/edit?type=edit&id=${this.productId}&relationId=${this.relationId}`
      )
    },
  },
}
</script>

<style lang="scss" scoped>
@media screen and (min-width: 768px) {
  .page {
    @include useTheme() {
      background: #fff;

      .page-top {
        height: 360px;
        background: fetch('pc-banner-record-device');
        background-size: auto 360px;
        .logo {
          display: block;
          width: 120px;
          height: 120px;
          border-radius: 50%;
          background: #fff;
        }
        .name {
          font-size: 30px;
          color: #fff;
        }
      }
      .page-content {
        width: 600px;
        margin: 0 auto;
        overflow: hidden;
        min-height: calc(100vh - 80px - 80px - 360px);
        box-sizing: border-box;
        padding-bottom: 40px;

        .page-title {
          font-size: 24px;
          font-weight: bold;
          text-align: center;
          padding: 40px 0;
        }

        .params-list {
          .param {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            grid-column-gap: 8px;
            grid-row-gap: 16px;
            .param-name {
              text-align: right;
            }
          }
        }

        .row {
          display: flex;
          justify-content: flex-start;
          align-items: flex-start;
          font-size: 18px;
          margin: 24px 0;

          .col {
            &.success {
              color: #f3920d !important;
            }
            &.warning {
              color: #1890ff !important;
            }
            &.danger {
              color: #f94b4b !important;
            }
            &:first-child {
              width: 100px;
              color: #666;
              text-align: right;
            }

            &:last-child {
              color: #282828;
            }
          }

          .el-image {
            width: 120px;
            height: 120px;
            margin-right: 12px;
            box-sizing: border-box;
            border-radius: 4px;
          }
        }

        .control {
          margin-top: 62px;
          .button {
            width: 295px;
            height: 50px;

            cursor: pointer;

            &.edit {
              border: 1px solid fetch('color');
              color: fetch('color');
            }
          }
        }
      }
    }
  }
}

@media screen and (max-width: 768px) {
  .page {
    @include useTheme() {
      background: #fff;

      .page-top {
        height: 46vw;
        background: fetch('h5-banner-record-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 {
        box-sizing: border-box;
        padding: 8vw 7vw;

        .page-title {
          font-size: 4.2vw;
          font-weight: bold;
          text-align: center;
          color: #282828;
          margin-bottom: 4.6vw;
        }

        .params-list {
          .param {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            grid-column-gap: 1.2vw;
            grid-row-gap: 2.4vw;
            .param-name {
              text-align: right;
            }
          }
        }

        .row {
          display: flex;
          justify-content: flex-start;
          align-items: flex-start;
          font-size: 3.4vw;
          margin: 5.6vw 0;

          .col {
            &.success {
              color: #f3920d !important;
            }
            &.warning {
              color: #1890ff !important;
            }
            &.danger {
              color: #f94b4b !important;
            }
            &:first-child {
              width: 19vw;
              color: #666;
              white-space: nowrap;
              flex-shrink: 0;
              // text-align: right;
            }

            &:last-child {
              color: #282828;
            }
          }

          .el-image {
            width: 26vw;
            height: 26vw;
            border-radius: 1vw;
          }
        }

        .control {
          margin-top: 22.8vw;
          .button {
            width: 100%;
            height: 12vw;
            cursor: pointer;

            &.edit {
              border: 1px solid fetch('color');
              color: fetch('color');
            }
          }
        }
      }
    }
  }
}
</style>
