<template>
  <div class="AppServicePublic">
    <div class="header-top">
      <div>区域选择</div>
      <AiAreaPicker v-model="areaId" :areaId="areaId" @select="areaSelect"></AiAreaPicker>
    </div>

    <u-search class="serach_content" placeholder="请输入公开标题" :show-action="false" v-model="keyword" @clear="clearSearch" @search="search"></u-search>

    <template v-if="datas.length > 0">
      <u-card v-for="(item, index) in datas" :key="index" :foot-border-top="false" :head-border-bottom="false" :show-head="false" :border-radius="32" @click="goDetail(item, 1)">
        <view class="body" slot="body">
          <view class="u-body-item">
            <div class="title">{{ item.createUserName }}</div>
          </view>

          <view class="u-body-item">
            <div class="flex">
              <span class="left">
                <span class="garydiv">财务公开</span>
                <span class="times">2021-12-16</span>
              </span>

              <span class="right">
                <span class="font">1111</span>
                <span>人看过</span>
              </span>
            </div>
          </view>
        </view>
      </u-card>

      <u-loadmore :status="loadmore" color="#999" font-size="24" margin-top="32" margin-bottom="80" />
    </template>

    <AiEmpty description="暂无数据" v-else></AiEmpty>

    <AiFixedBtn>
      <div class="addBtn iconfont iconfont-iconfangda" @tap.stop="toAdd()" />
    </AiFixedBtn>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: 'AppServicePublic',
  appName: '三务公开',
  components: {},
  props: {},
  data() {
    return {
      datas: [],
      keyword: '',
      areaId: '',
      current: 1,
      size: 10,
      pages: 0,
    }
  },
  computed: {
    ...mapState(['user']),

    loadmore() {
      return this.pages <= this.current ? 'loading ' : 'nomore'
    },
  },
  watch: {},
  onLoad() {
    this.areaId = this.user.areaId
    this.getList()
  },
  mounted() {},
  methods: {
    getList() {
      this.$http
        .post('/app/appvisitvondolence/list', null, {
          params: {
            size: 6,
            current: this.current,
            areaId: this.areaId,
            title: this.keyword,
          },
        })
        .then((res) => {
          if (res.code == 0) {
            this.datas = this.current > 1 ? [...this.datas, ...res.data.records] : res.data.records
            this.pages = res.data.pages
          }
        })
    },

    areaSelect(e) {
      if (e.type == 5) {
        this.areaId = e.id
      } else {
        return this.$u.toast('请选择到村')
      }
      this.getList()
    },

    goDetail(item) {
      uni.navigateTo({ url: `./Detail?id=${item.id}` })
    },

    toAdd() {
      uni.navigateTo({ url: `./Add` })
    },
  },
  onReachBottom() {
    this.current = this.current + 1
    this.getList()
  },
}
</script>

<style scoped lang="scss">
uni-page-body {
  height: 100%;
}
.AppServicePublic {
  height: 100%;
  .header-top {
    display: flex;
    background: #fff;
    justify-content: space-between;
    align-items: center;
    padding: 10px 30px;
    border-bottom: 1px solid #d8dde6;
  }

  .u-search {
    background: #fff;
    padding: 20px 30px;
  }

  .u-card {
    ::v-deep .u-card__body {
      .body {
        position: relative;
        .u-body-item {
          .title {
            font-size: 36px;
            font-weight: 500;
            margin-bottom: 16px;
          }
          .flex {
            display: flex;
            justify-content: space-between;
            .left {
              .garydiv {
                font-size: 28px;
                color: #999999;
                background: #eeeeee;
                border-radius: 24px;
                padding: 4px 16px;
              }
              .times {
                margin-left: 16px;
                font-size: 28px;
                color: #999999;
              }
            }

            .right {
              font-size: 28px;
              color: #999;
              .font {
                color: #4181ff;
              }
            }
          }
        }
      }
    }
  }

  .AiFixedBtn {
    .movableArea {
      .addBtn {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 96px;
        height: 96px;
        flex-shrink: 0;
        background: $uni-color-primary;
        box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
        font-size: 48px;
        color: #fff;
        border-radius: 50%;
      }
    }
  }
}
</style>
