<template>
  <div class="infoList">
    <!-- tab栏 -->
    <div style="position: fixed; top: 0; left: 0;width: 100%;">
      <div class="area">
        <div>区域选择</div>
        <div>
          <AiAreaPicker v-model="areaId" :areaId="user.areaId" @select="changeArea" :name.sync="areaName">
            <span style="margin-left: 4px" v-if="areaName">{{ areaName }}</span>
            <span v-else>请选择</span>
            <u-icon name="arrow-right" color="#666" size="28" style="margin-left: 4px" />
          </AiAreaPicker>
        </div>
      </div>
      <div class="tab-select">
        <div class="item" :class="tabIndex == index ? 'active' : ''" v-for="(item, index) in tabs" :key="index" @click="tabClick(index)">{{item}}<span></span></div>
      </div>
      <div class="search-box">
        <div class="integral-types" @click="showType = true">
          <span>{{ topicType? topicType:'话题类型' }}</span>
          <u-icon name="arrow-down"></u-icon></div>
        <u-search placeholder="请输入标题/发布人" v-model="content" :show-action="false" @search="getList()" @clear="getList()"></u-search>
      </div>
    </div>
    <!-- 列表 -->
    <div class="card-list" v-if="villagerList.length">
      <div class="card-item" v-for="(item,index) in villagerList" :key="index" @click="toDetail(item)">
        <div class="card-title">{{ item.content }}</div>
        <div class="card-name">
          <div class="name">{{$dict.getLabel('villagerCircleTopic',item.topic)}}</div>
          <div class="time">{{ item.createTime }}</div>
        </div>
        <div class="card-type">
          <div>{{ item.createUserName }}</div>
          <div class="type" :style="{color: item.status==0? '#4181FF':item.status==1? '#07c160' : '#dd5347'}">{{$dict.getLabel('auditStatus',item.status)}}</div>
        </div>
      </div>
    </div>
    <AiEmpty description="暂无数据" class="emptyWrap" style="padding-top:150px" v-else></AiEmpty>
    <u-select v-model="showType" :list="list" label-name="dictName" value-name="dictValue"
            @confirm="confirmTypeSelect"/>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'infoList',
  data () {
    return {
      tabs: ['全部', '待处理', '已处理'],
      tabIndex: '',
      showType: false,
      content: '',
      typeList: [],
      villagerList: [],
      current: 1,
      topic: '',
      topicType: '',
      list: [],
      areaId: '',
      areaName: '',
    }
  },
  computed: {
    ...mapState(['user'])
  },
  onLoad() {
    this.areaId = this.user.areaId
    this.areaName = this.user.areaName
    this.getList()
    this.$dict.load('villagerCircleTopic','auditStatus').then(()=>{
      uni.$on('update',()=>{
        this.current = 1
        this.getList()
      })
    })
    let all = [{ dictName: '全部', dictValue: '', dictColor: null }]
    this.list = [...all, ...this.$dict.getDict('villagerCircleTopic')]
  },
  methods: {
    tabClick(index) {
      this.tabIndex = index
      this.current = 1,
      this.topic = '',
      this.topicType = '',
      this.villagerList = [],
      this.getList()
    },
    changeArea(e) {
      this.areaId = e
      this.getList()
    },
    getList() {
      this.$http.post('app/appvillagercircleinfo/list',null,{
        params: {
          current: this.current,
          auditType: this.tabIndex == 0 ? '': this.tabIndex == 1 ? 0 : 1,
          topic: this.topic,
          content: this.content,
          areaId: this.areaId
        }
      }).then(res=>{
        if(res?.data) {
          this.villagerList = this.current >1 ? [...this.villagerList,...res.data.records]:res.data.records
        }
      })
    },

    confirmTypeSelect(e) {
      this.topic = e[0].value,
      this.topicType = e[0].label
      this.current = 1,
      this.villagerList = []
      this.getList()
    },

    toDetail(item) {
      uni.navigateTo({url: `./infoDetail?id=${item.id}`})
    }
  },
  onShow() {
    document.title = '发布信息审核'
  },
  onReachBottom() {
    this.current ++,
    this.getList()
  }
}
</script>

<style lang="scss" scoped>
.infoList {
  .area {
    display:flex;
    justify-content:space-between; 
    padding: 0 30px;
    height: 80px; 
    line-height: 80px;
    background: #FFFF;
  }
  .tab-select {
    width: 100%;
    height: 96px;
    line-height: 96px;
    background: #FFFFFF;
    display: flex;
    border-bottom: 1px solid #ddd;
    border-top: 1px solid #ddd;

    .item{
      flex: 1;
      text-align: center;
      font-size: 28px;
      font-family: PingFangSC-Regular, PingFang SC;
      color: #333;
    }

    .active{
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 600;
      position: relative;
      color: #3975C6;
      span{
        width: 48px;
        height: 4px;
        background: #3975C6;
        position: absolute;
        bottom: 14px;
        left: 50%;
        margin-left: -24px;
      }
    }
  }

  .search-box {
    display: flex;
    width: 100%;
    height: 112px;
    line-height: 112px;
    background-color: #FFFFFF;
    padding: 0 32px;
    box-sizing: border-box;

    .integral-types {
      display: flex;
      white-space:nowrap;
      justify-content:flex-start;
      margin-right: 20px;
      width: 180px;
      span {
        display: block;
        width:160px;
        overflow:hidden;
        text-overflow:ellipsis;
        white-space:nowrap;
      }
      u-icon {
        width: 40px;
      }
    }
  }

  .card-list {
    width: 100%;
    padding: 280px 32px 20px 32px;
    box-sizing: border-box;
    background: #f5f5f5;

    .card-item {
      margin-top: 24px;
      background-color: #FFFFFF;
      box-shadow: 0px 0px 16px 16px rgba(0, 0, 0, 0.04);
      border-radius: 16px;
      padding: 30px 32px 20px 32px;

      .card-title {
        height: 60px;
        line-height: 60px;
        font-size: 36px;
        color: #333333;
        overflow:hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        -o-text-overflow:ellipsis;
      }

      .card-name {
        margin-top: 30px;
        display: flex;
        height: 50px;
        line-height: 50px;
        font-size: 28px;
        color: #999999;

        .name {
          padding: 0 15px;
          background: #EEEEEE;
          border-radius: 24px;
          margin-right: 20px;
        }
      }

      .card-type {
        display: flex;
        justify-content: space-between;
        margin-top: 30px;
        font-size: 28px;

        .num {
          font-size: 34px;
          color: #E6736E;
        }

        .status0 {
          color: #FF9B2B;
        }

        .status1 {
          color: #4181FF;
        }

      }
    }
  }
}
</style>
