<template>
  <div id="deduction_check_statistics" class="body" v-loading="load" :element-loading-text="loadText">
    <div>
      <el-radio-group v-model="isPeriods">
        <el-radio-button :label="true"
        >当前属期数据统计
        </el-radio-button
        >
        <el-radio-button :label="false"
        >历史属期数据统计
        </el-radio-button
        >
      </el-radio-group>
    </div>
    <div class="statistics_div" v-show="isPeriods">
      <div>
        <div class="title_bar">
          <div>
            <span class="title_bar_font">税款所属期：</span>
            <span style="color: red">{{ nowDate }}</span>
            <span style="margin-left: 5px">报表类型：</span>
            <el-radio-group v-model="reportType">
              <el-radio :label="1">发票统计表</el-radio>
              <!--              <el-radio :label="2">异常发票统计表</el-radio>-->
            </el-radio-group>
          </div>
          <div>
            <el-button
                v-print="'#deductionInfo'"
                type="primary"
                round
            >打印
            </el-button
            >
            <el-button
                type="primary"
                v-on:click="getTaxControlData(1)"
                round
            >统计查询
            </el-button
            >
          </div>
        </div>
        <div class="title_bar_end">
          <el-button
              type="primary"
              v-if="status === 1 && deductionStatus !== '2'"
              v-on:click="applicationConfirmation(1)"
              round
          >申请统计
          </el-button
          >
          <el-button
              type="primary"
              v-if="status === 2"
              v-on:click="passwordConfirm"
              round
          >确认
          </el-button
          >
          <el-button
              type="primary"
              v-if="status !== 1"
              v-on:click="revokeInfo"
              round
          >撤销统计
          </el-button
          >
        </div>
        <div style="margin: 20px" v-if="reportType === 1">
          <el-steps
              :active="applyStatus"
              finish-status="success"
              align-center
          >
            <el-step
                title="申请统计"
                :description="applyTime"
            ></el-step>
            <el-step
                title="统计完成"
                :description="completeTime"
            ></el-step>
            <el-step
                title="确认"
                :description="confirmTime"
            ></el-step>
          </el-steps>
          <!--          <el-button style="margin-top: 12px;" @click="next">下一步</el-button>-->
        </div>
        <div id="deductionInfo" v-if="reportType === 1" style="">
          <div>
            <div class="table_title" style="text-align: center">
              发票统计表
              <!--              <span style="display:none;">&nbsp;——&nbsp;</span>-->
              <!--              <span class="font_4"></span>-->
            </div>
            <div style="text-align: center" v-if="status === 3">
                            <span class="font_4"
                            >（报表更新时间：{{ submitTime }})</span
                            >
            </div>
            <table width="100%" class="table_height_title_font">
              <tbody>
              <tr v-if="status === 3">
                <td>
                                        <span
                                            class="table_height_title_font color_2"
                                        >纳税人名称：{{ entName }}</span
                                        >
                </td>
                <td>
                                        <span
                                            class="table_height_title_font color_2"
                                        >纳税人识别号：{{ entTaxId }}</span
                                        >
                </td>
                <td>
                                        <span
                                            class="table_height_title_font color_2"
                                        >所属月份：{{ month }}</span
                                        >
                </td>
                <td align="right">
                                        <span
                                            class="table_height_title_font color_2 mar_l_30"
                                        >单位：（份、元）</span
                                        >
                </td>
              </tr>
              </tbody>
            </table>
            <div>
              <table
                  class="table_height_title_font resultTable"
                  border="1"
              >
                <tbody>
                <tr>
                  <th width="20%" rowspan="2">
                    <div class="out">
                      <b style="left: -45px">用途</b>
                      <em style="color: #000000"
                      >发票类型</em
                      >
                    </div>
                  </th>
                  <th width="40%" colspan="3">抵扣</th>
                  <th width="40%" colspan="3">不抵扣</th>
                </tr>
                <tr>
                  <th>份数</th>
                  <th>金额</th>
                  <th>有效税额</th>
                  <th>份数</th>
                  <th>金额</th>
                  <th>有效税额</th>
                </tr>
                <tr
                    v-bind:key="index"
                    v-for="(item, index) in dataList"
                    style="text-align: center"
                >
                  <td>{{ item.categoryMemo }}</td>
                  <td>{{ item.deductedCount }}</td>
                  <td>{{ item.deductedAmt }}</td>
                  <td>{{ item.deductedTaxEffective }}</td>
                  <td>{{ item.undeductedCount }}</td>
                  <td>{{ item.undeductedAmt }}</td>
                  <td>
                    {{ item.undeductedTaxEffective }}
                  </td>
                </tr>
                <tr
                    v-if="dataList.length === 0"
                    style="text-align: center"
                >
                  <td colspan="7">
                    未找到符合条件的数据
                  </td>
                </tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                <tr></tr>
                </tbody>
              </table>
            </div>
            <div class="mainBox1">
              <div class="title_two">
                <span class="two_info">备注</span>
              </div>
              <div class="tips color_2">
                1、本统计表包括当前税款所属期内所有勾选为抵扣和不抵扣的增值税发票、海关缴款书；<br/>2、一个属期内对已勾选的发票、海关缴款书支持多次申请统计操作；<br/>3、申报期内，对已勾选数据进行申请统计后，系统将自动锁定当期抵扣勾选操作；如需继续勾选发票、海关缴款书，可在撤销统计成功后继续进行发票、海关缴款书勾选或撤勾选操作；<br/>4、申报期内，申请统计完成后正式进行申报前，需在本平台对抵扣统计表进行确认操作；<br/>5、申报期内，对抵扣统计表确认后申报完成前，支持撤销统计，系统将自动撤销抵扣统计表和确认，撤销完成后可以继续勾选发票、海关缴款书，修正完毕后需再次进行申请统计和确认操作；<br/>6、当发票统计表显示为“<span
                  style="color: #d75452"
              >预统计</span
              >”时，表示当前时间还未到当前属期的申报时间，不能对统计表进行确认操作。请于下月1日后重新申请统计，再进行确认操作。
              </div>
            </div>
          </div>
        </div>
        <!--        <div v-if="reportType === 2" style="">-->
        <!--          <div>-->
        <!--            <div class="table_title" style="text-align: center">-->
        <!--              异常发票统计表-->
        <!--            </div>-->
        <!--            <table width="100%" class="table_height_title_font" style="">-->
        <!--              <tbody>-->
        <!--              <tr>-->
        <!--                <td><span class="table_height_title_font color_2">纳税人名称：云南滇阁商贸有限公司</span></td>-->
        <!--                <td><span class="table_height_title_font color_2">纳税人识别号：91530102MA6NWGCQ6G</span></td>-->
        <!--                <td><span class="table_height_title_font color_2">所属月份：2020年10月</span></td>-->
        <!--                <td align="right"><span class="table_height_title_font color_2 mar_l_30">单位：（份、元）</span></td>-->
        <!--              </tr>-->
        <!--              </tbody>-->
        <!--            </table>-->
        <!--            <div>-->
        <!--              <table class="table_height_title_font resultTable" border="1">-->
        <!--                <tbody>-->
        <!--                <tr>-->
        <!--                  <th width="20%" rowspan="2">-->
        <!--                    <div class="out">-->
        <!--                      <b style="left: -45px">用途</b>-->
        <!--                      <em style="color:#000000;">发票类型</em>-->
        <!--                    </div>-->
        <!--                  </th>-->
        <!--                  <th width="40%" colspan="3">抵扣</th>-->
        <!--                  <th width="40%" colspan="3">不抵扣</th>-->
        <!--                </tr>-->
        <!--                <tr>-->
        <!--                  <th>份数</th>-->
        <!--                  <th>金额</th>-->
        <!--                  <th>有效税额</th>-->
        <!--                  <th>份数</th>-->
        <!--                  <th>金额</th>-->
        <!--                  <th>有效税额</th>-->
        <!--                </tr>-->
        <!--                <tr>-->
        <!--                  <td>增值税专用发票</td>-->
        <!--                  <td>1</td>-->
        <!--                  <td>44,036.70</td>-->
        <!--                  <td>3,963.30</td>-->
        <!--                  <td>0</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0.00</td>-->
        <!--                </tr>-->
        <!--                <tr>-->
        <!--                  <td>机动车销售统一发票</td>-->
        <!--                  <td>0</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0.00</td>-->
        <!--                </tr>-->
        <!--                <tr>-->
        <!--                  <td>增值税电子专用发票</td>-->
        <!--                  <td>0</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0.00</td>-->
        <!--                </tr>-->
        <!--                <tr>-->
        <!--                  <td>通行费电子发票</td>-->
        <!--                  <td>0</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0.00</td>-->
        <!--                </tr>-->
        <!--                <tr>-->
        <!--                  <td>海关缴款书</td>-->
        <!--                  <td>0</td>-->
        <!--                  <td>-</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0</td>-->
        <!--                  <td>-</td>-->
        <!--                  <td>0.00</td>-->
        <!--                </tr>-->
        <!--                <tr>-->
        <!--                  <td>出口转内销发票</td>-->
        <!--                  <td>0</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0.00</td>-->
        <!--                </tr>-->
        <!--                <tr>-->
        <!--                  <td>出口转内销海关缴款书</td>-->
        <!--                  <td>0</td>-->
        <!--                  <td>-</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0</td>-->
        <!--                  <td>-</td>-->
        <!--                  <td>0.00</td>-->
        <!--                </tr>-->
        <!--                <tr>-->
        <!--                  <td>出口转内销电子专用发票</td>-->
        <!--                  <td>0</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0.00</td>-->
        <!--                </tr>-->
        <!--                <tr>-->
        <!--                  <td>总计</td>-->
        <!--                  <td>1</td>-->
        <!--                  <td>44,036.70</td>-->
        <!--                  <td>3,963.30</td>-->
        <!--                  <td>0</td>-->
        <!--                  <td>0.00</td>-->
        <!--                  <td>0.00</td>-->
        <!--                </tr>-->
        <!--                <tr></tr>-->
        <!--                <tr></tr>-->
        <!--                <tr></tr>-->
        <!--                <tr></tr>-->
        <!--                </tbody>-->
        <!--              </table>-->
        <!--            </div>-->
        <!--            <div class="mainBox1">-->
        <!--              <div class="title_two"><span class="two_info">备注</span></div>-->
        <!--              <div class="tips color_2">异常发票统计表为申报完成后在本属期变为异常的增值税发票、海关缴款书，请按照税务相关规定进行转出处理。-->
        <!--              </div>-->
        <!--            </div>-->
        <!--            <div>-->
        <!--              <div class="title_bar">-->
        <!--                <div>-->
        <!--                  <span class="title_bar_font">发票清单：</span>-->
        <!--                </div>-->
        <!--                <div>-->
        <!--                  <el-button type="primary" round>查询</el-button>-->
        <!--                </div>-->
        <!--              </div>-->
        <!--              <div class="title_bar">-->
        <!--                <div>-->
        <!--                  <span>发票类别：</span>-->
        <!--                  <el-radio-group v-model="invoiceType">-->
        <!--                    <el-radio :label="1">增值税发票</el-radio>-->
        <!--                    <el-radio :label="2">海关缴款书</el-radio>-->
        <!--                    <el-radio :label="3">出口转内销发票</el-radio>-->
        <!--                    <el-radio :label="4">出口转内销海关缴款书</el-radio>-->
        <!--                  </el-radio-group>-->
        <!--                </div>-->
        <!--              </div>-->
        <!--              <div class="select_info">-->
        <!--                <div v-if="invoiceType === 3 || invoiceType === 4">-->
        <!--                  <span>转内销证明编号：</span>-->
        <!--                  <el-input v-model="input" placeholder="请输入内容" class="input_style"></el-input>-->
        <!--                </div>-->
        <!--                <div v-if="invoiceType === 1 || invoiceType === 3">-->
        <!--                  <span>发票代码：</span>-->
        <!--                  <el-input v-model="input" placeholder="请输入内容" class="input_style"></el-input>-->
        <!--                </div>-->
        <!--                <div v-if="invoiceType === 1 || invoiceType === 3">-->
        <!--                  <span>发票号码：</span>-->
        <!--                  <el-input v-model="input" placeholder="请输入内容" class="input_style"></el-input>-->
        <!--                </div>-->
        <!--                <div v-if="invoiceType === 1 || invoiceType === 3">-->
        <!--                  <span>开票日期：</span>-->
        <!--                  <el-date-picker-->
        <!--                      v-model="value1"-->
        <!--                      type="date"-->
        <!--                      placeholder="选择日期">-->
        <!--                  </el-date-picker>-->
        <!--                  —-->
        <!--                  <el-date-picker-->
        <!--                      v-model="value1"-->
        <!--                      type="date"-->
        <!--                      placeholder="选择日期">-->
        <!--                  </el-date-picker>-->
        <!--                </div>-->
        <!--                <div v-if="invoiceType === 2 || invoiceType === 4">-->
        <!--                  <span>海关缴款书号码：</span>-->
        <!--                  <el-input v-model="input" placeholder="请输入内容" class="input_style"></el-input>-->
        <!--                </div>-->
        <!--                <div v-if="invoiceType === 2 || invoiceType === 4">-->
        <!--                  <span>填发日期：</span>-->
        <!--                  <el-date-picker-->
        <!--                      v-model="value1"-->
        <!--                      type="date"-->
        <!--                      placeholder="选择日期">-->
        <!--                  </el-date-picker>-->
        <!--                  —-->
        <!--                  <el-date-picker-->
        <!--                      v-model="value1"-->
        <!--                      type="date"-->
        <!--                      placeholder="选择日期">-->
        <!--                  </el-date-picker>-->
        <!--                </div>-->
        <!--              </div>-->
        <!--              <div class="title_bar">-->
        <!--                <span class="title_bar_font">查询结果：</span>-->
        <!--              </div>-->
        <!--              <div>-->
        <!--                <div>-->
        <!--                  <table width="100%" class="table_height_title_font" style="">-->
        <!--                    <tbody>-->
        <!--                    <tr>-->
        <!--                      <td><span class="table_height_title_font color_2">纳税人名称：云南滇阁商贸有限公司</span></td>-->
        <!--                      <td><span class="table_height_title_font color_2">纳税人识别号：91530102MA6NWGCQ6G</span>-->
        <!--                      </td>-->
        <!--                      <td><span class="table_height_title_font color_2">所属月份：2020年10月</span></td>-->
        <!--                      <td align="right"><span class="table_height_title_font color_2 mar_l_30">单位：（份、元）</span></td>-->
        <!--                    </tr>-->
        <!--                    </tbody>-->
        <!--                  </table>-->
        <!--                  <div>-->
        <!--                    <tax_table v-if="invoiceType === 1" ref="taxTable" :inputTaxTable="this"></tax_table>-->
        <!--                    <customs_table v-if="invoiceType === 2" ref="customsTable"-->
        <!--                                   :inputCustomsTable="this"></customs_table>-->
        <!--                    <export_to_domestic v-if="invoiceType === 3" ref="exportToDomestic"-->
        <!--                                        :inputExportToDomestic="this"></export_to_domestic>-->
        <!--                    <export_to_customs v-if="invoiceType === 4" ref="exportToCustoms"-->
        <!--                                       :inputExportToCustoms="this"></export_to_customs>-->
        <!--                  </div>-->
        <!--                </div>-->
        <!--              </div>-->
        <!--            </div>-->
        <!--          </div>-->
        <!--        </div>-->
      </div>
    </div>
    <div class="statistics_div" v-show="!isPeriods">
      <div>
        <div class="title_bar">
          <div>
            <span>税款所属期：</span>
            <el-date-picker
                v-model="selectDate"
                type="month"
                placeholder="选择日期"
                value-format="yyyyMM"
                :editable="false"
                :picker-options="dateOptions"
            >
            </el-date-picker>
            <span>报表类型：</span>
            <el-radio-group v-model="historyReportType">
              <el-radio :label="1">发票统计表</el-radio>
              <!--              <el-radio :label="2">异常发票统计表</el-radio>-->
            </el-radio-group>
          </div>
          <div>
            <el-button
                v-print="'#historyDeductionInfo'"
                type="primary"
                round
            >打印
            </el-button
            >
            <el-button
                type="primary"
                v-on:click="getTaxControlData(2)"
                round
            >统计查询
            </el-button
            >
          </div>
        </div>
      </div>
      <div id="historyDeductionInfo">
        <div class="table_title" style="text-align: center">
          发票统计表
          <span id="wq_table_" style="display: none"
          >&nbsp;——&nbsp;</span
          >
          <span id="wq_table_text" class="font_4"></span>
          <span class="font_4" v-if="historyStatus === 2"
          >（报表更新时间：{{ historySubmitTime }})</span
          >
        </div>
        <table width="100%" class="table_height_title_font" style="">
          <tbody>
          <tr v-if="historyStatus === 2">
            <td>
                                <span class="table_height_title_font color_2"
                                >纳税人名称：{{ entName }}</span
                                >
            </td>
            <td>
                                <span class="table_height_title_font color_2"
                                >纳税人识别号：{{ entTaxId }}</span
                                >
            </td>
            <td>
                                <span class="table_height_title_font color_2"
                                >所属月份：{{ month }}</span
                                >
            </td>
            <td align="right">
                                <span
                                    class="table_height_title_font color_2 mar_l_30"
                                >单位：（份、元）</span
                                >
            </td>
          </tr>
          </tbody>
        </table>
        <div>
          <table
              class="table_height_title_font resultTable"
              border="1"
          >
            <tbody>
            <tr>
              <th width="20%" rowspan="2">
                <div class="out">
                  <b id="wq_rzfs_b" style="left: -45px"
                  >用途</b
                  >
                  <em style="color: #000000">发票类型</em>
                </div>
              </th>
              <th width="40%" colspan="3">抵扣</th>
              <th width="40%" colspan="3">不抵扣</th>
            </tr>
            <tr>
              <th>份数</th>
              <th>金额</th>
              <th>有效税额</th>
              <th>份数</th>
              <th>金额</th>
              <th>有效税额</th>
            </tr>
            <tr
                v-bind:key="index"
                v-for="(item, index) in historyDataList"
                style="text-align: center"
            >
              <td>{{ item.categoryMemo }}</td>
              <td>{{ item.deductedCount }}</td>
              <td>{{ item.deductedAmt }}</td>
              <td>{{ item.deductedTaxEffective }}</td>
              <td>{{ item.undeductedCount }}</td>
              <td>{{ item.undeductedAmt }}</td>
              <td>{{ item.undeductedTaxEffective }}</td>
            </tr>
            <tr
                v-if="historyDataList.length === 0"
                style="text-align: center"
            >
              <td colspan="7">未找到符合条件的数据</td>
            </tr>
            <tr id="wq_row_9"></tr>
            <tr id="wq_row_10"></tr>
            <tr id="wq_row_11"></tr>
            <tr id="wq_tjbb_row"></tr>
            </tbody>
          </table>
        </div>
        <div class="mainBox1">
          <div class="title_two">
            <span class="two_info">备注</span>
          </div>
          <div class="tips color_2">
            1、本统计表包括当前选定税款所属期内所有勾选为抵扣和不抵扣的增值税发票、海关缴款书；<br/>2、本统计表只允许查询下载近一年数据。
          </div>
        </div>
      </div>
      <div>
        <div class="title_bar">
          <div>
            <span class="title_bar_font">发票清单：</span>
          </div>
          <div>
            <!--            <el-button type="primary" round>查询明细下载</el-button>-->
            <el-button
                type="primary"
                round
                v-on:click="invoiceSearch"
            >查询
            </el-button
            >
            <el-button
                type="primary"
                round
                v-on:click="invoiceExport"
            >导出
            </el-button
            >
          </div>
        </div>
        <div class="title_bar">
          <div>
            <span>发票类别：</span>
            <el-radio-group v-model="invoiceType">
              <el-radio :label="1">增值税发票</el-radio>
              <!--              <el-radio :label="2">海关缴款书</el-radio>-->
              <!--              <el-radio :label="3">出口转内销发票</el-radio>-->
              <!--              <el-radio :label="4">出口转内销海关缴款书</el-radio>-->
            </el-radio-group>
          </div>
        </div>
        <div class="select_info">
          <!--          <div v-if="invoiceType === 3 || invoiceType === 4">-->
          <!--            <span>转内销证明编号：</span>-->
          <!--            <el-input v-model="input" placeholder="请输入内容" class="input_style"></el-input>-->
          <!--          </div>-->
          <!--          <div v-if="invoiceType === 2 || invoiceType === 4">-->
          <!--            <span>海关缴款书号码：</span>-->
          <!--            <el-input v-model="input" placeholder="请输入内容" class="input_style"></el-input>-->
          <!--          </div>-->
          <div v-if="invoiceType === 1 || invoiceType === 3">
            <span>发票代码：</span>
            <el-input
                v-model="invoiceCode"
                placeholder="请输入内容"
                class="input_style"
                clearable
            ></el-input>
          </div>
          <div v-if="invoiceType === 1 || invoiceType === 3">
            <span>发票号码：</span>
            <el-input
                v-model="invoiceNumber"
                placeholder="请输入内容"
                class="input_style"
                clearable
            ></el-input>
          </div>
          <div v-if="invoiceType === 1 || invoiceType === 3">
            <span>销方税号：</span>
            <el-input
                v-model="sellTaxId"
                placeholder="请输入内容"
                class="input_style"
                clearable
            ></el-input>
          </div>
          <!--          <div>-->
          <!--            <span>勾选日期：</span>-->
          <!--            <el-date-picker-->
          <!--                v-model="checkDateBegin"-->
          <!--                type="date"-->
          <!--                placeholder="选择日期">-->
          <!--            </el-date-picker>-->
          <!--            —-->
          <!--            <el-date-picker-->
          <!--                v-model="checkDateEnd"-->
          <!--                type="date"-->
          <!--                placeholder="选择日期">-->
          <!--            </el-date-picker>-->
          <!--          </div>-->
          <!--          <div>-->
          <!--            <span>用途：</span>-->
          <!--            <el-radio-group v-model="invoiceType">-->
          <!--              <el-radio :label="1">全部</el-radio>-->
          <!--              <el-radio :label="2">抵扣</el-radio>-->
          <!--              <el-radio :label="3">不抵扣</el-radio>-->
          <!--            </el-radio-group>-->
          <!--          </div>-->
        </div>
        <div class="title_bar">
          <span class="title_bar_font">查询结果：</span>
        </div>
        <div>
          <div>
            <table
                width="100%"
                class="table_height_title_font"
                id="wq_tjbb"
                style=""
            >
              <tbody>
              <tr v-if="historyStatus === 2">
                <td>
                                        <span
                                            class="table_height_title_font color_2"
                                        >纳税人名称：{{ entName }}</span
                                        >
                </td>
                <td>
                                        <span
                                            class="table_height_title_font color_2"
                                        >纳税人识别号：{{ entTaxId }}</span
                                        >
                </td>
                <td>
                                        <span
                                            class="table_height_title_font color_2"
                                        >所属月份：{{ month }}</span
                                        >
                </td>
                <td align="right">
                                        <span
                                            class="table_height_title_font color_2 mar_l_30"
                                        >单位：（份、元）</span
                                        >
                </td>
              </tr>
              </tbody>
            </table>
            <div v-if="historyReportType === 1">
              <history_tax_table
                  v-if="invoiceType === 1"
                  ref="historyTaxTable"
                  :inputHistoryTaxTable="this"
              ></history_tax_table>
              <history_customs_table
                  v-if="invoiceType === 2"
                  ref="historyCustomsTable"
                  :inputHistoryCustomsTable="this"
              ></history_customs_table>
              <history_export_to_domestic
                  v-if="invoiceType === 3"
                  ref="historyExportToCustoms"
                  :inputHistoryExportToDomestic="this"
              ></history_export_to_domestic>
              <history_export_to_customs
                  v-if="invoiceType === 4"
                  ref="historyExportToDomestic"
                  :inputHistoryExportToCustoms="this"
              ></history_export_to_customs>
            </div>
            <div v-if="historyReportType === 2">
              <history_abnormal_tax_table
                  v-if="invoiceType === 1"
                  ref="HistoryAbnormalTaxTable"
                  :inputHistoryAbnormalTaxTable="this"
              ></history_abnormal_tax_table>
              <history_abnormal_customs_table
                  v-if="invoiceType === 2"
                  ref="HistoryAbnormalCustomsTable"
                  :inputHistoryAbnormalCustomsTable="this"
              ></history_abnormal_customs_table>
              <history_abnormal_export_to_domestic
                  v-if="invoiceType === 3"
                  ref="HistoryAbnormalExportToDomestic"
                  :inputHistoryAbnormalExportToDomestic="this"
              ></history_abnormal_export_to_domestic>
              <history_abnormal_export_to_customs
                  v-if="invoiceType === 4"
                  ref="HistoryAbnormalExportToCustoms"
                  :inputHistoryAbnormalExportToCustoms="this"
              ></history_abnormal_export_to_customs>
            </div>
          </div>
        </div>
      </div>
    </div>
    <el-dialog
        title="提示信息"
        :visible.sync="isShowPassword"
        width="30%"
        v-on:before-close="passwordPageClose"
    >
      <span>请输入确认密码：</span>
      <el-input
          style="width: 250px"
          show-password
          v-model="password"
          placeholder="请输入确认密码"
      ></el-input>
      <div slot="footer" class="customer">
        <el-button @click="isShowPassword = false">取 消</el-button>
        <el-button
            type="primary"
            v-on:click="certificationStatisticsPassword"
        >确 定
        </el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
// import TaxTable from './components/tax_table'
// import CustomsTable from './components/customs_table'
// import ExportToCustoms from './components/export_to_customs'
// import ExportToDomestic from './components/export_to_domestic'
import HistoryTaxTable from './components/history_tax_table'
import HistoryCustomsTable from './components/history_customs_table'
import HistoryExportToCustoms from './components/history_export_to_customs'
import HistoryExportToDomestic from './components/history_export_to_domestic'
import HistoryAbnormalTaxTable from './components/history_abnormal_tax_table'
import HistoryAbnormalCustomsTable from './components/history_abnormal_customs_table'
import HistoryAbnormalExportToCustoms from './components/history_abnormal_export_to_customs'
import HistoryAbnormalExportToDomestic from './components/history_abnormal_export_to_domestic'
import { AxiosRequestData } from '@/data/axios_request'
import cache from '@/utils/cache'
import { getDeductionSyncInputData } from '@/api/invoice-deduction'

export default {
  name: 'deduction_check_statistics',
  components: {
    // tax_table: TaxTable,
    // customs_table: CustomsTable,
    // export_to_customs: ExportToCustoms,
    // export_to_domestic: ExportToDomestic,
    history_tax_table: HistoryTaxTable,
    history_customs_table: HistoryCustomsTable,
    history_export_to_customs: HistoryExportToCustoms,
    history_export_to_domestic: HistoryExportToDomestic,
    history_abnormal_tax_table: HistoryAbnormalTaxTable,
    history_abnormal_customs_table: HistoryAbnormalCustomsTable,
    history_abnormal_export_to_customs: HistoryAbnormalExportToCustoms,
    history_abnormal_export_to_domestic: HistoryAbnormalExportToDomestic,
  },
  data() {
    return {
      load: false,
      loadText: '查询中，请稍等',
      isPeriods: true,
      reportType: 1,
      historyReportType: 1,
      applyStatus: -1,
      invoiceType: 1,
      nowDate: '',
      nowDates: '',
      applyTime: '',
      completeTime: '',
      confirmTime: '',
      status: 1,
      entTaxId: '',
      entName: '',
      account: '',
      token: '',
      selectDate: '',
      historyStatus: 1,
      historyDataList: [],
      historySubmitTime: '',
      submitTime: '',
      month: '',
      dataList: [],
      invoiceCode: '',
      invoiceNumber: '',
      sellTaxId: '',
      checkDateBegin: '',
      checkDateEnd: '',
      isShowPassword: false,
      password: '',
      dateOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now() - 8.64e6
        },
      },
      deductionStatus: '1',
    }
  },
  async created() {
    await this.getNowDate()
    let user = JSON.parse(cache.getSession('user'))
    let company = JSON.parse(cache.getSession('company'))
    this.entName = company.entName
    this.entTaxId = company.entTaxId
    this.account = user.account
    this.token = cache.getToken()
    // this.entTaxId = '9122222222222A0090'
    await this.getTaxControlData(1)
  },
  methods: {
    next() {
      this.applyStatus += 1
    },
    // 获取当前所属期日期
    async getNowDate() {
      // this.nowDate = '2020年09月'
      // this.nowDates = '202009'
      let date = await getDeductionSyncInputData()
      this.nowDate =
          date.data.periodYear + '年' + date.data.periodMonth + '月'
      if (date.data.periodMonth > 9) {
        this.nowDates =
            date.data.periodYear.toString() +
            date.data.periodMonth.toString()
      } else {
        this.nowDates =
            date.data.periodYear.toString() +
            '0' +
            date.data.periodMonth.toString()
      }
    },
    // 获取当前所属期日期
    getNowDateTime() {
      let nowDate = new Date()
      let date = {
        year: nowDate.getFullYear(),
        month: nowDate.getMonth() + 1,
        date: nowDate.getDate(),
        hour: nowDate.getHours(),
        minute: nowDate.getMinutes(),
        second: nowDate.getSeconds(),
      }
      return (
          date.year +
          '-' +
          date.month +
          '-' +
          date.date +
          ' ' +
          date.hour +
          ':' +
          date.minute +
          ':' +
          date.second
      )
    },
    // 统计申请和撤销
    applicationConfirmation(type) {
      if (type === 1) {
        this.$confirm('是否确定申请生成统计报表！', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
            .then(() => {
              this.certificationStatistics(type)
            })
            .catch(() => {
            })
      } else {
        this.$confirm('请确认是否撤销当前统计报表！', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
            .then(() => {
              this.certificationStatistics(type)
            })
            .catch(() => {
            })
      }
    },
    // 发票申请认证和撤销
    async certificationStatistics(type) {
      const url = '/sys/invoice/deduction/statRequest'
      if (this.token && this.entTaxId) {
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              entTaxId: this.entTaxId,
              mobile: this.account,
              period: this.nowDates,
              taskType: type,
              delayStat: 0,
              reqChannel: 4,
            },
            false,
            1
        )
        if (response) {
          if (response.code === 0) {
            this.$alert(response.data.statusMemo, '提示', {
              confirmButtonText: '确定',
              callback: (action) => {
                // 无操作
              },
            })

            if (type === 1) {
              this.applyStatus = 1
              await this.getTaxControlData(type)
            } else {
              // await this.certificationStatisticsAutograph(2)
              this.applyStatus = -1
              this.applyTime = ''
              this.status = 1
              this.dataList = []
              this.completeTime = ''
              this.confirmTime = ''
            }
          } else {
            this.$message.error(response.msg)
          }
        }
      }
    },
    // 发票申请认证签名确认
    async certificationStatisticsAutograph(type) {
      const url = '/sys/invoice/deduction/signRequest'
      if (this.token && this.entTaxId) {
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              entTaxId: this.entTaxId,
              mobile: this.account,
              period: this.nowDates,
              taskType: type,
              delayConfirm: 0,
              reqChannel: 4,
            },
            false,
            1
        )
        if (response) {
          if (response.code === 0) {
            this.$alert(response.data.statusMemo, '提示', {
              confirmButtonText: '确定',
              callback: (action) => {
                // 无操作
              },
            })

            if (type === 1) {
              this.load = false
              this.isShowPassword = false
              this.applyStatus = 3
            } else {
              this.applyStatus = -1
              this.applyTime = ''
              this.status = 1
              this.dataList = []
              this.completeTime = ''
              this.confirmTime = ''
            }
          } else {
            this.load = false
            this.$message.error(response.msg)
          }
        }
      }
    },
    // 发票申请认证密码确认
    async certificationStatisticsPassword() {
      if (this.password === '') {
        this.$message({
          message: '请输入密码！',
          type: 'warning',
        })
        return
      }
      const url = '/sys/invoice/deduction/confirmPasswd'
      if (this.token && this.entTaxId) {
        this.loadText = '密码确认中，请稍等！'
        this.load = true
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              entTaxId: this.entTaxId,
              mobile: this.account,
              reqSource: 'password',
              confirmPassword: this.password,
            },
            false,
            1
        )
        if (response) {
          if (response.code === 0) {
            await this.certificationStatisticsAutograph(1)
          } else {
            this.load = false
            this.$message.error(response.msg)
          }
        }
      }
    },
    // 获取所属期数据
    async getTaxControlData(type) {
      this.loadText = '查询中，请稍等'
      let date = ''
      if (type === 1) {
        this.month = this.nowDate
        date = this.nowDates
      } else {
        this.month =
            this.selectDate.substring(0, 4) +
            '年' +
            this.selectDate.substring(4)
        date = this.selectDate
        if (date === '') {
          this.$message.error('税款所属期不能为空！')
          return
        }
      }
      const url = '/sys/invoice/deduction/periodStat'
      if (this.token && this.entTaxId) {
        this.load = true
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              entTaxId: this.entTaxId,
              period: date,
            },
            false,
            2
        )
        if (response) {
          this.load = false
          if (response.data !== null) {
            this.$message(response.data.statStatusMemo)
          }
          if (response.code === 0 && response.data !== null) {
            this.deductionStatus = response.data.statStatus
            if (type === 1) {
              if (response.data.statStatus === '2') {
                this.applyStatus = 1
                this.applyTime = response.data.commitStatTime
                this.submitTime = response.data.commitStatTime
              }
              if (response.data.statData !== null) {
                this.dataList = response.data.statData
                this.submitTime = response.data.commitStatTime
                this.applyTime = response.data.commitStatTime
                if (
                    response.data.statStatus === '3' ||
                    response.data.statStatus === '4'
                ) {
                  this.applyStatus = 2
                  this.status = 2
                  this.completeTime =
                      response.data.commitStatTime
                }
                if (response.data.statStatus === '5') {
                  this.status = 3
                  this.applyStatus = 3
                  this.completeTime =
                      response.data.commitStatTime
                  this.confirmTime =
                      response.data.commitSignTime
                }
              }
            } else {
              if (response.data.statData !== null) {
                if (response.data.statStatus !== '1' || response.data.statStatus !== '2') {
                  this.historyStatus = 2
                  this.historySubmitTime =
                      response.data.commitStatTime
                  this.historyDataList =
                      response.data.statData
                } else {
                  this.historyStatus = 1
                  this.historySubmitTime = ''
                  this.historyDataList = []
                }
              } else {
                this.historyStatus = 1
                this.historySubmitTime = ''
                this.historyDataList = []
              }
            }
          } else {
            this.$message.error(response.msg)
          }
        }
      }
    },
    // 显示密码确认框
    passwordConfirm() {
      this.$confirm(
          '是否确认，确认后当前统计报表将作为纳税申报的依据！',
          '提示',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
          }
      )
          .then(() => {
            this.isShowPassword = true
          })
          .catch(() => {
          })
    },
    // 关闭密码确认框前清空数据
    passwordPageClose() {
      this.password = ''
    },
    // 历史发票数据查询
    invoiceSearch() {
      let present = true
      if (this.nowDates !== this.selectDate) {
        present = false
      }
      let searchData = {
        entTaxId: this.entTaxId,
        selectDate: this.selectDate,
        present: present,
        invoiceDateBegin: '',
        invoiceDateEnd: '',
        invoiceCode: this.invoiceCode,
        invoiceNumber: this.invoiceNumber,
        inputInvoiceCategory: '',
        sellerName: '',
        sellerEntTaxId: this.sellTaxId,
        pageNum: 1,
        pageSize: 10,
      }
      this.$refs.historyTaxTable.setSearchData(searchData)
    },
    // 撤销统计信息
    revokeInfo() {
      if (this.deductionStatus === '5') {
        this.$confirm('请确认是否撤销当前统计报表！', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
            .then(() => {
              this.certificationStatisticsAutograph(2)
            })
            .catch(() => {
            })
      }
      if (this.deductionStatus === '3') {
        this.$confirm('请确认是否撤销当前统计报表！', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
            .then(() => {
              this.certificationStatistics(2)
            })
            .catch(() => {
            })
      }
    },
    // 发票清单导出
    invoiceExport() {
      this.$refs.historyTaxTable.invoiceExport()
    }
  },
}
</script>

<style scoped>
.title_bar {
  display: flex;
  justify-content: space-between;
  align-content: center;
  align-items: center;
  margin-bottom: 10px;
}

.select_info {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
}

.select_info div {
  margin-right: 5px;
  margin-bottom: 5px;
}

.title_bar_end {
  display: flex;
  justify-content: flex-end;
}

.statistics_div {
  margin-top: 10px;
}

.title_bar_font {
  border-left: 5px solid #16307a;
  padding-left: 12px;
  display: inline-block;
}

.title_two {
  font-size: 16px;
  font-weight: 700;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid #ebebeb;
  position: relative;
}

.title_two .two_info {
  border-left: 5px solid #16307a;
  padding-left: 12px;
  display: inline-block;
}

.mainBox1 {
  margin-top: 10px;
  clear: both;
}

.table_title {
  font-size: 16px;
  font-weight: 700;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid #ebebeb;
  position: relative;
}

.dsa {
  font-size: 14px;
  font-family: "Microsoft YaHei", Tahoma, Arial, sans-serif;
  border-collapse: collapse;
  padding: 0;
  margin: 0;
  line-height: 40px;
  color: #888 !important;
}

.table_height_title_font {
  color: #333;
  font-size: 14px;
  font-family: "Microsoft YaHei", Tahoma, Arial, sans-serif;
  width: 100%;
  border-top-width: 1px;
  border-right-width: 1px;
  border-bottom-width: 1px;
  border-left-width: 1px;
  padding: 0;
  margin: 0;
  border-collapse: collapse;
  line-height: 40px;
}

.color_2 {
  color: #888 !important;
}

.out {
  border-top: 7em #56627f solid;
  border-left: 20em #fff solid;
  position: relative;
}

b,
em {
  font-style: normal;
  display: block;
  position: absolute;
  top: -5em;
}

.resultTable th {
  background: #56627f;
  color: #fff;
  border: 1px solid #000;
}

b {
  font-weight: bold;
}

th {
  font-weight: bold;
  /*text-align: -internal-center;*/
}

em {
  left: -270px;
}

.input_style {
  width: 250px;
}
</style>
