<template>
  <el-row class="app-container zap-main">
    <el-row v-if="activeIndex === '0'" class="zap-table-search">
      <el-row style="padding-top: 16px;">
        <right-toolbar
          class="zap-right-toolbar"
          :showSearch.sync="showSearch"
          @queryTable="getList"
        >收起</right-toolbar>
        <span class="zap-table-search__title">所选条件:</span>
        <div style="float: right;margin-right:1%">
          <el-button type="cyan" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery" style="float: ;">重置00</el-button>
          <column-setting
            class="zap-column-setting"
            :checkList="checkList"
            :tableList="tableList"
            :selfDom="selfDom"
            :tableId="tableId"
          ></column-setting>
        </div>
        <hr style="margin-top: 16px;" />
        <el-form
          :model="queryParams"
          ref="queryForm"
          :inline="true"
          v-show="showSearch"
          label-width="auto"
        >
          <el-form-item label="融资编号" prop="zfrNumber" size="large">
            <el-input
              maxlength="30"
              v-model="queryParams.zfrNumber"
              placeholder="请输入融资编号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="开立企业" prop="coreScyName" size="large">
            <el-input
              maxlength="30"
              v-model="queryParams.coreScyName"
              placeholder="请输入开立企业名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="融资企业" prop="supScyName" size="large">
            <el-input
              maxlength="30"
              v-model="queryParams.supScyName"
              placeholder="请输入融资企业名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="融资状态" prop="zfrStatus" size="large">
            <el-select v-model="queryParams.zfrStatus" placeholder="融资状态" clearable>
              <el-option
                v-for="dict in zfrStatusOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="费用状态" prop="zciStatus" size="large">
            <el-select v-model="queryParams.zciStatus" placeholder="费用状态" clearable>
              <el-option
                v-for="dict in zciStatusOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="发票状态" prop="zciInvoiceStatus" size="large">
            <el-select v-model="queryParams.zciInvoiceStatus" placeholder="发票状态" clearable>
              <el-option
                v-for="dict in invoiceStatusOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="创建时间" size="large">
            <el-date-picker
              v-model="dateRange"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-form>
      </el-row>
    </el-row>
    <el-row v-if="activeIndex === '1'" class="zap-table-search">
      <el-row style="padding-top: 16px;">
        <right-toolbar
          class="zap-right-toolbar"
          :showSearch.sync="showSearch"
          @queryTable="getInvoice"
        >收起</right-toolbar>
        <span class="zap-table-search__title">所选条件:</span>
        <div style="float: right;margin-right:1%">
          <el-button type="cyan" icon="el-icon-search" @click="handleInvoiceQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetInvoiceQuery" style="float: ;">重置</el-button>
          <column-setting
            class="zap-column-setting"
            :checkList="checkList"
            :tableList="tableList"
            :selfDom="selfDom"
            :tableId="tableId"
          ></column-setting>
        </div>
        <hr style="margin-top: 16px;" />
        <el-form
          :model="invoiceParams"
          ref="queryInvoiceForm"
          :inline="true"
          v-show="showSearch"
          label-width="auto"
        >
          <el-form-item label="融资编号" prop="zfrNumber" size="large">
            <el-input
              maxlength="30"
              v-model="invoiceParams.zfrNumber"
              placeholder="请输入融资编号"
              clearable
              @keyup.enter.native="handleInvoiceQuery"
            />
          </el-form-item>
          <el-form-item label="开立企业" prop="coreScyName" size="large">
            <el-input
              maxlength="30"
              v-model="invoiceParams.coreScyName"
              placeholder="请输入开立企业名称"
              clearable
              @keyup.enter.native="handleInvoiceQuery"
            />
          </el-form-item>
          <el-form-item label="融资企业" prop="supScyName" size="large">
            <el-input
              maxlength="30"
              v-model="invoiceParams.supScyName"
              placeholder="请输入融资企业名称"
              clearable
              @keyup.enter.native="handleInvoiceQuery"
            />
          </el-form-item>
          <el-form-item label="创建时间" size="large">
            <el-date-picker
              v-model="dateInvoiceRange"
              size="small"
              style="width: 225px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-form>
      </el-row>
    </el-row>
    <!-- ________________________________________平台用________________________________________________ -->
    <el-row class="zap-form zap-margin-top">
      <el-tabs v-model="activeIndex">
      <el-tab-pane label="费用列表">
        <div class="zap-content">
          <el-button
            type="warning"
            @click="handleExport"
            v-hasPermi="['service:cost:export']"
            :disabled="total == 0"
          >导出</el-button>
        </div>

        <el-table v-loading="loading" :data="costList" stripe>
          <el-table-column label="序号" type="index" width="50" align="center">
            <template slot-scope="scope">
              <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="融资编号"
            align="center"
            prop="zfrNumber"
            v-if="uncheckList.zfrNumber"
          />
          <el-table-column
            label="融资企业"
            align="center"
            prop="supScyName"
            v-if="uncheckList.supScyName"
          />
          <el-table-column
            label="开立企业"
            align="center"
            prop="coreScyName"
            v-if="uncheckList.coreScyName"
            show-overflow-tooltip
          />
          <el-table-column
            label="融资产品"
            align="center"
            prop="zfpName"
            v-if="uncheckList.zfpName"
            show-overflow-tooltip
          />
          <el-table-column
            label="融资金额"
            align="center"
            prop="zfrAmount"
            :formatter="moneyFormat"
            v-if="uncheckList.zfrAmount"
            show-overflow-tooltip
          />
          <el-table-column
            label="融资状态"
            align="center"
            prop="zfrStatus"
            :formatter="zfrStatusFormat"
            v-if="uncheckList.zfrStatus"
            show-overflow-tooltip
          />
          <el-table-column
            label="费用状态"
            align="center"
            prop="zciStatus"
            :formatter="zciStatusFormat"
            v-if="uncheckList.zciStatus"
            show-overflow-tooltip
          />
          <el-table-column
            label="创建时间"
            align="center"
            prop="createTime"
            v-if="uncheckList.createTime"
            show-overflow-tooltip
          />
          <el-table-column
            label="手续费"
            align="center"
            prop="zciAmount"
            :formatter="moneyFormat"
            v-if="uncheckList.zciAmount "
            show-overflow-tooltip
          />
          <el-table-column
            label="发票状态"
            align="center"
            prop="zciInvoiceStatus"
            :formatter="zciInvoiceStatusFormat"
            v-if="uncheckList.zciInvoiceStatus"
            show-overflow-tooltip
          />
          <el-table-column
            label="快递单号"
            align="center"
            prop="zciExpressNo"
            v-if="uncheckList.zciExpressNo"
            show-overflow-tooltip
          />
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            width="150"
          >
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.zciInvoiceStatus != '0'"
                size="mini"
                type="text"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['service:cost:update']"
              >编辑</el-button>
              <el-button
                v-if="scope.row.zciInvoiceStatus == '2' || scope.row.zciInvoiceStatus == '4'"
                size="mini"
                type="text"
                @click="handleInvoiceDelete(scope.row)"
                v-hasPermi="['service:cost:update']"
              >作废</el-button>
              <el-button
                v-if="scope.row.zciInvoiceStatus == '2' || scope.row.zciInvoiceStatus == '3'"
                size="mini"
                type="text"
                @click="handleInvoiceFlush(scope.row)"
                v-hasPermi="['service:cost:update']"
              >冲红</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-tab-pane>

      <el-tab-pane label="开票列表">
        <div class="zap-content">
          <el-button
            type="warning"
            @click="handleExportInvoice"
            :disabled="invoiceTotal == 0"
            v-hasPermi="['service:cost:export']"
          >导出</el-button>
        </div>

        <!-- 开票列表 -->
        <el-table v-loading="loading" :data="invoiceList" stripe>
          <el-table-column label="序号" type="index" width="50" align="center">
            <template slot-scope="scope">
              <span>{{(invoiceParams.pageNum - 1) * invoiceParams.pageSize + scope.$index + 1}}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="融资编号"
            align="center"
            prop="zfrNumber"
            v-if="uncheckList.zfrNumber"
          />
          <el-table-column
            label="融资企业"
            align="center"
            prop="supScyName"
            v-if="uncheckList.supScyName"
          />
          <el-table-column
            label="开立企业"
            align="center"
            prop="coreScyName"
            v-if="uncheckList.coreScyName"
            show-overflow-tooltip
          />
          <el-table-column
            label="融资产品"
            align="center"
            prop="zfpName"
            v-if="uncheckList.zfpName"
            show-overflow-tooltip
          />
          <el-table-column
            label="融资金额"
            align="center"
            prop="zfrAmount"
            :formatter="moneyFormat"
            v-if="uncheckList.zfrAmount"
            show-overflow-tooltip
          />
          <el-table-column
            label="融资状态"
            align="center"
            prop="zfrStatus"
            :formatter="zfrStatusFormat"
            v-if="uncheckList.zfrStatus"
            show-overflow-tooltip
          />
          <el-table-column
            label="费用状态"
            align="center"
            prop="zciStatus"
            :formatter="zciStatusFormat"
            v-if="uncheckList.zciStatus"
            show-overflow-tooltip
          />
          <el-table-column
            label="创建时间"
            align="center"
            prop="createTime"
            v-if="uncheckList.createTime"
            show-overflow-tooltip
          />
          <el-table-column
            label="手续费"
            align="center"
            prop="zciAmount"
            :formatter="moneyFormat"
            v-if="uncheckList.zciAmount "
            show-overflow-tooltip
          />
          <el-table-column
            label="发票状态"
            align="center"
            prop="zciInvoiceStatus"
            :formatter="zciInvoiceStatusFormat"
            v-if="uncheckList.zciInvoiceStatus"
            show-overflow-tooltip
          />
          <el-table-column
            label="快递单号"
            align="center"
            prop="zciExpressNo"
            v-if="uncheckList.zciExpressNo"
            show-overflow-tooltip
          />
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            width="150"
          >
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.zciInvoiceStatus == '1' && scope.row.zciStatus == '02' && (scope.row.zfrStatus == '01' || scope.row.zfrStatus == '03') "
                size="mini"
                type="text"
                @click="handleInvoiceOpen(scope.row)"
                v-hasPermi="['service:cost:update']"
              >开票</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="invoiceTotal > 0"
          :total="invoiceTotal"
          :page.sync="invoiceParams.pageNum"
          :limit.sync="invoiceParams.pageSize"
          @pagination="getInvoice"
        />
      </el-tab-pane>

      <!-- 发票框 -->
      <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="auto" :inline="true">
          <el-form-item label="企业名称" prop="scyName" size="large">
            <el-input v-model="form.scyName" disabled />
          </el-form-item>
          <el-form-item label="企业统一代码" prop="scySocialCode" size="large">
            <el-input v-model="form.scySocialCode" disabled />
          </el-form-item>
          <el-form-item label="企业注册电话" prop="scyPhone" size="large">
            <el-input v-model="form.scyPhone" disabled />
          </el-form-item>
          <el-form-item label="收件人" prop="ziaContacts" size="large">
            <el-input v-model="form.ziaContacts" disabled />
          </el-form-item>
          <el-form-item label="收件人电话" prop="ziaContactsPhone" size="large">
            <el-input v-model="form.ziaContactsPhone" disabled />
          </el-form-item>
          <el-form-item label="邮寄地址" prop="ziaAddress" size="large">
            <el-input v-model="form.ziaAddress" disabled />
          </el-form-item>
          <el-form-item label="快递单号" prop="zciExpressNo" size="large">
            <el-input
              v-model="form.zciExpressNo"
              placeholder="请输入快递单号"
              maxlength="30"
              show-word-limit
            />
          </el-form-item>
        </el-form>
        <el-row style="height: 109px;" type="flex" align="middle" justify="center">
          <el-button type="primary" plain @click="cancel">取 消</el-button>
          <el-button type="primary" @click="submitForm">确 定</el-button>
        </el-row>
      </el-dialog>

      <!-- 发票列表开票框 -->
      <el-dialog :title="openInvoiceTitle" :visible.sync="openInvoice" width="800px" append-to-body>
        <el-form
          ref="formInvoice"
          :model="formInvoice"
          :rules="rules"
          label-width="auto"
          :inline="true"
        >
          <el-form-item label="企业名称" prop="scyName" size="large">
            <el-input v-model="formInvoice.scyName" disabled />
          </el-form-item>
          <el-form-item label="企业统一代码" prop="scySocialCode" size="large">
            <el-input v-model="formInvoice.scySocialCode" disabled />
          </el-form-item>
          <el-form-item label="企业注册电话" prop="scyPhone" size="large">
            <el-input v-model="formInvoice.scyPhone" disabled />
          </el-form-item>
          <el-form-item label="收件人" prop="ziaContacts" size="large">
            <el-input v-model="formInvoice.ziaContacts" disabled />
          </el-form-item>
          <el-form-item label="收件人电话" prop="ziaContactsPhone" size="large">
            <el-input v-model="formInvoice.ziaContactsPhone" disabled />
          </el-form-item>
          <el-form-item label="邮寄地址" prop="ziaAddress" size="large">
            <el-input v-model="formInvoice.ziaAddress" disabled />
          </el-form-item>
          <el-form-item label="快递单号" prop="zciExpressNo" size="large">
            <el-input
              v-model="formInvoice.zciExpressNo"
              placeholder="请输入快递单号"
              maxlength="30"
              show-word-limit
            />
          </el-form-item>
        </el-form>
        <el-row style="height: 109px;" type="flex" align="middle" justify="center">
          <el-button type="primary" @click="submitFormInvoice">确 定</el-button>
          <el-button @click="cancelInvoice">取 消</el-button>
        </el-row>
      </el-dialog>

      <!-- 发票列表冲红框 -->
      <el-dialog :title="openFlushTitle" :visible.sync="openFlush" width="800px" append-to-body>
        <el-form
          ref="formFlush"
          :model="formFlush"
          :rules="rules"
          label-width="140px"
          :inline="true"
        >
          <el-form-item label="企业名称" prop="scyName">
            <el-input v-model="formFlush.scyName" disabled />
          </el-form-item>
          <el-form-item label="企业统一代码" prop="scySocialCode">
            <el-input v-model="formFlush.scySocialCode" disabled />
          </el-form-item>
          <el-form-item label="企业注册电话" prop="scyPhone">
            <el-input v-model="formFlush.scyPhone" disabled />
          </el-form-item>
          <el-form-item label="收件人" prop="ziaContacts">
            <el-input v-model="formFlush.ziaContacts" disabled />
          </el-form-item>
          <el-form-item label="收件人电话" prop="ziaContactsPhone">
            <el-input v-model="formFlush.ziaContactsPhone" disabled />
          </el-form-item>
          <el-form-item label="邮寄地址" prop="ziaAddress">
            <el-input v-model="formFlush.ziaAddress" disabled />
          </el-form-item>
          <el-form-item label="快递单号" prop="zciExpressNo">
            <el-input
              v-model="formFlush.zciExpressNo"
              placeholder="请输入快递单号"
              maxlength="30"
              show-word-limit
            />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitFormFlush">确 定</el-button>
          <el-button @click="cancelFlush">取 消</el-button>
        </div>
      </el-dialog>
    </el-tabs>
    </el-row>
  </el-row>
</template>

<script>
import {
  listCost,
  listInvoice,
  selectInvoiceList,
  applyInvoice,
  invoicing,
  daleteInvoice,
  getUser
} from "@/api/service/cost/costManage";
import { uploadFileNew } from "@/api/common/file";
import { getToken } from "@/utils/auth";
import { columnQuery, columnfilter } from "@/api/common/columnSetting";
import ColumnSetting from "../../../components/Table/columnSetting.vue";
import SearchBar from '@/components/SearchBar/index.vue'
export default {
  name: "costManage",
  components: {
    ColumnSetting,
    SearchBar
  },
  data() {
    return {
      activeIndex: "",
      //费用列表
      costList: [],
      //开票列表
      invoiceList: [],
      //创建时间范围
      dateRange: [],
      dateInvoiceRange: [],
      //费用状态
      zciStatusOptions: [],
      //发票状态
      zciInvoiceStatusOptions: [],
      invoiceStatusOptions: [],
      //融资状态
      zfrStatusOptions: [],
      //操作员Id
      userId: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      // 弹出层标题
      title: "",
      openInvoiceTitle: "",
      openFlushTitle: "",
      total: 0,
      invoiceTotal: 0,
      // 是否显示弹出层
      open: false,
      openInvoice: false,
      openFlush: false,
      // 链属查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        zfrNumber: null,
        coreScyName: null,
        supScyName: null,
        zciStatus: null,
        zfrStatus: null,
        zciInvoiceStatus: null
      },
      invoiceParams: {
        pageNum: 1,
        pageSize: 10,
        zfrNumber: null,
        supScyName: null,
        coreScyName: null,
        zciStatus: null,
        zfrStatus: null,
        zciInvoiceStatus: null
      },
      //筛选按钮的数据列表，与table表头的数据一致 --显示隐藏列用
      tableList: [
        {
          label: "zfrNumber",
          value: "融资编号"
        },
        {
          label: "supScyName",
          value: "融资企业"
        },
        {
          label: "coreScyName",
          value: "开立企业"
        },
        {
          label: "zfpName",
          value: "融资产品"
        },
        {
          label: "zfrAmount",
          value: "融资金额"
        },
        {
          label: "zciStatus",
          value: "费用状态"
        },
        {
          label: "zfrStatus",
          value: "融资状态"
        },
        {
          label: "createTime",
          value: "创建时间"
        },
        {
          label: "zciAmount",
          value: "手续费"
        },
        {
          label: "zciInvoiceStatus",
          value: "发票状态"
        },
        {
          label: "zciExpressNo",
          value: "快递单号"
        }
      ],
      checkList: [], //筛选列选中的数据列表--显示隐藏列用
      uncheckList: {}, //控制筛选列显示隐藏--显示隐藏列用
      selfDom: this,
      tableId: "/sc-service/cost/list",
      // 表单参数
      form: {
        zciId: null,
        scyId: null,
        scyName: null,
        scySocialCode: null,
        scyPhone: null,
        ziaContacts: null,
        ziaContactsPhone: null,
        ziaAddress: null,
        zciExpressNo: null,
        zciInvoiceStatus: null
      },
      formInvoice: {
        zciId: null,
        scyId: null,
        scyName: null,
        scySocialCode: null,
        scyPhone: null,
        ziaContacts: null,
        ziaContactsPhone: null,
        ziaAddress: null,
        zciExpressNo: null,
        zciInvoiceStatus: null
      },
      formFlush: {
        zciId: null,
        scyId: null,
        scyName: null,
        scySocialCode: null,
        scyPhone: null,
        ziaContacts: null,
        ziaContactsPhone: null,
        ziaAddress: null,
        zciExpressNo: null,
        zciInvoiceStatus: null
      },
      // 表单校验
      rules: {
        // zciExpressNo: [
        //   { required: true, message: "快递单号不能为空", trigger: "blur" },
        // ]
      }
    };
  },
  activated() {
    this.getDicts("ser_zci_status").then(response => {
      this.zciStatusOptions = response.data;
    });
    this.getDicts("ser_zci_invoice_status").then(response => {
      this.zciInvoiceStatusOptions = response.data;
    });
    this.getDicts("ser_invoice_status").then(response => {
      this.invoiceStatusOptions = response.data;
    });
    this.getDicts("ser_zfr_status").then(response => {
      this.zfrStatusOptions = response.data;
    });
    this.getList();
    this.getInvoice();
    this.getUser();
  },
  // activated() {
  //   this.getDicts("ser_zci_status").then(response => {
  //     this.zciStatusOptions = response.data;
  //   });
  //   this.getDicts("	ser_zci_invoice_status").then(response => {
  //     this.zciInvoiceStatusOptions = response.data;
  //   });
  //   this.getDicts("	ser_zfr_status").then(response => {
  //     this.zfrStatusOptions = response.data;
  //   });
  //   this.getList();
  //   this.getInvoice();
  //   this.getUser();
  // },
  mounted() {
    this.columnQuery();
  },
  methods: {
    //列表格式化金额
    moneyFormat(row, column, cellValue) {
      if (cellValue == null || cellValue == undefined || cellValue == "") {
        cellValue = "0.00";
      }
      cellValue += "";
      if (!cellValue.includes(".")) {
        cellValue += ".00";
      }
      return cellValue
        .replace(/(\d)(?=(\d{3})+\.)/g, function($0, $1) {
          return $1 + ",";
        })
        .replace(/\.$/, "");
    },
    //获取当前客户是否之前设置过列展示隐藏
    columnQuery() {
      //获取页面路径
      var psfPagePath = window.location.pathname;
      //用请求后台的url作为唯一标识
      var psfTableName = this.tableId;
      var columnForm = {};
      columnForm.psfPagePath = psfPagePath;
      columnForm.psfTableName = psfTableName;
      columnQuery(columnForm).then(response => {
        if (response.data && response.data.psfShowData) {
          this.checkList = response.data.psfShowData;
        }
        this.filter();
      });
    },
    //控制隐藏显示的函数
    filter(checkList) {
      if (!!checkList) {
        this.checkList = checkList;
      }
      columnfilter(this.selfDom);
    },

    //菜单状态字典翻译
    zciStatusFormat(row, column) {
      return this.selectDictLabel(this.zciStatusOptions, row.zciStatus);
    },
    zciInvoiceStatusFormat(row, column) {
      return this.selectDictLabel(
        this.zciInvoiceStatusOptions,
        row.zciInvoiceStatus
      );
    },
    zfrStatusFormat(row, column) {
      return this.selectDictLabel(this.zfrStatusOptions, row.zfrStatus);
    },
    /** 查询链属列表 */
    getList() {
      this.loading = true;
      listCost(this.addDateRange(this.queryParams, this.dateRange)).then(
        response => {
          this.costList = response.data.records;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    getInvoice() {
      this.loading = true;
      selectInvoiceList(
        this.addDateRange(this.invoiceParams, this.dateInvoiceRange)
      ).then(response => {
        this.invoiceList = response.data.records;
        this.invoiceTotal = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.resetForm("form");
      this.resetForm("formInvoice");
      this.resetForm("formFlush");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.dateRange = [];
      this.handleQuery();
    },
    //发票列表
    handleInvoiceQuery() {
      this.invoiceParams.pageNum = 1;
      this.getInvoice();
    },
    resetInvoiceQuery() {
      this.resetForm("queryInvoiceForm");
      this.dateInvoiceRange = [];
      this.handleInvoiceQuery();
    },
    /** 编辑按钮操作 */
    handleUpdate(row) {
      this.reset();
      if (row.zciId) {
      } else {
        this.$message({
          type: "warning",
          message: "无费用数据"
        });
        return;
      }
      if (row.zfiSupplierId) {
      } else {
        this.$message({
          type: "warning",
          message: "无融资企业信息"
        });
        return;
      }
      const zciId = row.zciId || this.ids;
      const scyId = row.zfiSupplierId || this.ids;
      listInvoice(scyId, zciId).then(response => {
        this.form = response.data[0];
        this.form.zciId = zciId;
      });
      this.open = true;
      this.title = "发票信息";
    },

    /** 提交按钮 */
    submitForm() {
      var self = this;
      this.$refs["form"].validate(valid => {
        let fd = new FormData();
        for (var key in self.form) {
          fd.append(key, self.form[key]);
        }
        if (valid) {
          if (this.form.scyId != null) {
            const loading = this.$loading({
              lock: true,
              text: "Loading",
              spinner: "el-icon-loading",
              background: "rgba(0, 0, 0, 0.7)"
            });
            invoicing(self.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
              this.getInvoice();
            });
            loading.close();
          }
        }
      });
    },

    /* 开票作废 */
    handleInvoiceDelete(row) {
      const zciId = row.zciId || this.ids;
      const zciInvoiceStatus = "3";
      const data = { zciId, zciInvoiceStatus };
      this.$confirm("确认作废此发票?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function() {
          return invoicing(data);
        })
        .then(() => {
          this.getList();
          this.getInvoice();
          this.msgSuccess("作废成功");
        })
        .catch(() => {
          this.$message({
            type: "warning",
            message: "已取消作废"
          });
        });
    },

    /* 发票列表开票按钮 */
    handleInvoiceOpen(row) {
      this.reset();
      if (row.zciId) {
      } else {
        this.$message({
          type: "warning",
          message: "无费用数据"
        });
        return;
      }
      if (row.zfiSupplierId) {
      } else {
        this.$message({
          type: "warning",
          message: "无融资企业信息"
        });
        return;
      }
      const zciId = row.zciId || this.ids;
      const scyId = row.zfiSupplierId || this.ids;
      listInvoice(scyId, zciId).then(response => {
        this.formInvoice = response.data[0];
        this.formInvoice.zciId = zciId;
      });
      this.openInvoice = true;
      this.openInvoiceTitle = "开票";
    },
    //发票列表开票取消
    cancelInvoice() {
      (this.openInvoice = false), this.reset();
    },
    //发票列表开票提交
    submitFormInvoice() {
      var self = this;
      this.$refs["formInvoice"].validate(valid => {
        let fd = new FormData();
        for (var key in self.formInvoice) {
          fd.append(key, self.formInvoice[key]);
        }
        if (valid) {
          if (this.formInvoice.scyId != null) {
            const loading = this.$loading({
              lock: true,
              text: "Loading",
              spinner: "el-icon-loading",
              background: "rgba(0, 0, 0, 0.7)"
            });
            this.formInvoice.zciInvoiceStatus = "2";
            invoicing(self.formInvoice).then(response => {
              this.msgSuccess("开票成功");
              this.openInvoice = false;
              this.getList();
              this.getInvoice();
            });
            loading.close();
          }
        }
      });
    },

    //冲红按钮
    handleInvoiceFlush(row) {
      this.reset();
      if (row.zciId) {
      } else {
        this.$message({
          type: "warning",
          message: "无费用数据"
        });
        return;
      }
      if (row.zfiSupplierId) {
      } else {
        this.$message({
          type: "warning",
          message: "无融资企业信息"
        });
        return;
      }
      const zciId = row.zciId || this.ids;
      const scyId = row.zfiSupplierId || this.ids;
      listInvoice(scyId, zciId).then(response => {
        this.formFlush = response.data[0];
        this.formFlush.zciId = zciId;
      });
      this.openFlush = true;
      this.openFlushTitle = "开票";
    },
    //发票列表冲红取消
    cancelFlush() {
      (this.openFlush = false), this.reset();
    },
    //发票列表冲红提交
    submitFormFlush() {
      var self = this;
      this.$refs["formFlush"].validate(valid => {
        let fd = new FormData();
        for (var key in self.formFlush) {
          fd.append(key, self.formFlush[key]);
        }
        if (valid) {
          if (this.formFlush.scyId != null) {
            const loading = this.$loading({
              lock: true,
              text: "Loading",
              spinner: "el-icon-loading",
              background: "rgba(0, 0, 0, 0.7)"
            });
            this.formFlush.zciInvoiceStatus = "4";
            invoicing(self.formFlush).then(response => {
              this.msgSuccess("冲红成功");
              this.openFlush = false;
              this.getList();
              this.getInvoice();
            });
            loading.close();
          }
        }
      });
    },

    /** 导出按钮操作 */
    handleExport() {
      // this.getList();
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      this.download(
        "/sc-service/cost/export",
        {
          ...this.queryParams,
          ...this.dateRange
        },
        "费用信息.xlsx"
      );
      setTimeout(() => {
        loading.close();
      }, 2000);
    },

    /** 导出按钮操作 */
    handleExportInvoice() {
      // this.getList();
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      this.download(
        "/sc-service/cost/exportInvoice",
        {
          ...this.invoiceParams,
          ...this.dateInvoiceRange
        },
        "发票信息.xlsx"
      );
      setTimeout(() => {
        loading.close();
      }, 2000);
    },

    //获取操作员Id
    getUser() {
      getUser().then(response => {
        this.userId = response.data.userId;
      });
    }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .el-tabs__item {
  width: 105px;
  height: 55px;
  padding: 0;
  line-height: 55px;
  text-align: center;
  font-size: 16px;
}
</style>