<template>
  <div>
    <Modal v-model="is_confirm_applyMd" title="确认信息" id="confirm_apply" width="320" :mask-closable='false'>
      <Form ref="applyInfo" :model="applyInfo" :rules="applyInfo_role" :label-width="160">
        <FormItem label="申请账号" class="mar_T_5">
          <p class="item_con">{{username}}</p>
        </FormItem>
        <FormItem label="可用荣誉值">
          <p class="item_con">{{honorNumber}}</p>
        </FormItem>
        <FormItem label="兑换所需荣誉值">
          <p class="item_con">{{applyInfo.honor_num}}</p>
        </FormItem>
        <FormItem label="剩余荣誉值">
          <p class="item_con">{{Number(honorNumber-applyInfo.honor_num)}}</p>
        </FormItem>
        <FormItem label="申请特权">
          <p class="item_con" v-for="item in applyInfo.privilege" :key="item.title">{{item.title}}</p>
        </FormItem>
        <div style="width:100%" class="form_btn pad_B_15 mar_T_5">
          <Button class="return_btn mar_L_70 " style="padding-top:3px!important" @click="is_confirm_applyMd=false">取消</Button>
          <Button type="primary" class="mar_L_15" style="padding-top:3px!important" @click="applyPower">确认</Button>
        </div>
      </Form>
    </Modal>
  </div>
</template>
<script>
import { mapState } from "vuex";
import { getStore } from "@/utils/utils";
export default {
  name: "confirm_apply",
  props: {
    is_confirm_apply: Boolean,
    curInfo: Object,
    pindex:Number,
    honorNumber: Number,
  },
  data() {
    return {
      applyInfo: {
        manager_name:'',
        honor_num:'',
        privilege:[],
      },
      applyInfo_role: {}
    };
  },
  computed: {
    is_confirm_applyMd: {
      get() {
        return this.is_confirm_apply;
      },
      set(val) {
        this.$emit("update:is_confirm_apply", val);
      }
    },
    username(){
      return getStore('userInfo').name
    },
    ...mapState({
      nickname: state => state.adminInfo.nickname
    }),
  },
  watch:{
    is_confirm_apply(n){
      if(n){
        if(this.curInfo.apply_status == 2) {
          this.curInfo.honor_num = 0
        }
        this.applyInfo=this.curInfo 
      }
    }
  },
  methods:{
    applyPower(){
      this.$api.applePower({id:this.applyInfo.id}).then(data=>{
        if(data.code==200){
          this.$Message.info(data.msg)
          this.is_confirm_applyMd=false
          this.$emit('loadList',this.pindex)
        }else{
          this.$Message.info(data.msg)
        }
      })
    }
  }
};
</script>
<style>
#confirm_apply .ivu-modal-footer{
  display: none
}
#confirm_apply .ivu-form-item{
  margin-bottom: 5px!important
}
#confirm_apply .item_con{
  padding-left: 12px;
  color: rgb(0, 156, 255)
}
</style>
