<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="5" :lg="7" :md="8" :sm="24">
              <a-form-item label="时间">
                <a-range-picker
                    style="width: 100% !important"
                    v-model="DateTime"
                    :allowClear = 'false'
                    format="YYYY-MM"
                    :mode="mode2"
                    :open="open"
                    :placeholder="['开始时间', '结束时间']"
                    @panelChange="handlePanelChange2"
                    @openChange="onDateChange"
                    @change="changeData"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="5" :lg="7" :md="8" :sm="24">
              <a-form-item label="公司">
                <a-select  v-model="queryParam.orgName">
                    <a-select-option value="">所有</a-select-option>
                    <a-select-option value="正织">正织</a-select-option>
                    <a-select-option value="森语">森语</a-select-option>
                    <a-select-option value="马菲羊">马菲羊</a-select-option>
                  </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="5" :lg="7" :md="8" :sm="24">
              <a-form-item label="部门">
                <j-search-select-tag v-model="queryParam.sysOrgCode" placeholder="请选择部门" 
                     dict="sys_depart,depart_name,depart_name,org_type='3' or org_code='TBD' order by org_code"/>
              </a-form-item>
            </a-col>
            <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="姓名">
                <j-search-select-tag v-model="queryParam.name" placeholder="请选择名称" 
                     dict="sys_user,realname,realname" allowClear/>
              </a-form-item>
            </a-col>
            <a-col :xl="5" :lg="7" :md="8" :sm="24">
              <a-form-item label="雇佣状态">
                <a-select  v-model="queryParam.syHireType" mode="multiple">
                    <a-select-option value="">所有</a-select-option>
                    <a-select-option value="在职">在职</a-select-option>
                    <a-select-option value="离职">离职</a-select-option>
                    <a-select-option value="退休返聘">退休返聘</a-select-option>
                    <a-select-option value="运维">运维</a-select-option>
                  </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :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>
              </span>
            </a-col>
  
          </a-row>
        </a-form>
      </div>
  
      <!-- 操作按钮区域 -->

  
        <a-table
          ref="tableRef"
          size="middle"
          bordered
          rowKey="userId"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :scroll="{x: 2000}"
          :loading="loading"
          :footer="showTotal"
          @change="handleTableChange">
        </a-table>
      </div>
      <!-- table区域-end -->
  
      <!-- 表单区域 -->
    </a-card>
  </template>
  
  <script>
  
    import { JeecgListMixin } from '@/mixins/JeecgListMixin'
    import { getAction } from '@/api/manage'
    import moment from 'moment'
    import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
    export default {
      name: "SalarysStatistics",
      mixins: [JeecgListMixin],
      components: {
        moment,
        JSearchSelectTag
      },
      data () {
        return {
          description: '薪资统计',
          DateTime:[moment().subtract(1, 'months'),moment().subtract(1, 'months'),],
          mode2: ['month', 'month'],
          open:false,
          // 表头
          columns: [
            {
              title: '序号',
              width: 80,
              align:"center",
              dataIndex: 'code',
              customRender:function (text, record, index) {
                if(record.name=='合计'){
                  return ''
                }else{
                  return parseInt(index)+1;
                }              
              },
              fixed:'left'
            },
            {
              title: '姓名',
              align:"center",
              dataIndex: 'name',
              width: 100,
              fixed:'left'
            },
            {
              title: '基本薪资',
              align:"center",
              dataIndex: 'beforeAdjustment',
            },
            {
              title: '话费补贴',
              align:"center",
              dataIndex: 'phoneBill'
            },
            {
              title: '午餐补贴',
              align:"center",
              dataIndex: 'lunch'
            },
            {
              title: '住房补贴',
              align:"center",
              dataIndex: 'housingSubsidies',
            },
            {
              title: '全勤奖',
              align:"center",
              dataIndex: 'fullAttendance'
            },
            {
              title: '加班工资',
              align:"center",
              dataIndex: 'overtimePay'
            },
            {
              title: '年休工资',
              align:"center",
              dataIndex: 'yearSalary'
            },
            {
              title: '合计应发',
              align:"center",
              dataIndex: 'totalPayable'
            },
            {
              title: '社保',
              align:"center",
              dataIndex: 'socialSecurity'
            },
            {
              title: '公积金',
              align:"center",
              dataIndex: 'accumulationFund'
            },
            {
              title: '个税',
              align:"center",
              dataIndex: 'personalTax'
            },
            {
              title: '迟到',
              align:"center",
              dataIndex: 'latenessCost'
            },
            {
              title: '事假',
              align:"center",
              dataIndex: 'personalCost'
            },
            {
              title: '病假',
              align:"center",
              dataIndex: 'sickCost'
            },
            {
              title: '婚假',
              align:"center",
              dataIndex: 'marriageCost'
            },
            {
              title: '丧假',
              align:"center",
              dataIndex: 'funeralCost'
            },
            {
              title: '合计应扣',
              align:"center",
              dataIndex: 'totalDeduction'
            },
            {
              title: '实发合计',
              align:"center",
              dataIndex: 'actualOccurrence',
              width: 120,
              fixed:'right'
            },
          ],
          ipagination:{},
          queryParam:{
            beginDate:moment().subtract(1, 'months').format('YYYY-MM'),
            endDate:moment().subtract(1, 'months').format('YYYY-MM'),
            syHireType:['在职','退休反聘']
          },
          dataSource:[{}],
          // 请求参数
        //   url: {

        //      },
          }
        },
        watch:{
            dataSource(){
                this.$nextTick(()=>{  
                    const dom = this.$refs.tableRef.$el.getElementsByClassName('ant-table-body')[0];
                    dom.addEventListener(
                        'scroll',
                        () => {
                             this.$refs.tableInfo.$el.querySelectorAll(
                             '.ant-table-body'
                            )[0].scrollLeft = dom.scrollLeft
                        },
                        true
                    )
                 })
            }
        },
        computed: {
                // 合计展示
            totalDataSource(){
                // 开票成本-衬衣 合计
                 var item = {
                     "name":"合计"
                 };
                var allNumber = 0
                for (let row of this.dataSource){
                    allNumber += row.actualOccurrence*1;
                }
      
                item.actualOccurrence= parseFloat(allNumber.toFixed(2));
                return [item];

            }
        },
      created () {
        this.getTableList()
      },
      methods: {
        getTableList(){
          var param = Object.assign({}, this.queryParam)
          param.syHireType = (param.syHireType).toString()
          getAction('/salary/salaryManagement/querySalaryTotalList',param).then(res=>{
            if(res.success){
                this.dataSource =res.result.records
                this.ipagination = {
                  total: res.result.total,
                  current: res.result.current,
                  pageSize: res.result.size
                }
            }else{
                this.$message.error(res.message);
            }
          })
        },
        changeData(value){
            this.DateTime = value
        },
        onDateChange(status) {
            if(status){
                this.open = true;
            }else{
                this.open = false
            }
        },
        handlePanelChange2(value,mode){
            if (this.DateTime[1] && this.DateTime[1]._d != value[1]._d) {
                this.open = false;
            }
            this.DateTime = value
            this.queryParam.beginDate = this.DateTime[0]&&this.DateTime[0]!==''?moment(this.DateTime[0]).format('YYYY-MM'):''
            this.queryParam.endDate = this.DateTime[1]&&this.DateTime[1]!==''?moment(this.DateTime[1]).format('YYYY-MM'):''
            this.mode2 = [mode[0] === 'date' ? 'month' : mode[0], mode[1] === 'date' ? 'month' : mode[1]];
        },
        searchQuery(){
          this.queryParam.pageNo = 1
          this.getTableList()
        },
        searchReset(){
          this.queryParam={
            beginDate:moment().subtract(1, 'months').format('YYYY-MM'),
            endDate:moment().subtract(1, 'months').format('YYYY-MM'),
            syHireType:['在职','退休反聘']
          }
          this.getTableList()
        },
        handleTableChange(pagination, filters, sorter) {
            this.queryParam.pageNo = pagination.current
            this.queryParam.pageSize = pagination.pageSize
            this.getTableList()
        },
        showTotal(data) {
                return (
                    <a-table
                        ref="tableInfo"
                        pagination={false}
                        columns={this.columns}
                        dataSource={this.totalDataSource || []}
                        showHeader={false}
                        scroll={{x:2000 }}
                    ></a-table>
                )
            },
      }
    }
  </script>
  <style scoped lang="less">
    // @import '~@assets/less/common.less';
    /deep/ .ant-table-footer .ant-table-body {
        overflow: hidden !important;
    }
    /deep/.ant-table-footer{
        padding:0 !important;
        overflow: hidden !important;
    }
    /deep/.ant-table-fixed-left{
        min-width:180px !important
    }
    /deep/.ant-table-bordered .ant-table-thead > tr > th{
      min-width: 120px !important;
    }
    /deep/ .ant-table-bordered .ant-table-tbody > tr > td{
      min-width: 120px !important;
    }
  </style>