<template>
  <d2-container>
    <div class="d2-table-view-full" style="overflow: hidden">
      <div class="d2-table-view-header">
        <el-form labelPosition="center" 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="daterange"
                    value-format="yyyy-MM-dd"
                    @change="dateChange"
										style="width: 300px;"
                    range-separator="至"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间">
            </el-date-picker>
          </el-form-item>
          <!--<el-form-item label="员工姓名">-->
            <!--<el-input v-model="filter.empName" placeholder="员工姓名"/>-->
          <!--</el-form-item>-->
			 <el-form-item label="工号">
			<el-input v-model="filter.userNo" placeholder="工号" style="width: 160px;" clearable/>
			</el-form-item>
				 <el-form-item label="卡号">
			<el-input v-model="filter.cardCode" placeholder="卡号" style="width: 160px;" clearable/>
			</el-form-item>
		  <el-form-item label="补贴类型">
			<custom-select :isAll="true" :value="filter.allowanceKind" v-model="filter.allowanceKind" typeName="补贴类型" style="width: 160px;"/>
		  </el-form-item>
          <!--<el-form-item label="卡号">-->
            <!--<el-input v-model="filter.cardCode" placeholder="卡号"/>-->
          <!--</el-form-item>-->

          <!--<el-form-item label="是否已领">-->
            <!--<el-select style="width: 150px" value="filter.receiveType" v-model="filter.receiveType">-->
              <!--<el-option label="全部" :value="null"/>-->
              <!--<el-option label="是" value="1"/>-->
              <!--<el-option label="否" value="0"/>-->
            <!--</el-select>-->
          <!--</el-form-item>-->
          <!--<el-form-item label="是否有效">-->
            <!--<el-select style="width: 150px" value="filter.wxstate" v-model="filter.wxstate">-->
              <!--<el-option label="全部" :value="null"/>-->
              <!--<el-option label="无效" value="1"/>-->
              <!--<el-option label="有效" value="0"/>-->
            <!--</el-select>-->
          <!--</el-form-item>-->
       <!-- <el-form-item label="审核状态">
         <el-select   value="filter.auditState" v-model="filter.auditState" style="width: 160px;">
           <el-option label="全部" :value="null"/>
           <el-option label="已审核结转" value="1"/>
					 <el-option label="已审核作废" value="2"/>
           <el-option label="未审核" value="0"/>
         </el-select>
       </el-form-item>
			<el-form-item label="状态" >
				<el-select value="filter.state" v-model="filter.state" style="width: 160px;">
					<el-option label="作废" value="1"/>
					<el-option label="正常" value="0"/>
				</el-select>
			</el-form-item> -->
			<el-form-item label="是否已领">
			<el-select   value="filter.receiveStatus" v-model="filter.receiveStatus" style="width: 160px;">
			  <el-option label="全部" :value="null"/>
			  <el-option label="是" value="1"/>
			  <el-option label="否" value="0"/>
			</el-select>
			</el-form-item>
			<el-form-item label="是否有效">
			<el-select   value="filter.status" v-model="filter.status" style="width: 160px;">
			  <el-option label="全部" :value="null"/>
			  <el-option label="是" value="1"/>
			  <el-option label="否" value="0"/>
			</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">
				<div class="d2-table-view-handle">
					 <!-- 	<label slot="headerButton" style="margin-right: 15px; color: red;"  >合计：{{total}}行</label>
					 <label slot="headerButton" style="margin-right: 30px;  color: red;"  >金额：{{monkey}}</label> -->
					 <el-button   type="primary" @click="subsidyAudit" size="small" slot="headerButton">审核</el-button>
					 <el-button   @click="operVisible = !operVisible" size="small" icon="el-icon-plus" slot="headerButton">新增</el-button>
					     <label slot="headerButton" for="upload-input">
					       <span   class="import-button">导入</span>
					     </label>
					 <el-button   @click="exportOperation" type="warning" size="small" slot="headerButton">导出</el-button>
					 <el-button   @click="downTemplate" type="primary" size="small" slot="headerButton">下载导入模板</el-button>
					</div>
        <d2-crud
				        title="补贴发放管理列表"
                ref="d2Crud"
                :loading="loading"
                :columns="columns"
                :data="data"
                :options="tableOptions"
                selection-row
				:rowHandle="rowHandle"
				@delete="handleRowRemove"
        @selection-change="handleSelectionChange">
        </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>
      <input id="upload-input" style="display: none" type="file"
             multiple
             ref="upload"
             name="file"
             @change="upload($event)">
    </div>
	<el-dialog
			title="上传进度"
			:show-close="false"
			:close-on-click-modal="false"
			:close-on-press-escape="false"
			:visible.sync="progressVisible"
			width="20%">
	  <el-progress :percentage="progress"/>
	</el-dialog>
    <el-dialog
            :title="diaLogName"
            :visible.sync="operVisible"
            @close="clearForm"
			@open="openDialog"
            width="60%"
						:close-on-click-modal="false">
		<div class="d2-fl d2-tree-view" style="width: 260px">
			<div class="double-tree" style="display:inline-block">
				<div>
					<div>选择人员</div>
					<el-tree
							style="height:300px;overflow: auto;padding: 20px;box-sizing: border-box;"
							:data="empTree"
							default-expand-all
							:props="defaultProps"
							node-key="value"
							ref="empTree"
							show-checkbox>
							<span class="icon-tree" slot-scope="{ node, data }">
								<div v-if="data.alias == 'top'">
									<i class="fa fa-university"></i>
									<span>&nbsp;{{node.label}}</span>
								</div>
								<div v-if="data.alias == 'JG001'">
									<i class="fa fa-building"></i>
									<span>&nbsp;{{node.label}}</span>
								</div>
								<div v-if="data.alias == 'JG002'">
									<i class="fa fa-building"></i>
									<span>&nbsp;{{node.label}}</span>
								</div>
								<div v-if="data.alias == 'user'">
									<i class="fa fa-users"></i>
									<span>&nbsp;{{node.label}}</span>
								</div>
						</span>
					</el-tree>
				</div>
			</div>
		</div>
		<!--<div-->
				<!--@click="isExpend = !isExpend"-->
				<!--:class="[{'angle-view':isExpend},{'angle-view-none':!isExpend}]"-->
		<!--&gt;-->
			<!--<i :class="['fa', {'fa-angle-left':isExpend},{'fa-angle-right':!isExpend}]"></i>-->
		<!--</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 style="overflow: hidden">
      <el-form ref="form" :model="form" label-width="100px" labelPosition="right" :rules="rulesForm" style="height: 300px">
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="补贴起止时间">
              <el-date-picker
                      v-model="formTime"
                      type="datetimerange"
                      value-format="yyyy-MM-dd HH:mm:ss"
											:default-time="['00:00:00', '23:59:59']"
                      @change="formDateChange"
                      range-separator="至"
                      start-placeholder="开始时间"
                      end-placeholder="结束时间"
											style="width: 100%;">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <!--<el-col :span="12">-->
            <!--<el-form-item label="补贴机" prop="eqpId">-->
               <!--<el-select v-model="form.eqpId" placeholder="请选择" style="width: 100%;">-->
									<!--<el-option-->
										<!--v-for="item in options"-->
										<!--:key="item.eqpId"-->
										<!--:label="item.eqpNm"-->
										<!--:value="item.eqpId">-->
									<!--</el-option>-->
								<!--</el-select>-->
            <!--</el-form-item>-->
          <!--</el-col>-->
          <el-col :span="24">
            <el-form-item label="补贴类型" prop="allowanceKind">
              <custom-select v-model="form.allowanceKind" :value="form.allowanceKind" typeName="补贴类型" style="width: 100%;"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="发放金额" prop="theAmount">
              <el-input  v-model="form.theAmount" maxlength="14" clearable/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
		</div>
      <span slot="footer" class="dialog-footer">
    <el-button   @click="operInstance('form')">确 定</el-button>
  </span>
    </el-dialog>

  </d2-container>
</template>

<script>
  import {getSubsidies,saveOrUpdataList,getList,deleteList,getEquipment,TreeNode,SubsidyAuditCheck} from '../../../api/cost/subsidy'
  import { tableOptions } from '../../../assets/options'
  import util from '../../../libs/util'
 // import departmentTree from '../../../components/department-tree/index'
  import { Loading } from 'element-ui';
  export default {
    name: 'attendance-subsidy',
   /* components:{
      departmentTree
    }, */
    data () {
		let checksubsidyAmount = (rule, value, callback) => {
		let reg =  /^[-]?\d+(\.\d+)?$/
		  if(!reg.test(value)){
			return callback(new Error('请输入少于14位的实数'))
		}else{
			callback ()
		}
		}
      return {
				falg:true,
				total:0,
				monkey:0,
				// options:[],
				subLoading:false,
				func:{
					add:false,
					select:false,
					delete:false,
					out:false,
					put:false,
					audit:false,
					download:false
				},
        isExpend:true,
        empLoading:false,
        loading: false,
        operVisible:false,
        progressVisible:false,
		    progress:0,
        currentPage:1,
        diaLogName:'新增',
        filterText:'',
        tableOptions,
        equTree:[],
        empTreeAll:[],
        empTree:[],
        // equipTree:[],
        time:[],
        formTime: '',
        form:{
          userId:'',
          clockserialnos:'',
          startTime:'',
          endTime:'',
          validDate:'',
          allowanceKind:'',
          theAmount:''
        },
        filter: {
          userNo:'',
					cardCode:'',
					allowanceKind:'',
					receiveStatus:'',
					status:'',
					startTime:'',	
					endTime:'',
					pageSize:10,
					pageNum:1
        },
        pagination: {
          total: 0
        },
        columns: [
          {
            title: '序号',
            key: 'index',
            minWidth: '60',
            formatter (row, column, cellValue, index) {
              return index + 1
            }
          },
          {
            title: '补贴日期',
            key: 'subsidiesToDate',
            minWidth: '120'
          },
          {
            title: '工号/学号',
            key: 'userNo',
            minWidth: '120'
          },
          {
            title: '姓名',
            key: 'userNm',
            minWidth: '90'
          },
          /* {
            title: '部门',
            key: 'orgName',
            minWidth: '120'
          }, */
          {
            title: '卡号',
            key: 'cardCode',
            minWidth: '130',
          },
          {
            title: '补贴类型',
            key: 'paramName',
            minWidth: '110',
          },
           {
             title: '补贴金额',
             key: 'subsidiesDeposit',
             minWidth: '120',
						sortable:true,
			 			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: '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: 'addAmount',
             minWidth: '120',
			 			sortable:true,
						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: 'subsidiesForBatch',
            minWidth: '90',
          },
          /* {
            title: '操作员',
            key: 'userName',
            minWidth: '130',
          }, */
					 {
					title: '是否补贴',
					key: 'subsidiesStatus',
					minWidth: '90',
					formatter (row, column, cellValue, index) {
					  if (cellValue === '1') {
					    return '是'
					  } else if(cellValue === '0'){
					    return '否'
					  }
					}
					},
          {
            title: '是否有效',
            key: 'status',
            minWidth: '90',
            formatter (row, column, cellValue, index) {
              if (cellValue === '1') {
                return '有效'
              } else if(cellValue === '0'){
                return '无效'
              }
							}
            },
					/* 	  {
						  title: '是否已领',
						  key: 'wxstate',
						  minWidth: '90',
						  formatter (row, column, cellValue, index) {
						    if (cellValue === '1') {
						      return '是'
						    } else if(cellValue === '0'){
						      return '否'
						    }
						  }
          }, */
          {
            title: '有效日期',
            key: 'validTime',
            minWidth: '240',
            showOverflowTooltip: true
          },
					  {
					  title: '版本',
					  key: 'version',
					  minWidth: '90',
					  showOverflowTooltip: true
					},
          {
            title: '审核状态',
            key: 'auditStatus',
            minWidth: '110',
            fixed: 'right',
            formatter (row, column, cellValue, index) {
              if (cellValue === '0') {
                return '未审核'
              } else if(cellValue === '1'){
              return '已审核结转'
              }else if(cellValue === '2'){
              return '已审核作废'
              }
            }
          },
					 /* {
							title: '审核员',
							key: 'auditUserName',
							minWidth: '120',
	
						}, */
					/* {
							title: '状态',
							key: 'state',
							minWidth: '90',
	            formatter (row, column, cellValue, index) {
								if (cellValue === '0') {
									return '正常'
								} else if(cellValue === '1') {
								return '作废'
	
								}
							}
						} */
        ],
        rowHandle: {
          columnHeader: '操作',
          minWidth: '180',
          align:'center',
         custom: [
             /* {
               text: '编辑',
               type: 'primary',
              size: 'small',
               emit: 'edit'
             }, */
            {
              text: '删除',
              type: 'danger',
              size: 'small',
              emit: 'delete'
            }
          ],

        },
        defaultProps: {
          children: 'children',
          label: 'name'
        },
				rulesForm: {
                  theAmount: [{ validator: checksubsidyAmount, trigger: 'blur' }],
                  // eqpId:[{required: true, message: '请选择补贴机', trigger: 'blur'}],
                  allowanceKind:[{required: true, message: '请选择补贴类型', trigger: 'blur'}],
						},
        data: [],
        selection:[]
      }
    },
    watch: {
      filterText(val) {
        if (val) {
          this.falg=true
		}
      },
			/* 'form.leaveType':function(val){
				 this.leaLoading=false
			}, */
    },
    methods: {
			searchClick(){
				/* this.falg=false
				EmpTreeAll({
				  params:this.filterText
				}).then(res=>{
				  this.empTreeAll = JSON.parse(res.data)
				}) */
			},
      filterNode(value, data) {
        if (!value) return true;
        return data.title.indexOf(value) !== -1;
      },
      downTemplate () {
        window.open(`${process.env.VUE_APP_API}downExcelByType?type=subsidy`)
      },
      upload (e) {
        this.files = []
        let files = e.target.files
        let formData = new FormData()
        for (let k in files) {
          if (files.hasOwnProperty(k)) {
            formData.append('file', files[k])
          }
        }
        //this.progressVisible = true

      /*  let time = setInterval(()=>{
          if (this.progress < 99) {
            this.progress ++
          }
        },1000) */
				let loadingInstance_2=Loading.service({ fullscreen: true,text:'导入中...',background:"rgba(0, 0, 0, 0.8)" })
        SubsidyUpload(formData).then(res => {
         // clearInterval(time)
          //this.progress = 100
          //setTimeout(()=>{
           // this.progressVisible = false
            //this.progress = 0
            this.$message({
              message: '导入成功',
              type: 'success'
            })
						this.$nextTick(() => {  
						loadingInstance_2.close();
						});
						if(res.msg) {
						        window.open(`${process.env.VUE_APP_API}downErrorExcelByName?fileName=${res.msg}`)
						      }
            this.handleList()
         // },1000)
        }).catch(err=>{
					this.$nextTick(() => {  
					loadingInstance_2.close();
					});
          //clearInterval(time)
          //this.progressVisible = false
         // this.progress = 0
        })

        this.$refs.upload.value = null
      },
      handleList (val) {
        if(val){this.filter.pageNum=1
        this.currentPage = 1}
      this.loading = true
        getSubsidies(this.filter).then(res => {
          this.loading = false
          this.data = res.page.list
          this.pagination.total = res.page.total
					/* this.total=res.count.giveOutCount
					this.monkey=res.count.giveOutCountMoney */
        }).catch(err => {
          this.loading = false
        })
      },
      handleRowRemove ({index, row}) {
			  if(row.auditStatus!=='0'){
                this.$message({
                  message: '未审核状态才能删除',
                  type: 'warning'
                })
				return
			  }
        this.$confirm(`确定要删除吗?`, '确认操作', {
          confirmButtonText: '确定',
          cancelButtonText: '放弃',
          type: 'warning'
        }).then(() => {
          let tempId = row.tempId
          deleteList({
            tempId
          }).then(res=>{
            this.$message({
              message: '删除成功',
              type: 'success'
            })
            this.handleList()
          })
        })
      },
      exportOperation () {
        if (!this.data.length){
          this.$message({
            message: '页面无数据,无法导出',
            type: 'error'
          })
          return false
        }
        const token = util.cookies.get('token')
        window.open(`${process.env.VUE_APP_API}/cons/dowloadSubsidyAddMoney?startDate=${this.filter.startDate}&endDate=${this.filter.endDate}&empName=${this.filter.empName}&levelCode=${this.filter.levelCode}&workLevelCode=${this.filter.workLevelCode}&empCode=${this.filter.empCode}&receiveType=${this.filter.receiveType || ''}&wxstate=${this.filter.wxstate || ''}&state=${this.filter.state || ''}&auditState=${this.filter.auditState || ''}&token=${token}`)
      },
      operInstance (formEquName) {
        let empNodes =this.$refs.empTree.getCheckedNodes()

	/* 	if (this.filterText) {
          empNodes = this.$refs.empTreeAll.getCheckedNodes()
		}

        let equNodes =this.$refs.equTree.getCheckedNodes() */


		// return false
        let empTemp = []
		//let deptTemp = []
       // let equTemp = []
        empNodes.forEach(item=>{
          if (item.alias === 'user') {
            empTemp.push(item)
          }
        })
        this.form.userId = empTemp.map(item => item.id).join(',')
     this.$refs[formEquName].validate((valid) => {
     		if (valid) {
     		  if(!this.form.startTime){
                this.$message({
                  message: '请选择补贴时间',
                  type: 'warning'
                })
				return
			  }
			  if(!this.form.userId){
                this.$message({
                  message: '请选择人员',
                  type: 'warning'
                })
                return
			  }
					this.subLoading=true
					 saveOrUpdataList (this.form).then(res=>{
					          this.operVisible = false
										this.subLoading=false
					          this.$message({
					            message: '新增成功',
					            type: 'success'
					          })
					          this.handleList()
					        })
				}
				})
      },

      handleCurrentChange (val) {
        this.filter.pageNum = val
        this.handleList()
      },
			handleSizeChange (val) {
			this.filter.pageNum = 1
			this.filter.pageSize = val
			this.handleList()
			},
	  openDialog () {
		this.empLoading = true
        /* EmpTree().then(res=>{
          this.empTree = JSON.parse(res.data)
          this.empLoading = false
        }) */
	  },
      loadEmpTree (node,resolve) {

		if (node.level === 0) {
          return resolve (this.empTree)
		}
		//
		if (node.level === 1) {
           return resolve (this.empTree[0].data)
        }

        if (node.level > 1) {

          if (node.data.alias === 'emp') {
            return resolve([])
		  }

          EmpTree({
			orgId:node.data.value
		  }).then(res=>{
            // console.log(res)
			let temp = JSON.parse(res.data) || []
			// console.log(temp)
            if (node.data.data.length) {
              temp = temp.concat(node.data.data)
            }
            return resolve (temp)
          })

        }


      },
      clearForm () {
        if (this.$refs['form']!==undefined) {
          this.$refs['form'].resetFields()
        }
       // this.$refs.equTree.setCheckedKeys([])
        this.form = {
            userId:'',
            clockserialnos:'',
            startTime:'',
            endTime:'',
            validDate:'',
            allowanceKind:'',
            theAmount:''
        }
        this.formTime= ''
        this.$refs.empTree.setCheckedKeys([])
        this.filterText = ''
        // this.empTree = []
      },
      EquTreeTraverse (node) {
        if (!node || !node.data) {return}
        if (node.alias === 'sb_child') {
          node.disabled = false
        } else {
          node.disabled = true
        }
        node.data.forEach((item) => {
          this.EquTreeTraverse(item)
        })
      },
      EmpTreeTraverse (node) {
        if (!node || !node.data) {return}
        if (node.alias === 'emp') {
          node.disabled = false
        } else {
          node.disabled = true
        }
        node.data.forEach((item) => {
          this.EmpTreeTraverse(item)
        })
      },
      dateChange (val) {
        if(val == null){
        	this.filter.startDate = ''
        	this.filter.endDate = ''
        }else{
        	this.filter.startDate = val[0]
        	this.filter.endDate = val[1]
        }
      },
      formDateChange (val) {
        this.form.startTime = val[0]
        this.form.endTime = val[1]
      },
      handleSelectionChange (selection) {
				selection.forEach((item,idx)=>{
				  if (item.employeeCode == '合计') {
				    selection=selection.splice(0,selection.length-1);	
				  }
				})
        this.selection = selection
      },
      subsidyAudit () {
        if (!this.selection.length) {
          this.$message({
            message: '请先选择需要审核的补贴',
            type: 'error'
          })
		  return false
		}

		let temp = []
		this.selection.forEach((item,idx)=>{
		  if (item.auditStatus !== '0') {
		    temp.push(idx + 1)
		  }
		})

		if (temp.length) {
          // let str = temp.map(item=>item).join(',')
          this.$message({
            message: `已选有${temp.length}条已审核,请重新选择未审核项`,
            type: 'error'
          })
		  return false
		}
		
		let type = null
		
   this.$confirm('是否添加补贴?', '提示', {
		distinguishCancelAndClose: true,
   	confirmButtonText: '是',
   	cancelButtonText: '取消',
   	type: 'error'
   }).then(() => {
		 let loadingInstance=Loading.service({ fullscreen: true,text:'审核中...',background:"rgba(0, 0, 0, 0.8)" })
     type = '1'
		 SubsidyAuditCheck({
           tempId: this.selection.map(item=> item.tempId).join(',')
		 }).then(res=>{
			 this.handleList()
		 	this.$message({
		 		message: '审核成功',
		 		type: 'success'
		 	})
				this.$nextTick(() => {  
			loadingInstance.close();
			});
		 }).catch(err=>{
				this.$nextTick(() => {  
				loadingInstance.close();
				});
        })
   }).catch(action => {
		 // if(action === 'cancel'){
			// let loadingInstance_1= Loading.service({ fullscreen: true,text:'作废中...',background:"rgba(0, 0, 0, 0.8)" })
			//  type = '2'
			//  SubsidyAudit({
			//  ids: this.selection.map(item=> item.subsidyAddmoneyId).join(','),
			//  type
			//  }).then(res=>{
			// this.handleList()
			//  this.$message({
			//  	message: '审核成功',
			//  	type: 'success'
			//  })
			//   this.$nextTick(() => {
			//  loadingInstance_1.close();
			//  });
			//  }).catch(err=>{
			// 	this.$nextTick(() => {
			// 	loadingInstance_1.close();
			// 	});
        // })
		 // }
      });
       
      },
      clearDepartment(){
        this.filter.levelCode=''
      },
      clearWorkDepartment () {
        this.filter.workLevelCode=''
	  },
	/* 	 getFunction () {
		  this.$GetFunction({
		    menuUrl:this.$route.path
		  }).then(res=>{
		    res.data.forEach(item=>{
					// console.log(item)
		      if (item.functionType === 'add') {
		        if (item.remarks === 'true') {
		          this.func.add = true
		        } else {
		          this.func.add = false
		        }
		      } else if(item.functionType === 'select') {
		        if (item.remarks === 'true') {
		          this.func.select = true
		        } else {
		          this.func.select = false
		        }
		      }else if(item.functionType === 'out') {
		        if (item.remarks === 'true') {
		          this.func.out = true
		        } else {
		          this.func.out = false
		        }
		      } else if(item.functionType === 'put') {
		        if (item.remarks === 'true') {
		          this.func.put = true
		        } else {
		          this.func.put = false
		        }
		      } else if(item.functionType === ' download') {
		        if (item.remarks === 'true') {
		          this.func.download = true
		        } else {
		          this.func.download = false
		        }
		      }else if(item.functionType === 'audit') {
		        if (item.remarks === 'true') {
		          this.func.audit = true
		        } else {
		          this.func.audit = false
		        }
		      } else if(item.functionType === 'delete') {
		        if (item.remarks === 'true') {
		          this.$set(this.rowHandle,'custom',[
		            {
		              text: '删除',
		              type: 'danger',
		              size: 'small',
		              emit: 'delete',
									show(index,row ){
										if(row.employeeCode == '合计'){
											return false
										}else{
											return true
										}
									}
		            }
		          ])
		        }
		      }
		    })
		  })
		} */
    },
    mounted () {
	  //this.getFunction()
      this.time = this.$setInitTime()
      this.filter.startDate = this.time[0].format('yyyy-MM-dd')
      this.filter.endDate = this.time[1].format('yyyy-MM-dd')
			this.filter.pageSize = this.tableOptions.pageList[0]

			 this.tableOptions = this.$calcTableHeight(tableOptions,90)
      this.handleList()
     TreeNode({
        depType:''
      }).then(res=>{
        this.empTree = JSON.parse(res.msgDat)
        this.EquTreeTraverse(this.empTree[0])
      })
			
			// getEquipment().then(res=>{
			//    this.equipTree = res.msgDat
			//   console.log(this.equipTree)
			//  })
   //本页合计
					this.tableOptions.showSummary = true
					this.tableOptions.summaryMethod = function (param) {
						const { columns, data } = param
						const sums = []
						columns.forEach((column, index) => {
							if (index === 1) {
								sums[index] = '合计'
								return
							}
							if (index === 2 || index === 5 || index === 0 || index === 3 || index === 6 || index===4 || index ===14 || index ===11 || index === 13 || index === 10 || index === 12 || index === 16) {
								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>

<style lang="scss" scoped>
  .d2-table-view-header {
	min-width: 1300px !important;
  }

</style>
