<template>
  <div class="AppFourNeighbor">
    <AiTopFixed>
      <div flex>
        <div class="time-select" @click="showTimeSelect=true">
          <img src="./components/img/time-icon.png" alt="" class="time-icon">
          <span>{{search.linksageDate || '日期选择' }}</span>
          <img src="./components/img/down-icon-666.png" alt="" v-if="!search.linksageDate" class="mar-r16">
        </div>
        <u-icon name="close-circle" color="#999" size="32" v-if="search.linksageDate"  @click="clearTime" class="mar-r16"></u-icon>
        <u-search placeholder="请输入四邻对象、描述、党员信息" :show-action="false" search-icon-color="#ccc" v-model="search.title"
          @search="isMore = false, search.current = 1, getList()"/>
      </div>
    </AiTopFixed>
    <div class="list-content" v-if="list.length">
      <div class="item" @click="toDetail(item.id)" v-for="(item, index) in list" :key="index">
        <div class="top">
          <p class="title">{{item.description}}</p>
          <div class="info"><span class="label">党员信息</span>{{item.partyName}}</div>
          <div class="info"><span class="label">四邻对象</span>{{item.residentName}}</div>
          <div class="info"><span class="label">事件日期</span>{{item.linksageDate}}</div>
        </div>
        <div class="bottom" :class="`status${item.status}`">
          <span class="tips"></span>{{$dict.getLabel('partyFourLinkageStatus', item.status)}}
        </div>
      </div>
    </div>
    <AiEmpty v-else></AiEmpty>
    <div class="footer" @click="toAdd">
      <div class="btn">新增联动记录</div>
    </div>
    <u-picker v-model="showTimeSelect" mode="time" :params="params" @confirm="selectTime"></u-picker>
  </div>
</template>

<script>
import {mapState} from "vuex";

export default {
  name: 'AppFourNeighbor',
  appName: '四邻联动',
  data() {
    return {
      search: {title: '', linksageDate: ''},
      showTimeSelect: false,
      params: {year: true, month: true, day: true, hour: false, minute: false, second: false},
      current: 1,
      list: []
    }
  },
  computed: {
    ...mapState(['user']),
    
  },
  created() {
    this.$dict.load('partyFourLinkageStatus').then(() => {
      this.getList()
    })
    uni.$on('reload', () => {
      this.getListInit()
    })
  },
  onShow() {
    document.title = '四邻联动'
  },
  methods: {
    getList() {
      this.$http.post('/app/apppartyfourlinkage/list', null, {
        params: {
          size: 20,
          current: this.current,
          linksageDate: this.search.linksageDate
        },
      })
      .then((res) => {
        if (res.code == 0) {
          this.list = this.current > 1 ? [...this.list, ...res.data.records] : res.data.records
        }
      })
    },
    getListInit() {
      this.current = 1
      this.datas = []
      this.getList()
    },
    clearTime() {
      this.search.linksageDate = ''
    },
    selectTime(e) {
      this.search.linksageDate = e.year + '-' + e.month + '-' + e.day
      this.getListInit()
    },
    toAdd() {
      uni.navigateTo({url: './Add'})
    },
    toDetail(id) {
      uni.navigateTo({url: `./Detail?id=${id}`})
    }
  },
  onReachBottom() {
    this.current = this.current + 1
    this.getList()
  },
}
</script>

<style lang="scss" scoped>
.AppFourNeighbor {
  // background-color: #F3F6F9;
  ::v-deep .AiTopFixed .u-search {
    margin-bottom: 0 !important;
  }

  .mar-r16{
    margin-right: 16px;
  }

  .time-select{
    img{
      width: 32px;
      height: 32px;
      vertical-align: bottom;
    }
    .time-icon{
      width: 40px;
      height: 40px;
    }
    span{
      display: inline-block;
      margin: 0 4px;
      font-size: 28px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #666;
      line-height: 40px;
    }
  }

  .list-content{
    padding: 24px 32px 144px;
    .item{
      width: 100%;
      background: #FFF;
      box-shadow: inset 0px 0px 0px 0px #DDDDDD;
      border-radius: 16px;
      margin-bottom: 24px;
      .top{
        padding: 32px 32px 24px;
        border-bottom: 1px solid #ddd;
        .title{
          font-size: 32px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #333;
          line-height: 44px;
          margin-bottom: 32px;
        }
        .info{
          font-size: 26px;
          font-family: PingFangSC-Regular, PingFang SC;
          line-height: 36px;
          margin-bottom: 8px;
          color: #333;
          .label{
            display: inline-block;
            color: #999;
            width: 150px;
          }
        }
      }
      .bottom{
        padding: 32px;
        font-size: 28px;
        font-family: PingFangSC-Regular, PingFang SC;
        line-height: 40px;
        .tips{
          display: inline-block;
          width: 8px;
          height: 8px;
          margin-right: 8px;
          border-radius: 50%;
          vertical-align: middle;
        }
      }
      .status0{
        color: #FF883C;
        .tips{
          background: #FF883C;
        }
      }
      .status1{
        color: #2EA222;
        .tips{
          background: #2EA222;
        }
      }
      .status2{
        color: #F46;
        .tips{
          background: #F46;
        }
      }
    }
  }

  .footer {
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
  }

  .btn {
    width: 100%;
    height: 112px;
    line-height: 112px;
    text-align: center;
    background: #3975C6;
    font-size: 32px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #fff;
  }
}
</style>
