<template>
  <d2-container>
<!--   <div v-if="isExpend" class="d2-fl d2-tree-view" >
      <el-tree highlight-current :data="treeData" :default-expanded-keys="['mTop']" node-key="alias" :props="defaultProps" @node-click="handleNodeClick" >
					<span class="icon-tree" slot-scope="{ node, data }">
							<div v-if="data.alias == 'mTop'">
								<i class="fa fa-university"></i>
								<span>&nbsp;{{node.label}}</span>
							</div>
							<div v-if="data.alias == 'company'">
								<i class="fa fa-building"></i>
								<span>&nbsp;{{node.label}}</span>
							</div>
						<div v-if="data.alias == 'dept'">
						<i class="fa fa-users"></i>
						<span>&nbsp;{{node.label}}</span>
					</div>
					</span>
      </el-tree>
    </div>
   <div @click="isExpend = !isExpend" :class="[{'angle-view':isExpend},{'angle-view-none':!isExpend}]">
   	<i :class="['fa', {'fa-angle-left':isExpend},{'fa-angle-right':!isExpend}]"></i>
   </div>
   <div :class="[{'d2-fl':isExpend},{'d2-table-view':isExpend},{'d2-table-view-full':!isExpend}]" > -->
		  <div class="d2-table-view-full" style="overflow: hidden">
      <div class="d2-table-view-header">
      <el-form size="small" :inline="true" :model="filter" @keyup.enter.native="handleList" class="demo-form-inline">
				<!-- <el-form-item label="发放补贴日期">
					<el-date-picker
									v-model="time"
									type="datetimerange"
									value-format="yyyy-MM-dd HH:mm:ss"
									:default-time="['00:00:00', '23:59:59']"
									@change="dateChange"
									range-separator="至"
									start-placeholder="开始日期"
									end-placeholder="结束日期">
					</el-date-picker>
				</el-form-item> -->
				<el-form-item label="工号/学号" label-width="90px">
				   <el-input v-model="filter.userNo" style="width: 180px;" clearable/>
				 </el-form-item>
				<el-form-item label="卡号">
					<el-input v-model="filter.cardCode" placeholder="卡号" clearable/>
				</el-form-item>
				<el-form-item label="员工姓名">
					<el-input v-model="filter.userNm" placeholder="员工姓名" clearable/>
				</el-form-item>
				<el-form-item label="部门">
				  <department-tree @clearInput="clearDepartment" v-model="filter.depId" :isClear="isClear"/>
				</el-form-item>
        <el-form-item label="补贴类型">
          <custom-select v-model="filter.allowanceKind" :isAll="true" :value="filter.allowanceKind" typeName="补贴类型" clearable />
        </el-form-item>
				<el-form-item label="是否补贴">
				   <el-select v-model="filter.subsidiesStatus" placeholder="请选择">
						 <el-option label="全部" value=""></el-option>
						<el-option 	label="是"	value="1"></el-option>
						<el-option 	label="否"	value="0"></el-option>
					</el-select>
				</el-form-item>
        <el-form-item>
          <el-button   type="primary" @click="handleList('1')">查询</el-button>
        </el-form-item>
      </el-form>
      </div>
      <div class="d2-table-view-content">
      <d2-crud
              title="补贴发放统计列表"
              ref="d2Crud"
              :options="tableOptions"
              :loading="loading"
              :columns="columns"
              :data="data">
      </d2-crud>
      </div>
      <div class="d2-table-view-footer">
      <el-pagination
      				@current-change="handleCurrentChange"
      				@size-change="handleSizeChange"
					    :current-page.sync="currentPage"
      				:page-size="tableOptions.pageList[0]"
      				:page-sizes="tableOptions.pageList"
      				layout="total,sizes, prev, pager, next,jumper"
      				:total="pagination.total">
      </el-pagination>
      </div>
    </div>
  </d2-container>
</template>

<script>
  import { getSubsidiesStatistics} from '../../../api/cost/report'
  import {tableOptions} from '../../../assets/options'
  export default {
    name: 'attendance-giveSubsidyCount',
    data () {
      return {
				func:{
					select:false
				},
				isClear:'123',
				time:'',
				isExpend:true,
        tableOptions,
        loading:false,
        currentPage:1,      
        systemRoles:[],
        filter:{
					userNo:'',
          subsidiesStatus:'',
					allowanceKind:null,
					userNm:'',
					cardCode:'',
          pageSize: 10,
          pageNum:1
        },
        pagination:{
          total: 0
        },
        treeData: [],
        defaultProps: {
          children: 'children',
          label: 'name'
        },
        columns: [
					{
						title: '序号',
						key: 'index',
						minWidth: '50',
						formatter (row, column, cellValue, index) {
							return index+1
						}
					},
          {
            title: '工号/学号',
            key: 'userNo',
            minWidth: '90'
          },
          {
            title: '员工姓名',
            key: 'userNm',
            minWidth: '90'
          },
          {
            title: '部门',
            key: 'depNm',
            minWidth: '90'
          },
          {
            title: '卡号',
            key: 'cardCode',
            minWidth: '90',
            showOverflowTooltip: true
          },
          {
            title: '补贴金额',
            key: 'subsidiesDeposit',
            minWidth: '100',
						align: 'right',
						formatter (row, column, cellValue, index) {
							let str = /^\d+$/
							let str_1 =  /^\d+(\.\d)?$/
							if(str.test(cellValue)){
								cellValue=cellValue+".00"
							}
							if(str_1.test(cellValue)){
								cellValue=cellValue+"0"
							}
							return cellValue
						}
          },
          {
            title: '发放金额',
            key: 'theAmount',
            minWidth: '100',
						align: 'right',
						formatter (row, column, cellValue, index) {
							let str = /^\d+$/
							let str_1 =  /^\d+(\.\d)?$/
							if(str.test(cellValue)){
								cellValue=cellValue+".00"
							}
							if(str_1.test(cellValue)){
								cellValue=cellValue+"0"
							}
							return cellValue
						}
          },
					{
						title: '被累加金额',
						key: 'addAmount',
					  minWidth: '120',
						align: 'right',
						formatter (row, column, cellValue, index) {
							let str = /^\d+$/
							let str_1 =  /^\d+(\.\d)?$/
							if(str.test(cellValue)){
								cellValue=cellValue+".00"
							}
							if(str_1.test(cellValue)){
								cellValue=cellValue+"0"
							}
							return cellValue
						}
					},
					{
						title: '补贴类型',
						key: 'paramName',
						minWidth: '90'
					},
					{
						title: '是否补贴',
						key: 'subsidiesStatus',
						minWidth: '90',
						formatter (row, column, cellValue, index) {
							if(cellValue === '1'){
								return '是'
							}else if(cellValue === '0'){
								return '否'
							}
						}
					}
        ],
        data: []
      }
    },
    methods: {
      handleNodeClick(data,node,com) {
			/* 		if(data.flag){
					  this.filter.selectedId = data.id
					 this.handleList()
				}else{
						this.$message({
					  message: '无此数据权限',
					  type: 'error'
					})
					return false
				} */
      },
      handleTreeNode () {
      /*  findOrganizationByTree({
          isCompany:1
        }).then(res=>{
          this.treeData = JSON.parse(res.data)
          //this.handleList()
        }) */
      },
      handleList (val) {
        if(val){this.filter.pageNum=1
        this.currentPage = 1}
      this.loading = true
        getSubsidiesStatistics(this.filter).then(res=>{
          this.loading = false
          this.data = res.page.list
          this.pagination.total = res.page.total
        }).catch(err=>{
          this.loading = false
        })
      },

      handleCurrentChange (val) {
        this.filter.pageNum = val
        this.handleList()
      },
			handleSizeChange (val) {
			this.filter.pageNum = 1
			this.filter.pageSize = val
			this.handleList()
			},
			dateChange (val) {
			if(val == null){
				this.filter.startDate = ''
				this.filter.endDate = ''
			}else{
				this.filter.startDate = val[0] 
				this.filter.endDate = val[1]
			}
			},
			clearDepartment(){
				this.filter.depId = ''
			}
			/* 		getFunction () {
			  this.$GetFunction({
			    menuUrl:this.$route.path
			  }).then(res=>{
			    res.data.forEach(item=>{
			      if (item.functionType === 'select') {
			        if (item.remarks === 'true') {
			          this.func.select = true
			        } else {
			          this.func.select = false
			        }
			      }  
			    })
			  })
			} */
    },
    mounted () {
		//	this.getFunction()
		function 	setDate(date){
      y=date.getFullYear();
      m=date.getMonth()+1;
      d=date.getDate();
      m=m<10?"0"+m:m;
			d=d<10?"0"+d:d;
     return y+"-"+m+"-"+d;
     }
			//this.time = this.$setInitTime()
			//this.filter.startDate = this.$timestampToTime(this.time[0].setDate(1))
			//this.filter.endDate = this.time[1].format('yyyy-MM-dd hh:mm:ss')
			this.filter.pageSize = this.tableOptions.pageList[0]
      this.tableOptions = this.$calcTableHeight(tableOptions,60)
      this.handleList()
						this.tableOptions.showSummary = true
						this.tableOptions.summaryMethod = function (param) {
							const { columns, data } = param
							const sums = []
							columns.forEach((column, index) => {
								if (index === 0) {
									sums[index] = '合计'
									return
								}
								if (index === 2|| index === 3 ||index === 1 || index === 4 ||index === 8 ||index === 9) {
									sums[index] = ''
									return
								}
								const values = data.map(item => Number(item[column.property]))
								if (!values.every(value => isNaN(value))) {
									sums[index] = values.reduce((prev, curr) => {
										const value = Number(curr)
										if (!isNaN(value)) {
											let real = this.NP.plus(prev,curr)
											return this.NP.round(real,2)
										} else {
											return prev
										}
									}, 0)
									sums[index] += ''
								} else {
									sums[index] = ''
								}
							})
			
							return sums
						}
    }
  }
</script>
