<template>
  <div class="wrapper">
    <div class="fixed">
      <p><span>积分申请：</span>通过民主程序，将基层治理和服务各项事务转化为数量化指标，对个人日常行为进行评价。申请积分需管理员审核通过后系统自动发放积分。</p>
    </div>
    <div class="list">
      <div class="item" v-for="(item, index) in list" :key="index" @click="toAdd(item)">
        <div class="left">
          <h2>{{item.eventName}}</h2>
          <p>{{item.eventDesc}}</p>
        </div>
        <div class="right">
          <h2 class="color-E6736E">
            <span v-if="item.ruleType == 0">＋{{item.integral}}</span>
            <span v-if="item.ruleType == 1">＋{{item.ladderRule[0].integral}}-{{item.ladderRule[1].integral}}</span>
            <span v-if="item.ruleType == 2">＋{{item.integralMin}}-{{item.integralMax}}</span>
            <u-icon name="arrow-right" color="#ddd" size="24" style="margin-left: 4px" ></u-icon>
          </h2>
        </div>
      </div>
      <AiEmpty v-if="!list.length"/>
    </div>
    <div class="footer" @click="linkTo(`./list`)">
      <div class="btn">申请记录</div>
    </div>
  </div>
</template>
<script>
import {mapState} from 'vuex';

export default {
  name: "AppApplyPoint",
  appName: "党员积分申报",
  computed: {
    ...mapState(['user']),
  },
  data() {
    return {
      current: 1,
      pages: 2,
      list: []
    };
  },
  onLoad() {
    uni.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: "#E76056",
    })
    this.getList()
  },
  methods: {
    toAdd(row) {
      this.$instance.post(`/app/apppartyintegralrule/integralApply?integralId=${row.id}&partyId=${this.user.partyId}`).then(res => {
        if (res.code == 0) {
          uni.navigateTo({url: `./add?integralRuleId=${row.id}&integralRuleName=${row.eventName}`})
        }else {
          this.$u.toast(res.msg)
        }
      }).catch((err) => {
        this.$u.toast(err)
      })
    },
    getList() {
      if(this.current > this.pages) return
      this.$instance.post(`/app/apppartyintegralrule/list?classify=0&size=20&current=${this.current}`).then(res => {
        if (res.code == 0) {
          this.pages = res.data.pages
          res.data.records.map((item) => {
            item.ladderRule = JSON.parse(item.ladderRule)
          })
          if (this.current > 1) {
            this.list = [...this.list, ...res.data.records]
          } else {
            this.list = res.data.records
          }
        }
      })
    },
    linkTo(url) {
      uni.navigateTo({url})
    }
  },
  onReachBottom() {
    this.current ++
    this.getList()
  }
};
</script>
<style lang="scss" scope>
@import "~dvcp-wui/common";
.fixed{
  position: fixed;
  top: 0;
  left: 0;
  background-color: #FCEFEE;
  width: 100%;
  height: 172px;
  padding: 32px;
  box-sizing: border-box;
  p{
    font-size: 26px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #E76056;
    line-height: 36px;
    span{
      font-weight: 600;
    }
  }
}
.list{
  padding: 172px 0 120px 0;
  .item{
    padding: 32px;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    background-color: #fff;
    h2{
      font-size: 32px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #333;
      line-height: 44px;
      margin-bottom: 8px;
    }
    p{
      font-size: 26px;
      font-family: PingFangSC-Regular, PingFang SC;
      color: #999;
      line-height: 36px;
      overflow:hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    .left{
      width: 480px;
    }
    .right{
      width: calc(100% - 480px);
      text-align: right;
      h2{
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
      }
    }
    .color-E6736E{
      color: #E6736E;
    }
    .color-F0A046{
      color: #F0A046;
    }
  }
}
.footer{
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 16px 32px;
  background-color: #f3f6f9;
  z-index: 99;
  .btn{
    width: 686px;
    height: 88px;
    line-height: 88px;
    text-align: center;
    background: #E76056;
    border-radius: 16px;
    font-size: 34px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #FFF;
  }
}
</style>
