<template>
  <div class="app-container">
  
     开发中
  </div>
</template>

<script>
// 引入
import { GetDataByName, GetDataByNames, getRecuData, GetAccount } from '@/api/common'
import waves from '@/directive/waves'
 
import { parseTime, json2excel, sortChange } from '@/utils/index.js'
import Pagination from '@/components/Pagination'
import TreeSelect from '@/components/TreeSelect'
import Cookies from 'js-cookie'
export default {
  name: 'StopRecord',
  components: { Pagination, TreeSelect },
  directives: { waves },
  data() {
    return {
      findAllPasture: [], findAllDepart: [],
      requestParams: [
        { name: 'findAllPasture', offset: 0, pagecount: 0, returntype: 'Map', parammaps: { 'id': Cookies.get('pastureid') }}
      ],
      getDepartParam: { name: 'findAllDepart1', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid'), 'eId': Cookies.get('employeid') }},
      disabled: false, placeholder: '请选择设备类别',
 
  
 
   
      getRecuListParm: { name: 'getAssetTypeList', idname: 'id', params: [-1] },
      tableKey: 0,
      list: [
         
      ],

      selectData: '',
      pickerMinDate: '',
      pickerRange:3600 * 1000 * 24 * 60,
      pickerOptions: {
      //   onPick:({maxDate,minDate }) => {
      //     if (minDate && this.pickerMinDate) {
      //       this.pickerMinDate = null
      //     } else if (minDate) {
      //       this.pickerMinDate = minDate.getTime()
      //     }
      //  },
      //   disabledDate: (time) => {
      //     if (this.pickerMinDate) {
      //         return (time.getTime() > (this.pickerMinDate + this.pickerRange))  ||(time.getTime() < (this.pickerMinDate - this.pickerRange))
      //     }
      //   return false
      //   },
      },


      total: 0,
      listLoading: true,
      getdataListParm: {
        name: 'getRecordsOfRepairman', page: 1, offset: 1, pagecount: 10, returntype: 'Map',inputDatetime: '',
        parammaps: { pastureId: Cookies.get('pastureid'), pastureName: Cookies.get('pasturename'), departmentName: '', eqClassId: '', startTime: "",
        stopTime: "",departmentId: "" ,inputDatetime: [parseTime(new Date().getTime() - 30 * 24 * 60 * 60 * 1000, '{y}-{m}-{d}'), parseTime(new Date().getTime() - 24 * 60 * 60 * 1000, '{y}-{m}-{d}')],}
      },
      requestParam: { name: 'insertAsset', offset: 0, pagecount: 0, parammaps: {}}, statueReason: false,
      downLoadParm: {},
      downLoadList: [],
      pageNum: 0,
      pageSize: 0,
      isPercentage: false,
      percentage: 1,
      isokDisable: false,
      rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
      cellStyle: { padding: 0 + 'px' }
    }
  },
  created() {
    // this.get_select_list()
    //  this.get_table_data()
 
  },
  methods: {

    getSummaries1(param) {
        const { columns, data } = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
              sums[index] = '合计';
            return;
          }
          const values = data.map(item => Number(item[column.property]));
          console.log(column.property)
          console.log(values)
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            // sums[index] += ' 元';
          } else {
            sums[index] = '-';
          }
        });

        return sums;
    },

    get_select_list() {
      GetDataByNames(this.requestParams).then(response => {
        if (response.data.list !== null) {
          this.findAllPasture = response.data.findAllPasture.list
          this.getDepartDownList()
        }
      })
    },
    getDepartDownList() {
      GetDataByName(this.getDepartParam).then(response => {
        this.findAllDepart = response.data.list
      })
    },
    changePastureName(item) {
      this.getDepartParam.parammaps.pastureId = this.findAllPasture.find(obj => obj.name == item).id
      this.getdataListParm.parammaps.departmentId = ''
      this.getDepartDownList()
    },
    get_table_data() {
      this.listLoading = true
      if (this.getdataListParm.parammaps.pastureName == '现代牧业') {
        // this.getdataListParm.parammaps.pastureName = ''
        this.getdataListParm.parammaps.pastureId = ''
      }

      if (this.$refs['inputDatetime'] !== undefined && this.$refs['inputDatetime'].value !== null) {
        this.getdataListParm.parammaps.startTime = this.$refs['inputDatetime'].value[0]
        this.getdataListParm.parammaps.stopTime = this.$refs['inputDatetime'].value[1]
      } else {
        this.getdataListParm.parammaps.startTime = ''
        this.getdataListParm.parammaps.stopTime = ''
      }
      GetDataByName(this.getdataListParm).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          this.list = response.data.list
          this.pageNum = response.data.pageNum
          this.pageSize = response.data.pageSize
        } else {
          this.list = []
        }
        this.total = response.data.total
        setTimeout(() => {
          this.listLoading = false
        }, 100)
      })
    },
    form_search() {
      this.listLoading = true
      this.getdataListParm.offset = 1
      this.getdataListParm.parammaps.pastureId = this.findAllPasture.find(obj => obj.name == this.getdataListParm.parammaps.pastureName).id
      this.get_table_data()
    },

  
  
    tableCellStyle({ row, column, rowIndex, columnIndex }) {
      // if (columnIndex === 3) {
      //   return {
      //     textDecoration: 'underline'
      //   }
      // }
      // return {
      //   textDecoration: 'none'
      // }
    },
   

    handleDownload() {
      this.$alert('报修人记录正在导出中，请勿刷新或离开本页面，若导出时间过长，建议缩小导出数据范围重新导出', {})
      this.isPercentage = true
      this.percentage = 1
      var timer = setInterval(() => {
        this.percentage += 5
        if (this.percentage > 95) {
          this.percentage = 99
          clearInterval(timer)
        }
        this.percentage = this.percentage
      }, 1000)
      this.downLoadParm.name = 'getRecordsOfRepairman'
      this.downLoadParm.parammaps = this.getdataListParm.parammaps
      GetAccount(this.downLoadParm).then(response => {
        this.downLoadList = response.data.list
        if (response.data.list !== '') {
          this.percentage = 99
          setTimeout(() => {
            this.isPercentage = false
          }, 2000)
        }
        console.log(this.downLoadList)
        const elecExcelDatas = [
          {
            tHeader: ['牧场', '月份', '部门', '姓名', '报修次数'],
            filterVal: ['pasturename', 'date', 'departmentName', 'empname', 'count' ],
            tableDatas: this.downLoadList,
            sheetName: '报修人记录'
          }
        ]
        json2excel(elecExcelDatas, '报修人记录', true, 'xlsx')
      })
    }
 

  }
}
</script>
<style lang="scss" scoped>
  .el-autocomplete-suggestion li{
    padding:0 3px!important;
  }
  .el-table .warning-row {
      background: oldlace;
  }
  .el-table .success-row {
      background: #f0f9eb;
  }
</style>
<style lang="scss">
  .upkeepgrade .el-form-item__label{
    line-height: 20px;
  }
  .inputDatetime .el-range-separator{
   padding: 0;
   margin: 0 10px;
  }
  .el-radio__label{
    padding-left: 2px !important;
  }
  .typeSelect span .el-popover__reference .el-input--suffix {
    top:-3px;
    .el-input__inner{
      height:40px !important;
    }
  }
</style>
