<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item prop="year">
        <el-date-picker
          v-model="queryParams.year"
          value-format="yyyy"
          type="year"
          placeholder="选择年"
          clearable
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入项目名称"
          clearable
          @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-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          size="mini"
          @click="clickTotalVoucherView(1)"
          v-hasPermi="['buyer:voucherinfo:add']"
        >选择生成汇总表
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          size="mini"
          @click="clickTotalVoucherView(2)"
          v-hasPermi="['buyer:voucherinfo:export']"
        >全部生成汇总表
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table stripe v-loading="loading" :data="voucherinfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="项目名称" align="center" prop="name" />
      <el-table-column label="项目负责人" align="center" prop="employeeName">
        <template slot-scope="scope">
          <el-link type="primary" @click="clickProjectMember(scope.row)">{{ scope.row.employeeName }}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="项目成员" align="center">
        <template slot-scope="scope">
          <el-link type="primary" @click="clickProjectMember(scope.row)">{{ scope.row.buyerProjectMemberList.length }}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="项目开始时间/结束时间" align="center" prop="proportion">
        <template slot-scope="scope">
          {{ scope.row.startDate }} - {{ scope.row.endDate }}
        </template>
      </el-table-column>
      <el-table-column label="关联凭证数" align="center">
        <template slot-scope="scope">
          <el-link type="primary" @click="clickLinkInfo(scope.row)">{{ scope.row.voucherProjects.length }}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="项目状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.buyer_project_status" :value="scope.row.status" />
        </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-view"
            @click="clickVoucherView(scope.row)"
            v-hasPermi="['buyer:voucherinfo:edit']"
          >预览
          </el-button>
          <el-button
            type="text"
            icon="el-icon-download"
            size="mini"
            @click="handleExport(scope.row)"
            v-hasPermi="['buyer:voucherinfo:export']"
          >导出
          </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="projectMemberTitle" :visible.sync="projectMemberOpen" width="600px" append-to-body>
      <el-table stripe :data="projectMemberList" :show-header="false">
        <el-table-column label="项目负责人姓名" align="center" prop="deptEmployee" />
        <el-table-column label="添加人" align="center" prop="createBy" />
        <el-table-column label="添加时间" align="center" prop="createTime" />
        <el-table-column label="操作" align="center" prop="cz" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button v-if="scope.row.cz != '操作'"
                       size="mini"
                       type="text"
                       icon="el-icon-view"
                       @click="getEmployeeInfo(scope.row)"
            >查看
            </el-button>
            <span v-else>{{ scope.row.cz }}</span>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 关联凭证明细对话框 -->
    <el-dialog :title="linkInfoTitle" :visible.sync="linkInfoOpen" width="600px" append-to-body>
      <el-table stripe :data="linkInfoList">
        <el-table-column label="凭证编号" align="center" prop="deptEmployee">
          <template slot-scope="scope">
            <dict-tag style="float: left" :options="dict.type.voucher_type" :value="scope.row.voucherType" />
            <span style="float: left">-{{ scope.row.voucherCode }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作人" align="center" prop="createBy" />
        <el-table-column label="添加时间" align="center" prop="createTime" />
        <el-table-column label="操作" align="center" prop="cz" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini"
                       type="text"
                       icon="el-icon-view"
                       @click="handleView(scope.row)"
            >查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 预览对话框 -->
    <el-dialog :title="voucherViewTitle" :visible.sync="voucherViewOpen" width="80%" append-to-body>
      <el-row>
        <el-col :span="12">
          <el-button type="primary" icon="el-icon-down" @click="handleExport(selectProjectInfo)">导 出</el-button>
          <el-button @click="voucherViewOpen = false">返 回</el-button>
        </el-col>
      </el-row>
      <el-table stripe :data="voucherViewList" style="margin-top: 20px">
        <el-table-column align="center" label="凭证信息">
          <el-table-column label="日期" align="center" prop="date" />
          <el-table-column label="种类" align="center" prop="type" />
          <el-table-column label="号数" align="center" prop="code" />
          <el-table-column label="摘要" align="center" prop="summary" />
        </el-table-column>
        <el-table-column label="支出类型" align="center" prop="expenseType" />
        <el-table-column label="会计凭证记载金额" align="center" prop="accountAmount" />
        <el-table-column label="税法规定的归集金额" align="center" prop="lawAmount" />

        <el-table-column align="center" label="费用明细（税法规定）">
          <el-table-column label="人员人工费用" align="center" prop="type1Amount" />
          <el-table-column label="直接投入费用" align="center" prop="type2Amount" />
          <el-table-column label="折旧费用与长期待摊费用" align="center" prop="type3Amount" />
          <el-table-column label="无形资产摊销费用" align="center" prop="type4Amount" />
          <el-table-column label="设计费用" align="center" prop="type5Amount" />
          <!--          <el-table-column label="装备调试费用与试验费用" align="center" prop="type6Amount" />-->
          <el-table-column label="其他相关费用" align="center" prop="type9Amount" />
          <el-table-column align="center" label="委托研发费用">
            <el-table-column label="委托境内机构或个人进行研发活动所发生的费用" align="center" prop="type7Amount" />
            <el-table-column label="委托境外机构进行研发活动所发生的费用" align="center" prop="type8Amount" />
          </el-table-column>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 汇总对话框 -->
    <el-dialog :title="totalVoucherViewTitle" :visible.sync="totalVoucherViewOpen" width="100%" append-to-body>
      <el-row>
        <el-col :span="12">
          <el-button type="primary" icon="el-icon-down" @click="handleTotalExport()">导 出</el-button>
          <el-button @click="totalVoucherViewOpen = false">返 回</el-button>
        </el-col>
      </el-row>
      <el-table stripe :data="totalVoucherViewList" style="margin-top: 20px">
        <el-table-column label="项目编号" align="center" prop="projectCode" />
        <el-table-column label="项目名称" align="center" prop="projectName" />
        <el-table-column label="完成情况" align="center" prop="projectStatus" />
        <el-table-column label="支出类型" align="center" prop="expenseType" />
        <el-table-column label="允许加计扣除金额合计" align="center" prop="deductionAmount" />

        <el-table-column label="人员人工费用" align="center" prop="type1Amount" />
        <el-table-column label="直接投入费用" align="center" prop="type2Amount" />
        <el-table-column label="折旧费用与长期待摊费用" align="center" prop="type3Amount" />
        <el-table-column label="无形资产摊销费用" align="center" prop="type4Amount" />
        <el-table-column label="设计费用" align="center" prop="type5Amount" />
        <!--        <el-table-column label="装备调试费用与试验费用" align="center" prop="type6Amount" />-->
        <el-table-column label="前五项小计" align="center" prop="type66Amount" />

        <el-table-column align="center" label="其他相关费用及限额">
          <el-table-column label="其他相关费用合计" align="center" prop="type7Amount" />
          <el-table-column label="经限额调整后的其他相关费用" align="center" prop="type71Amount" />
        </el-table-column>

        <el-table-column align="center" label="委托研发费用及限额">
          <el-table-column label="委托境内机构或个人进行研发活动所发生的费用" align="center" prop="type8Amount" />
          <el-table-column label="允许加计扣除的委托境内机构或个人进行研发活动所发生的费用" align="center" prop="type81Amount" />
          <el-table-column label="委托境外机构进行研发活动所发生的费用" align="center" prop="type9Amount" />
          <el-table-column label="经限额调整后的委托境外机构进行研发活动所发生的费用" align="center" prop="type91Amount" />
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 添加或修改辅助帐凭证详细列对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
        <el-form-item label="公司id" prop="companyId">
          <el-input v-model="form.companyId" placeholder="请输入公司id" />
        </el-form-item>
        <el-form-item label="占比" prop="proportion">
          <el-input v-model="form.proportion" placeholder="请输入占比" />
        </el-form-item>
        <el-form-item label="金额" prop="price">
          <el-input v-model="form.price" placeholder="请输入金额" />
        </el-form-item>
        <el-form-item label="摘要" prop="summary">
          <el-input v-model="form.summary" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="科目1" prop="subject1">
          <el-input v-model="form.subject1" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="科目2" prop="subject2">
          <el-input v-model="form.subject2" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="借方余额" prop="debitBalance">
          <el-input v-model="form.debitBalance" placeholder="请输入借方余额" />
        </el-form-item>
        <el-form-item label="贷方余额" prop="creditBalance">
          <el-input v-model="form.creditBalance" placeholder="请输入贷方余额" />
        </el-form-item>
        <el-form-item label="凭证id" prop="voucherId">
          <el-input v-model="form.voucherId" placeholder="请输入凭证id" />
        </el-form-item>
      </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>


    <!-- 企业信息员工对话框 -->
    <el-dialog :title="employeeTitle" :visible.sync="employeeOpen" width="700px" append-to-body>
      <el-form ref="form" :model="employeeInfoList" label-width="80px">
        <el-form-item label="姓名" prop="name">
          <el-input readonly v-model="employeeInfoList.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-radio-group disabled v-model="employeeInfoList.sex">
            <el-radio
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.value"
            >{{ dict.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="证件号码" prop="idNumber">
          <el-input readonly v-model="employeeInfoList.idNumber" placeholder="请输入证件号码" />
        </el-form-item>
        <el-form-item label="出生日期" prop="birthdate">
          <el-date-picker
            readonly
            clearable
            v-model="employeeInfoList.birthdate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出生日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="学历" prop="education">
          <el-select disabled v-model="employeeInfoList.education" placeholder="请选择学历">
            <el-option
              v-for="dict in dict.type.buyer_employee_education"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="毕业院校" prop="college">
          <el-input readonly v-model="employeeInfoList.college" placeholder="请输入毕业院校" />
        </el-form-item>
        <el-form-item label="所学专业" prop="major">
          <el-input readonly v-model="employeeInfoList.major" placeholder="请输入专业" />
        </el-form-item>
        <el-form-item label="职称" prop="professional">
          <el-input readonly v-model="employeeInfoList.professional" placeholder="请输入职称" />
        </el-form-item>
        <el-form-item label="部门" prop="dept">
          <el-input readonly v-model="employeeInfoList.dept" placeholder="请输入部门" />
        </el-form-item>
        <el-form-item label="职务" prop="post">
          <el-input readonly v-model="employeeInfoList.post" placeholder="请输入职务" />
        </el-form-item>
        <el-form-item label="员工类型" prop="employeeType">
          <el-select disabled v-model="employeeInfoList.employeeType" placeholder="请选择员工类型">
            <el-option
              v-for="dict in dict.type.employee_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="员工状态" prop="employeeStatus">
          <el-radio-group disabled v-model="employeeInfoList.employeeStatus">
            <el-radio
              v-for="dict in dict.type.employee_status"
              :key="dict.value"
              :label="dict.value"
            >{{ dict.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="入职日期" prop="hiredate">
          <el-date-picker
            readonly
            clearable
            v-model="employeeInfoList.hiredate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择入职日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="离职日期" prop="resignationDate" v-if="employeeInfoList.employeeStatus === '2'">
          <el-date-picker
            readonly
            clearable
            v-model="employeeInfoList.resignationDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择离职日期"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 查看凭证 -->
    <el-dialog :title="voucherTitle" :visible.sync="voucherOpen" width="100%" append-to-body>
      <el-form :model="voucherForm" ref="voucherForm" size="small" :inline="true">
        <el-form-item prop="type">
          <div>
            <div v-for="dict in dict.type.voucher_type" :key="dict.value">
              <span v-if="dict.value == voucherForm.type">{{ dict.label }}</span>
            </div>
          </div>
        </el-form-item>
        <el-form-item prop="code" style="width: 90px;">
          <el-row>
            <el-col :span="20">
              <span>{{ voucherForm.code }}</span>
            </el-col>
            <el-col :span="4">号</el-col>
          </el-row>
        </el-form-item>
        <el-form-item prop="date" style="margin-left: 20px">
          <span>{{ voucherForm.date }}</span>
        </el-form-item>
        <el-form-item label="附单据:" prop="accessoryNumber" style="margin-left: 20px">
          <el-row>
            <el-col :span="4">{{ fileList.length }}</el-col>
            <el-col :span="4">张</el-col>
            <el-col :span="16">
              <el-button type="primary" style="margin-left: 10px;" @click="openFileList">查看附件</el-button>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="制单人:" prop="producer" style="margin-left: 20px">
          <span>{{ voucherForm.producer }}</span>
        </el-form-item>
        <el-form-item label="支出类型:" prop="expenseType" style="margin-left: 20px">
          <div>
            <div v-for="dict in dict.type.voucher_expense_type" :key="dict.value">
              <span v-if="dict.value == voucherForm.expenseType">{{ dict.label }}</span>
            </div>
          </div>
        </el-form-item>
        <el-form-item>
          <el-button v-if="voucherForm.buyerVoucherProjects && voucherForm.buyerVoucherProjects.length > 0"
                     type="primary"
                     size="mini"
                     @click="handleViewProject(voucherForm)"
          >查看关联项目
          </el-button>
          <el-button @click="voucherOpen=false">关 闭</el-button>
        </el-form-item>
      </el-form>

      <el-row>
        <el-col :span="24">
          <el-table
            show-summary
            :data="voucherTableData"
            style="width: 100%"
          >
            <el-table-column label="摘要信息" align="center" prop="summary">
              <template slot-scope="{row ,$index}">
                <div>{{ row.summary }}</div>
              </template>
            </el-table-column>
            <el-table-column label="科目名称1" align="center" prop="subject1">
              <template slot-scope="{row ,$index}">
                <dict-tag :options="dict.type.voucher_subject_1" :value="row.subject1" />
              </template>
            </el-table-column>
            <el-table-column label="科目名称2" align="center" prop="subject2">
              <template slot-scope="{row ,$index}">
                <dict-tag :options="dict.type.voucher_subject_2" :value="row.subject2" />
              </template>
            </el-table-column>
            <el-table-column label="借方余额" align="center" prop="debitBalance">
              <el-table-column prop="debitUnit1" label="亿" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.debitUnit1 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="debitUnit2" label="千万" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.debitUnit2 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="debitUnit3" label="百万" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.debitUnit3 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="debitUnit4" label="十万" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.debitUnit4 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="debitUnit5" label="万" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.debitUnit5 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="debitUnit6" label="千" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.debitUnit6 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="debitUnit7" label="百" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.debitUnit7 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="debitUnit8" label="十" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.debitUnit8 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="debitUnit9" label="元" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.debitUnit9 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="debitUnit10" label="角" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.debitUnit10 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="debitUnit11" label="分" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.debitUnit11 }}</div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column label="贷方余额" align="center" prop="creditBalance">
              <el-table-column prop="creditUnit1" label="亿" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.creditUnit1 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="creditUnit2" label="千万" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.creditUnit2 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="creditUnit3" label="百万" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.creditUnit3 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="creditUnit4" label="十万" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.creditUnit4 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="creditUnit5" label="万" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.creditUnit5 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="creditUnit6" label="千" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.creditUnit6 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="creditUnit7" label="百" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.creditUnit7 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="creditUnit8" label="十" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.creditUnit8 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="creditUnit9" label="元" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.creditUnit9 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="creditUnit10" label="角" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.creditUnit10 }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="creditUnit11" label="分" width="60">
                <template slot-scope="{row ,$index}">
                  <div>{{ row.creditUnit11 }}</div>
                </template>
              </el-table-column>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
    </el-dialog>

    <!-- 关联项目明细对话框详情 -->
    <el-dialog title="关联项目明细" :visible.sync="viewProjectOpen" width="50%" append-to-body>
      <el-tabs v-model="activeName">
        <el-tab-pane v-for="(item,index) in selectVoucher.buyerVoucherProjects"
                     :label="item.subjectLabel"
                     :name="item.subject"
                     :key="index"
        >
          <el-table stripe :data="item.buyerVoucherProjects">
            <el-table-column prop="projectId" label="项目名称">
              <template slot-scope="{row ,$index}">
                <div v-for="project in projectList" :key="project.id">
              <span v-if="project.id == row.projectId">
                {{ project.name }}
              </span>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="proportion" label="占比（%）"></el-table-column>
            <el-table-column prop="price" label="金额"></el-table-column>
          </el-table>
          <el-row style="margin-top: 20px; margin-left: 20px">
            <el-col :span="24">
              <span>操作人：{{ item.buyerVoucherProjects[0].createBy }}</span>
              <span style="margin-left: 35px">时间：{{ item.buyerVoucherProjects[0].createTime }}</span>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>

    <!-- 文件列表对话框详情 -->
    <el-dialog title="上传文件" :visible.sync="fileListOpen" width="50%" append-to-body>
      <el-table stripe :data="fileList" style="padding-top: 20px">
        <el-table-column prop="fileAddr" label="名称"></el-table-column>
        <el-table-column label="时间" align="center" prop="createTime" width="180"></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="handleDownLoad(scope.row)"
            >下载
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer" style="margin-top: 30px;margin-left: 40%">
        <el-button @click="fileListOpen = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listVoucherinfo,
  getVoucherinfo,
  delVoucherinfo,
  addVoucherinfo,
  updateVoucherinfo,
  voucherInfoViewList,
  totalVoucherInfoList
} from '@/api/buyer/voucherinfo'
import { listAuxiliaryvoucher } from '@/api/buyer/auxiliaryvoucher'
import { listForVoucher, listProject } from '@/api/buyer/project'
import { getEmployee } from '@/api/buyer/employee'
import download from '@/plugins/download'

export default {

  name: 'Voucherinfo',
  dicts: [
    'buyer_project_status',
    'voucher_type',
    'employee_status',
    'employee_type',
    'buyer_employee_education',
    'sys_user_sex',
    'voucher_subject_1',
    'voucher_subject_2',
    'voucher_expense_type'
  ],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 辅助帐凭证详细列表格数据
      voucherinfoList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      // 选择的详情情况
      selectProjectInfo: {},

      // 弹出层标题
      projectMemberTitle: '',
      // 是否显示弹出层
      projectMemberOpen: false,
      // 项目成员
      projectMemberList: [],
      // 弹出层标题
      linkInfoTitle: '',
      // 是否显示弹出层
      linkInfoOpen: false,
      // 关联凭证信息列表
      linkInfoList: [],

      // 弹出层标题
      voucherViewTitle: '',
      // 是否显示弹出层
      voucherViewOpen: false,
      // 关联凭证信息列表
      voucherViewList: [],

      // 弹出层标题
      totalVoucherViewTitle: '',
      // 是否显示弹出层
      totalVoucherViewOpen: false,
      // 关联凭证信息列表
      totalVoucherViewList: [],

      employeeTitle: '',
      employeeOpen: false,
      employeeInfoList: {},

      voucherTitle: '',
      voucherOpen: false,
      voucherTableData: [],
      fileList: [],
      voucherForm: {},

      fileListOpen: false,
      selectVoucher: {},
      viewProjectOpen: false,
      projectList: [],
      activeName: ''
    }
  },
  created() {
    this.getList()
    this.getListProject()
  },
  methods: {
    /** 查询辅助帐凭证详细列列表 */
    getList() {
      this.loading = true
      listForVoucher(this.queryParams).then(response => {
        this.voucherinfoList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remarks: null,
        delFlag: null,
        companyId: null,
        proportion: null,
        price: null,
        summary: null,
        subject1: null,
        subject2: null,
        debitBalance: null,
        creditBalance: null,
        voucherId: null
      }
      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
    },
    // 点击项目负责人和项目成员
    clickProjectMember(obj) {
      this.projectMemberList = []
      this.selectProjectInfo = obj
      this.projectMemberTitle = '查看项目成员'
      this.projectMemberOpen = true
      this.projectMemberList.push({
        deptEmployee: '项目负责人姓名',
        createBy: '添加人',
        createTime: '添加时间',
        cz: '操作'
      })
      this.projectMemberList.push({
        deptEmployee: this.selectProjectInfo.employeeName,
        createBy: this.selectProjectInfo.createBy,
        deptEmployeeId: this.selectProjectInfo.employeeId,
        createTime: this.selectProjectInfo.createTime
      })
      this.projectMemberList.push({
        deptEmployee: '成员姓名',
        createBy: '添加人',
        createTime: '添加时间',
        cz: '操作'
      })
      this.projectMemberList = this.projectMemberList.concat(this.selectProjectInfo.buyerProjectMemberList)
    },

    // 点击预览按钮
    clickVoucherView(obj) {
      this.voucherViewList = []
      this.selectProjectInfo = obj
      this.voucherViewTitle = '“' + this.selectProjectInfo.name + '”辅助帐导出'
      this.voucherViewOpen = true
      this.loading = true
      voucherInfoViewList({ projectId: this.selectProjectInfo.id }).then(response => {
        this.voucherViewList = response.rows
        this.loading = false
      })
    },

    // 点击汇总按钮
    clickTotalVoucherView(type) {
      this.totalVoucherViewTitle = '汇总辅助帐导出'
      // 选择项目
      if (type == 1) {
        if (!this.ids || this.ids.length == 0) {
          this.$modal.msgWarning('请至少选择一行数据！')
        } else {
          this.loading = true
          totalVoucherInfoList(this.ids).then(response => {
            this.totalVoucherViewOpen = true
            this.totalVoucherViewList = response.rows
            this.loading = false
          })
        }
      } else {
        this.loading = true
        totalVoucherInfoList([]).then(response => {
          this.totalVoucherViewOpen = true
          this.totalVoucherViewList = response.rows
          this.loading = false
        })
      }
    },

    // 关联凭证数
    clickLinkInfo(obj) {
      this.linkInfoList = []
      this.selectProjectInfo = obj
      this.linkInfoTitle = '关联凭证明细'
      this.linkInfoOpen = true
      this.linkInfoList = this.selectProjectInfo.voucherProjects
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加辅助帐凭证详细列'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.selectProjectInfo = row
      this.reset()
      const id = row.id || this.ids
      getVoucherinfo(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改辅助帐凭证详细列'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateVoucherinfo(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addVoucherinfo(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除辅助帐凭证详细列选中的数据项？').then(function() {
        return delVoucherinfo(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport(row) {
      this.selectProjectInfo = row
      this.download('buyer/voucherinfo/selectBuyerVoucherInfoListExport', {
        ...{ projectId: this.selectProjectInfo.id }
      }, `辅助帐导出.xlsx`)
    },

    /** 导出按钮操作 */
    handleTotalExport() {
      this.download('buyer/voucherinfo/totalVoucherInfoListExport', { projectIds: this.ids }, `汇总辅助帐导出.xlsx`)
    },

    // 查看员工信息
    getEmployeeInfo(row) {
      getEmployee(row.deptEmployeeId).then(response => {
        this.employeeInfoList = response.data
        this.employeeTitle = '“' + row.deptEmployee + '”企业信息员工'
        this.employeeOpen = true
      })
    },

    /** 查看凭证 */
    handleView(row) {
      this.loading = true
      listAuxiliaryvoucher({ id: row.voucherId }).then(response => {
        if (response.rows && response.rows.length > 0) {
          this.voucherForm = response.rows[0]
          this.fileList = this.voucherForm.buyerFileInfos
          this.voucherTableData = this.voucherForm.buyerVoucherInfos
          this.voucherOpen = true
          this.voucherTitle = '查看凭证'
        }
        this.loading = false
      })
    },

    // 打开文件上传列表
    openFileList() {
      this.fileListOpen = true
    },

    /** 查看关联项目 */
    handleViewProject(obj) {
      this.selectVoucher = obj
      this.viewProjectOpen = true
      for (const item of this.selectVoucher.buyerVoucherInfos) {
        if (item.subject1 == 'type1') {
          // 初始化定义第一个为活动的tab页
          this.activeName = item.subject2
          break
        }
      }
    },

    // 下载文件
    handleDownLoad(row) {
      download.name(row.fileName, 0)
    },

    /** 查询項目列表 */
    getListProject() {
      listProject(null).then(response => {
        this.projectList = response.rows
      })
    }
  }
}
</script>
