<template>
  <view class="">
    <view class="personnel_list">
      <view class="item" v-for="(item, index) in list" :key="item.id">
        <view class="top">
          <image class="avatar" src="../../static/img/public/record.png"></image>
          <view class="body">
            <view>姓名:<text class="name">{{item.name}}</text></view>
            <view>片区:<text class="name">{{item.address}}</text></view>
            <view>电话:<text class="name">{{item.phone}}</text></view>
          </view>
        </view>
        <u-line color="#cccccc"></u-line>
        <view class="bottom">
          <view>更新时间: {{item.create_time}}</view>
          <view class="right" v-if="showView">
            <view class="update" @click="navTo('/subpkg/updateArchives/updateArchives?id='+item.id)">
              更新
            </view>
            <view class="look" @click="navTo('/subpkg/archivesDetail/archivesDetail?id='+item.id)">
              查看
            </view>
          </view>
        </view>
      </view>
      <u-empty v-if="loadConfig.status=='nomore'&& list.length==0" text="没有档案" icon="/static/img/empty/list.png">
      </u-empty>
      <u-loadmore v-else :status="loadConfig.status" :loading-text="loadConfig.loadingText"
        :loadmore-text="loadConfig.loadmoreText" :nomore-text="loadConfig.nomoreText" />
    </view>
    <mybtn text="信息登记" v-if="showView" @click="navTo('/subpkg/newArchives/newArchives')"></mybtn>
  </view>
</template>

<script>
  import {
    informationList
  } from "@/api/information.js"
  import {
    Toast
  } from "../../libs/uniApi";
  export default {
    data() {
      return {
        user_id: -1,
        list: [],
        loadConfig: {
          page: 1,
          limit: 15,
          loadingText: '努力加载中',
          loadmoreText: '轻轻上拉',
          nomoreText: '我也是有底线的~~',
          status: 'loadmore'
        },
      }
    },
    onLoad(options) {
      if (options.id) this.user_id = options.id;
      else if (this.$store.state.app.userInfo.admin_id == 0) { //如果用户是小队长,将带上自己的id
        this.user_id = this.$store.state.app.userInfo.id;
      }
      this.loadInformationList();
      uni.$on('loadArchives', this.initLoad);
    },
    onShow() {

    },
    computed: {
      // 是否显示查看和更新按钮
      showView() {
        return !this.$store.state.app.userInfo.admin_id && this.$store.state.app.userInfo.is_captain;
      }
    },
    onReachBottom() {
      this.loadInformationList();
    },
    methods: {
      navTo(url) {
        if (url) {
          uni.showLoading({
            title: '加载中',
            mask: true
          })
          uni.navigateTo({
            url: url,
            success() {
              uni.hideLoading()
            }
          })
        } else Toast('暂未开放');
      },
      async initLoad() {
        this.loadConfig.page = 1;
        this.loadConfig.status = "loadmore";
        this.list = [];
        await this.loadInformationList();
        uni.stopPullDownRefresh();
      },
      async loadInformationList() {
        let that = this;
        if (this.loadConfig.status == "nomore") return;
        this.loadConfig.status = "loading"
        let res = await informationList({
          page: this.loadConfig.page,
          limit: this.loadConfig.limit,
          user_id: that.user_id
        })
        this.loadConfig.status = "loadmore"
        if (res.data.length < this.loadConfig.limit) {
          this.loadConfig.status = "nomore"
        } else {
          this.loadConfig.page++;
        }
        this.list = [...this.list, ...res.data];
      }
    },
    onPullDownRefresh() {
      this.initLoad();
    }
  }
</script>

<style lang="scss">
  .new_btn {
    position: fixed;
    bottom: 28rpx;
    left: 50%;
    transform: translate(-50%);
    margin-top: 32rpx;
    // margin-bottom: 40rpx;
    width: 694rpx;
    height: 84rpx;
    background: $theme-oa-color;
    border-radius: 42rpx 42rpx 42rpx 42rpx;
    color: #fff;
    line-height: 80rpx;
    text-align: center;
  }

  .personnel_list {
    padding: 28rpx 0;
    margin-bottom: 130rpx;

    .item {
      margin: 0 auto;
      width: 694rpx;
      // height: 201rpx;
      background: #FFFFFF;
      border-radius: 14rpx 14rpx 14rpx 14rpx;
      opacity: 1;
      margin-bottom: 21rpx;
      box-sizing: border-box;
      padding: 28rpx;
      font-size: 24.53rpx;
      color: #999999FF;

      .top {
        display: flex;
        align-items: center;
        width: 100%;

        .avatar {
          width: 120rpx;
          height: 120rpx;
          margin-right: 18rpx;
          margin-bottom: 12rpx;
        }

        .body {
          flex: 1;
          font-size: 28rpx;
          color: #333;
          font-weight: bold;

          .name {
            font-size: 28rpx;
            color: #333;
            font-weight: 500;
            display: inline-block;
            margin-left: 18rpx;
          }
        }
      }

      .bottom {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 20rpx;
        font-size: 25rpx;

        .right {
          font-size: 28rpx;
          display: flex;

          .look {
            color: $theme-oa-color;
          }

          .update {
            color: #34A853;
            margin-right: 38rpx;
          }
        }

      }


    }

  }
</style>