<!-- @format -->

<template>
  <view
    style="height: 100vh; background-color: #f3f4f9; padding: 20rpx"
    class=""
  >
    <view v-if="ledgerList.length">
      <view
        v-for="item in ledgerList"
        style="
          background-color: #fff;
          border-radius: 20rpx;
          padding: 20rpx;
          margin: 0rpx auto 20rpx;
        "
        class=""
      >
        <view @click="detailInfo(item)" class="">
          <view style="display: inline-block" class="">
            <view
              style="line-height: 60rpx; font-size: 36rpx; font-weight: 700"
              class=""
            >
              {{ item.title }}
            </view>
            <view>
              {{ item.typeName }}
            </view>
            <view style="line-height: 50rpx; color: #929292" class="">
              {{ item.createTime }}
            </view>
          </view>
          <view style="float: right; margin-top: 30rpx" class="">
            <view v-if="item.readStatus == 1" style="color: limegreen" class="">
              已读
            </view>
            <view v-if="item.readStatus == 0" style="color: red" class="">
              未读
            </view>
          </view>
        </view>
      </view>
    </view>
    <view v-else>
      <u-empty mode="message"> </u-empty>
    </view>
  </view>
</template>

<script>
import { msgList } from "@/api/work.js";
export default {
  data() {
    return {
      readColor: {
        已撤回: "#fa3534",
        已接收: "#2979ff",
        待提交: "#2979ff",
        备案中: "#2979ff",
        已拒绝: "#fa3534",
        勿备案: "#fa3534",
        未备案: "#909399",
        免备案: "#909399",
        已退回: "#fa3534",
      },

      read: [], //备案字典
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      ledgerList: [],
      total: 0,
      current: 0,
      swiperDotIndex: 0,
      data: [
        {
          image: "/static/images/banner/banner01.jpg",
        },
        {
          image: "/static/images/banner/banner02.jpg",
        },
        {
          image: "/static/images/banner/banner03.jpg",
        },
      ],
    };
  },
  onLoad() {
    // useDict("read_status").then((res) => {
    // 	this.read = res;
    // });
    this.getList();
    uni.startPullDownRefresh();
  },
  onPullDownRefresh() {
    this.getList();
    console.log("refresh");
    setTimeout(function () {
      uni.stopPullDownRefresh();
    }, 800);
  },
  methods: {
    detailInfo(item) {
      uni.navigateTo({
        url: "/pages/work/detailInfo?id=" + item.id,
      });
    },
    getList() {
      msgList({
        ...this.queryParams,
      }).then(({ rows, total }) => {
        this.ledgerList = rows;
        this.total = total;
      });
    },
    onReachBottom() {
      //触底事件
      if (this.queryParams.pageNum * this.queryParams.pageSize >= this.total) {
        uni.showToast({
          title: "没有更多数据了",
          icon: "none",
          duration: 1000,
        });
        setTimeout(() => {
          uni.hideLoading();
        }, 500);
      } else {
        if (this.queryParams.pageNum <= this.queryParams.pageNum - 1) {
          setTimeout(() => {
            uni.hideLoading();
          }, 500);
        } else {
          uni.showLoading({
            title: "加载中",
          });
          this.queryParams.pageNum++;

          msgList({
            ...this.queryParams,
          }).then(({ rows, total }) => {
            this.ledgerList = [...this.ledgerList, ...rows];
            this.total = total;
          });
        }
        setTimeout(() => {
          uni.hideLoading();
        }, 500);
      }
    },
    clickBannerItem(item) {
      console.info(item);
    },
    changeSwiper(e) {
      this.current = e.detail.current;
    },
    changeGrid(e) {
      this.$modal.showToast("模块建设中~");
    },
  },
};
</script>

<style lang="scss">
/* #ifndef APP-NVUE */
page {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  background-color: #fff;
  min-height: 100%;
  height: auto;
}

view {
  font-size: 14px;
  line-height: inherit;
}

/* #endif */

.text {
  text-align: center;
  font-size: 26rpx;
  margin-top: 10rpx;
}

.grid-item-box {
  flex: 1;
  /* #ifndef APP-NVUE */
  display: flex;
  /* #endif */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 15px 0;
}

.uni-margin-wrap {
  width: 690rpx;
  width: 100%;
}

.swiper {
  height: 300rpx;
}

.swiper-box {
  height: 150px;
}

.swiper-item {
  /* #ifndef APP-NVUE */
  display: flex;
  /* #endif */
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #fff;
  height: 300rpx;
  line-height: 300rpx;
}

@media screen and (min-width: 500px) {
  .uni-swiper-dot-box {
    width: 400px;
    /* #ifndef APP-NVUE */
    margin: 0 auto;
    /* #endif */
    margin-top: 8px;
  }

  .image {
    width: 100%;
  }
}
</style>
