<template>
    <div class="panel panel-info auto">
        <div class="panel-heading auto" style="height: 35px">
            <h4 style="display:inline-block;margin-top: auto">开票信息</h4>
        </div>
        <div class="auto info-content" v-if="data">
            <div class="row">
                <label class="col-sm-4 ">名称:</label>
                <span class="col-sm-8">{{data.f_paper_name}}</span>
            </div>
            <div class="row">
                <label class="col-sm-4 ">地址电话:</label>
                <span class="col-sm-8">{{data.f_address_phone}}</span>
            </div>
            <div class="row">
                <label class="col-sm-4 ">纳税人识别号:</label>
                <span class="col-sm-8">{{data.f_taxpayer_id}}</span>
            </div>
            <div class="row">
                <label class="col-sm-4 ">开户行及账号:</label>
                <span class="col-sm-8">{{data.f_paper_account}}</span>
            </div>
            <div class="row">
                <label class="col-sm-4 ">票据类型:</label>
                <span class="col-sm-8">{{data.f_paper_type}}</span>
            </div>
            <div class="row" v-if="state">
              <label class="col-sm-4 " style="padding-top:0.4em">领取状态:</label>
              <span class="col-sm-8">{{state}}&emsp;
                  <button v-if="state==='未领'" class="button_search"
                    style="width: max-content"  @click="showInvoice">查看发票</button>
              </span>

            </div>
        </div>
      <div class="auto info-content" v-if="!data">
        <div class="row">
          <strong>暂无开票信息</strong>
        </div>
      </div>

      <modal :show.sync="show" v-ref:modal backdrop="true" width="1000px">
        <article slot="modal-body" class="modal-body">
          <div class="form-group auto" style="max-height: 1000px">
              <div class="form-horizontal select-overspread container-fluid auto" v-for="row in innvoice" style="margin-top:20px;flex: 1;">
                <div class="row">
                   <p class="form-control-static  col-sm-3">开&ensp;票&ensp;人:{{row.f_operator}}</p>
                    <p class="form-control-static  col-sm-3">发票类型:{{row.f_invoice_type}}</p>
                    <p class="form-control-static  col-sm-3">发票代码:{{row.f_invoice_dm}}</p>
                    <p class="form-control-static  col-sm-3">发票号码:{{row.f_invoice_num}}</p>
                    <p class="form-control-static  col-sm-3">发票金额:{{row.f_invoice_money}}</p>
                    <p class="form-control-static  col-sm-3">开票时间:{{row.f_invoice_date}}</p>
                    <p class="form-control-static  col-sm-3">备&emsp;&emsp;注:{{row.f_comments}}</p>
                </div>
                <div class="flex-row row" style="float:right;">
                  <button class="button_search"
                          style="width: max-content" title="权限:发票领用" :disabled="!this.$login.r.includes('发票领用')" @click="receive(row)">领取发票</button>

                </div>
              </div>

          </div>
        </article>
        <footer slot="modal-footer" class="modal-footer"></footer>
      </modal>
    </div>
</template>
<script>
  /**
   *用户信息
   *开票信息
   */

  import {DataModel, HttpResetClass} from 'vue-client'

  export default {
    title: '开票信息',
    data () {
      return {
        model: {},
        innvoice:[],
        hasCheck: -1,
        show:false
      }
    },
    props: ['data','state'],
    async ready(){
      console.log(88888888888888888888888888888,this.data)
    },
    methods:{
      showInvoice(){
        this.show= !this.show
        this.getinvoice(this.data.f_userinfo_code)
      },
      async receive(row){
        var params={
          id:row.id,
          f_state:'已领'
        }
        await this.$resetpost('rs/entity/t_invoiceuse', params, {resolveMsg: '领取成功', rejectMsg: '领取失败'})
        this.getinvoice(this.data.f_userinfo_code)

      },
      async getinvoice(val){
        let invo = await this.$resetpost('rs/sql/saleSingleTable',
          {data: {tablename:'t_invoiceuse',condition: ` f_invoice_usercode = '${val}' and f_state <> '无效' and f_state <> '已领'`}}, {resolveMsg: '', rejectMsg: '获取发票信息失败'})
        if(invo.data.length>0){
          this.innvoice=invo.data
          this.$dispatch('setstate',false)
        }else {
          this.show=false
          this.$dispatch('setstate',true)
        }
      }

    },
    watch:{
      // async 'data.f_userinfo_code'(val){
      //   if(val){
      //     await this.getinvoice(val)
      //   }
      // }
    }
  }
</script>
