<template>
  <modal :show.sync="modal" width="50%" title="提示信息">
    <article slot="modal-body">
      <div style="width:98%;margin: auto" v-show="showInformation">
        <div v-show="filesNotComplete" style="font-size: 15px;padding: 10px"> 用户档案信息不全，请完善
          <span style="float: right">
            <button class="button_search" @click="operational('files_complete')">完善信息</button>
            <button class="button_search" @click="close" >取消</button>
          </span>
        </div>
        <div v-show="isBlackList" style="font-size: 15px;padding: 10px"> 黑名单用户,无法进行收费操作
          <span style="float: right">
            <button class="button_search" @click="close">确定</button>
          </span>
        </div>
        <div v-show="!isBlackList&&isBasicLiving" style="font-size: 15px;padding: 10px"> {{basicinformation}}
          <span style="float: right">
            <button class="button_search" @click="operational('basic-living')">低保续保</button>
            <button class="button_search" @click="operational('stop-basic-living')" v-if="stopBasicLiving">停止续保</button>
            <button class="button_search" @click="success('isBasicLiving')" v-if="!stopBasicLiving">确认</button>
          </span>
        </div>
        <p>{{authorityInformation}}</p>
      </div>
      <div style="width:98%;margin: auto" v-show="!showInformation" ><route v-ref:route @close="close" @success="success" v-show="!showInformation" :data="row"></route></div>
    </article>
    <footer slot="modal-footer" class="modal-footer" style="text-align: center;border: 0">
      <!--如果想忽略到期信息，modal的值设为null-->
      <!--      <button class="button_clear" @click="ignore" v-if="basicLiving">忽略</button>-->
    </footer>
  </modal>
</template>
<script>

  import {HttpResetClass} from 'vue-client'
  import Vue from "vue";

  let initGen = async function (self) {

    self.modal=true
    if(!self.row.f_price_id || !self.row.f_gasmodel_id || !self.row.f_gasbrand_id){
        self.filesNotComplete = true
    }
    let _this = self
    self.$login.f.functions[1].children.forEach(function (value) {
      if (value.name === '特殊用户') {
        _this.basicLivingAuthority = true
      }
    })
    console.log("============================",self.data)
    self.data.data.forEach(function (value) {
      if (value.f_parameter_key === 'dibaohu_endDate' && _this.basicLivingAuthority) {
        if (value.days <= 0) {
          _this.isBasicLiving = true
          _this.basicinformation = '低保已到期' + (-value.days) + '天'
          _this.stopBasicLiving = true
        } else if(value.days> 0 && value.days<self.dibao_remind){
          _this.isBasicLiving = true
          _this.basicinformation = '低保还有' + (value.days) + '天到期'
        }else {
          console.log('低保剩余天数大于提醒天数')
        }
      }else  if (value.f_parameter_key === 'blackList' && _this.filesCompleteAuthority) {
        _this.isBlackList = true
      }
    })
    if(!self.filesNotComplete && !self.isBlackList && !self.isBasicLiving){
      self.authorityInformation = '您没有相关的业务操作权限, 请联系管理员！！'
    }
  }

  export default {
    title: '收费弹出框',
    props: {
      //动态属性表数据
      data: {
        type: Object,
      },
      //双击用户的数据
      row:{
        type: Object,
      },
    },
    data() {
      return {
        showInformation:true,
        modal:true,
        informationtype:'',
        //档案不完善
        filesNotComplete:false,
        //黑名单
        isBlackList:false,
        //低保户到期
        isBasicLiving:false,
        //终止低保户 必选低保户到期
        stopBasicLiving:false,
        //低保户信息
        basicinformation:'',
        //低保户到期提醒时间
        dibao_remind:this.$appdata.getSingleValue('低保快到期提醒')? this.$appdata.getSingleValue('低保快到期提醒'):0,
        //低保户权限
        basicLivingAuthority:false,
        //档案完善权限
        filesCompleteAuthority:this.$login.r.includes('档案完善')
      }
    },
    ready(){
      console.log(this.data,"===============")
    },
    methods: {
      close(){
        this.$emit('close')
      },
      async success(val){
        //
        if(val === 'filesNotComplete') {
          this.filesNotComplete = false
        }else if(val === 'isBasicLiving') {
            this.isBasicLiving=false;
        }
        //如果所有提示信息均处理，获取改户数据，进入收费操作
        if(!this.filesNotComplete && !this.isBlackList && !this.isBasicLiving){
          this.showInformation = false
          let data =await this.$resetpost('rs/sql/sale_getUser', {data: {condition:`1=1 and f_userinfo_code = '${this.row.f_userinfo_code}' and u.f_filialeid = ${this.$login.f.orgid}`}}, {resolveMsg: '', rejectMsg: ''})
          this.$emit('modalsuccess',data.data[0])
        }else{//没有处理完，显示提示信息
          this.showInformation = true
        }
      },
      operational(val) {
        this.showInformation = false
        this.$refs.route.init(val, {data: this.row})
      },
    },
    ready(){
      initGen(this)
    },
    watch: {
      'modal'(val){
        console.log(val,"==================")
        if(!val){
          this.$emit('close')
        }
      }
    }
  }
</script>
<style>
  .basic-main {
    width: 79%;
  }
</style>
