<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="任务号">
              <a-input placeholder="请输入任务号" v-model="queryParam.taskno"></a-input>
            </a-form-item>
          </a-col>
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="任务名称">
              <a-input placeholder="请输入任务名称" v-model="queryParam.taskname"></a-input>
            </a-form-item>
          </a-col> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目进度">
              <a-input placeholder="请输入项目进度" v-model="queryParam.processpercent"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="型号">
                <a-input placeholder="请输入型号" v-model="queryParam.xhname"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="阶段">
                <a-input placeholder="请输入阶段" v-model="queryParam.yzjdname"></a-input>
              </a-form-item>
            </a-col> -->
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="计划完成时间">
                <j-date placeholder="请选择计划完成时间" v-model="queryParam.jhwcsj"></j-date>
              </a-form-item>
            </a-col> -->
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="任务类型">
                <a-input placeholder="请输入任务类型" v-model="queryParam.tasktype"></a-input>
              </a-form-item>
            </a-col> -->
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="审计审价">
                <a-input placeholder="请输入审计审价" v-model="queryParam.auditprice"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="任务状态">
                <a-input placeholder="请输入任务状态" v-model="queryParam.iflag"></a-input>
              </a-form-item>
            </a-col> -->
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="项目进度">
                <a-input placeholder="请输入项目进度" v-model="queryParam.processpercent"></a-input>
              </a-form-item>
            </a-col> -->
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="成本进度">
                <a-input placeholder="请输入成本进度" v-model="queryParam.costPercent"></a-input>
              </a-form-item>
            </a-col> -->
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="业务员">
                <a-input placeholder="请输入业务员" v-model="queryParam.businessman"></a-input>
              </a-form-item>
            </a-col> -->
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="下达部门id">
                <a-input placeholder="请输入下达部门id" v-model="queryParam.jycsid"></a-input>
              </a-form-item>
            </a-col> -->
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="下达部门">
                <a-input placeholder="请输入下达部门" v-model="queryParam.jycs"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="责任部门">
                <a-input placeholder="请输入责任部门" v-model="queryParam.zrbm"></a-input>
              </a-form-item>
            </a-col>
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="批产任务号">
                <a-input placeholder="请输入批产任务号" v-model="queryParam.pccode"></a-input>
              </a-form-item>
            </a-col> -->
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="备产任务号">
                <a-input placeholder="请输入备产任务号" v-model="queryParam.bccode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="备料任务号">
                <a-input placeholder="请输入备料任务号" v-model="queryParam.blcode"></a-input>
              </a-form-item>
            </a-col> -->
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> -->
      <a-button @click="handleExpand" type="primary" icon="column-height">折叠/展开</a-button>
      <a-button @click="handleAdd" type="primary" icon="plus">导入</a-button>
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('项目成本')">导出</a-button> -->
      <!-- <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-button @click="batchDuiBi" :disabled="chooseStatus"><a-icon type="shrink" />对比</a-button>
      <!-- <a-dropdown v-if="selectedRowKeys.length > 0"> -->
        <!-- <a-menu slot="overlay"> -->
          <!-- <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>对比</a-menu-item> -->
          <!-- <a-menu-item key="1" @click="batchDuiBi"><a-icon type="shrink" />对比</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button> -->
      <!-- </a-dropdown> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>

        <span style="float:right;">
          <a @click="loadData()"><a-icon type="sync" />刷新</a>
          <a-divider type="vertical" />
          <a-popover title="自定义列" trigger="click" placement="leftBottom">
            <template slot="content">
              <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
                <a-row style="width: 400px">
                  <template v-for="(item, index) in defColumns">
                    <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                        <a-col :span="12" :key="index">
                          <a-checkbox :value="item.dataIndex" :disabled="!!item.fixed" :checked="!!item.fixed">
                            {{ item.title }}</a-checkbox>
                        </a-col>
                    </template>
                  </template>
                </a-row>
              </a-checkbox-group>
            </template>
            <a><a-icon type="setting" />自定义列</a>
          </a-popover>
        </span>
      </div>
 
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :expandedRowKeys="expandedRowKeys"
        @expand="onExpand"
        @mousedown.native="mouseDownHandler"
        @mouseup.native="mouseUpHandler"
        @mousemove.native="mouseMoveHandler"
        :rowSelection="{
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChange,
          onSelect: onSelect,
          getCheckboxProps: (record) => ({
            props: {
              //disabled: record.id == 'amount', // 禁选的条件为：合计行不可选
              disabled: record.id == 'amount' ||
              (record.ji== '1' && chooseRowType == 'huiji') ||
              (record.ji== '2' && chooseRowType == 'chengben')
            },
          }),}"
        @change="handleTableChange"
        :indentSize="12">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <div slot="filterDropdown">
          <a-card>
            <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
              <a-row style="width: 400px">
                <template v-for="(item, index) in defColumns">
                  <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                    <a-col :span="12" :key="index"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                  </template>
                </template>
              </a-row>
            </a-checkbox-group>
          </a-card>
        </div>
        <a-icon slot="filterIcon" type='setting' :style="{ fontSize:'16px',color:  '#108ee9' }" />

        <span slot="contractfpe" slot-scope="text, record">
          <!-- <a-button type="link">{{text}}</a-button> -->
          <a-button type="link" @click.native="detailClick(text,record,'contractfpe','合同额')" :style="{color: (record.children || record.id === 'amount') ? 'rgba(0,0,0,.65)' : ''}">{{(Number(text)/10000).toFixed(2)}}</a-button>
        </span>
        <span slot="taskmoney" slot-scope="text, record">
          <a-button type="link" @click="detailClick(text,record,'taskmoney','已收款')" :style="{color: (record.children || record.id === 'amount') ? 'rgba(0,0,0,.65)' : ''}">{{(Number(text)/10000).toFixed(2)}}</a-button>
        </span>
        <span slot="clf" slot-scope="text, record">
          <a-button type="link" @click="detailClick(text,record,'clf','材料费')" :style="{color: (record.children || record.id === 'amount') ? 'rgba(0,0,0,.65)' : ''}">{{(Number(text)/10000).toFixed(2)}}</a-button>
        </span>
        <span slot="zyf" slot-scope="text, record">
          <a-button type="link" @click="detailClick(text,record,'zyf','专用费')" :style="{color: (record.children || record.id === 'amount') ? 'rgba(0,0,0,.65)' : ''}">{{(Number(text)/10000).toFixed(2)}}</a-button>
        </span>
        <span slot="swf" slot-scope="text, record">
          <a-button type="link" @click="detailClick(text,record,'swf','事务费')" :style="{color: (record.children || record.id === 'amount') ? 'rgba(0,0,0,.65)' : ''}">{{(Number(text)/10000).toFixed(2)}}</a-button>
        </span>
        <span slot="wxf" slot-scope="text, record">
          <a-button type="link" @click.native="detailClick(text,record,'wxf','外协费')" :style="{color: (record.children || record.id === 'amount') ? 'rgba(0,0,0,.65)' : ''}">{{(Number(text)/10000).toFixed(2)}}</a-button>
        </span>
        <span slot="zjcb" slot-scope="text, record">
          <a-button type="link" @click="detailClick(text,record,'zjcb','装机成本')" :style="{color: (record.children || record.id === 'amount') ? 'rgba(0,0,0,.65)' : ''}">{{(Number(text)/10000).toFixed(2)}}</a-button>
        </span>
        <span slot="workhour" slot-scope="text, record">
          <a-button type="link" @click="detailClick(text,record,'workhour','工时')" :style="{color: (record.children || record.id === 'amount') ? 'rgba(0,0,0,.65)' : ''}">{{text}}</a-button>
        </span>
        

        <span slot="action" slot-scope="text, record">
          <!-- <a @click="handleEdit(record)">编辑</a> -->
          <a-tooltip v-if="record.id !== 'amount' && record.ji === 1">
            <template slot="title">
              汇集层无预算执行
            </template>
            <span style="color: rgba(0,0,0,.25);">预算执行</span>
          </a-tooltip>
          <a @click="handleXushi(record)" v-if="record.ji === 2">预算执行</a>
          <!-- <a @click="handleXushi(record)" v-if="record.id !== 'amount'" :disabled="record.ji === 1">预算执行</a> -->

          <!-- <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown> -->
        </span>

      </a-table>

    </div>

    <project-detail-modal ref="proCostDetail"></project-detail-modal>

    <j-modal
      :width="1200"
      :visible="duiBi"
      switchFullscreen
      @cancel="handleGb">

      <a-tabs default-active-key="1">
        <a-tab-pane key="1" tab="总体对比">
          <all-list :duibiList="duibiList"></all-list>
        </a-tab-pane>
        <a-tab-pane key="2" tab="材料费对比" force-render>
          <wuliao-list :duibiclList="duibiclList"></wuliao-list>
        </a-tab-pane>
      </a-tabs>

      <template slot="footer">
        <a-button @click="handleGb">关闭</a-button>
      </template>
    </j-modal>

    <!-- 虚实成本对比（堆叠图） -->
    <contrast-modal ref="xushi"></contrast-modal>

    <!-- 导入弹框 -->
    <project-import-list-modal ref="modalForm" @ok="modalFormOk"></project-import-list-modal>
  </a-card>
</template>

<script>
  import Vue from 'vue';
  // import VueDraggableResizable from 'vue-draggable-resizable';
  // Vue.component('vue-draggable-resizable', VueDraggableResizable);

  import { columnsSelect, columnsEdit, proCostYSKdetail, proCostContractdetail, getDbList, getHjList, getDbClList } from '@/api/kzksApi.js'

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ProjectDetailModal from './modulesDetail/ProjectDetailModal'
  import AllList from '../projectContrastList/allList.vue'
  import WuliaoList from '../projectContrastList/wuliaoList.vue'
  import { getAction } from '@/api/manage'
  import ContrastModal from '../projectXushiContrast/contrastModal.vue'
  import ProjectImportListModal from '../projectImportList/modules/ProjectImportListModal.vue'
import { number } from 'echarts';

  export default {
    name: 'ProjectCostList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
        AllList,
        WuliaoList,
        ProjectDetailModal,
        ContrastModal,
        ProjectImportListModal,
    },
    data () {
      return {
        /* 分页参数 */
        ipagination:{
          current: 1,
          pageSize: 11, // 设置a-table调用时加上筛选行
          pageSizeOptions: ['11', '21', '31'],
          showTotal: (total, range) => {
            // console.log(total, range, this.ipagination.current)
            var current = this.ipagination.current
            if(this.showListTotal){
              return (range[0] - current + 1) + "-" + (range[1] - current) + " 共" + this.showListTotal + "条"
            } else {
              return range[0] + "-" + range[1] + " 共" + total + "条"
            }
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
          // 显示时减去筛选行
          buildOptionText: (size) => {
            return new Number(size.value) - 1 + '条/页'
          }
        },
        // 用来前端显示出去筛选行的total
        showListTotal: 0,
        description: '项目成本管理页面',
        // 一键折叠/展开
        expandedRowKeys: [],
        // 是否全部展开
        isExpanded: false,
        // 获取对比级
        chooseRowType: undefined,
        // 对比状态
        chooseStatus: true,
        // 获取到的对比数据
        duibiList: [],
        // 获取到的材料费对比数据
        duibiclList: [],
        // 对比弹框是否显示
        duiBi: false,
        // 表头：当前显示的列，初始为全部
        columns: [],
        //列设置：多选弹窗显示的
        settingColumns:[],
        //列定义：所有列
        defColumns: [
          // {
          //   title: '#',
          //   dataIndex: '',
          //   key:'rowIndex',
          //   width:60,
          //   align:"center",
          //   customRender:function (t,r,index) {
          //     return parseInt(index)+1;
          //   }
          // },
          {
            title:'任务号',
            fixed:"left",
            dataIndex: 'taskno',
            width: 140,
            customHeaderCell:() => ({
              style: {
                textAlign: 'center', // 表头居中
              }
            })
          },
          {
            title:'任务名称',
            align:"center",
            fixed:"left",
            width: 120,
            dataIndex: 'taskname'
          },
          {
            title:'型号',
            align:"center",
            dataIndex: 'xhname'
          },
          {
            title:'计划完成时间',
            align:"center",
            dataIndex: 'jhwcsj',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'阶段',
            align:"center",
            dataIndex: 'yzjdname'
          },
          {
            title:'项目进度',
            align:"center",
            dataIndex: 'processpercent',
            customRender: (text, record) => {
              return record.id === 'amount'?null:parseInt(text)+ '%'
            },
          },
          {
            title:'成本进度',
            align:"center",
            dataIndex: 'costPercent',
            customRender: (text, record) => {
              return record.id === 'amount'?null:(Number(text)).toFixed(1) + '%'
            },
          },
          {
            title:'研制数量',
            align:"center",
            dataIndex: 'yzsl'
          },
          {
            title:'单台收入',
            align:"center",
            dataIndex: 'oneIncome',
            customRender: (text, record) => {
              return record.id === 'amount'?null:(Number(text)/10000).toFixed(2)
            },
          },
          {
            title:'单台成本',
            align:"center",
            dataIndex: 'oneCost',
            customRender: (text, record) => {
              return record.id === 'amount'?null:(Number(text)/10000).toFixed(2)
            },
          },
          {
            title:'单台利润',
            align:"center",
            dataIndex: 'oneProfit',
            customRender: (text, record) => {
              return record.id === 'amount'?null:(Number(text)/10000).toFixed(2)
            },
          },
          {
            title:'利润额',
            align:"center",
            dataIndex: 'lre',
            customRender: (text) => {
              return (Number(text)/10000).toFixed(2)
            },
          },
          {
            title:'合同额',
            align:"center",
            dataIndex: 'contractfpe',
            scopedSlots: {
              customRender: 'contractfpe',
            },
            // customCell: this.getClickColumn,
          },
          {
            title:'预估价',
            align:"center",
            dataIndex: 'estimationcoat',
            customRender: (text) => {
              return Number(text).toFixed(2)
            },
          },
          {
            title:'利润率',
            align:"center",
            dataIndex: 'lrl',
            customRender: (text) => {
              return Number(text).toFixed(1) + '%'
            },
          },
          {
            title:'已收款',
            align:"center",
            dataIndex: 'taskmoney',
            scopedSlots: {
              customRender: 'taskmoney',
            },
            // customCell: this.getClickColumn,
          },
          {
            title:'总成本',
            align:"center",
            dataIndex: 'zcb',
            customRender: (text) => {
              return (Number(text)/10000).toFixed(2)
            },
          },
          {
            title:'材料预算',
            align:"center",
            dataIndex: 'clys',
            customRender: (text) => {
              return Number(text).toFixed(2)
            },
          },
          {
            title:'材料费',
            align:"center",
            dataIndex: 'clf',
            scopedSlots: {
              customRender: 'clf',
            },
            // customCell: this.getClickColumn,
          },
          {
            title:'专用费',
            align:"center",
            dataIndex: 'zyf',
            scopedSlots: {
              customRender: 'zyf',
            },
            // customCell: this.getClickColumn,
          },
          {
            title:'事务费',
            align:"center",
            dataIndex: 'swf',
            scopedSlots: {
              customRender: 'swf',
            },
            // customCell: this.getClickColumn,
          },
          {
            title:'外协预算',
            align:"center",
            dataIndex: 'wxys',
            customRender: (text) => {
              return Number(text).toFixed(2)
            },
          },
          {
            title:'外协费',
            align:"center",
            dataIndex: 'wxf',
            scopedSlots: {
              customRender: 'wxf',
            },
            // customCell: this.getClickColumn,
          },
          {
            title:'燃动费',
            align:"center",
            dataIndex: 'rldlf',
            customRender: (text) => {
              return (Number(text)/10000).toFixed(2)
            },
          },
          {
            title:'固资费',
            align:"center",
            dataIndex: 'gdzczj',
            customRender: (text) => {
              return (Number(text)/10000).toFixed(2)
            },
          },
          {
            title:'工资费',
            align:"center",
            dataIndex: 'gzjlwf',
            customRender: (text) => {
              return (Number(text)/10000).toFixed(2)
            },
          },
          {
            title:'管理费',
            align:"center",
            dataIndex: 'glf',
            customRender: (text) => {
              return (Number(text)/10000).toFixed(2)
            },
          },
          {
            title:'装机成本',
            align:"center",
            dataIndex: 'zjcb',
            scopedSlots: {
              customRender: 'zjcb',
            },
            // customCell: this.getClickColumn,
          },
          {
            title:'内部试验',
            align:"center",
            dataIndex: 'lbsy'
          },
          {
            title:'工时(h)',
            align:"center",
            dataIndex: 'workhour',
            scopedSlots: {
              customRender: 'workhour',
            },
            // customCell: this.getClickColumn,
          },
          {
            title:'责任部门',
            align:"center",
            dataIndex: 'zrbm'
          },
          // {
          //   title:'下达部门id',
          //   align:"center",
          //   dataIndex: 'jycsid'
          // },
          {
            title:'下达部门',
            align:"center",
            dataIndex: 'jycs'
          },
          // {
          //   title:'1：横向 2：纵向',
          //   align:"center",
          //   dataIndex: 'hxzxid'
          // },
          {
            title:'横向纵向',
            align:"center",
            dataIndex: 'hxzxname'
          },
          {
            title:'任务类型',
            align:"center",
            dataIndex: 'tasktype'
          },
          {
            title:'审计审价',
            align:"center",
            dataIndex: 'auditprice'
          },
          {
            title:'任务状态',
            align:"center",
            dataIndex: 'iflag'
          },
          {
            title:'提出单位简称',
            align:"center",
            dataIndex: 'brief'
          },
          {
            title:'父级任务',
            align:"center",
            dataIndex: 'reftaskno'
          },
          {
            title:'批产任务号',
            align:"center",
            dataIndex: 'pccode'
          },
          {
            title:'备产任务号',
            align:"center",
            dataIndex: 'bccode'
          },
          {
            title:'备料任务号',
            align:"center",
            dataIndex: 'blcode'
          },
          {
            title:'业务员',
            align:"center",
            dataIndex: 'businessman'
          },
          {
            title:'设计工时',
            align:"center",
            dataIndex: 'sjgs'
          },
          {
            title:'生产工时',
            align:"center",
            dataIndex: 'scgs'
          },
          // {
          //   title:'级别',
          //   align:"center",
          //   dataIndex: 'ji',
          //   customCell: this.getClickColumn,
          // },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width: 100,
            scopedSlots: {
              // filterDropdown: 'filterDropdown',
              // filterIcon: 'filterIcon',
              customRender: 'action',
            }
          }
        ],

        url: {
          list: "/projectCostHuiji/projectCostHuiji/list",
          // delete: "/projectCost/projectCost/delete",
          // deleteBatch: "/projectCost/projectCost/deleteBatch",
          exportXlsUrl: "/projectCostHuiji/projectCostHuiji/exportXls",
          importExcelUrl: "projectCost/projectCost/importExcel",

        },
        dictOptions:{},
        superFieldList:[],

        // 拖拽
        handlerFirstTime: null,
        isClick: false,
        mouseFlag: false,
        mouseOffset: null,
      }
    },
    created() {
      this.loadData()
      this.initColumns();
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      // 按下鼠标记录鼠标位置
      mouseDownHandler(e) {
        this.mouseOffset = e.clientX;
        this.handlerFirstTime = new Date().getTime()
        this.mouseFlag = true;
      },
      mouseUpHandler(e) {
        var lastTime = new Date().getTime();
        this.mouseFlag = false;
        if( (lastTime - this.handlerFirstTime) < 100){
          this.isClick = true
        } else {
          this.isClick = false
        }
      },
      mouseMoveHandler(e) {
        // 这里面需要注意，通过ref需要那个那个包含table元素的父元素
        let v=document.getElementsByClassName("ant-table-body")[0]
        if (this.mouseFlag) {
          // 设置水平方向的元素的位置
          v.scrollLeft -= (- this.mouseOffset + (this.mouseOffset = e.clientX));
        }
      },
      loadData(arg) {
        console.log(111)
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams();//查询条件
        console.log(params)
        // 查询时减去筛选行
        params.pageSize = (Number(params.pageSize) - 1).toString()
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          console.log(res)
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.pageList.records||res.result.pageList;
            var amount = res.result.projectCostHuijiSum
            amount.taskno = '筛选合计：'
            amount.id = 'amount'
            // amount.id = 'amount'+res.result.pageList.current
            this.dataSource.unshift(amount)
            if(res.result.pageList.total)
            {
              // 解决页数显示不对的问题：因为a-table当前默认是加上筛选行的，合计时几页就加上几
              // 例如：当前total后端返回32，一页10个应该是4页，但是a-table调用的是一页11个，所以32/11 会显示3页
              this.ipagination.total = res.result.pageList.total + res.result.pageList.pages;
              // 设置显示的total数
              this.showListTotal = res.result.pageList.total
            }else{
              this.ipagination.total = 0;
            }
            console.log(this.dataSource)
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          }else{
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },
      initDictConfig(){
      },
      initColumns(){
        //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
        // this.defColumns = colAuthFilter(this.defColumns,'testdemo:');
        columnsSelect().then(res => {
          let colSettings = res
          if(colSettings==null||colSettings==undefined || colSettings.length === 0){
            let allSettingColumns = [];
            this.defColumns.forEach(function (item,i,array ) {
              allSettingColumns.push(item.dataIndex);
            })
            this.settingColumns = allSettingColumns;
            this.columns = this.defColumns;
          }else{
            this.settingColumns = colSettings;
            const cols = this.defColumns.filter(item => {
              if(item.key =='rowIndex'|| item.dataIndex=='action'){
                return true;
              }
              if (colSettings.includes(item.dataIndex)) {
                return true;
              }
              return false;
            })
            this.columns =  cols;
          }
        })
        // 储存浏览器方式
        // var key = this.$route.name+":colsettings";
        // let colSettings= Vue.ls.get(key);
      },
      //列设置更改事件
      onColSettingsChange (checkedValues) {
        console.log(checkedValues)
        // 获取浏览器方式
        // var key = this.$route.name+":colsettings";
        // Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
        this.settingColumns = checkedValues;
        const cols = this.defColumns.filter(item => {
          if(item.key =='rowIndex'|| item.dataIndex=='action'){
            return true
          }
          if (this.settingColumns.includes(item.dataIndex)) {
            return true
          }
          return false
        })
        this.columns = cols;
        columnsEdit({checkedValues: checkedValues})
      },
      detailClick(text, record, columnValue, columnTitle){
        if(!this.isClick){
          return
        }
        console.log(text, record, columnValue, columnTitle)
        // 没有值不弹窗
        if(!text || record.children || record.id === 'amount'){
          return
        }
        this.$refs.proCostDetail.taskno = record.taskno
        if(record.status === '1'){
          // 批产参数
          this.$refs.proCostDetail.pichanInfo = {
            pccode: record.pccode,
            proportion: record.proportion,
            columnValue: columnValue,
          }
          this.$refs.proCostDetail.columnValue = 'pichanTask'
          this.$refs.proCostDetail.title = columnTitle + '批产明细'
        } else {
          this.$refs.proCostDetail.columnValue = columnValue
          this.$refs.proCostDetail.title =  columnTitle + '明细'
        }
        this.$refs.proCostDetail.show()
      },
      getClickColumn(record, index){
        if(record.children || record.id === 'amount'){
          return false
        }
        return {
          style: {
            'color': '#1890ff',
            'cursor': 'pointer',
          },
          on: {
            click: (event)=> {
              // 没有值不弹窗
              if(!event.target.textContent){
                return
              }
              // console.log(record, index, event, event.target.cellIndex)
              // console.log(this.columns[event.target.cellIndex - 1])
              var clickColumn = this.columns[event.target.cellIndex - 1].dataIndex
              var title = this.columns[event.target.cellIndex - 1].title
              this.$refs.proCostDetail.taskno = record.taskno
              if(record.status === '1'){
                // 批产参数
                this.$refs.proCostDetail.pichanInfo = {
                  pccode: record.pccode,
                  proportion: record.proportion,
                  columnValue: clickColumn,
                }
                this.$refs.proCostDetail.columnValue = 'pichanTask'
                this.$refs.proCostDetail.title = title + '批产明细'
              } else {
                this.$refs.proCostDetail.columnValue = clickColumn
                this.$refs.proCostDetail.title =  title + '明细'
              }
              // console.log(this.$refs.proCostDetail.columnValue)
              this.$refs.proCostDetail.show()
            },
          }
        }
      },
      // 对比
      batchDuiBi(){
        console.log(this.selectedRowKeys,this.selectionRows)
        // console.log(JSON.stringify(this.selectedRowKeys))
        if (this.chooseRowType == 1) {
          var a = this.selectedRowKeys
          var ids = a.toString()
          getHjList({ids: ids}).then((res) => {
            console.log(res)
            this.duibiList = res
            this.duibiclList = []
})
          var selectTasknos = this.selectionRows.map( res => {
            return res.taskno
          })
          var tasknos = selectTasknos.toString()
          console.log(tasknos)
          getDbClList({tasknos: tasknos}).then((res) => {
            console.log(res)
            this.duibiclList = res
            this.duiBi = true
          })
        } else {
          var a = this.selectedRowKeys
          var ids = a.toString()
          getDbList({ids: ids}).then((res) => {
            console.log(res)
            this.duibiList = res
          })
          var selectTasknos = this.selectionRows.map( res => {
            return res.taskno
          })
          var tasknos = selectTasknos.toString()
          console.log(tasknos)
          getDbClList({tasknos: tasknos}).then((res) => {
            console.log(res)
            this.duibiclList = res
            this.duiBi = true
          })
        }
        // var a = this.selectedRowKeys
        // var ids = a.toString()
        // getDbList({ids: ids}).then((res) => {
        //   console.log(res)
        //   this.duibiList = res
        // })
        // var selectTasknos = this.selectionRows.map( res => {
        //   return res.taskno
        // })
        // var tasknos = selectTasknos.toString()
        // console.log(tasknos)
        // getDbClList({tasknos: tasknos}).then((res) => {
        //   console.log(res)
        //   this.duibiclList = res
        //   this.duiBi = true
        // })
      },
      // 关闭对比弹框
      handleGb(){
        this.duiBi = false
        this.duibiList = []
        this.duibiclList = []
      },
      // 一键折叠展开
      handleExpand(){
        console.log(this.isExpanded)
        if(this.isExpanded){
          // 当前为展开，全部折叠
          this.expandedRowKeys = []
        } else {
          // 当前为折叠，全部展开
          this.expandedRowKeys = this.dataSource.map(res => res.id)
        }
        this.isExpanded = !this.isExpanded
      },
      onExpand (expanded, record) {
        if (expanded) {
          console.log(record.id)
          // 设置展开窗Key，代表展开操作
          this.expandedRowKeys.push(record.id)
        } else {
          // 代表折叠操作
          if (this.expandedRowKeys.length) {
            this.expandedRowKeys = this.expandedRowKeys.filter(v => {
              return v !== record.id
            })
          }
        }
      },
      // 虚实对比（堆叠图）
      handleXushi(record){
        console.log(record)
        this.$refs.xushi.open(record)
      },
      // 对比禁选判断
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
      },
      onSelect(record, selected, selectedRows, nativeEvent){
        console.log(record, selected, selectedRows, nativeEvent)
        if(selected) {
          if (selectedRows.length == 1) {
            this.chooseRowType = record.ji
            this.chooseStatus = true
          } else {
            console.log(this.chooseRowType,record.ji)
            if (this.chooseRowType != record.ji) {
              this.chooseRowType = this.chooseRowType
              this.chooseStatus = true
              this.$message.error("请选择同级项进行对比");
            } else{
              // this.chooseStatus = false
              for (let i = 0; i < selectedRows.length; i++) {
                const element = selectedRows[i].ji;
                console.log(888,this.chooseRowType,element)
                if (this.chooseRowType != element) {
                  this.chooseStatus = true
                } else {
                  this.chooseStatus = false
                }
              }
            }
          }
        } else{
          if (selectedRows.length == 1) {
            console.log(777,this.selectionRows[0].ji)
            this.chooseRowType = this.selectionRows[0].ji
            this.chooseStatus = true
          } else {
            for (let i = 0; i < selectedRows.length; i++) {
              const element = selectedRows[i].ji;
              console.log(888,this.chooseRowType,element)
              if (this.chooseRowType != element) {
                this.chooseStatus = true
                this.$message.error("请选择同级项进行对比");
              } else {
                this.chooseStatus = false
              }
            }
            // 第一版
            // if (this.chooseRowType != record.ji) {
            //   this.chooseRowType = this.chooseRowType
            //   this.chooseStatus = true
            //   this.$message.error("请选择同级项进行对比");
            // }else{
            //   // this.chooseStatus = false
            //   for (let i = 0; i < selectedRows.length; i++) {
            //     const element = selectedRows[i].ji;
            //     console.log(888,this.chooseRowType,element)
            //     if (this.chooseRowType != element) {
            //       this.chooseStatus = true
            //     } else {
            //       this.chooseStatus = false
            //     }
            //   }
            // }
          }
        }
        // console.log(record.ji)
        // if (record.ji == '2') {
        //   // 选中二级，一级禁选
        //   this.chooseRowType == 'chengben'
        // } else {
        //   // 选中一级，二级禁选
        //   this.chooseRowType == 'huiji'
        // }
      },

      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'taskno',text:'任务号',dictCode:''})
        fieldList.push({type:'string',value:'taskname',text:'任务名称',dictCode:''})
        fieldList.push({type:'string',value:'xhname',text:'型号',dictCode:''})
        fieldList.push({type:'date',value:'jhwcsj',text:'计划完成时间'})
        fieldList.push({type:'string',value:'yzjdname',text:'阶段',dictCode:''})
        fieldList.push({type:'string',value:'processpercent',text:'项目进度',dictCode:''})
        fieldList.push({type:'string',value:'costPercent',text:'成本进度',dictCode:''})
        fieldList.push({type:'int',value:'yzsl',text:'研制数量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'oneIncome',text:'单台收入',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'oneCost',text:'单台成本',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'oneProfit',text:'单台利润',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'lre',text:'利润额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'lrl',text:'利润率',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'estimationcoat',text:'预估价',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'contractfpe',text:'合同额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'taskmoney',text:'已收款',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'zcb',text:'总成本',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'clf',text:'材料费',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'zyf',text:'专用费',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'swf',text:'事务费',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'wxf',text:'外协费',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'rldlf',text:'燃料动力费',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'gdzczj',text:'固定资产折旧',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'gzjlwf',text:'工资及劳务费',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'glf',text:'管理费',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'zjcb',text:'装机成本',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'lbsy',text:'内部试验',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'workhour',text:'工时(h)',dictCode:''})
        fieldList.push({type:'string',value:'zrbm',text:'责任部门',dictCode:''})
        fieldList.push({type:'int',value:'jycsid',text:'下达部门id',dictCode:''})
        fieldList.push({type:'string',value:'jycs',text:'下达部门',dictCode:''})
        // fieldList.push({type:'int',value:'hxzxid',text:'1：横向 2：纵向/来自科研任务',dictCode:''})
        fieldList.push({type:'string',value:'hxzxname',text:'横向纵向',dictCode:''})
        fieldList.push({type:'string',value:'tasktype',text:'任务类型',dictCode:''})
        fieldList.push({type:'string',value:'auditprice',text:'审计审价',dictCode:''})
        fieldList.push({type:'string',value:'iflag',text:'任务状态',dictCode:''})
        fieldList.push({type:'string',value:'brief',text:'提出单位简称',dictCode:''})
        fieldList.push({type:'int',value:'reftaskno',text:'父级任务',dictCode:''})
        fieldList.push({type:'int',value:'pccode',text:'批产任务号',dictCode:''})
        fieldList.push({type:'int',value:'bccode',text:'备产任务号',dictCode:''})
        fieldList.push({type:'int',value:'blcode',text:'备料任务号',dictCode:''})
        fieldList.push({type:'string',value:'businessman',text:'业务员',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'sjgs',text:'设计工时',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'scgs',text:'生产工时',dictCode:''})
        this.superFieldList = fieldList
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>