<template>
  <div class="app-container">
    <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="['cs:csIncomeDetails:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['cs:csIncomeDetails:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['cs:csIncomeDetails:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-upload2" size="mini" @click="handleImport"
          v-hasPermi="['cs:csIncomeDetails:import']">导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['cs:csIncomeDetails:export']">导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-download" size="mini" @click="handleExportTemplate"
          v-hasPermi="['cs:csIncomeDetails:export']">导出模板</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button plain size="mini" @click="handleSearch">高级搜索</el-button>
      </el-col>
      <el-col :span="8">
        <span style="padding-right: 10px;">表格设置</span>
        <el-select v-model="tableHeaderList" multiple collapse-tags placeholder="请选择" @change="changeSelect">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <div v-if="showSearch" ref="showSearch" class="searchForm">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="关键词">
          <el-input placeholder="请输入关键词" v-model="queryParams.keyword" />
        </el-form-item>
        <el-form-item label="项目/合同名称" prop="projectName">
          <el-input v-model="queryParams.projectName" placeholder="请输入项目/合同名称" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="付款人" prop="paymentPerson">
          <el-input v-model="queryParams.paymentPerson" placeholder="请输入付款人" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="付款单位" prop="paymentCompany">
          <el-input v-model="queryParams.paymentCompany" placeholder="请输入付款单位" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="部门/院系" prop="deptId">
          <el-input v-model="queryParams.deptId" placeholder="请输入部门/院系" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="账户信息" prop="accountInfo">
          <el-input v-model="queryParams.accountInfo" placeholder="请输入账户信息" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="经办人" prop="operatorUser">
          <el-input v-model="queryParams.operatorUser" placeholder="请输入经办人" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="隶属部门" prop="deptName">
          <el-input v-model="queryParams.deptName" placeholder="请输入隶属部门" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="入账日期" prop="accountingTime">
          <el-date-picker clearable v-model="queryParams.accountingTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择入账日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="金额(元)" prop="price">
          <el-input v-model="queryParams.price" placeholder="请输入金额(元)" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="凭证编号" prop="documentNumber">
          <el-input v-model="queryParams.documentNumber" placeholder="请输入凭证编号" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="设备名称" prop="deviceName">
          <el-input v-model="queryParams.deviceName" placeholder="请输入设备名称" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="设备编号" prop="deviceNumber">
          <el-input v-model="queryParams.deviceNumber" placeholder="请输入设备编号" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="收入来源分类" prop="accountingClassId">
          <el-input v-model="queryParams.accountingClassId" placeholder="请输入收入来源分类" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="提交时间" prop="dateRange">
          <el-date-picker clearable v-model="queryParams.dateRange" type="daterange" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd">
          </el-date-picker>
        </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>
    </div>
    <el-table v-loading="loading" :data="csIncomeDetailsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="sort">
        <template slot-scope="scope">
          {{ ((queryParams.pageNum - 1) * queryParams.pageSize) + (scope.$index + 1) }}
        </template>
      </el-table-column>
      <el-table-column label="部门合同编号" align="center" prop="departmentContractNumber"
        v-if="tableHeaderList.indexOf('departmentContractNumber') != -1" />
      <el-table-column label="合同签订时间" align="center" prop="signingTime"
        v-if="tableHeaderList.indexOf('signingTime') != -1">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.signingTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="终止日期" align="center" prop="endTime" v-if="tableHeaderList.indexOf('endTime') != -1">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目/合同名称" align="center" prop="projectName"
        v-if="tableHeaderList.indexOf('projectName') != -1" />
      
      <el-table-column label="需方" align="center" prop="demandingSide"
        v-if="tableHeaderList.indexOf('demandingSide') != -1" />
      <el-table-column label="需方VPN" align="center" prop="demandingSideVpn"
        v-if="tableHeaderList.indexOf('demandingSideVpn') != -1" />
      <!-- <el-table-column label="需方AC" align="center" prop="demandingSideAc"
        v-if="tableHeaderList.indexOf('demandingSideAc') != -1" /> -->
      <!-- <el-table-column label="供方" align="center" prop="supplier" v-if="tableHeaderList.indexOf('supplier') != -1" /> -->
      <el-table-column label="经办人" align="center" prop="operatorUser"
        v-if="tableHeaderList.indexOf('operatorUser') != -1" />
        
      <!-- <el-table-column label="隶属部门" align="center" prop="deptName" v-if="tableHeaderList.indexOf('deptName') != -1" /> -->
      <!-- <el-table-column label="摘要" align="center" prop="accountingAbstract"
        v-if="tableHeaderList.indexOf('accountingAbstract') != -1" /> -->
      <el-table-column label="入账日期" align="center" prop="accountingTime" width="180"
        v-if="tableHeaderList.indexOf('accountingTime') != -1">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.accountingTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="金额(元)" align="center" prop="price" 
        v-if="tableHeaderList.indexOf('price') != -1" />
        <el-table-column label="AC充值额度" align="center" prop="acRecharge" 
        v-if="tableHeaderList.indexOf('acRecharge') != -1" />
        <el-table-column label="状态" align="center" prop="detailedStatus" 
        v-if="tableHeaderList.indexOf('detailedStatus') != -1" />
      <!-- <el-table-column label="凭证编号" align="center" prop="documentNumber"
        v-if="tableHeaderList.indexOf('documentNumber') != -1" /> -->
      <el-table-column label="到账地点" align="center" prop="deliveryLocation"
        v-if="tableHeaderList.indexOf('deliveryLocation') != -1" />
      <!-- <el-table-column label="设备名称" align="center" prop="deviceName"
        v-if="tableHeaderList.indexOf('deviceName') != -1" /> -->
      <el-table-column label="资源备注" align="center" prop="resourceRemarks"
        v-if="tableHeaderList.indexOf('resourceRemarks') != -1" />
      <el-table-column label="资源到期时间" align="center" prop="expirationTime"
        v-if="tableHeaderList.indexOf('expirationTime') != -1" />
      <!-- <el-table-column label="设备编号" align="center" prop="deviceNumber"
        v-if="tableHeaderList.indexOf('deviceNumber') != -1" /> -->
      <!-- <el-table-column label="付款单位" align="center" prop="paymentCompany"
        v-if="tableHeaderList.indexOf('paymentCompany') != -1" /> -->
      <!-- <el-table-column label="附件" align="center" prop="annexList" v-if="tableHeaderList.indexOf('annexList') != -1">
        <template slot-scope="scope">
          <span style="cursor: pointer;" @click="lookannex(scope.row)">查看</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="备注" align="center" prop="remarks" v-if="tableHeaderList.indexOf('remarks') != -1" /> -->
      <!-- <el-table-column label="收入来源分类" align="center" prop="accountingClass"
        v-if="tableHeaderList.indexOf('accountingClass') != -1" /> -->
      <!-- <el-table-column label="录入时间" align="center" prop="createAt" width="180"
        v-if="tableHeaderList.indexOf('createAt') != -1">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="是否提供原件" align="center" prop="isOriginal"
        v-if="tableHeaderList.indexOf('isOriginal') != -1">

        <template slot-scope="scope">
          <span>{{ scope.row.isOriginal == 1 ? '是' : '否' }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="服务清单编号" align="center" prop="inventoryNumber"
        v-if="tableHeaderList.indexOf('inventoryNumber') != -1" /> -->

      <!-- <el-table-column label="付款人" align="center" prop="paymentPerson"
        />
  
      <el-table-column label="账户信息" align="center" prop="accountInfo"
        />
      -->

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['cs:csIncomeDetails:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['cs:csIncomeDetails:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

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

    <!-- 添加或修改收入明细对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="200px">
        <el-form-item label="部门合同编号" prop="departmentContractNumber">
          <el-input v-model="form.departmentContractNumber" placeholder="请输入部门合同编号" />
        </el-form-item>
        <el-form-item label="合同签订时间" prop="signingTime">
          <el-date-picker clearable v-model="form.signingTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择合同签订时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="终止日期" prop="endTime">
          <el-date-picker clearable v-model="form.endTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择终止日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="项目/合同名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入项目/合同名称" />
        </el-form-item>
        <el-form-item label="需方" prop="demandingSide">
          <el-input v-model="form.demandingSide" placeholder="请输入需方" />
        </el-form-item>
        <el-form-item label="需方VPN" prop="demandingSideVpn">
          <el-input v-model="form.demandingSideVpn" placeholder="请输入需方VPN" />
        </el-form-item>
        <el-form-item label="需方AC" prop="demandingSideAc">
          <el-input v-model="form.demandingSideAc" placeholder="请输入需方AC" />
        </el-form-item>
        <el-form-item label="供方" prop="supplier">
          <el-input v-model="form.supplier" placeholder="请输入供方" />
        </el-form-item>
        <el-form-item label="经办人" prop="operatorUser">
          <el-input v-model="form.operatorUser" placeholder="请输入经办人" />
        </el-form-item>
        <el-form-item label="隶属部门" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入隶属部门" />
        </el-form-item>
        <el-form-item label="摘要" prop="accountingAbstract">
          <el-input v-model="form.accountingAbstract" placeholder="请输入摘要" />
        </el-form-item>
        <el-form-item label="入账日期" prop="accountingTime">
          <el-date-picker clearable v-model="form.accountingTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择入账日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="金额(元)" prop="price">
          <el-input v-model="form.price" placeholder="请输入金额(元)" />
        </el-form-item>
        <el-form-item label="AC充值额度" prop="acRecharge">
          <el-input v-model="form.acRecharge" placeholder="请输入AC充值额度" />
        </el-form-item>
        <el-form-item label="AC赠送额度" prop="acGive">
          <el-input v-model="form.acGive" placeholder="请输入AC赠送额度" />
        </el-form-item>
        <el-form-item label="收入明细状态" prop="detailedStatus">
          <el-input v-model="form.detailedStatus" placeholder="请输入收入明细状态" />
        </el-form-item>
        <el-form-item label="凭证编号" prop="documentNumber">
          <el-input v-model="form.documentNumber" placeholder="请输入凭证编号" />
        </el-form-item>
        <el-form-item label="到账地点" prop="deliveryLocation">
          <el-input v-model="form.deliveryLocation" placeholder="请输入到账地点" />
        </el-form-item>
        <el-form-item label="设备名称" prop="deviceName">
          <el-input v-model="form.deviceName" placeholder="请输入设备名称" />
        </el-form-item>
        <el-form-item label="资源备注" prop="resourceRemarks">
          <el-input v-model="form.resourceRemarks" placeholder="请输入资源备注" />
        </el-form-item>
        <el-form-item label="资源到期时间" prop="expirationTime">
          <el-date-picker clearable v-model="form.expirationTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择资源到期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="设备编号" prop="deviceNumber">
          <el-input v-model="form.deviceNumber" placeholder="请输入设备编号" />
        </el-form-item>
        <el-form-item label="付款单位" prop="paymentCompany">
          <el-input v-model="form.paymentCompany" placeholder="请输入付款单位" />
        </el-form-item>
        <el-form-item label="上传附件" prop="annexList">
          <el-upload class="upload-demo" :action="$baseUrl + '/api/common/uploadFileLocal'" :on-change="handleChange"
            :on-remove="handleMove" :file-list="form.fileList" :on-preview="handlePreview">
            <el-button size="small" type="primary" icon="el-icon-upload2">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">支持扩展名：excle.pdf.xlsx…</div>
          </el-upload>
        </el-form-item>
        <el-form-item label="材料完备性自检情况说明" prop="situationExplain">
          <el-input v-model="form.situationExplain" placeholder="请输入材料完备性自检情况说明" />
        </el-form-item>
        <el-form-item label="付费用户编号" prop="payUserNumber">
          <el-input v-model="form.payUserNumber" placeholder="请输入付费用户编号" />
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="收入来源分类" prop="accountingClass">
          <el-input v-model="form.accountingClass" placeholder="请输入收入来源分类" />
        </el-form-item>
        <el-form-item label="是否提供原件" prop="isOriginal">
          <el-radio-group v-model="form.isOriginal">
            <el-radio label="0">否</el-radio>
            <el-radio label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- <el-form-item label="服务清单编号" prop="inventoryNumber">
          <el-input v-model="form.inventoryNumber" placeholder="请输入服务清单编号" />
        </el-form-item> -->
        <el-form-item label="是否提供服务清单" prop="isServiceList">
          <el-radio-group v-model="form.isServiceList">
            <el-radio label="0">否</el-radio>
            <el-radio label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="资源到期剩余天数" prop="surplusDays">
          <el-input v-model="form.surplusDays" placeholder="请输入资源到期剩余天数" />
        </el-form-item>
        <el-form-item label="服务对象类型" prop="serviceType">
          <el-input v-model="form.serviceType" placeholder="请输入服务对象类型" />
        </el-form-item>

        <el-form-item label="服务对象类型-细分" prop="serviceTypeDetailed">
          <el-input v-model="form.serviceTypeDetailed" placeholder="请输入服务对象类型-细分" />
        </el-form-item>
        
        <el-form-item label="产业院转入情况" prop="transferSituation">
          <el-input v-model="form.transferSituation" placeholder="请输入产业院转入情况" />
        </el-form-item>

        <el-form-item label="剩余金额（元）" prop="surplusPrice">
          <el-input v-model="form.surplusPrice" placeholder="请输入剩余金额（元）" />
        </el-form-item>
        <el-form-item label="充值工单标题" prop="orderTitle">
          <el-input v-model="form.orderTitle" placeholder="请输入充值工单标题" />
        </el-form-item>
        <el-form-item label="工单附件是否齐全" prop="isComplete">
          <el-input v-model="form.isComplete" placeholder="请输入工单附件是否齐全" />
        </el-form-item>
        <el-form-item label="一级单位" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入单位" />
        </el-form-item>
        <el-form-item label="二级单位" prop="secondUnit">
          <el-input v-model="form.secondUnit" placeholder="请输入单位" />
        </el-form-item>
        <el-form-item label="单位类型" prop="unitType">
          <el-input v-model="form.unitType" placeholder="请输入单位类型" />
        </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="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="查看" :visible.sync="isShowfu" width="800px" append-to-body>
      <el-table :data="form.annexList&&form.annexList.filter(v => v.delFlag != '1')" :border="true"
        header-cell-class-name="headerClassName">
        <el-table-column prop="sort" label="序号" width="90" align="center" />
        <el-table-column prop="annexName" label="附件名称" />
        <el-table-column prop="annexFormat" label="格式" />
        <el-table-column prop="annexSize" label="大小" />
        <el-table-column label="操作">
          <template slot-scope="scope">
            <!-- <el-button type="text" @click="handleRemove(scope.row)">删除</el-button> -->
            <el-button type="text" @click="viewFile(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { getToken } from "@/utils/auth";
import { listCsIncomeDetails, getCsIncomeDetails, delCsIncomeDetails, addCsIncomeDetails, updateCsIncomeDetails } from "@/api/cs/csIncomeDetails";

export default {
  name: "CsIncomeDetails",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 收入明细表格数据
      csIncomeDetailsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        keyword: '',
        projectName: null,
        paymentPerson: null,
        paymentCompany: null,
        deptId: null,
        accountInfo: null,
        operatorUser: null,
        deptName: null,
        accountingTime: null,
        price: null,
        documentNumber: null,
        deviceName: null,
        deviceNumber: null,
        accountingClassId: null,
        dateRange: [],
      },
      // 表单参数
      form: { annexList: [] },
      // 表单校验
      rules: {
      },
      options: [
        // {
        //   value: 'departmentContractNumber',
        //   label: '部门合同编号'
        // }, 
        // {
        //   value: 'signingTime',
        //   label: '合同签订时间'
        // }, 
        // {
        //   value: 'endTime',
        //   label: '终止日期'
        // }, 
        // {
        //   value: 'projectName',
        //   label: '项目/合同名称'
        // }, 
        {
          value: 'price',
          label: '金额(元)'
        },
        {
          value: 'demandingSide',
          label: '需方'
        }, {

          value: 'demandingSideVpn',
          label: '需方VPN'
        },
        // {
        //   value: 'demandingSideAc',
        //   label: '需方AC'
        // }, 
        // {
        //   value: 'supplier',
        //   label: '供方'
        // }, 
        {
          value: 'operatorUser',
          label: '经办人'
        },
        // {
        //   value: 'deptName',
        //   label: '隶属部门'
        // }, 
        // {
        //   value: 'accountingAbstract',
        //   label: '摘要'
        // }, 
        {
          value: 'accountingTime',
          label: '入账日期'
        },
        // {
        //   value: 'documentNumber',
        //   label: '凭证编号'
        // }, 
        {
          value: 'deliveryLocation',
          label: '到账地点'
        },
        // {
        //   value: 'deviceName',
        //   label: '设备名称'
        // }, 
        {
          value: 'resourceRemarks',
          label: '资源备注'
        },
        {
          value: 'deviceNumber',
          label: '设备编号'
        },
        {
          value: 'acRecharge',
          label: 'AC充值额度'
        },
        {
          value: 'detailedStatus',
          label: '状态'
        },
        {
          value: 'expirationTime',
          label: '资源到期时间'
        },
        // {
        //   value: 'paymentCompany',
        //   label: '付款单位'
        // }, 
        // {
        //   value: 'annexList',
        //   label: '附件'
        // },
        //  {
        //   value: 'remarks',
        //   label: '备注'
        // },
        //  {
        //   value: 'accountingClass',
        //   label: '收入来源分类'
        // },
        //  {
        //   value: 'createAt',
        //   label: '录入时间'
        // },
        //  {
        //   value: 'isOriginal',
        //   label: '是否提供原件'
        // }
      ],
      tableHeaderList: ['expirationTime','acRecharge','detailedStatus','departmentContractNumber', 'signingTime', 'endTime', 'projectName', 'price', 'demandingSide', 'demandingSideVpn', 'demandingSideAc', 'supplier', 'operatorUser', 'deptName', 'accountingAbstract', 'accountingTime', 'documentNumber', 'deliveryLocation', 'deviceName', 'resourceRemarks', 'deviceNumber', 'paymentCompany', 'annexList', 'remarks', 'accountingClass', 'createAt', 'isOriginal', 'inventoryNumber'],
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: false,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/cs/csIncomeDetails/importCsIncomeDetails"
      },
      isShowfu: false

    };
  },
  // watch: {
  //   tableHeaderList: {
  //     handler(newVal, oldVal) {
  //       console.log(newVal, oldVal);

  //     },
  //     deep: true
  //   }
  // },
  created() {
    this.getList();
  },
  mounted() {
    // document.addEventListener(
    //   "click",
    //   (e) => {
    //     let showSearch = this.$refs.showSearch;
    //     if (!showSearch.contains(e.target)) {
    //       this.showSearch = false;
    //     }
    //   },
    //   true
    // );
    this.tableHeaderList = localStorage.getItem('revenueDetail') ? localStorage.getItem('revenueDetail').split(',') : this.tableHeaderList
  },
  methods: {
    viewFile(e) {
      window.open(e.annexUrl, '_blank');
    },

    lookannex(row) {
      const incomeDetailsId = row.incomeDetailsId || this.ids
      getCsIncomeDetails(incomeDetailsId).then(response => {
        console.log(response);
        this.form = response.data;
        this.form.fileList = []
        // response.data.annexList.forEach(v => {
        //   console.log(v);

        //   this.form.fileList.push({
        //     name: v.annexName,
        //     fileSize: v.annexSize,
        //     url: v.annexUrl,
        //     delFlag: v.delFlag
        //   })
        // })
        this.form.annexList = response.data.annexList
        this.isShowfu = true
      });
    },
    changeSelect(e, t) {
      localStorage.setItem('revenueDetail', e)
    },
    /** 查询收入明细列表 */
    getList() {
      this.loading = true;
      if (null != this.queryParams.dateRange && '' != this.queryParams.dateRange) {
        this.queryParams["beginCreateAt"] = this.queryParams.dateRange[0];
        this.queryParams["endCreateAt"] = this.queryParams.dateRange[1];
      }
      listCsIncomeDetails(this.queryParams).then(response => {
        this.csIncomeDetailsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleSearch() {
      this.showSearch = !this.showSearch
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        incomeDetailsId: null,
        keyword: '',
        resId: null,
        resName: null,
        resType: null,
        resourceClassId: null,
        resourceClass: null,
        projectName: null,
        paymentPerson: null,
        paymentCompany: null,
        annexList: null,
        accountInfo: null,
        accountingAbstract: null,
        accountingTime: null,
        price: null,
        documentNumber: null,
        deliveryLocation: null,
        deviceName: null,
        resourceRemarks: null,
        deviceNumber: null,
        accountingClassId: null,
        accountingClass: null,
        operatorUser: null,
        deptId: null,
        deptName: null,
        remarks: null,
        content: null,
        status: "0",
        sort: null,
        createAt: null,
        updateAt: null,
        delFlag: null,
        fileList: []
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.showSearch = false
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        keyword: '',
        projectName: null,
        paymentPerson: null,
        paymentCompany: null,
        deptId: null,
        accountInfo: null,
        operatorUser: null,
        deptName: null,
        accountingTime: null,
        price: null,
        documentNumber: null,
        deviceName: null,
        deviceNumber: null,
        accountingClassId: null,
        dateRange: []
      }
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.incomeDetailsId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加收入明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      console.log(row.incomeDetailsId, this.ids);

      const incomeDetailsId = row.incomeDetailsId || this.ids
      getCsIncomeDetails(incomeDetailsId).then(response => {
        console.log(response);
        this.form = response.data;
        this.form.fileList = []
        response.data.annexList.forEach(v => {
          console.log(v);

          this.form.fileList.push({
            name: v.annexName,
            fileSize: v.annexSize,
            url: v.annexUrl,
            delFlag: v.delFlag
          })
        })
        this.form.annexList = response.data.annexList
        this.open = true;
        this.title = "修改收入明细";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // let annexList = this.form.annexList
          // let imgs = []
          // annexList.map(item => {
          //   console.log(item);

          //   imgs.push(item.url)
          // })
          // this.form.annexList = imgs
          if (this.form.incomeDetailsId != null) {
            updateCsIncomeDetails(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCsIncomeDetails(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const incomeDetailsIds = row.incomeDetailsId || this.ids;
      this.$modal.confirm('是否确认删除收入明细编号为"' + incomeDetailsIds + '"的数据项？').then(function () {
        return delCsIncomeDetails(incomeDetailsIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('cs/csIncomeDetails/export', {
        ...this.queryParams
      }, `收入明细_${new Date().getTime()}.xlsx`)
    },
    handleExportTemplate() {
      this.download('/cs/csIncomeDetails/exportTemplate', {
        ...this.queryParams
      }, `收入明细模板_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    handleChange(file, fileList) {
      if (file.status == 'success') {
        console.log(file, fileList)
        this.form.fileList = fileList
        let small = {
          sort: fileList.length,
          annexName: file.name,
          annexFormat: file.name.split('.')[1],
          annexSize: ((file.size / 1000 / 1024).toFixed(2)) + 'M',
          annexUrl: file.response.url
        }
        console.log(small);

        this.form.annexList.push(small)
      }
    },
    // handleMove(file, fileList) {
    //   this.form.annexList = fileList
    // },
    handlePreview(file) {
      console.log(file)
      let str = file.url.split('.')
      if (str[str.length - 1] == 'pdf' || str[str.length - 1] == 'doc' || str[str.length - 1] == 'docx'
        || str[str.length - 1] == 'xls' || str[str.length - 1] == 'xlsx' || str[str.length - 1] == 'text') {
        console.log(file.url);

        window.open('https://view.officeapps.live.com/op/view.aspx?src=' + file.url)
      } else {
        window.open(file.url)
      }
    },

    handleMove({ annexUrl, sort }) {
      if (this.applyId) {
        this.form.annexList = this.form.annexList.map(v => {
          if (v.url == annexUrl) {
            v.delFlag = '1'
          }
          return v
        })
      } else {
        this.form.annexList.splice(sort, 1)
      }
      this.form.fileList = this.form.fileList.filter(v => {
        if (v.response) {
          return v.response.url != annexUrl
        } else {
          return v.url != annexUrl
        }
      })
      console.log(this.form.fileList)
    },
  }
};
</script>


<style scoped>
::v-deep .dialog1 {
  background-color: #F8F8F8;
}

.searchForm {
  width: 650px;
  padding: 20px;
  position: absolute;
  left: 200px;
  z-index: 100;
  background-color: #FFFFFF;
  border: 1px solid #777777;
}
</style>
