<template>
    <div class="reply" ref = "replyModal">
      <a-modal
        title="加班工资单"
        width="85%"
        :visible="visible"
        :confirmLoading="loading"
        :getContainer ='()=>$refs.replyModal'
        @cancel="handleCancel"
        destroyOnClose
       >
            <template #footer>
                <a-button  @click="handleCancel" style="margin-left: 8px;">取消</a-button>
            </template>
            <div class="table-page-search-wrapper">
                <a-form-model layout="inline" ref="form" :model="formState" >
                    <a-row :gutter="24">
                        <a-col :md="6" :sm="8">
                            <a-form-model-item label="姓名"  >
                                <j-search-select-tag v-model="formState.name" placeholder="请选择名称" 
                                    dict="sys_user,realname,realname" allowClear/>
                            </a-form-model-item>
                        </a-col>
                        <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
                            <a-form-item label="部门">
                                <j-search-select-tag v-model="formState.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 :md="6" :sm="8">
                            <a-form-model-item label=""  >
                                <a-button type="primary" icon="search" @click="searchSonList">查询</a-button>
                            </a-form-model-item>
                        </a-col>
                    </a-row>
                </a-form-model>
                <a-table
                    ref="tableRef"
                    bordered
                    :columns="columns"
                    :data-source="dataSource"
                    :loading="loading"
                    :scroll="{x: 1000 ,y:400}"
                    :pagination="false"
                    :footer="showTotal"
                >
                </a-table>
            </div>
      </a-modal>
    </div>
</template>
<script>
    
      import moment from 'moment'
      import pick from 'lodash.pick'
      import { FormTypes } from '@/utils/JEditableTableUtil'
      import { putAction,getAction } from '@/api/manage'
      import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
      import JEllipsis from '@/components/jeecg/JEllipsis'
      export default {
        name: 'OvertimePayroll',
        components: {
            moment,
            JSearchSelectTag,
            JEllipsis
        },
        data() {
          let ellipsis = (v, l) => <j-ellipsis value={v} length={l} />
          return {
              formState:{},
              dataSource: [{}],
              visible:false,
              loading:false,
              columns: [
                {
                    title: '序号',
                    align:"center",
                    width:'5%',
                    dataIndex: 'index',
                    customRender:function (t, record, index) {
                        if(record.name=='合计'){
                            return ''
                        }else{
                            return parseInt(index)+1;
                        } 
                    }
                },
                {
                    title: '姓名',
                    align: "center",
                    dataIndex: 'name',
                    customRender: (t) => ellipsis(t,17),
                    width:'10%'
                },
                // {
                //     title: '编号',
                //     align: "center",
                //     dataIndex: 'code',
                //     customRender: (t) => ellipsis(t,17),
                //     width:'10%'
                // },
                
                {
                    title: '加班工资',
                    align: "center",
                    dataIndex: 'workOvertimeCost',
                    ellipsis: true,
                    width:'10%'
                },
                {
                    title: '个税',
                    align: "center",
                    dataIndex: 'personalTax',
                    ellipsis: true,
                    width:'10%'
                },
                {
                    title: '实发合计',
                    align: "center",
                    dataIndex: 'actualOccurrence',
                    customRender: (t) => ellipsis(t,10),
                    width:'10%'
                },
             ]
          }
        },
        created(){
        },
        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
                var allPersonalTax = 0
                for (let row of this.dataSource){
                    allNumber += row.actualOccurrence*1;
                    allPersonalTax+=row.personalTax*1
                }
      
                item.actualOccurrence= parseFloat(allNumber.toFixed(2));
                item.personalTax =  parseFloat(allPersonalTax.toFixed(2));
                return [item];

            }
        },
        methods: {
            handleCancel(){
                this.visible = false
                this.dataSource=[]
                this.formState={}
            },
            detail(id){
                this.formState = {}
                this.formState.id = id
                this.getTableList()
            },
            getTableList(){
                this.loading = true
                getAction('/salary/salaryManagement/querySalaryManagementWorkOvertimeListByMainId',this.formState).then(res=>{
                    this.loading = false
                    if(res.success){
                        this.dataSource =res.result
                        var all=0
                        this.dataSource.map(item=>{
                            item.actualOccurrence = Number(item.actualOccurrence).toFixed(2)
                        })
                    }else{
                        this.$message.error(res.message);
                    }
                })
            },
            searchSonList(){
                this.getTableList()
            },
            showTotal(data) {
                return (
                    <a-table
                        ref="tableInfo"
                        pagination={false}
                        columns={this.columns}
                        dataSource={this.totalDataSource || []}
                        showHeader={false}
                        scroll={{x:1000 }}
                    ></a-table>
                )
            },
        }
    }
    </script>
    
    <style scoped lang="less">
    /deep/ .nresume .ant-input{
      height: 100px !important;
    }

    /deep/ .ant-select{
      width: 100%;
    }
    .form-table-heard:before {
          content: '*';
          color: red;
    }
    /deep/ .ant-calendar-picker{
      width: 113px !important;
    }
    /deep/ .ant-table-footer .ant-table-body {
        overflow-x: hidden !important;
    }
    /deep/.ant-table-footer{
        padding:0 !important;
        overflow: hidden !important;
    }
    /deep/.ant-table-fixed-left .ant-table-body-inner {
        margin-right: -28px !important;
        padding-right: 20px !important;
    }
    </style>