<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <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-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>
        <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>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <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>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</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-cost-huiji-modal ref="modalForm" @ok="modalFormOk"></project-cost-huiji-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ProjectCostHuijiModal from './modules/ProjectCostHuijiModal'
  import { getAction } from '@/api/manage'

  export default {
    name: 'ProjectCostHuijiList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      ProjectCostHuijiModal
    },
    data () {
      return {
        description: '项目成本汇集表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'任务号/来自科研任务',
            align:"center",
            dataIndex: 'taskno'
          },
          {
            title:'任务名称/来自科研任务',
            align:"center",
            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'
          },
          {
            title:'成本进度',
            align:"center",
            dataIndex: 'costPercent'
          },
          {
            title:'研制数量/来自科研任务',
            align:"center",
            dataIndex: 'yzsl'
          },
          {
            title:'单台收入/（合同额or预估价）/研制数量',
            align:"center",
            dataIndex: 'oneIncome'
          },
          {
            title:'单台成本/  总成本额/研制数量',
            align:"center",
            dataIndex: 'oneCost'
          },
          {
            title:'单台利润/  利润额/研制数量',
            align:"center",
            dataIndex: 'oneProfit'
          },
          {
            title:'利润额/（合同额or预估价）-总成本额',
            align:"center",
            dataIndex: 'lre'
          },
          {
            title:'利润率/ 利润额/（合同额or预估价）*100%',
            align:"center",
            dataIndex: 'lrl'
          },
          {
            title:'预估价/来自财务预算',
            align:"center",
            dataIndex: 'estimationcoat'
          },
          {
            title:'合同额/来自收款合同的合同分配额 ',
            align:"center",
            dataIndex: 'contractfpe'
          },
          {
            title:'已收款/ 来自合同收款详细的任务收款额',
            align:"center",
            dataIndex: 'taskmoney'
          },
          {
            title:'总成本/ 直接成本+间接费用/直接成本=材料费（出库）+外协费+专用费+事务费/间接费用=工资费+管理费+燃动费+固资费',
            align:"center",
            dataIndex: 'zcb'
          },
          {
            title:'材料费/物资出库单明细 实发主数量*采购单价',
            align:"center",
            dataIndex: 'clf'
          },
          {
            title:'专用费',
            align:"center",
            dataIndex: 'zyf'
          },
          {
            title:'事务费',
            align:"center",
            dataIndex: 'swf'
          },
          {
            title:'外协费',
            align:"center",
            dataIndex: 'wxf'
          },
          {
            title:'燃料动力费/（材料费+外协费+事务费+专用费）×1.5%',
            align:"center",
            dataIndex: 'rldlf'
          },
          {
            title:'固定资产折旧/（材料费+外协费+事务费+专用费）×2.5%',
            align:"center",
            dataIndex: 'gdzczj'
          },
          {
            title:'工资及劳务费/（材料费+外协费+事务费+专用费）×17%',
            align:"center",
            dataIndex: 'gzjlwf'
          },
          {
            title:'管理费/（材料费+外协费+事务费+专用费）×5%',
            align:"center",
            dataIndex: 'glf'
          },
          {
            title:'装机成本/ mes装机信息卡的采购单价*数量',
            align:"center",
            dataIndex: 'zjcb'
          },
          {
            title:'内部试验',
            align:"center",
            dataIndex: 'lbsy'
          },
          {
            title:'工时(h)/来自科研报工，每次科研报工累加计时',
            align:"center",
            dataIndex: 'workhour'
          },
          {
            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: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/projectCostHuiji/projectCostHuiji/list",
          delete: "/projectCostHuiji/projectCostHuiji/delete",
          deleteBatch: "/projectCostHuiji/projectCostHuiji/deleteBatch",
          exportXlsUrl: "/projectCostHuiji/projectCostHuiji/exportXls",
          importExcelUrl: "projectCostHuiji/projectCostHuiji/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      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();//查询条件
        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)
            {
              this.ipagination.total = 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(){
      },
      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:'单台收入/（合同额or预估价）/研制数量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'oneCost',text:'单台成本/  总成本额/研制数量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'oneProfit',text:'单台利润/  利润额/研制数量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'lre',text:'利润额/（合同额or预估价）-总成本额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'lrl',text:'利润率/ 利润额/（合同额or预估价）*100%',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:'燃料动力费/（材料费+外协费+事务费+专用费）×1.5%',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'gdzczj',text:'固定资产折旧/（材料费+外协费+事务费+专用费）×2.5%',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'gzjlwf',text:'工资及劳务费/（材料费+外协费+事务费+专用费）×17%',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'glf',text:'管理费/（材料费+外协费+事务费+专用费）×5%',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'zjcb',text:'装机成本/ mes装机信息卡的采购单价*数量',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>