<template>
  <div class="AppPointsReview">
    <AiTopFixed>
      <div class="top-search">
        <div class="left">
          <u-search v-model="search.createUserName" :clearabled="true" placeholder="请输入申请人、审批人" :show-action="false" bg-color="#F5F5F5"
            search-icon-color="#999" color="#999" height="58" @search="getListInit" @clear="getListInit">
          </u-search>
        </div>
      </div>
      <div class="top-select">
        <div class="item" @click="showDateSelect=true">
          <span v-if="!search.startTime" style="color:#999;">日期筛选</span>
          <span v-else>{{ search.startTime }}至{{ search.endTime }}</span>
          <u-icon name="arrow-down" color="#666" size="28" style="margin-left: 4px" v-if="!search.startTime" />
          <img src="./img/del-icon.png" alt="" class="del-icon" v-else @click.stop="clearDate">
        </div>
        <div class="item" @click="isShowType=true">
          <span style="color:#999;" v-if="!search.type">事件类型</span>
          <span v-else>{{ search.typeName }}</span>
          <u-icon name="arrow-down" color="#666" size="28" style="margin-left: 4px" v-if="!search.type"/>
          <img src="./img/del-icon.png" alt="" class="del-icon" v-else @click.stop="clearType">
        </div>
      </div>
    </AiTopFixed>
    <div class="list-content">
      <div class="item" v-for="(item, index) in list" :key="index" @click="toDetail(item.id)">
        <div class="title-flex">
          <p class="title">{{item.applyItemName}}</p>
          <div class="btn" v-if="item.status == 1">
            <p v-if="item.pushStatus == 1">已推送</p>
            <div @click.stop="pushNew(item.id)" v-else>推送精选</div>
          </div>
        </div>
        <div class="user-name">{{item.createUserName}}<span>积分+{{item.applyIntegral}}</span></div>
        <div class="time-flex">
          <span>{{item.createTime}}</span>
          <span :class="`color-${item.status}`">{{ $dict.getLabel('appIntegralApplyEventStatus', item.status) }}</span>
        </div>
      </div>
    </div>
    <AiEmpty v-if="!list.length" description="暂无数据"></AiEmpty>
    <AiEmpty v-if="!isGridMember" no-permit :description="`<p>您不是网格员<br/>无法使用网格员相关功能哦~</p>`"/>

    <u-calendar v-model="showDateSelect" mode="range" min-year="2023" @change="dateConfirm"></u-calendar>
    <u-select v-model="isShowType" :list="typeList" value-name="id" label-name="ruleName" @confirm="typeConfirm"></u-select>
    <u-modal v-model="showPush" :show-cancel-button="true" content="是否将精选内容对全体居民公开，选择否将只对本村/社区公开" 
      confirm-text="是" cancel-text="否" @confirm="pushNewConfirm(1)" @cancel="pushNewConfirm(1)" :mask-close-able="true"></u-modal>

  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: "AppPointsReview",
  appName: "积分审核",
  data() {
    return {
      keyword: '',
      areaId: '',
      areaName: '',

      showDateSelect: false,
      search: {
        createUserName: '',
        startTime: '',
        endTime: '',
        type: '',
        typeName: ''
      },
      list: [],
      current: 1,
      pages: 2,
      typeList: [],
      isShowType: false,
      showPush: false,
      pushNewId: ''
    };
  },
  computed: {
    ...mapState(['user']),
    isGridMember() {
      return this.user.girdCheckType > 0
    },
  },
  onLoad() {
    this.$dict.load('appIntegralApplyEventStatus').then(() => {
      this.getListInit()
    })
    this.getTypeList()
    uni.$on('updateList', () => {
      this.getListInit()
    })
  },
  methods: {
    getListInit() {
      this.current = 1
      this.pages = 2
      this.getList()
    },
    getList() {
      console.log(4)
      if (this.current > this.pages) return
      console.log(5)
      this.$http.post(`/app/appintegraluserapply/listByGridMember`,null, {
        params:{
          ...this.search,
          current: this.current,
          size: 10,
          girdId: this.user.girdId,
          applyItemId: this.search.type,
          createTimeStart: this.search.startTime,
          createTimeEnd: this.search.endTime
        }
      }).then(res=> {
        if(res?.data) {
          res.data.records.map((item) => {
            item.createTime = item.createTime.substring(0, 16)
          })
          this.list = this.current > 1 ? [...this.list, ...res.data.records]: res.data.records
          this.pages = Math.ceil(res.data.total / 10)
        }
      })
    },
    dateConfirm(e) {
      console.log(123)
      this.search.startTime = e.startDate
      this.search.endTime = e.endDate
      this.getListInit()
    },
    toDetail(id) {
      uni.navigateTo({url: `./detail?id=${id}`})
    },
    getTypeList() {
      this.$http.post(`/app/appintegralrule/listByFD?size=100`).then(res=> {
        if(res?.data) {
          this.typeList = res.data
        }
      })
    },
    typeConfirm(e) {
      this.search.type = e[0].value
      this.search.typeName = e[0].label
      this.getListInit()
    },
    pushNew(id) {
      this.pushNewId = id
      this.showPush = true
    },
    pushNewConfirm(status) {
      this.$http.post(`/app/appintegraluserapply/pushById?id=${this.pushNewId}&status=${status}`).then(res=> {
        if(res.code == 0) {
          this.$u.toast('推送成功')
          this.getListInit()
        }
      })
    },
    clearDate() {
      this.search.startTime = ''
      this.search.endTime = ''
      this.getListInit()
    },
    clearType() {
      this.search.type = ''
      this.search.typeName = ''
      this.getListInit()
    }
  },
  onReachBottom() {
    this.current = this.current + 1;
    this.getList();
  },
};
</script>

<style lang="scss" scoped>
.AppPointsReview {
  height: 100%;
  ::v-deep .AiTopFixed {
    .placeholder {
      .content {
        padding: 0 !important;
      }
    }
    .fixed {
      margin: 0 !important;
      .content {
        padding: 0 !important;
      }
    }
  }
  .top-search {
    padding: 20px 32px;
    display: flex;
    .left {
      width: 100%;
    }
  }
  .top-select {
    display: flex;
    padding: 28px 0;
    .item {
      flex: 1;
      // padding: 0 8px;
      text-align: center;
      span {
        display: inline-block;
        font-family: PingFangSC-Medium;
        font-weight: 500;
        font-size: 28px;
        color: #666;
        line-height: 40px;
      }
      .del-icon {
        width: 32px;
        height: 32px;
        vertical-align: middle;
        margin-left: 4px;
      }
    }
  }
  .list-content {
    padding: 32px;
    .item {
      border-radius: 8px;
      padding: 32px;
      background-color: #fff;
      margin-bottom: 32px;
      .title-flex {
        display: flex;
        .title {
          word-break: break-all;
          text-overflow: -o-ellipsis-lastline;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;	
          -webkit-line-clamp: 2;
          line-clamp: 2;					
          -webkit-box-orient: vertical;
          margin-bottom: 16px;
          color: #333;
          font-size: 32px;
          font-weight: 500;
          font-family: "PingFang SC";
          line-height: 44px;
          width: calc(100% - 182px);
        }
        .btn {
          width: 182px;
          text-align: right;
          padding-left: 32px;
          box-sizing: border-box;
          div {
            width: 150px;
            text-align: center;
            border-radius: 8px;
            line-height: 56px;
            background: #1365DD;
            color: #fff;
            font-size: 28px;
          }
          p {
            font-size: 28px;
            color: #666;
          }
        }
      }
      .user-name {
        font-size: 28px;
        color: #666;
        line-height: 34px;
        margin-bottom: 16px;
        span {
          margin-left: 32px;
        }
      }
      .time-flex {
        display: flex;
        justify-content: space-between;
        font-size: 28px;
        color: #999;
        line-height: 34px;
        .color-0{
          color: #FF9A40;
        }
        .color-1{
          color: #42D784;
        }
        .color-2{
          color: #cd413aff;
        }
      }
    }
  }
}
</style>