<template>
  <div class="app-container">
    <el-card>
      <!-- 搜索工作栏 -->
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
        label-width="128px"
      >
        <div class="filter-box">
          <div class="filter-lf">
            <el-form-item label="回单编号" prop="receiptNum">
              <el-input
                v-model="queryParams.receiptNum"
                placeholder="请输入回单编号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="流程编号" prop="flowCode">
              <el-input
                v-model="queryParams.flowCode"
                placeholder="请输入流程编号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="交易日期" prop="tradTime">
              <el-date-picker
                v-model="queryParams.tradTime"
                style="width: 240px"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
            <el-form-item label="借/贷" prop="debitOrCredit">
              <el-select
                v-model="queryParams.debitOrCredit"
                placeholder="请选择"
                clearable
                @keyup.enter.native="handleQuery"
              >
                <el-option
                  v-for="item in options"
                  :key="item.label"
                  :label="item.label"
                  :value="item.label"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="我方账户" prop="myCompany">
              <el-input
                v-model="queryParams.myCompany"
                placeholder="请输入我方账户"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="我方账号" prop="myNum">
              <el-input
                v-model="queryParams.myNum"
                placeholder="请输入我方账号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="对方账户" prop="adverseCompany">
              <el-input
                v-model="queryParams.adverseCompany"
                placeholder="请输入对方账户"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="对方账号" prop="adverseNum">
              <el-input
                v-model="queryParams.adverseNum"
                placeholder="请输入对方账号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="银行交易流水" prop="serialNum">
              <el-input
                v-model="queryParams.serialNum"
                placeholder="请输入银行交易流水"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="银行" prop="bank">
              <el-input
                v-model="queryParams.bank"
                placeholder="请输入银行"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                icon="el-icon-search"
                @click="handleQuery"
                >搜索</el-button
              >
              <el-button icon="el-icon-refresh" @click="resetQuery"
                >重置</el-button
              >
            </el-form-item>
            <el-row style="display: inline-block">
              <el-button round type="primary" @click="handleOneMonth"
                >一个月内</el-button
              >
              <el-button round type="primary" @click="handleHalfYear"
                >半年内</el-button
              >
              <el-button round type="primary" @click="handleOneYear"
                >一年内</el-button
              >
            </el-row>
          </div>
        </div>
      </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="['archives:bank-slip:create']"
            >新增</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple1"
            @click="handleDelete"
            >删除</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            :loading="exportLoading"
            v-hasPermi="['archives:bank-slip:export']"
            >导出</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleDownloadData"
            v-hasPermi="['archives:bank-slip:export']"
            >下载元数据</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-document"
            size="mini"
            :disabled="multiple"
            @click="handleGLPZ"
            >关联凭证</el-button
          >
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>

      <!-- 列表 -->
      <el-table
        v-loading="loading"
        :data="list"
        stripe
        border
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="流程编号" align="center" prop="flowCode" />
        <el-table-column
          label="交易日期"
          align="center"
          prop="tradTime"
          width="180"
        >
          <template v-slot="scope">
            <span>{{ parseTime(scope.row.tradTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="银行" align="center" prop="bank" />
        <el-table-column label="交易类型" align="center" prop="type" />
        <el-table-column label="我方账户" align="center" prop="myCompany" />
        <el-table-column label="我方账号" align="center" prop="myNum" />
        <el-table-column
          label="对方账户"
          align="center"
          prop="adverseCompany"
        />
        <el-table-column label="对方账号" align="center" prop="adverseNum" />
        <el-table-column label="业务实体" align="center" prop="company" />
        <el-table-column label="所属部门" align="center" prop="dept" />
        <el-table-column label="借/贷" align="center" prop="debitOrCredit" />
        <el-table-column label="币种" align="center" prop="currency" />
        <el-table-column label="状态" align="center" prop="status" />
        <el-table-column label="交易流水号" align="center" prop="serialNum" />
        <el-table-column label="借方金额" align="center" prop="debitMoney" />
        <el-table-column label="交易金额" align="center" prop="tradMoney" />
        <el-table-column label="贷方金额" align="center" prop="creditMoney" />
        <el-table-column label="余额" align="center" prop="balance" />
        <el-table-column label="业务单号" align="center" prop="busNum" />
        <el-table-column label="回单编号" align="center" prop="receiptNum" />
        <el-table-column label="摘要" align="center" prop="digest" />
        <el-table-column label="扩展摘要" align="center" prop="digestExtend" />
        <el-table-column
          label="业务摘要"
          align="center"
          prop="businessDigest"
        />
        <el-table-column label="用途" align="center" prop="purpose" />
        <el-table-column label="业务编号" align="center" prop="businessNum" />
        <el-table-column label="业务名称" align="center" prop="businessName" />
        <el-table-column label="票据号" align="center" prop="billNum" />
        <el-table-column
          label="商务支付订单号"
          align="center"
          prop="businessOrder"
        />
        <el-table-column label="企业识别码" align="center" prop="headingCode" />
        <el-table-column label="对方银行码" align="center" prop="bankCode" />
        <el-table-column label="对方开户地址" align="center" prop="bankSite" />
        <el-table-column
          label="对方开户地区"
          align="center"
          prop="bankRegion"
        />
        <el-table-column
          label="创建时间"
          align="center"
          prop="createTime"
          width="180"
        >
          <template v-slot="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          fixed="right"
          width="180px"
        >
          <template v-slot="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              v-if="scope.row.fileUrl"
              @click="handleViewFJ(scope.row)"
              >查看附件
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleView(scope.row)"
              >查看
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-s-check"
              v-if="
                scope.row.subscriptionStatus == 0 ||
                scope.row.subscriptionStatus == null
              "
              @click="handleComfirm(scope.row)"
              >认款
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-s-check"
              v-if="scope.row.subscriptionStatus == 1"
              @click="handleUnComfirm(scope.row)"
              >取消认款
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['archives:bank-slip:update']"
              >修改</el-button
            >
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['archives:bank-slip:delete']"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNo"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <!-- 对话框(添加 / 修改) -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1000px"
      append-to-body
    >
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="130px"
        :disabled="this.title === '查看银行回单'"
      >
        <el-row v-if="optType != 'view'">
          <el-col :span="8">
            <UploadBankSlip
              :files="fileList"
              @onConfirm="handleImg"
              @onScan="handleScan"
            />
          </el-col>
        </el-row>
        <el-divider>银行回单信息</el-divider>
        <el-row>
          <el-col :span="8">
            <el-form-item label="交易日期" prop="tradTime">
              <el-date-picker
                clearable
                v-model="form.tradTime"
                type="date"
                value-format="timestamp"
                placeholder="手动填写"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="交易类型" prop="type">
              <!-- <el-select v-model="form.type" placeholder="请选择交易类型">
                <el-option label="请选择字典生成" value="" />
              </el-select> -->
              <el-input v-model="form.type" placeholder="请输入交易类型" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="银行" prop="bank">
              <el-input v-model="form.bank" placeholder="请输入银行" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="我方账户" prop="myCompany">
              <el-input v-model="form.myCompany" placeholder="请输入我方账户" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="我方账号" prop="myNum">
              <el-input v-model="form.myNum" placeholder="请输入我方账号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="流程编号" prop="flowCode">
              <el-input v-model="form.flowCode" placeholder="请输入流程编号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="对方账户" prop="adverseCompany">
              <el-input
                v-model="form.adverseCompany"
                placeholder="请输入对方账户"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="对方账号" prop="adverseNum">
              <el-input
                v-model="form.adverseNum"
                placeholder="请输入对方账号"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="借/贷" prop="debitOrCredit">
              <el-select v-model="form.debitOrCredit" placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.label"
                  :label="item.label"
                  :value="item.label"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="币种" prop="currency">
              <el-input v-model="form.currency" placeholder="请输入币种" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="交易流水号" prop="serialNum">
              <el-input
                v-model="form.serialNum"
                placeholder="请输入交易流水号"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="借方金额" prop="debitMoney">
              <el-input
                v-model="form.debitMoney"
                placeholder="请输入借方金额"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="交易金额" prop="tradMoney">
              <el-input v-model="form.tradMoney" placeholder="请输入交易金额" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="贷方金额" prop="creditMoney">
              <el-input
                v-model="form.creditMoney"
                placeholder="请输入贷方金额"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="余额" prop="balance">
              <el-input v-model="form.balance" placeholder="请输入余额" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="业务单号" prop="busNum">
              <el-input v-model="form.busNum" placeholder="请输入业务单号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="回单编号" prop="receiptNum">
              <el-input
                v-model="form.receiptNum"
                placeholder="请输入回单编号"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="摘要" prop="digest">
              <el-input v-model="form.digest" placeholder="请输入摘要" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="扩展摘要" prop="digestExtend">
              <el-input
                v-model="form.digestExtend"
                placeholder="请输入扩展摘要"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="业务摘要" prop="businessDigest">
              <el-input
                v-model="form.businessDigest"
                placeholder="请输入业务摘要"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="用途" prop="purpose">
              <el-input v-model="form.purpose" placeholder="请输入用途" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="业务编号" prop="businessNum">
              <el-input
                v-model="form.businessNum"
                placeholder="请输入业务编号"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="业务名称" prop="businessName">
              <el-input
                v-model="form.businessName"
                placeholder="请输入业务名称"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="票据号" prop="billNum">
              <el-input v-model="form.billNum" placeholder="请输入票据号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="商务支付订单号" prop="businessOrder">
              <el-input
                v-model="form.businessOrder"
                placeholder="请输入商务支付订单号"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="企业识别码" prop="headingCode">
              <el-input
                v-model="form.headingCode"
                placeholder="请输入企业识别码"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="对方银行码" prop="bankCode">
              <el-input
                v-model="form.bankCode"
                placeholder="请输入对方银行码"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="对方开户地址" prop="bankSite">
              <el-input
                v-model="form.bankSite"
                placeholder="请输入对方开户地址"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="对方开户地区" prop="bankRegion">
              <el-input
                v-model="form.bankRegion"
                placeholder="请输入对方开户地区"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-if="optType != 'view'"
          >确 定</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 密码输入框-->
    <el-dialog
      :title="title"
      :visible.sync="open1"
      width="800px"
      append-to-body
    >
      <el-form
        ref="queryForm"
        :model="queryParams"
        :rules="rules"
        label-width="140px"
      >
        <el-row>
          <el-col :span="14">
            <el-form-item label="密码" prop="inputPassword">
              <el-input
                v-model="queryParams.inputPassword"
                placeholder="请输入密码"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm1">确 定</el-button>
        <el-button @click="cancel1">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 认款弹出框-->
    <el-dialog title="认款" :visible.sync="open3" width="800px" append-to-body>
      <el-form ref="form1" :model="form1" :rules="rules" label-width="140px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="经办人" prop="staffName">
              <el-select
                v-model="form1.staffName"
                filterable
                placeholder="请选择经办人"
                value-key="id"
                @change="handleSelectUser"
              >
                <el-option
                  v-for="item in userOptions"
                  :key="item.id"
                  :value="item"
                  :label="item.username"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="流程编号" prop="flowCode">
              <el-input v-model="form1.flowCode" placeholder="请输入流程编号" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm3">确 定</el-button>
        <el-button @click="cancel3">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 会计凭证选择框-->
    <el-dialog
      title="关联凭证"
      :visible.sync="open2"
      width="800px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="140px">
        <el-row>
          <el-col :span="14">
            <el-form-item label="会计凭证" prop="voucherId">
              <el-input
                v-model="form.voucherId"
                placeholder="请选择凭证"
                readonly
              >
                <el-button
                  slot="append"
                  @click="handleSelectVoucher"
                  icon="el-icon-search"
                  style="
                    border-color: #46a6ff;
                    background-color: #46a6ff;
                    color: white;
                  "
                ></el-button>
              </el-input>
              <VoucherSelect
                ref="VoucherSelect"
                @onSelected="onVoucherSelected"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm2">确 定</el-button>
        <el-button @click="cancel2">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  createBankSlip,
  updateBankSlip,
  deleteBankSlip,
  getBankSlip,
  getBankSlipPage,
  exportBankSlipExcel,
  downloadXml,
  getBankSlipPageTime,
} from "@/api/accounting/bankSlip";
import { getAccessToken, getTenantId } from "@/utils/auth";
import { listUser } from "@/api/system/user";
import VoucherSelect from "@/components/VoucherSelect/single.vue";

export default {
  name: "BankSlip",
  components: {
    UploadBankSlip: () => import("@/components/UploadBankSlip"),
    VoucherSelect,
  },
  data() {
    return {
      optType: undefined,
      // 遮罩层
      loading: true,
      // 多个禁用
      multiple: true,
      // 非多个禁用
      multiple1: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 银行回单列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open1: false,
      open2: false,
      open3: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        voucherId: null,
        flowCode: null,
        tradTime: [],
        bank: null,
        type: null,
        myCompany: null,
        myNum: null,
        adverseCompany: null,
        adverseNum: null,
        companyId: null,
        company: null,
        deptId: null,
        dept: null,
        debitOrCredit: null,
        currency: null,
        status: null,
        serialNum: null,
        debitMoney: null,
        tradMoney: null,
        creditMoney: null,
        balance: null,
        busNum: null,
        receiptNum: null,
        digest: null,
        digestExtend: null,
        businessDigest: null,
        theOther: null,
        purpose: null,
        businessNum: null,
        businessName: null,
        billNum: null,
        businessOrder: null,
        headingCode: null,
        bankCode: null,
        bankSite: null,
        bankRegion: null,
        createTime: [],
        encrypt: null,
        archiveId: null,
        archiveState: null,
        password: null,
        inputPassword: null,
      },
      userOptions: [], //用户数据
      options: [
        {
          label: "借",
        },
        {
          label: "贷",
        },
      ],
      // 表单参数
      form: {},
      form1: {},
      // 表单校验
      rules: {
        staffName: [{ required: true, message: "请选择", trigger: "blur" }],
        tradTime: [
          { required: true, message: "请选择交易日期", trigger: "blur" },
        ],
      },
      fileList: [], // 文件列表
      uploadUrl:
        process.env.VUE_APP_BASE_API + "/admin-api/archives/flow/upload", // 上传地址地址
      headers: {
        Authorization: "Bearer " + getAccessToken(),
        "tenant-id": getTenantId(),
      }, // 设置上传的请求头
      time: "",
    };
  },
  created() {
    this.getList();
    this.getUserList();
  },
  methods: {
    // 上传文件事件
    handleImg(list) {
      this.fileList = list;
      this.reset();
    },
    handleScan(form) {
      console.log(form);
      this.form = form;
      this.form.adverseCompany = form.adverseCompany.slice(9, -2);
      this.form.bank = form.bank.slice(9, -2);
      this.form.digest = form.digest.slice(9, -2);
      this.form.myCompany = form.myCompany.slice(9, -2);
      this.form.purpose = form.purpose.slice(9, -2);
      this.form.receiptNum = form.receiptNum.slice(9, -2);
      this.form.serialNum = form.serialNum.slice(9, -2);
    },
    /**
     * 文件预览
     * @param fileUrl
     */
    openLink(fileUrl) {
      const url =
        process.env.VUE_APP_ONLINE_API +
        `/onlinePreview?url=${encodeURIComponent(this.base64Encode(fileUrl))}`;
      window.open(url);
    },
    /** 查看附件按钮操作 */
    handleViewFJ(row) {
      this.openLink(row.fileUrl);
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      getBankSlipPage(this.queryParams).then((response) => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 查询列表2 */
    getList2() {
      this.loading = true;
      // 执行查询
      getBankSlipPageTime({ months: this.time }).then((response) => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    //获取用户
    getUserList() {
      listUser().then((response) => {
        this.userOptions = response.data.list;
      });
    },
    handleOneMonth() {
      this.time = 1;
      this.getList2();
    },
    handleHalfYear() {
      this.time = 6;
      this.getList2();
    },
    handleOneYear() {
      this.time = 12;
      this.getList2();
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 取消按钮 */
    cancel1() {
      this.open1 = false;
      this.reset();
    },
    /** 取消按钮 */
    cancel2() {
      this.open2 = false;
      this.reset();
    },
    /** 取消按钮 */
    cancel3() {
      this.open3 = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        voucherId: undefined,
        flowCode: undefined,
        tradTime: undefined,
        bank: undefined,
        type: undefined,
        myCompany: undefined,
        myNum: undefined,
        adverseCompany: undefined,
        adverseNum: undefined,
        companyId: undefined,
        company: undefined,
        deptId: undefined,
        dept: undefined,
        debitOrCredit: undefined,
        currency: undefined,
        status: undefined,
        serialNum: undefined,
        debitMoney: undefined,
        tradMoney: undefined,
        creditMoney: undefined,
        balance: undefined,
        busNum: undefined,
        receiptNum: undefined,
        digest: undefined,
        digestExtend: undefined,
        businessDigest: undefined,
        theOther: undefined,
        purpose: undefined,
        businessNum: undefined,
        businessName: undefined,
        billNum: undefined,
        businessOrder: undefined,
        headingCode: undefined,
        bankCode: undefined,
        bankSite: undefined,
        bankRegion: undefined,
        encrypt: undefined,
        archiveId: undefined,
        archiveState: undefined,
        password: undefined,
      };
      this.form1 = {
        id: undefined,
        staffId: undefined,
        staffName: undefined,
        subscriptionStatus: undefined,
        flowCode: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加银行回单";
      this.fileList = [];
      this.optType = "add";
    },
    // 上传成功的函数
    handleSuccess(res) {
      console.log(res);
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.reset();
      this.optType = "view";
      const id = row.id;
      getBankSlip(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "查看银行回单";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.optType = "edit";
      const id = row.id;
      getBankSlip(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改银行回单";
      });
    },
    /** 认款按钮操作 */
    handleComfirm(val) {
      this.reset();
      this.form1.id = val.id;
      this.form1.flowCode = val.flowCode;
      this.open3 = true;
    },
    handleSelectUser(val) {
      this.form1.staffId = val.id;
      this.form1.staffName = val.username;
    },
    submitForm3() {
      this.form1.subscriptionStatus = 1;
      this.$refs["form1"].validate((valid) => {
        if (!valid) {
          return;
        }
        updateBankSlip(this.form1).then((response) => {
          this.$modal.msgSuccess("认款成功");
          this.open3 = false;
          this.getList();
        });
      });
    },
    /** 取消认款按钮操作 */
    handleUnComfirm(val) {
      this.reset();
      const data = { id: val.id, subscriptionStatus: 0 };
      this.$modal
        .confirm('是否确认取消银行回单编号为"' + val.id + '"的认款?')
        .then(function () {
          updateBankSlip(data).then((response) => {});
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("取消成功");
        });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (!valid) {
          return;
        }
        // 修改的提交
        if (this.form.id != null) {
          updateBankSlip(this.form).then((response) => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
          return;
        }
        // 添加的提交
        createBankSlip(this.form).then((response) => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
      });
    },
    //下载元数据
    handleDownloadData() {
      this.reset();
      this.open1 = true;
      this.queryParams.inputPassword = null;
    },
    submitForm1() {
      this.$refs["queryForm"].validate((valid) => {
        if (!valid) {
          return;
        }
        // 处理查询参数
        let params = { ...this.queryParams };
        downloadXml(params)
          .then((response) => {
            console.log(response.size);
            if (response.size == 39) {
              this.$modal.msgError("密码错误");
              return false;
            } else {
              this.$download.excel(response, "银行回单元数据.xml");
              this.open1 = false;
            }
          })
          .catch(() => {});
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除银行回单编号为"' + id + '"的数据项?')
        .then(function () {
          return deleteBankSlip(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = { ...this.queryParams };
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.$modal
        .confirm("是否确认导出所有银行回单数据项?")
        .then(() => {
          this.exportLoading = true;
          return exportBankSlipExcel(params);
        })
        .then((response) => {
          this.$download.excel(response, "银行回单.xls");
          this.exportLoading = false;
        })
        .catch(() => {});
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      console.log(selection);
      this.ids = selection.map((item) => item.id);
      if (selection.length == 1) {
        this.multiple = false;
        this.form = selection[0];
      } else {
        this.multiple = true;
      }
      this.multiple1 = !selection.length;
    },
    //关联凭证
    handleGLPZ() {
      this.form.voucherId = null;
      this.open2 = true;
      console.log(this.form);
    },
    submitForm2() {
      this.$refs["form"].validate((valid) => {
        if (!valid) {
          return;
        }
        updateBankSlip(this.form).then((response) => {
          this.$modal.msgSuccess("关联成功");
          this.open2 = false;
          this.multiple = true;
          this.getList();
        });
      });
    },
    handleSelectVoucher() {
      this.$refs.VoucherSelect.showFlag = true;
    },
    onVoucherSelected(obj) {
      console.log(obj);
      if (obj != undefined && obj != null) {
        this.form.voucherId = obj.id;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/assets/styles/header/index.scss";
@import "@/assets/styles/common/index.scss";
</style>
