<template>
  <div id="red_letter_info_print">
    <div id="app" class="wrap">
      <div data-v-2eaedb6d="" class="print-container">
        <div data-v-2eaedb6d="" class="BwButton_wrap" style="margin-bottom: -20px;">
          <el-button v-print="'#localPrint'" type="primary" size="mini">打印</el-button>
        </div>
        <div data-v-2eaedb6d="" class="red-info-table-edit-container-print fit-needle-printer" id="localPrint">
          <div class="title-container"><p class="top-title">开具红字增值税专用发票信息表</p>
            <p class="info-title fit-font-size">填开日期：
              {{createTime}}
            </p></div>
          <table border="0" cellspacing="0" cellpadding="0" class="table">
            <tbody>
            <tr>
              <td rowspan="2" style="width: 70px;">销售方</td>
              <td>名称</td>
              <td colspan="2"><span class="content_td_blue">{{ sellerName }}</span></td>
              <td rowspan="2">购买方</td>
              <td>名称</td>
              <td colspan="2"><span class="content_td_blue">{{ buyerName }}</span></td>
            </tr>
            <tr>
              <td>纳税人识别号</td>
              <td colspan="2"><span class="content_td_blue fit-font-size">{{ sellerTaxNumber }}</span></td>
              <td>纳税人识别号</td>
              <td colspan="2"><span class="content_td_blue fit-font-size">{{ buyerTaxNumber }}</span></td>
            </tr>
            <tr>
              <td :rowspan="productNumber" style="line-height: 24px;"><p>开具</p>
                <p>红字</p>
                <p>专用</p>
                <p>发票</p>
                <p>内容</p></td>
              <td colspan="2">货物（劳务服务）名称</td>
<!--              <td>规格型号</td>-->
<!--              <td>单位</td>-->
              <td>数量</td>
              <td>单价</td>
              <td>金额</td>
              <td>税率</td>
              <td>税额</td>
            </tr>
            <tr v-for="(domain,index) in productData.product" :key="index">
              <td colspan="2" class="goods-line-height">
                <span :title="domain.productName" class="goods-content-td">{{ domain.productName }}</span>
              </td>
<!--              <td class="goods-line-height">-->
<!--                <span :title="domain.specification" class="goods-content-td">{{ domain.specification }}</span>-->
<!--              </td>-->
<!--              <td class="goods-line-height">-->
<!--                <span :title="domain.units" class="goods-content-td">{{ domain.units }}</span>-->
<!--              </td>-->
              <td class="goods-line-height">
                <span :title="domain.number" class="goods-content-td">{{ domain.number }}</span>
              </td>
              <td class="goods-line-height">
                <span :title="domain.price" class="goods-content-td">{{ domain.price }}</span>
              </td>
              <td class="goods-line-height">
                <span :title="domain.amount" class="goods-content-td">{{ domain.amount }}</span>
              </td>
              <td class="goods-line-height" v-if="domain.preferentialFlag !== 1">
                <span :title="domain.taxRate" class="goods-content-td">{{ domain.taxRate * 100 }}%</span>
              </td>
              <td class="goods-line-height" v-if="domain.preferentialFlag === 1">
                <span :title="domain.preferentialType" class="goods-content-td">{{ domain.preferentialType }}</span>
              </td>
              <td class="goods-line-height">
                <span :title="domain.taxAmount" class="goods-content-td">{{ domain.taxAmount }}</span>
              </td>
            </tr>
            <tr>
              <td colspan="2" class="goods-line-height">合计</td>
<!--              <td class="goods-line-height">&#45;&#45;&#45;&#45;</td>-->
<!--              <td class="goods-line-height">&#45;&#45;&#45;&#45;</td>-->
              <td class="goods-line-height">----</td>
              <td class="goods-line-height">----</td>
              <td class="goods-line-height">
                <span title="￥ -15406.44">￥ {{ totalAmount }}</span>
              </td>
              <td class="goods-line-height">--</td>
              <td class="goods-line-height">
                <span title="￥ -2002.84">￥ {{ totalTaxAmount }}</span>
              </td>
            </tr>
            <tr>
              <td>说明</td>
              <td colspan="7">
                <div class="footer-info">
                  <p class="top">一、购买方
                    <label v-if="this.sellerType === 2" class="ivu-checkbox-wrapper ivu-checkbox-wrapper-disabled ivu-checkbox-default">
                    <span class="ivu-checkbox ivu-checkbox-disabled">
                      <span class="ivu-checkbox-inner"></span>
                      <input type="checkbox" disabled="disabled" class="ivu-checkbox-input">
                    </span>
                    </label>
                    <label v-if="this.sellerType === 1"
                           class="ivu-checkbox-wrapper ivu-checkbox-wrapper-checked ivu-checkbox-wrapper-disabled ivu-checkbox-default">
                      <span class="ivu-checkbox ivu-checkbox-checked ivu-checkbox-disabled">
                        <span class="ivu-checkbox-inner"></span>
                        <input type="checkbox" disabled="disabled" class="ivu-checkbox-input">
                      </span>
                    </label>
                  </p>
                  <div class="inner"><p class="margin-left">对应蓝字专用发票抵扣增值税销项税额情况</p>
                    <p>1.已抵扣
                      <label v-if="this.sellerType === 2" class="ivu-checkbox-wrapper ivu-checkbox-wrapper-disabled ivu-checkbox-default">
                        <span class="ivu-checkbox ivu-checkbox-disabled">
                          <span class="ivu-checkbox-inner"></span>
                          <input type="checkbox" disabled="disabled" class="ivu-checkbox-input">
                        </span>
                      </label>
                      <label v-if="this.sellerType === 1 && this.deduction === true"
                          class="ivu-checkbox-wrapper ivu-checkbox-wrapper-checked ivu-checkbox-wrapper-disabled ivu-checkbox-default">
                      <span class="ivu-checkbox ivu-checkbox-checked ivu-checkbox-disabled">
                        <span class="ivu-checkbox-inner"></span>
                        <input type="checkbox" disabled="disabled" class="ivu-checkbox-input">
                      </span>
                      </label>
                    </p>
                    <p>2.未抵扣
                      <label v-if="this.sellerType === 2" class="ivu-checkbox-wrapper ivu-checkbox-wrapper-disabled ivu-checkbox-default">
                        <span class="ivu-checkbox ivu-checkbox-disabled">
                          <span class="ivu-checkbox-inner"></span>
                          <input type="checkbox" disabled="disabled" class="ivu-checkbox-input">
                        </span>
                      </label>
                      <label v-if="this.sellerType === 1 && this.deduction === false"
                             class="ivu-checkbox-wrapper ivu-checkbox-wrapper-checked ivu-checkbox-wrapper-disabled ivu-checkbox-default">
                      <span class="ivu-checkbox ivu-checkbox-checked ivu-checkbox-disabled">
                        <span class="ivu-checkbox-inner"></span>
                        <input type="checkbox" disabled="disabled" class="ivu-checkbox-input">
                      </span>
                      </label>
                    </p>
                    <p v-if="this.sellerType === 1" class="inner">
                      对应蓝字专用发票的代码：
                      <span class="underline fit-font-size">{{this.invoiceCode}}</span>号码：
                      <span class="underline fit-font-size">{{this.invoiceNumber}}</span>
                    </p>
                    <p v-if="this.sellerType === 2">
                      对应蓝字专用发票的代码：
                      <span>____________</span> 号码：
                      <span>________</span>
                    </p>
                  </div>
                  <p class="top">二、销售方
                    <label v-if="this.sellerType === 1" class="ivu-checkbox-wrapper ivu-checkbox-wrapper-disabled ivu-checkbox-default">
                        <span class="ivu-checkbox ivu-checkbox-disabled">
                          <span class="ivu-checkbox-inner"></span>
                          <input type="checkbox" disabled="disabled" class="ivu-checkbox-input">
                        </span>
                    </label>
                    <label v-if="this.sellerType === 2"
                           class="ivu-checkbox-wrapper ivu-checkbox-wrapper-checked ivu-checkbox-wrapper-disabled ivu-checkbox-default">
                      <span class="ivu-checkbox ivu-checkbox-checked ivu-checkbox-disabled">
                        <span class="ivu-checkbox-inner"></span>
                        <input type="checkbox" disabled="disabled" class="ivu-checkbox-input">
                      </span>
                    </label>
                  </p>
                  <div>
                    <p v-if="this.sellerType === 2" class="inner">
                    对应蓝字专用发票的代码：
                      <span class="underline fit-font-size">{{this.invoiceCode}}</span>号码：
                      <span class="underline fit-font-size">{{this.invoiceNumber}}</span>
                    </p>
                    <p v-if="this.sellerType === 1">
                      对应蓝字专用发票的代码：
                      <span>____________</span> 号码：
                      <span>________</span>
                    </p>
                  </div>
                </div>
              </td>
            </tr>
            <tr>
              <td style="line-height: 24px;">红字专<br>用发票<br>信息表<br>编号</td>
              <td colspan="7" style="text-align: left; padding-left: 10px;"><span
                  class="fit-font-size">{{this.redId}}</span>
              </td>
            </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import '@/utils/css/vendors_cloud.f1477f9009db57bbc536.css'
import '@/utils/css/cloud.54062173d5061201f805.css'
import '@/utils/css/199.10d0d599da4f7e87d765.css'
import { AxiosRequestData } from '@/data/axios_request'
import { InvoiceTotalAmount, RedLetterInfoProduct } from '@/data/invoice_calculation'
import cache from '@/utils/cache'

export default {
  name: 'red_letter_info_print',
  data() {
    return {
      token: '',
      requestId: '',
      buyerName: '',
      buyerTaxNumber: '',
      sellerName: '',
      sellerTaxNumber: '',
      productData: {
        product: [
          {
            productCheck: false,
            productName: '',
            productCode: '',
            specification: '',
            units: '',
            number: '',
            price: '',
            amount: '',
            taxRate: '',
            taxAmount: '',
            taxRates: '',
            totalAmountRate: '',
            preferentialFlag: 0,
            preferentialType: '',
            zeroRateFlag: null,
            rowStatus: 0 // 0表示正常行，1表示被折扣行，2表示折扣行，3表示开票成功展示数据, 4表示产品有优惠政策或者零税率，税率和税额不可修改
          }
        ]
      },
      invoiceCode: '',
      invoiceNumber: '',
      totalAmount: '',
      totalTaxAmount: '',
      totalAmountRate: '',
      discountTotalRate: '',
      sellerType: 1,
      deduction: false,
      redId: '',
      productNumber: 1,
      createTime: ''
    }
  },
  created() {
    this.token = cache.getToken()
  },
  mounted() {
    let data = this.$route.query.data.toString()
    this.requestId = JSON.parse(data).requestId
    this.redId = JSON.parse(data).redInfoNo
    let createTime = JSON.parse(data).createTime
    let date = createTime.split(' ')[0].split('-')
    this.createTime = date[0] + '年' + date[1] + '月' + date[2] + '日'
    this.getRedLetterData()
  },
  methods: {
    redInvoicePrint() {
    },
    // 计算总金额和总折扣金额
    calculationTotalAmount(products) {
      let total = InvoiceTotalAmount(products, this.isTaxIncluded)
      this.totalAmount = total.totalAmount
      this.totalTaxAmount = total.totalTaxRate
      this.totalAmountRate = total.totalAmountRate
      this.discountTotalRate = total.discountTotalRate
    },
    // 读取数据
    async getRedLetterData() {
      if (this.token) {
        const url = '/sys/invoice/redInfo/findApplyDetail'
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              requestId: this.requestId
            },
            false,
            2
        )
        if (response) {
          if (response.code === 0) {
            this.buyerName = response.data.REQUEST_COMMON_HZSQ.SPF_MC
            this.buyerTaxNumber = response.data.REQUEST_COMMON_HZSQ.SPF_NSRSBH
            this.sellerName = response.data.REQUEST_COMMON_HZSQ.KPF_MC
            this.sellerTaxNumber = response.data.REQUEST_COMMON_HZSQ.KPF_NSRSBH
            this.invoiceCode = response.data.REQUEST_COMMON_HZSQ.FPDM
            this.invoiceNumber = response.data.REQUEST_COMMON_HZSQ.FPHM
            if (response.data.REQUEST_COMMON_HZSQ.SQLX === 1) {
              this.sellerType = 1
              this.status = 1
            } else {
              this.sellerType = 2
              this.status = 2
            }
            if (response.data.REQUEST_COMMON_HZSQ.DKBZ) {
              this.deduction = true
              this.deductionFont = '已抵扣'
            } else {
              this.deduction = false
              this.deductionFont = '未抵扣'
            }
            this.invoiceType = response.data.REQUEST_COMMON_HZSQ.FPZL
            if (this.invoiceType === 1) {
              this.invoiceTypeName = '增值税普通电子发票'
            }
            if (this.invoiceType === 2) {
              this.invoiceTypeName = '增值税电子专用发票'
            }
            if (this.invoiceType === 3) {
              this.invoiceTypeName = '增值税普通纸质发票'
            }
            if (this.invoiceType === 4) {
              this.invoiceTypeName = '增值税专用纸质发票'
            }
            this.contactNumber = response.data.REQUEST_COMMON_HZSQ.LXDH
            this.explain = response.data.REQUEST_COMMON_HZSQ.SQLY
            let products = await RedLetterInfoProduct(response.data.REQUEST_COMMON_HZSQ
                .COMMON_FPKJ_XMXXS.COMMON_FPKJ_XMXX, this.entTaxId, this.token)
            this.calculationTotalAmount(products)
            this.productData.product = products
            this.productNumber = products.length + 2
          }
        }
      }
    }
  }
}
</script>

<style scoped>

</style>
