<template>
  <view class="">
    <view class="personnel_list">
      <view class="personnel_item" v-for="(item, index) in list" :key="item.id">
        <view class="top">
          <view class="left">
            <u--image class="u_avatar" :showLoading="true" :src="item.avatar||'../../static/img/public/man.png'"
              width="112.28rpx" height="112.28rpx" shape="circle"></u--image>
          </view>
          <view class="right">
            <view class="info_top">
              <view class="info_name">{{item.name}}</view>
            </view>
            <view class="info_bottom">
              <view class="item phone">
                年龄:
                {{item.age}}
              </view>
            </view>
            <view class="info_bottom">
              <view class="item phone">
                <uni-icons type="phone" color="#999999FF"></uni-icons>
                {{item.phone}}
              </view>
            </view>
          </view>
        </view>
        <view class="location">
          <view class="left">
            <uni-icons type="location" color="#999999FF"></uni-icons>
            <text>居住地址:</text>
          </view>
          <view>{{item.area_name+item.street_name+item.village_name}}</view>
        </view>
        <view class="time">
          <view class="left">
            <uni-icons type="calendar" color="#999999FF"></uni-icons>
            <text>更新时间:</text>
          </view>
          <view>{{item.update_time}}</view>
        </view>
        <u-line color="#999999FF" v-if="showView"></u-line>
        <view v-if="showView" class="bottom" style="margin-top: 28rpx;">
          <button class="look" @click="navTo()">更新信息</button>
          <button class="look" @click="navTo('/subpkg/archivesDetail/archivesDetail?id='+item.id)">查看</button>
        </view>
      </view>
      <u-loadmore :status="loadConfig.status" :loading-text="loadConfig.loadingText"
        :loadmore-text="loadConfig.loadmoreText" :nomore-text="loadConfig.nomoreText" />
    </view>
    <button class="new_btn" v-if="$store.state.app.userInfo.admin_id==0" @click="navTo('/subpkg/newArchives/newArchives')">信息登记</button>
    <!-- <button class="new_btn" @click="navTo('/subpkg/updateArchives/updateArchives')">信息更新(测试中)</button> -->
  </view>
</template>

<script>
  import { informationList } from "@/api/information.js"
  import { Toast } from "../../libs/uniApi";
  export default {
    data() {
      return {
        list: [],
        loadConfig: {
          page: 1,
          limit: 15,
          loadingText: '努力加载中',
          loadmoreText: '轻轻上拉',
          nomoreText: '我也是有底线的~~',
          status: 'loadmore'
        },
      }
    },
    onLoad(options) {
      console.log(options);
    },
    onShow() {
      this.initLoadconfig();
      this.loadInformationList();
    },
    computed:{
      // 是否显示查看和更新按钮
      showView(){
        return this.$store.state.app.userInfo.admin_id?false:true;
      }
    },
    methods: {
      navTo(url) {
        url ?
          uni.navigateTo({
            url: url,
          }) : Toast('暂未开放')
      },
      initLoadconfig(){
        this.loadConfig.page = 1;
        this.loadConfig.status = "loadmore";
        this.list = [];
      },
      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
        })
        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() {
      uni.stopPullDownRefresh()
    }
  }
</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: 100rpx;

    .personnel_item {
      margin: 0 auto;
      width: 694rpx;
      // height: 407rpx;
      background: #FFFFFF;
      border-radius: 14rpx 14rpx 14rpx 14rpx;
      margin-bottom: 32rpx;
      overflow: hidden;
      position: relative;
      padding: 28rpx;

      .top {
        // background-color: #3274F9;
        display: flex;

        .right {
          display: flex;
          flex-direction: column;
          justify-content: space-around;
          margin-left: 28rpx;
          font-size: 25rpx;
          font-weight: 400;
          overflow: hidden;
          color: #999999;

          .info_top {
            display: flex;
            align-items: flex-end;
            font-size: 25rpx;
            font-weight: 400;
            color: $theme-oa-color;
            margin-bottom: 8rpx;

            .info_name {
              font-size: 32rpx;
              font-weight: 400;
              color: #333333;
              margin-right: 18rpx;
            }
          }

          .info_bottom {
            display: flex;
            margin-bottom: 8rpx;

            .item {
              display: flex;
              align-items: center;
            }

            .phone {
              margin-right: 28rpx;
            }
          }
        }
      }

      .location {
        margin-top: 18rpx;
        display: flex;
        font-size: 25rpx;
        font-weight: 400;
        overflow: hidden;
        color: #999999;

        .left {
          display: flex;
          align-items: center;
        }
      }

      .time {
        margin-top: 8rpx;
        margin-bottom: 21rpx;
        display: flex;
        font-size: 25rpx;
        font-weight: 400;
        overflow: hidden;
        color: #999999;

        .left {
          display: flex;
          align-items: center;
        }
      }

      .bottom {
        display: flex;
        justify-content: right;

        .look {
          width: 158rpx;
          height: 53rpx;
          background: #FFFFFF;
          border-radius: 26rpx 26rpx 26rpx 26rpx;
          opacity: 1;
          border: 2rpx solid $theme-oa-color;
          font-size: 28rpx;
          font-weight: 400;
          margin-left: 28rpx;
          color: $theme-oa-color;
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }
    }
  }
</style>