<template>
  <div class="AppNeighborLinkage">
    <div class="header">
      <div class="search">
        <u-search placeholder="请输入四邻对象、描述" v-model="residentName" :show-action="false" @search="search" @clear="residentName='',getList()"></u-search>
      </div>
      <div class="select">
        <div class="item" >
          <AiSelect v-model="status" :list='array' @data='typeSelect'>
            <span v-if="!status">全部状态</span>
            <span v-else>{{ $dict.getLabel('partyFourLinkageStatus',status) }}</span>
            <u-icon name="arrow-down-fill" color="#666666" size="28"></u-icon>
            <!-- <u-icon name="close-circle" color="#666666" size="28" v-else @click="status='',getList()"></u-icon> -->
          </AiSelect>
        </div>
        
        <div class="item">
          <span v-if="!linksageDate">时间选择</span>
          <span v-else>{{ linksageDate }}</span>
          <u-icon name="close-circle" color="#666666" size="28" v-if="linksageDate" @click="linksageDate='',getList()" style="margin-right: 10px;"></u-icon>
          <u-icon name="arrow-down-fill" color="#666666" size="28" @click="isShowDate = true"></u-icon>
        </div>
        <u-picker mode="time" :params="params" v-model="isShowDate" @confirm="onDateChange"></u-picker>
      </div>
    </div>
    
    <div class="section" v-if="list.length">
      <div class="card" v-for="(item,index) in list" :key="index" @click="$linkTo(`./neighborDetail?id=${item.id}`)">
        <div class="info">
          <p>{{ item.description }}</p>
          <div><span>事件日期</span><span>{{ item.linksageDate }}</span></div>
          <div><span>四邻对象</span><span>{{ item.residentName }}</span></div>
        </div>
        <div class="status">
          <span :style="{background: item.status==0? '#FF883C': item.status==1? '#42D784': '#FF4466'}"></span>
          <span :style="{color: item.status==0? '#FF883C': item.status==1? '#42D784': '#FF4466'}">
            {{ $dict.getLabel('partyFourLinkageStatus',item.status) }}
          </span>
          <span class="score" v-if="item.status==1">积分：+1</span>
        </div>
      </div>
    </div>

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

    <div class="btn" v-if="isShowDate == false">
      <div class="myInfo" @click="$linkTo('./myNeighborInfo')">我的四邻信息</div>
      <div class="addBtn" @click="$linkTo('./addLinkage')">添加联动记录</div>
    </div>
  </div>
</template>

<script>
export default {
  name: "AppNeighborLinkage",
  appName: "四邻联动",
  data() {
    return {
      residentName:'',
      status: '',
      linksageDate: '',
      isShowDate: false,
      params: {
        year: true,
        month: true,
        day: true,
      },
      list: [],
      current: 1,
      array: [],
    }
  },
  onShow() {
    this.$dict.load('partyFourLinkageStatus').then(()=>{
      this.array = this.$dict.getDict('partyFourLinkageStatus').map(item=>{
        return {
          label: item.dictName,
          value: item.dictValue,
        }
      })
      this.array.unshift({
        label: '全部',
        value: ''
      })
    })
    uni.$on('update', ()=>{
      this.getList()
    })
    this.getList()
  },
  methods: {
    search(e) {
      this.list = []
      this.residentName = e
      this.current = 1
      this.getList()
    },
    typeSelect(e) {
      this.list = []
      this.status = e.value
      this.current = 1
      this.getList()
    },
    onDateChange(e) {
      this.list = []
      this.linksageDate = `${e.year}-${e.month}-${e.day}`
      this.current = 1
      this.getList()
    },
    getList() {
      this.$instance.post('/app/apppartyfourlinkage/listByApplet',null,{
        params: {
          current: this.current,
          status: this.status,
          linksageDate: this.linksageDate,
          residentName: this.residentName,
        }
      }).then(res=>{
        if (res?.data) {
          this.list = this.current==1? res.data.records : [...this.list, ...res.data.records]
        }
      })
    },
  },
  onReachBottom() {
    this.current ++,
    this.getList()
  }
}
</script>

<style lang="scss" scoped>
.AppNeighborLinkage {
  .header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    .search {
      box-sizing: border-box;
      padding: 24px 32px;
      background: #4181FF;
      height: 112px;
    }
    .select {
      display: flex;
      height: 112px;
      line-height: 112px;
      background: #FFF;
      
      .item {
        flex: 1;
        text-align: center;
        span {
          margin-right: 8px;
        }
      }
    }
  }
  .section {
    padding: 244px 32px 140px 32px;
    box-sizing: border-box;
    .card {
      background: #FFF;
      box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 0.04);
      border-radius: 16px;
      margin-bottom: 24px;
      .info {
        padding: 20px 30px 30px;
        box-sizing: border-box;
        border-bottom: 1px solid #DDDDDD;
        p {
          margin-bottom: 30px;
          font-size: 32px;
          font-weight: 600;
          overflow:hidden; 
          text-overflow:ellipsis;
          display:-webkit-box;
          -webkit-box-orient:vertical;
          -webkit-line-clamp:2;
        }
        div {
          span:first-child {
            color: #999999;
            margin-right: 32px;
          }
        }
        div:first-child {
          margin-top: 32px;
        }
      }
      .status {
        padding: 32px 32px;
        span:first-child {
          display: inline-block;
          width: 8px;
          height: 8px;
          border-radius: 50%;
          background: #FF883C;
          margin-right: 10px;
        }
        .score {
          float: right;
          color: #FF2244;
        }
      }
    }
  }
  .btn {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 120px;
    padding: 16px 32px;
    box-sizing: border-box;
    display: flex;
    background: #F3F6F9;
    .myInfo,
    .addBtn {
      flex: 1;
      height: 88px;
      line-height: 88px;
      text-align: center;
      color: #FFF;
      background: #4181FF;
      border-radius: 16px;
    }
    .myInfo {
      margin-right: 20px;
      color: #A0C0FF;
      background: #FFF;
      border: 1px solid #A0C0FF;
    }
  }
  ::v-deep .AiSelect {
    display: inline-block;
  }

  ::v-deep .emptyWrap .emptyImg {
    margin-top: 220px;
  }
}
</style>