<template>
  <div class="rule-container">
    <el-card class="rule-card">
      <div slot="header" class="header">
        <i class="el-icon-reading"></i>
        <span>读者规则信息查看</span>
      </div>

      <el-row
        :gutter="20"
        v-loading="loading"
        element-loading-text="加载中..."
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.7)"
      >
        <el-col :span="12" v-for="(item, index) in ruleList" :key="item.ruleId">
          <el-card
            class="rule-item"
            :class="{ 'rule-item-odd': index % 2 === 0 }"
          >
            <div class="rule-title">
              <i class="el-icon-document"></i>
              <span>借阅证规则 #{{ item.bookRuleId }}</span>
            </div>
            <div class="rule-content">
              <el-descriptions :column="1" border>
                <el-descriptions-item label="可借阅数量">
                  <el-tag size="medium">{{ item.bookLimitNumber }} 本</el-tag>
                </el-descriptions-item>
                <el-descriptions-item label="可借阅天数">
                  <el-tag size="medium" type="success"
                    >{{ item.bookDays }} 天</el-tag
                  >
                </el-descriptions-item>
                <el-descriptions-item label="可借阅图书馆">
                  <el-tag size="medium" type="warning">{{
                    item.bookLimitLibrary
                  }}</el-tag>
                </el-descriptions-item>
                <el-descriptions-item label="过期扣费/天">
                  <el-tag size="medium" type="danger"
                    >￥{{ item.bookOverdueFee }}</el-tag
                  >
                </el-descriptions-item>
              </el-descriptions>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "Rule",
  data() {
    return {
      ruleList: [],
      loading: true,
    };
  },
  methods: {
    async getRuleList() {
      try {
        const { data: res } = await this.$http.get("user/get_rulelist");
        if (res.status !== 200) {
          return this.$message.error(res.msg);
        }
        this.ruleList = res.data;
        this.$message.success({
          message: res.msg,
          duration: 1000,
        });
      } catch (error) {
        this.$message.error("获取规则列表失败");
      } finally {
        this.loading = false;
      }
    },
  },
  created() {
    this.getRuleList();
  },
};
</script>

<style lang="less" scoped>
.rule-container {
  padding: 20px;

  .rule-card {
    background: #f5f7fa;
    border: none;
    border-radius: 8px;

    .header {
      display: flex;
      align-items: center;
      font-size: 24px;
      color: #303133;
      margin-bottom: 20px;

      i {
        margin-right: 10px;
        font-size: 28px;
        color: #409eff;
      }
    }
  }

  .rule-item {
    margin-bottom: 20px;
    border-radius: 8px;
    transition: all 0.3s;

    &:hover {
      transform: translateY(-5px);
      box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
    }

    &.rule-item-odd {
      background: linear-gradient(135deg, #e6f3ff 0%, #ffffff 100%);
    }

    .rule-title {
      font-size: 18px;
      font-weight: 600;
      margin-bottom: 20px;
      color: #303133;
      display: flex;
      align-items: center;

      i {
        color: #409eff;
        margin-right: 8px;
      }
    }

    .rule-content {
      /deep/ .el-descriptions {
        .el-descriptions-item__label {
          width: 120px;
          color: #606266;
          background: #f5f7fa;
        }

        .el-descriptions-item__content {
          padding: 12px 15px;
        }

        .el-tag {
          font-size: 14px;
          padding: 0 12px;
          height: 28px;
          line-height: 26px;
        }
      }
    }
  }
}

// 响应式布局
@media screen and (max-width: 768px) {
  .rule-container {
    padding: 10px;

    .rule-card {
      .header {
        font-size: 20px;
      }
    }

    .rule-item {
      margin-bottom: 15px;

      .rule-title {
        font-size: 16px;
      }
    }
  }
}
</style>
