<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="110px">
      <el-row>
        <el-form-item label="购方名称" prop="buyerName">
          <el-input v-model="queryParams.buyerName" placeholder="请输入购方名称" clearable size="small"
                    @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="发票种类" prop="invoiceType">
          <el-select v-model="queryParams.invoiceType" placeholder="请选择发票种类" clearable size="small">
            <el-option v-for="dict in dict.type.invoice_type" :key="dict.value" :label="dict.label"
                       :value="dict.value"/>
          </el-select>
        </el-form-item>
        <el-form-item label="销方名称" prop="sellerName">
          <el-input
            v-model="queryParams.sellerName"
            placeholder="请输入销方名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="销方税号" prop="sellerTaxnum">
          <el-input
            v-model="queryParams.sellerTaxnum"
            placeholder="请输入销方税号"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
        <el-button type="text" @click="showMore = !showMore">
          {{ showMore === false ? "展开" : "隐藏" }}
          <i :class="[showMore === false ? 'el-icon-arrow-down' : 'el-icon-arrow-up']"></i>
        </el-button>
      </el-row>
      <el-row v-show="showMore">
        <el-form-item label="本系统订单号" prop="systemOrderno">
          <el-input v-model="queryParams.systemOrderno" placeholder="请输入本系统订单号" clearable size="small"
                    @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="客户系统订单号" prop="outTradeOrderno">
          <el-input v-model="queryParams.outTradeOrderno" placeholder="请输入客户系统订单号" clearable size="small"
                    @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="流水号" prop="fpqqlsh">
          <el-input v-model="queryParams.fpqqlsh" placeholder="请输入流水号" clearable size="small"
                    @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="购方税号" prop="buyerTaxnum">
          <el-input v-model="queryParams.buyerTaxnum" placeholder="请输入购方税号" clearable size="small"
                    @keyup.enter.native="handleQuery"/>
        </el-form-item>
      </el-row>

      <!-- <el-form-item label="购方地址" prop="buyerAddress">
        <el-input
          v-model="queryParams.buyerAddress"
          placeholder="请输入购方地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="购方电话" prop="buyerTelephone">
        <el-input
          v-model="queryParams.buyerTelephone"
          placeholder="请输入购方电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="购方开户行及账户" prop="buyerAccount">
        <el-input
          v-model="queryParams.buyerAccount"
          placeholder="请输入购方开户行及账户"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="购方邮箱" prop="buyerEmail">
        <el-input
          v-model="queryParams.buyerEmail"
          placeholder="请输入购方邮箱"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="购方联系电话" prop="buyerPhone">
        <el-input
          v-model="queryParams.buyerPhone"
          placeholder="请输入购方联系电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销方名称" prop="sellerName">
        <el-input
          v-model="queryParams.sellerName"
          placeholder="请输入销方名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销方税号" prop="sellerTaxnum">
        <el-input
          v-model="queryParams.sellerTaxnum"
          placeholder="请输入销方税号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销方地址" prop="sellerAddress">
        <el-input
          v-model="queryParams.sellerAddress"
          placeholder="请输入销方地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销方电话" prop="sellerTelephone">
        <el-input
          v-model="queryParams.sellerTelephone"
          placeholder="请输入销方电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销方开户行及账户" prop="sellerAccount">
        <el-input
          v-model="queryParams.sellerAccount"
          placeholder="请输入销方开户行及账户"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="message">
        <el-input
          v-model="queryParams.message"
          placeholder="请输入备注"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开票人" prop="clerk">
        <el-input
          v-model="queryParams.clerk"
          placeholder="请输入开票人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收款人" prop="payee">
        <el-input
          v-model="queryParams.payee"
          placeholder="请输入收款人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="复核人" prop="checker">
        <el-input
          v-model="queryParams.checker"
          placeholder="请输入复核人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="红字信息表编号" prop="redInvoiceInfoCode">
        <el-input
          v-model="queryParams.redInvoiceInfoCode"
          placeholder="请输入红字信息表编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开票分机号" prop="fjh">
        <el-input
          v-model="queryParams.fjh"
          placeholder="请输入开票分机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开票终端号" prop="terminalNumber">
        <el-input
          v-model="queryParams.terminalNumber"
          placeholder="请输入开票终端号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开票类型" prop="kptype">
        <el-select v-model="queryParams.kptype" placeholder="请选择开票类型" clearable size="small">
          <el-option
            v-for="dict in dict.type.invoice_kind"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="推送方式" prop="tsfs">
        <el-input
          v-model="queryParams.tsfs"
          placeholder="请输入推送方式"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="清单标志" prop="qdbz">
        <el-input
          v-model="queryParams.qdbz"
          placeholder="请输入清单标志"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="清单项目名称" prop="qdxmmc">
        <el-input
          v-model="queryParams.qdxmmc"
          placeholder="请输入清单项目名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="代开标志" prop="dkbz">
        <el-input
          v-model="queryParams.dkbz"
          placeholder="请输入代开标志"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="成品油标志" prop="cpybz">
        <el-input
          v-model="queryParams.cpybz"
          placeholder="请输入成品油标志"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开票状态" prop="state">
        <el-input
          v-model="queryParams.state"
          placeholder="请输入开票状态"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单来源" prop="source">
        <el-input
          v-model="queryParams.source"
          placeholder="请输入订单来源"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="服务公司" prop="serviceSupplierKey">
        <el-input
          v-model="queryParams.serviceSupplierKey"
          placeholder="请输入服务公司"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单据类型" prop="billType">
        <el-select v-model="queryParams.billType" placeholder="请选择单据类型" clearable size="small">
          <el-option
            v-for="dict in dict.type.bill_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="业务留存字段" prop="businessRemark">
        <el-input
          v-model="queryParams.businessRemark"
          placeholder="请输入业务留存字段"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开票时间" prop="invoicedTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.invoicedTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择开票时间">
        </el-date-picker>
      </el-form-item>
       -->
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['invoice:billinfo:add']">
          新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
                   v-hasPermi="['invoice:billinfo:edit']">
          修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
                   v-hasPermi="['invoice:billinfo:remove']">
          删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                   v-hasPermi="['invoice:billinfo:export']">
          导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="billinfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="序号" align="center" prop="id" width="60px"/>
      <!-- <el-table-column label="销方ID" align="center" prop="companyId" /> -->
      <el-table-column label="本系统订单号" align="center" prop="systemOrderno" width="120px"/>
      <el-table-column label="客户系统订单号" align="center" prop="outTradeOrderno" width="120px"/>
      <!-- <el-table-column label="流水号" align="center" prop="fpqqlsh" /> -->
      <el-table-column label="发票种类" align="center" prop="invoiceType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.invoice_type" :value="scope.row.invoiceType"/>
        </template>
      </el-table-column>
      <el-table-column label="购方名称" align="center" prop="buyerName"/>
      <el-table-column label="购方税号" align="center" prop="buyerTaxnum"/>
      <!-- <el-table-column label="购方地址" align="center" prop="buyerAddress" />
      <el-table-column label="购方电话" align="center" prop="buyerTelephone" />
      <el-table-column label="购方开户行及账户" align="center" prop="buyerAccount" />
      <el-table-column label="购方邮箱" align="center" prop="buyerEmail" />
      <el-table-column label="购方联系电话" align="center" prop="buyerPhone" />
      <el-table-column label="销方名称" align="center" prop="sellerName" />
      <el-table-column label="销方税号" align="center" prop="sellerTaxnum" />
      <el-table-column label="销方地址" align="center" prop="sellerAddress" />
      <el-table-column label="销方电话" align="center" prop="sellerTelephone" />
      <el-table-column label="销方开户行及账户" align="center" prop="sellerAccount" />
      <el-table-column label="备注" align="center" prop="message" />
      <el-table-column label="开票人" align="center" prop="clerk" />
      <el-table-column label="收款人" align="center" prop="payee" />
      <el-table-column label="复核人" align="center" prop="checker" />
      <el-table-column label="红字信息表编号" align="center" prop="redInvoiceInfoCode" /> -->
      <el-table-column label="开票分机号" align="center" prop="fjh"/>
      <el-table-column label="开票终端号" align="center" prop="terminalNumber"/>
      <el-table-column label="开票类型" align="center" prop="kptype">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.invoice_kind" :value="scope.row.kptype"/>
        </template>
      </el-table-column>
      <el-table-column label="推送方式" align="center" prop="tsfs">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tsfs" :value="scope.row.tsfs"/>
        </template>
      </el-table-column>
      <el-table-column label="清单标志" align="center" prop="qdbz">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.qdbz" :value="scope.row.qdbz"/>
        </template>
      </el-table-column>
      <!-- <el-table-column label="清单项目名称" align="center" prop="qdxmmc" /> -->
      <!-- <el-table-column label="代开标志" align="center" prop="dkbz">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.dkbz" :value="scope.row.dkbz" />
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="成品油标志" align="center" prop="cpybz">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cpybz" :value="scope.row.cpybz" />
        </template>
      </el-table-column> -->
      <el-table-column label="开票状态" align="center" prop="state">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bill_state" :value="scope.row.state"/>
        </template>
      </el-table-column>
      <el-table-column label="订单来源" align="center" prop="source">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.source" :value="scope.row.source"/>
        </template>
      </el-table-column>
      <!-- <el-table-column label="服务公司" align="center" prop="serviceSupplierKey">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.service_manage_service_suppliers" :value="scope.row.serviceSupplierKey" />
        </template>
      </el-table-column> -->
      <el-table-column label="单据类型" align="center" prop="billType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bill_type" :value="scope.row.billType"/>
        </template>
      </el-table-column>
      <el-table-column label="业务留存字段" align="center" prop="businessRemark" width="120px"/>
      <el-table-column label="开票时间" align="center" prop="invoicedTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.invoicedTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['invoice:billinfo:edit']">
            修改
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-cpu" @click="handlePush(scope.row)"
                     v-hasPermi="['invoice:billinfo:edit']">
            推送
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['invoice:billinfo:remove']">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

    <!-- 添加或修改开票信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="销方ID" prop="companyId">
          <el-input v-model="form.companyId" placeholder="请输入销方ID"/>
        </el-form-item>
        <el-form-item label="本系统订单号" prop="systemOrderno">
          <el-input v-model="form.systemOrderno" placeholder="请输入本系统订单号"/>
        </el-form-item>
        <el-form-item label="客户系统订单号" prop="outTradeOrderno">
          <el-input v-model="form.outTradeOrderno" placeholder="请输入客户系统订单号"/>
        </el-form-item>
        <el-form-item label="流水号" prop="fpqqlsh">
          <el-input v-model="form.fpqqlsh" placeholder="请输入流水号"/>
        </el-form-item>
        <el-form-item label="发票种类" prop="invoiceType">
          <el-select v-model="form.invoiceType" placeholder="请选择发票种类">
            <el-option v-for="dict in dict.type.invoice_type" :key="dict.value" :label="dict.label"
                       :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="购方名称" prop="buyerName">
          <el-input v-model="form.buyerName" placeholder="请输入购方名称"/>
        </el-form-item>
        <el-form-item label="购方税号" prop="buyerTaxnum">
          <el-input v-model="form.buyerTaxnum" placeholder="请输入购方税号"/>
        </el-form-item>
        <el-form-item label="购方地址" prop="buyerAddress">
          <el-input v-model="form.buyerAddress" placeholder="请输入购方地址"/>
        </el-form-item>
        <el-form-item label="购方电话" prop="buyerTelephone">
          <el-input v-model="form.buyerTelephone" placeholder="请输入购方电话"/>
        </el-form-item>
        <el-form-item label="购方开户行及账户" prop="buyerAccount">
          <el-input v-model="form.buyerAccount" placeholder="请输入购方开户行及账户"/>
        </el-form-item>
        <el-form-item label="购方邮箱" prop="buyerEmail">
          <el-input v-model="form.buyerEmail" placeholder="请输入购方邮箱"/>
        </el-form-item>
        <el-form-item label="购方联系电话" prop="buyerPhone">
          <el-input v-model="form.buyerPhone" placeholder="请输入购方联系电话"/>
        </el-form-item>
        <el-form-item label="销方名称" prop="sellerName">
          <el-input v-model="form.sellerName" placeholder="请输入销方名称"/>
        </el-form-item>
        <el-form-item label="销方税号" prop="sellerTaxnum">
          <el-input v-model="form.sellerTaxnum" placeholder="请输入销方税号"/>
        </el-form-item>
        <el-form-item label="销方地址" prop="sellerAddress">
          <el-input v-model="form.sellerAddress" placeholder="请输入销方地址"/>
        </el-form-item>
        <el-form-item label="销方电话" prop="sellerTelephone">
          <el-input v-model="form.sellerTelephone" placeholder="请输入销方电话"/>
        </el-form-item>
        <el-form-item label="销方开户行及账户" prop="sellerAccount">
          <el-input v-model="form.sellerAccount" placeholder="请输入销方开户行及账户"/>
        </el-form-item>
        <el-form-item label="备注" prop="message">
          <el-input v-model="form.message" placeholder="请输入备注"/>
        </el-form-item>
        <el-form-item label="开票人" prop="clerk">
          <el-input v-model="form.clerk" placeholder="请输入开票人"/>
        </el-form-item>
        <el-form-item label="收款人" prop="payee">
          <el-input v-model="form.payee" placeholder="请输入收款人"/>
        </el-form-item>
        <el-form-item label="复核人" prop="checker">
          <el-input v-model="form.checker" placeholder="请输入复核人"/>
        </el-form-item>
        <el-form-item label="红字信息表编号" prop="redInvoiceInfoCode">
          <el-input v-model="form.redInvoiceInfoCode" placeholder="请输入红字信息表编号"/>
        </el-form-item>
        <el-form-item label="开票分机号" prop="fjh">
          <el-input v-model="form.fjh" placeholder="请输入开票分机号"/>
        </el-form-item>
        <el-form-item label="开票终端号" prop="terminalNumber">
          <el-input v-model="form.terminalNumber" placeholder="请输入开票终端号"/>
        </el-form-item>
        <el-form-item label="开票类型" prop="kptype">
          <el-select v-model="form.kptype" placeholder="请选择开票类型">
            <el-option v-for="dict in dict.type.invoice_kind" :key="dict.value" :label="dict.label"
                       :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="推送方式" prop="tsfs">
          <el-input v-model="form.tsfs" placeholder="请输入推送方式"/>
        </el-form-item>
        <el-form-item label="清单标志" prop="qdbz">
          <el-input v-model="form.qdbz" placeholder="请输入清单标志"/>
        </el-form-item>
        <el-form-item label="清单项目名称" prop="qdxmmc">
          <el-input v-model="form.qdxmmc" placeholder="请输入清单项目名称"/>
        </el-form-item>
        <el-form-item label="代开标志" prop="dkbz">
          <el-input v-model="form.dkbz" placeholder="请输入代开标志"/>
        </el-form-item>
        <el-form-item label="成品油标志" prop="cpybz">
          <el-input v-model="form.cpybz" placeholder="请输入成品油标志"/>
        </el-form-item>
        <el-form-item label="开票状态" prop="state">
          <el-input v-model="form.state" placeholder="请输入开票状态"/>
        </el-form-item>
        <el-form-item label="订单来源" prop="source">
          <el-input v-model="form.source" placeholder="请输入订单来源"/>
        </el-form-item>
        <el-form-item label="服务公司" prop="serviceSupplierKey">
          <el-input v-model="form.serviceSupplierKey" placeholder="请输入服务公司"/>
        </el-form-item>
        <el-form-item label="单据类型" prop="billType">
          <el-select v-model="form.billType" placeholder="请选择单据类型">
            <el-option v-for="dict in dict.type.bill_type" :key="dict.value" :label="dict.label"
                       :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="业务留存字段" prop="businessRemark">
          <el-input v-model="form.businessRemark" placeholder="请输入业务留存字段"/>
        </el-form-item>
        <el-form-item label="开票时间" prop="invoicedTime">
          <el-date-picker clearable size="small" v-model="form.invoicedTime" type="date" value-format="yyyy-MM-dd"
                          placeholder="选择开票时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="删除标志，非空则删除" prop="deletedTime">
          <el-date-picker clearable size="small" v-model="form.deletedTime" type="date" value-format="yyyy-MM-dd"
                          placeholder="选择删除标志，非空则删除">
          </el-date-picker>
        </el-form-item>
        <el-divider content-position="center">发票明细信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddBillDetail">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteBillDetail">删除</el-button>
          </el-col>
        </el-row>
        <el-table :data="billDetailList" :row-class-name="rowBillDetailIndex"
                  @selection-change="handleBillDetailSelectionChange" ref="billDetail">
          <el-table-column type="selection" width="50" align="center"/>
          <el-table-column label="序号" align="center" prop="index" width="50"/>
          <el-table-column label="商品名称" prop="goodName">
            <template slot-scope="scope">
              <el-input v-model="scope.row.goodName" placeholder="请输入商品名称"/>
            </template>
          </el-table-column>
          <el-table-column label="商品数量" prop="num">
            <template slot-scope="scope">
              <el-input v-model="scope.row.num" placeholder="请输入商品数量"/>
            </template>
          </el-table-column>
          <el-table-column label="商品单价" prop="price">
            <template slot-scope="scope">
              <el-input v-model="scope.row.price" placeholder="请输入商品单价"/>
            </template>
          </el-table-column>
          <el-table-column label="含税标志" prop="hsbz">
            <template slot-scope="scope">
              <el-input v-model="scope.row.hsbz" placeholder="请输入含税标志"/>
            </template>
          </el-table-column>
          <el-table-column label="税率" prop="taxrate">
            <template slot-scope="scope">
              <el-input v-model="scope.row.taxrate" placeholder="请输入税率"/>
            </template>
          </el-table-column>
          <el-table-column label="规格型号" prop="spec">
            <template slot-scope="scope">
              <el-input v-model="scope.row.spec" placeholder="请输入规格型号"/>
            </template>
          </el-table-column>
          <el-table-column label="单位" prop="unit">
            <template slot-scope="scope">
              <el-input v-model="scope.row.unit" placeholder="请输入单位"/>
            </template>
          </el-table-column>
          <el-table-column label="税收分类编码" prop="spbm">
            <template slot-scope="scope">
              <el-input v-model="scope.row.spbm" placeholder="请输入税收分类编码"/>
            </template>
          </el-table-column>
          <el-table-column label="商品编码版本号" prop="bmbbh">
            <template slot-scope="scope">
              <el-input v-model="scope.row.bmbbh" placeholder="请输入商品编码版本号"/>
            </template>
          </el-table-column>
          <el-table-column label="自行编码" prop="zsbm">
            <template slot-scope="scope">
              <el-input v-model="scope.row.zsbm" placeholder="请输入自行编码"/>
            </template>
          </el-table-column>
          <el-table-column label="发票行性质" prop="fphxz">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fphxz" placeholder="请输入发票行性质"/>
            </template>
          </el-table-column>
          <el-table-column label="优惠政策标识" prop="yhzcbs">
            <template slot-scope="scope">
              <el-input v-model="scope.row.yhzcbs" placeholder="请输入优惠政策标识"/>
            </template>
          </el-table-column>
          <el-table-column label="增值税特殊管理" prop="zzstsgl">
            <template slot-scope="scope">
              <el-input v-model="scope.row.zzstsgl" placeholder="请输入增值税特殊管理"/>
            </template>
          </el-table-column>
          <el-table-column label="零税率标识" prop="lslbs">
            <template slot-scope="scope">
              <el-input v-model="scope.row.lslbs" placeholder="请输入零税率标识"/>
            </template>
          </el-table-column>
          <el-table-column label="扣除额" prop="kce">
            <template slot-scope="scope">
              <el-input v-model="scope.row.kce" placeholder="请输入扣除额"/>
            </template>
          </el-table-column>
          <el-table-column label="不含税金额" prop="taxfreeamt">
            <template slot-scope="scope">
              <el-input v-model="scope.row.taxfreeamt" placeholder="请输入不含税金额"/>
            </template>
          </el-table-column>
          <el-table-column label="税额" prop="tax">
            <template slot-scope="scope">
              <el-input v-model="scope.row.tax" placeholder="请输入税额"/>
            </template>
          </el-table-column>
          <el-table-column label="含税金额" prop="taxamt">
            <template slot-scope="scope">
              <el-input v-model="scope.row.taxamt" placeholder="请输入含税金额"/>
            </template>
          </el-table-column>
          <el-table-column label="特殊票种" prop="tspz">
            <template slot-scope="scope">
              <el-input v-model="scope.row.tspz" placeholder="请输入特殊票种"/>
            </template>
          </el-table-column>
          <el-table-column label="$comment" prop="updatedTime">
            <template slot-scope="scope">
              <el-input v-model="scope.row.updatedTime" placeholder="请输入$comment"/>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listBillinfo,
  getBillinfo,
  delBillinfo,
  addBillinfo,
  updateBillinfo,
  pushBillinfo
} from "@/api/invoice/billinfo";

export default {
  name: "Billinfo",
  dicts: ['invoice_type', 'invoice_kind', 'bill_type'],
  data() {
    return {
      showMore: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedBillDetail: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 开票信息表格数据
      billinfoList: [],
      // 发票明细表格数据
      billDetailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyId: null,
        systemOrderno: null,
        outTradeOrderno: null,
        fpqqlsh: null,
        invoiceType: null,
        buyerName: null,
        buyerTaxnum: null,
        buyerAddress: null,
        buyerTelephone: null,
        buyerAccount: null,
        buyerEmail: null,
        buyerPhone: null,
        sellerName: null,
        sellerTaxnum: null,
        sellerAddress: null,
        sellerTelephone: null,
        sellerAccount: null,
        message: null,
        clerk: null,
        payee: null,
        checker: null,
        redInvoiceInfoCode: null,
        fjh: null,
        terminalNumber: null,
        kptype: null,
        tsfs: null,
        qdbz: null,
        qdxmmc: null,
        dkbz: null,
        cpybz: null,
        state: null,
        source: null,
        serviceSupplierKey: null,
        billType: null,
        businessRemark: null,
        invoicedTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        state: [
          {required: true, message: "开票状态不能为空", trigger: "blur"}
        ],
        serviceSupplierKey: [
          {required: true, message: "服务公司不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询开票信息列表 */
    getList() {
      this.loading = true;
      listBillinfo(this.queryParams).then(response => {
        this.billinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        companyId: null,
        systemOrderno: null,
        outTradeOrderno: null,
        fpqqlsh: null,
        invoiceType: null,
        buyerName: null,
        buyerTaxnum: null,
        buyerAddress: null,
        buyerTelephone: null,
        buyerAccount: null,
        buyerEmail: null,
        buyerPhone: null,
        sellerName: null,
        sellerTaxnum: null,
        sellerAddress: null,
        sellerTelephone: null,
        sellerAccount: null,
        message: null,
        clerk: null,
        payee: null,
        checker: null,
        redInvoiceInfoCode: null,
        fjh: null,
        terminalNumber: null,
        kptype: null,
        tsfs: null,
        qdbz: null,
        qdxmmc: null,
        dkbz: null,
        cpybz: null,
        state: null,
        source: null,
        serviceSupplierKey: null,
        billType: null,
        businessRemark: null,
        invoicedTime: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        deletedTime: null
      };
      this.billDetailList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加开票信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getBillinfo(id).then(response => {
        this.form = response.data;
        this.billDetailList = response.data.billDetailList;
        this.open = true;
        this.title = "修改开票信息";
      });
    },
    // 重新推送
    handlePush(row) {
      const id = row.id || this.ids
      pushBillinfo(id).then(response => {
        this.$message.success("推送任务投入队列完成");
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.billDetailList = this.billDetailList;
          if (this.form.id != null) {
            updateBillinfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBillinfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除开票信息编号为"' + ids + '"的数据项？').then(function () {
        return delBillinfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 发票明细序号 */
    rowBillDetailIndex({row, rowIndex}) {
      row.index = rowIndex + 1;
    },
    /** 发票明细添加按钮操作 */
    handleAddBillDetail() {
      let obj = {};
      obj.goodName = "";
      obj.num = "";
      obj.price = "";
      obj.hsbz = "";
      obj.taxrate = "";
      obj.spec = "";
      obj.unit = "";
      obj.spbm = "";
      obj.bmbbh = "";
      obj.zsbm = "";
      obj.fphxz = "";
      obj.yhzcbs = "";
      obj.zzstsgl = "";
      obj.lslbs = "";
      obj.kce = "";
      obj.taxfreeamt = "";
      obj.tax = "";
      obj.taxamt = "";
      obj.tspz = "";
      obj.updatedTime = "";
      this.billDetailList.push(obj);
    },
    /** 发票明细删除按钮操作 */
    handleDeleteBillDetail() {
      if (this.checkedBillDetail.length == 0) {
        this.$modal.msgError("请先选择要删除的发票明细数据");
      } else {
        const billDetailList = this.billDetailList;
        const checkedBillDetail = this.checkedBillDetail;
        this.billDetailList = billDetailList.filter(function (item) {
          return checkedBillDetail.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleBillDetailSelectionChange(selection) {
      this.checkedBillDetail = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('invoice/billinfo/export', {
        ...this.queryParams
      }, `billinfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
