<template>
  <div class="right_con">
    <div class="news_info_fgx fl"></div>
    <p class="power_apply fl">特权申请</p>
    <div class="clear"></div>
    <Table :columns="powerApplyList" :data="powerApplyData" class="tables" border></Table>
    <div class="page">
      <Page :total="count" :current="pindex" :page-size="10" size="small" show-total show-elevator @on-change="getApplyPower"/>
    </div>
    
    <confirmApply :pindex='pindex' :is_confirm_apply.sync="is_confirm_apply" :curInfo='curInfo' :honorNumber='honorNumber' @loadList='loadList'></confirmApply>
  </div>
</template>
<script>
import confirmApply from "@@/honor/confirm_apply";
export default {
  name: "power_apply",
  components: { confirmApply },
  data() {
    return {
      is_confirm_apply: false,
      curInfo:{},
      pindex:1,
      count:0,
      honorNumber:null,
      powerApplyList: [
        {
          title: "荣誉名称",
          key: "name"
        },
        {
          title: "推广等级",
          key: "rank"
        },
        {
          title: "最低荣誉值",
          key: "honor_num"
        },
        {
          title: "特权",
          render:(h,params)=>{
            let privilege=params.row.privilege?params.row.privilege:[]
            return h('p',privilege.map((item)=>{
              return h('p',{
                style:{
                  marginTop:'10px',
                  marginBottom:'10px',
                }
              },item.title)
            }))
          }
        },
        {
          title: "状态",
          render:(h,params)=>{
            // -2:不可申请,-1:可申请,0:审核中,1:待发放,2:已驳回,3:已发放
            if(params.row.apply_status==-2){
              return h('span',{
                style: {
                  color: "rgba(96, 122, 149, 1)"
                },
              },'不可申请')
            }
            if(params.row.apply_status==-1){
              return h('span',{
                style:{
                  color: 'rgba(96, 122, 149, 1)'
                }
              },'可申请')
            }
            if(params.row.apply_status==0){
              return h('span',{
                style:{
                  color: '#F9AB43'
                }
              },'审核中')
            }
            if(params.row.apply_status==1){
              return h('span',{
                style:{
                  color: '#169BD5'
                }
              },'待发放')
            }
            if(params.row.apply_status==2){
              return h('span',{
                style: {
                  color: "#FF0000"
                },
              },'已驳回')
            }
            if(params.row.apply_status==3){
              return h('span',{
                style:{
                  color: '#029D1E'
                }
              },'已发放')
            }
          }
        },
        {
          title: "操作",
          render:(h,params)=>{
            const apply=h('span',{
              class:'operate-btn',
              style:{
                color: 'rgb(0, 156, 255)'
              },
              on:{
                click:()=>{
                  this.is_confirm_apply=true
                  this.curInfo=params.row
                }
              }
            },'申请')
            const aglin_apply=h('span',{
              class:'operate-btn',
              style:{
                color: 'rgb(0, 156, 255)'
              },
              on:{
                click:()=>{
                  this.is_confirm_apply=true
                  this.curInfo=params.row
                }
              }
            },'再次申请')
            const dis_apply=h('span',{
              class:'operate-btn',
              style:{
                color: '#999999',
                cursor:'not-allowed'
              },
            },'申请')
            const gghx=h('span',{
              class:'operate-btn',
              style:{
                color: 'rgb(0, 156, 255)',
                cursor:'default'
              },
            },'--')
            if(params.row.apply_status==-1||params.row.apply_status==2){
              return [apply]
            }else if(params.row.apply_status==-2){
              return [dis_apply]
            }else if(params.row.apply_status==3){
              return [aglin_apply]
            }else{
              return [gghx]
            }
          }
        }
      ],
      powerApplyData: []
    };
  },
  watch: {},
  methods: {
    loadList(pindex){
      this.getApplyPower(pindex)
    },
    getApplyPower(page=1){
      this.pindex=page
      this.$store.commit('changeloading',true)
      this.$api.getApplyPower({limit:10,page:this.pindex}).then(data=>{
        if(data.code==200){
          this.count=data.count
          this.powerApplyData=data.data
          this.honorNumber=data.current_honor_num
          this.$store.commit('changeloading',false)
        }else{
          this.$store.commit('changeloading',false)
          this.$Message.info(data.msg)
        }
      })
    }
  },
  created() {
    this.getApplyPower()
  }
};
</script>
<style>
.power_apply{
  font-size: 15px;
  margin-left: 5px;
  margin-top: 15px
}
</style>


