<template>
  <div class="integralapply">
    <u-tabs :list="list" :is-scroll="false" :current="currentTab" @change="change" style="width: 50%" bg-color="#197df0" active-color="#FFF;" inactive-color="#FFF"></u-tabs>

    <div class="middle">
      <div class="nav">
        <div class="navLeft" @click="showType = true">
          <span>{{ name ? name : '全部类型' }}</span>

          <u-icon name="arrow-down" v-if="!name"></u-icon>
        </div>

        <u-search v-model="searchObj" placeholder="请输入姓名或电话" :show-action="false" clearabled bg-color="#fff" search-icon-color="#6AA8F8" placeholder-color="#D0D4D4" @search="handerSearch" @clear=";(searchObj = ''), init()" />
      </div>

      <template v-if="data.length">
        <div class="items" v-for="(item, i) in data" :key="i" @click="toAdd(0, item)">
          <div class="cards">
            <div class="cont">{{ item.description }}</div>

            <div class="flex">
              <span class="tags">{{ $dict.getLabel('atWillReportType', item.applyIntegralType) }}</span>
              <span class="times">{{ item.createTime }}</span>
            </div>
          </div>

          <div class="card">
            <span :class="item.auditStatus == 0 ? 'status2' : item.auditStatus == 1 ? 'status0' : 'status1'" class="status">
              <span>{{ $dict.getLabel('auditStatus', item.auditStatus) }}</span>

              <span v-if="item.auditStatus == 1">
                <span v-if="item.auditIntegral * 1 > 0">+</span>
                <span>{{ item.auditIntegral }}分</span>
              </span>
            </span>
          </div>
        </div>
      </template>

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

    <div class="fixedBtn" @click="toAdd(1)">我要申请</div>

    <u-select v-model="showType" :list="$dict.getDict('atWillReportType')" value-name="dictValue" label-name="dictName" @confirm="confirm"></u-select>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: 'AppIntegralApply',
  appName: '积分申请',
  components: {},
  props: {},
  data() {
    return {
      name: '',
      list: [
        {
          name: '全部',
        },
        {
          name: '待审核',
        },
        {
          name: '已审核',
        },
      ],
      currentTab: 0,
      showType: false,
      value: '',
      name: '',
      searchObj: '',
      data: [],
      current: 1,
    }
  },
  computed: {
    ...mapState(['user']),
  },
  watch: {},
  onLoad() {
    this.$dict.load('atWillReportType', 'auditStatus').then(() => {
      this.getList()
    })
  },
  onshow() {
    uni.$on('updateList', () => {
      this.current = 1
      this.getList()
    })
  },
  methods: {
    getList() {
      this.$instance
        .post('/app/appvillagerintegraldeclare/list', null, {
          params: {
            size: 6,
            current: this.current,
            residentId: this.user.residentId,
            description: this.searchObj,
            applyIntegralType: this.value,
            auditType: this.currentTab == '0' ? '' : this.currentTab == '1' ? '0' : this.currentTab == 2 ? '1|2' : '',
          },
        })
        .then((res) => {
          if (res.code == 0) {
            this.data = this.current > 1 ? [...this.data, ...res.data.records] : res.data.records
          }
        })
    },

    toAdd(index, item) {
      if (index == '0') {
        this.$linkTo(`./detail?id=${item.id}`)
      }
      if (index == '1') {
        this.$linkTo(`./add`)
      }
    },

    init() {
      this.data = []
      this.current = 1
      this.getList()
    },

    change(index) {
      this.currentTab = index
      this.data = []
      this.current = 1
      this.getList()
    },

    confirm(e) {
      this.value = e[0].value
      this.name = e[0].label
      this.init()
    },

    handerSearch(e) {
      this.searchObj = e
      this.init()
    },
  },
  onReachBottom() {
    this.current = this.current + 1
    this.getList()
  },
}
</script>

<style scoped lang="scss">
.integralapply {
  height: 100%;
  ::v-deep .u-tabs {
    padding-right: 326px;
    padding-top: 24px;
    padding-bottom: 12px;
  }

  .middle {
    padding: 0 32px;
    padding-bottom: 112px;
    .nav {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 54px 0 14px 0;
      .navLeft {
        width: calc(100% - 460px);
      }
      ::v-deep u-search {
        width: 460px;
      }
    }

    .items {
      margin-top: 24px;
      .cards {
        padding: 32px;
        background: #fff;
        border-radius: 16px 16px 0px 0px;
        box-shadow: inset 0px -1px 0px 0px #dddddd;
        .cont {
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 3;
          -webkit-box-orient: vertical;
        }

        .flex {
          display: flex;
          justify-content: space-between;
          margin-top: 28px;
          .tags {
            display: inline-block;
            padding: 4px 16px;
            background: #eeeeee;
            border-radius: 24px;
          }
          .times {
            width: 53%;
            font-size: 28px;
            color: #999;
            margin-left: 15px;
          }
        }
      }

      .card {
        padding: 32px 0 32px 32px;
        background: #fff;
        box-shadow: inset 0px -1px 0px 0px #dddddd;
        border-radius: 0px 0px 16px 16px;
        .status {
          font-size: 28px;
        }
        .status0 {
          color: #42d784;
        }
        .status1 {
          color: #ff4466;
        }
        .status2 {
          color: #ff883c;
        }
      }
    }
  }

  .fixedBtn {
    position: fixed;
    bottom: 0;
    width: 100%;
    box-sizing: border-box;
    background: #4181ff;
    padding: 20px 0;
    text-align: center;
    border-radius: 16px;
    font-size: 34px;
    font-weight: 600;
    color: #ffffff;
    z-index: 999;
  }
}
</style>
