<template>
  <div class="club-device 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>
    <div class="page-content">
      <div class="page-title">设备认证</div>
      <FormClubDevice
        ref="formClubDevice"
        :formType="formType"
        @step="onClubDeviceFormStep"
      />
      <div class="control flex flex-col items-center">
        <div
          class="button submit flex justify-center items-center"
          @click="onSubmit"
        >
          提交
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import FormClubDevice from '../../form/components/form-club-device.vue'
import { mapGetters } from 'vuex'
export default {
  layout: 'app-ph',
  components: {
    FormClubDevice,
  },
  data() {
    return {
      productInfo: {},
      formData: {},
      productId: 0,
      relationId: '',
      formType: '',
    }
  },
  computed: {
    ...mapGetters(['supplierInfo', 'authUserId', 'routePrefix', 'authId']),
  },
  mounted() {
    this.formType = this.$route.query.type
    this.getProductDetails()
  },
  methods: {
    async onSubmit() {
      try {
        await this.$refs.formClubDevice.validate()
        if (this.formType === 'edit') {
          this.formData.authId = this.authId
        }
        await this.$http.api.authProducSave(this.formData)
        this.$toast('保存成功')
        this.$router.push(
          `${this.routePrefix}/record/device/detail?id=${this.productId}`
        )
      } catch (error) {
        console.log(error)
      }
    },
    // 获取认证机构信息
    async getProductDetails() {
      try {
        this.productId = this.$route.query.id
        this.relationId = this.$route.query.relationId
        const res = await this.$http.api.getProductDetails({
          productId: this.productId,
          relationId: this.relationId,
        })
        this.productInfo = res.data
        console.log('productInfo', this.productInfo)
        this.$refs.formClubDevice.init(this.productInfo)
      } catch (error) {}
    },
    onClubDeviceFormStep(data) {
      console.log(data)
      this.formData = data[0]
    },
  },
}
</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: 700px;
        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;
        }

        .el-select {
          width: 100%;
        }
        .control {
          margin-top: 62px;
          .button {
            width: 295px;
            height: 50px;

            cursor: pointer;

            &.submit {
              background-color: fetch('color');
              color: #fff;
            }
          }
        }

        .device-param-list {
          position: relative;
          .add-param {
            position: absolute;
            cursor: pointer;
            top: -40px;
            right: 0;
            text-decoration: underline;
            font-size: 14px;
            color: fetch('color');
          }

          .param {
            position: relative;
            .remove {
              position: absolute;
              right: 0;
              top: 0;
              width: 20px;
              height: 20px;
              background: #f94b4b;
              border-radius: 2px;
              cursor: pointer;
              color: #fff;
              font-size: 14px;
              text-align: center;
              line-height: 20px;
            }
          }
        }
      }
    }
  }
}

@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;
        }

        .el-select {
          width: 100%;
        }
        .control {
          .button {
            width: 100%;
            height: 12vw;

            cursor: pointer;

            &.submit {
              background-color: fetch('color');
              color: #fff;
            }
          }
        }

        .device-param-list {
          position: relative;
          .add-param {
            position: absolute;
            cursor: pointer;
            top: -40px;
            right: 0;
            font-size: 3.4vw;
            color: fetch('color');
          }

          .param {
            position: relative;
            .remove {
              position: absolute;
              right: 0;
              top: 0;
              width: 4.4vw;
              height: 4.4vw;
              background: #f94b4b;
              border-radius: 0.2vw;
              cursor: pointer;
              color: #fff;
              font-size: 3.4vw;
              text-align: center;
              line-height: 4.4vw;
            }
          }
        }
      }
    }
  }
}
</style>
