<template>
  <div class="">
    <Header />
    <Mainmenu activeIndex="2" />
    <div class="wrap">
      <div class="title">政策解读</div>
      <div class="policy-list">
        <Empty v-if="total < 1" text="暂无内容" />
        <div
          class="policy-item"
          @click="goPolicy(item.artId)"
          v-for="item in policyList"
          :key="item.artId"
        >
          <div class="left">{{ item.artTitle }}</div>
          <div class="right">{{ handleparseTime(item.updateTime) }}</div>
          <!-- <div class="right">{{ item.artPostTime }}</div> -->
        </div>
        <el-pagination
          :hide-on-single-page="true"
          @current-change="handleCurrentChange"
          :current-page.sync="queryParams.pageNum"
          :page-size="queryParams.pageSize"
          layout="prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import Header from "@/components/header.vue";
import Mainmenu from "@/components/mainmenu.vue";
import Empty from "@/components/empty.vue";
import { parseTime } from "@/utils/index";
import { getPolicyList } from "@/utils/api";
export default {
  name: "",
  components: {
    Header,
    Mainmenu,
    Empty,
  },
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      policyList: [],
      total: 10,
    };
  },
  computed: {
    handleparseTime() {
      return function (val) {
        // console.log("val", val);
        if (val) {
          return parseTime(val);
        } else {
          return null;
        }
      };
    },
  },
  created() {
    this.handelGetPolicyList();
  },
  methods: {
    handelGetPolicyList() {
      getPolicyList(this.queryParams)
        .then((res) => {
          // console.log("getPolicyList", res);
          this.policyList = res.rows;
          this.total = Number(res.total);
        })
        .catch((err) => {
          console.log("getPolicyList err", err);
        });
    },
    goPolicy(id) {
      // console.log("goPolicy", id);
      this.$router.push({ path: "/Policydetail", query: { id: id } });
    },
    handleCurrentChange(val) {
      this.handelGetPolicyList();
      console.log(`当前页: ${val}`);
    },
  },
};
</script>

<style lang='scss' scoped>
.wrap {
  margin-top: 40px;
}
.title {
  position: relative;
  margin-bottom: 24px;
  font-size: 24px;
  // padding-bottom: 10px;
  border-left: 2px solid #3d5d4c;
  padding-left: 10px;
  // border-bottom: 1px solid #ddd;
}
.policy-list {
  .policy-item {
    overflow: hidden;
    margin-bottom: 20px;
    cursor: pointer;
    .left {
      float: left;
    }
    .right {
      float: right;
    }
  }
}
</style>