<template>
  <div class="page-form-container cate-review">
    <div class="row">
      <div class="col">设备名称：</div>
      <div class="col">{{ cateData.name }}</div>
    </div>
    <div class="row">
      <div class="col">设备图片：</div>
      <div class="col">
        <el-image style="width: 120px; height: 120px" :src="cateData.image" :preview-src-list="[cateData.image]" />
      </div>
    </div>
    <div class="row">
      <div class="col">所属品牌：</div>
      <div class="col">{{ cateData.brandName }}</div>
    </div>
    <div class="row">
      <div class="col">相关参数：</div>
      <div class="col">
        <template v-for="(param, index) in cateData.paramList">
          <div :key="index" class="param">
            <div class="label">{{ param.paramName }}：</div>
            <div class="content">{{ param.paramContent }}</div>
          </div>
        </template>
      </div>
    </div>
    <el-form ref="auditForm" label-width="112px" :model="auditForm" :rules="rules">
      <el-form-item label="审核：">
        <el-radio-group v-model="auditForm.auditStatus">
          <el-radio :label="1">通过</el-radio>
          <el-radio :label="0">不通过</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="auditForm.auditStatus === 0" label="原因：" prop="invalidReason">
        <el-input v-model="auditForm.invalidReason" type="textarea" :rows="3" />
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="$_back">返回</el-button>
        <el-button type="primary" @click="submit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { auditProductCate, fetchAuthProductFormData } from '@/api/product'
import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      isLoading: false,
      auditForm: {
        auditBy: '', // 审核人id
        productTypeId: '', // 机构id
        auditStatus: 1, // 审核状态
        invalidReason: '' // 审核信息
      },
      rules: {
        invalidReason: { required: true, message: '不通过原因不能为空', tigger: 'blur' }
      },
      cateData: {}
    }
  },
  computed: {
    ...mapGetters(['authUserId'])
  },
  created() {
    this.getDetail()
  },
  methods: {
    // 数据回显
    async getDetail() {
      this.auditForm.productTypeId = this.$route.query.id
      // getAuthFormData({ authId: this.auditForm.authId }).then((res) => {
      //   this.clubInfo = { ...this.clubInfo, ...res.data }
      // })
      try {
        const { data } = await fetchAuthProductFormData({ productTypeId: this.auditForm.productTypeId })
        this.cateData = data
      } catch (error) {
        console.log(error)
      }
    },
    async onAudit() {
      this.isLoading = true
      this.auditForm.auditBy = this.authUserId
      try {
        const res = await auditProductCate(this.auditForm)
        this.$message.success(res.data)
        this.$store.dispatch('tagsView/delView', this.$route)
        this.$router.back()
      } catch (error) {
        console.log(error)
      } finally {
        this.isLoading = false
      }
    },
    // 提交审核信息
    async submit() {
      try {
        await this.$refs.auditForm.validate()
        await this.onAudit()
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.row {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  margin-bottom: 25px;
  .col {
    font-size: 14px;
    color: #333;
    &:first-child {
      min-width: 100px;
      text-align: right;
      margin-right: 8px;
      font-weight: bold;
      color: #666;
    }

    .param {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      // grid-template-rows: repeat(2, 1fr);
      grid-column-gap: 0px;
      grid-row-gap: 0px;

      div {
        padding-bottom: 16px;
        text-align: left;

        &:first-child {
          text-align: right;
        }
      }
    }

    .el-image {
      margin-left: 12px;
      &:first-child {
        margin-left: 0;
      }
    }
  }
}

.el-button {
  width: 120px;
}
</style>
