<template>
  <div class="app-table">
    <div class="search">
      <el-date-picker v-model="table.getdataListParm.parammaps.changetime" class="filter-item " type="date" style="width: 250px;" format="yyyy-MM-dd" value-format="yyyy-MM-dd" placeholder="年/月/日" />
      <el-button class="successBorder" @click="handleSearch">查询</el-button>
      <el-button class="successBorder" @click="handleRefresh">重置</el-button>
    </div>
    <div class="table">
      <el-table
        :key="table.tableKey"
        v-loading="table.listLoading"
        element-loading-text="给我一点时间"
        :data="table.list"
        border
        fit
        highlight-current-row
        style="width: 100%;"
        :row-style="rowStyle"
        :cell-style="cellStyle"
        class="elTable table-fixed"
      >
        <el-table-column :key="1" label="序号" prop="sort" align="center" width="50px" />
        <el-table-column :key="2" label="栏舍名称" prop="barname" min-width="90px" align="center" />
        <el-table-column :key="3" label="标准分数(分)" prop="standardscore" min-width="90px" align="center" />
        <el-table-column :key="4" label="牛头数(分)" prop="cowsum" min-width="90px" align="center" />
        <el-table-column :key="5" label="评分" min-width="90px" align="center">
          <el-table-column label="1分 (头)" prop="onescore" min-width="90px" align="center" />
          <el-table-column label="2分(头)" prop="twoscore" min-width="90px" align="center" />
          <el-table-column label="3分(头)" prop="threescore" min-width="90px" align="center" />
          <el-table-column label="4分(头)" prop="fourscore" min-width="90px" align="center" />
          <el-table-column label="5分(头)" prop="fivescore" min-width="90px" align="center" />
        </el-table-column>
        <el-table-column :key="6" label="操作" prop="operation" align="center" width="300" class-name="small-padding fixed-width" fixed="right">
          <template slot-scope="{row}">
            <a class="correcting" @click="handleSeeHistory (row)">{{ row.operation }}</a>
          </template>
        </el-table-column>
      </el-table>
      <Pagination v-show="table.total>0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
    </div>
    <el-dialog :visible.sync="seeHistory.dialogFormVisible" append-to-body :title="textMap[seeHistory.dialogStatus]" :close-on-click-modal="false" width="90%">
      <div class="seeHistory">
        <div class="search">
          <el-date-picker v-model="seeHistory.getdataListParm.parammaps.inputDatetime" class="inputDatetime filter-item" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;" />
          <el-button class="successBorder" @click="handleSearch2">查询</el-button>
          <el-button class="successBorder" @click="handleRefresh2">重置</el-button>
        </div>
        <div class="table">
          <el-table
            :key="seeHistory.tableKey"
            v-loading="seeHistory.listLoading"
            element-loading-text="给我一点时间"
            :data="seeHistory.list"
            border
            fit
            highlight-current-row
            style="width: 100%;"
            :row-style="rowStyle"
            :cell-style="cellStyle"
            class="elTable table-fixed"
          >
            <el-table-column :key="1" label="序号" prop="sort" align="center" width="50px" />
            <el-table-column :key="2" label="修改时间" prop="changetime1" min-width="90px" align="center" />
            <el-table-column :key="3" label="标准分数(分)" prop="standardscore" min-width="90px" align="center" />
            <el-table-column :key="4" label="牛头数(分)" prop="cowsum" min-width="90px" align="center" />
            <el-table-column :key="5" label="评分" min-width="90px" align="center">
              <el-table-column label="1分 (头)" prop="onescore" min-width="90px" align="center" />
              <el-table-column label="2分(头)" prop="twoscore" min-width="90px" align="center" />
              <el-table-column label="3分(头)" prop="threescore" min-width="90px" align="center" />
              <el-table-column label="4分(头)" prop="fourscore" min-width="90px" align="center" />
              <el-table-column label="5分(头)" prop="fivescore" min-width="90px" align="center" />
            </el-table-column>
          </el-table>
          <Pagination v-show="seeHistory.total>0" :total="seeHistory.total" :page.sync="seeHistory.getdataListParm.offset" :limit.sync="seeHistory.getdataListParm.pagecount" @pagination="getSeeHistoryList" />
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button class="cancelClose cancelClose1" @click="seeHistory.dialogFormVisible = false; ">关闭</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { GetDataByName } from '@/api/common'
import draggable from 'vuedraggable'
import Cookies from 'js-cookie'
import { parseTime } from '@/utils/index.js'
import Pagination from '@/components/Pagination'
export default {
  name: 'MaterialIssuancePlan',
  display: 'Two list header slot',
  order: 14,
  components: { Pagination },
  data() {
    return {
      table: {
        getdataListParm: {
          name: 'getDungandbodyhistory',
          page: 1,
          offset: 1,
          pagecount: 12,
          returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid'),
            changetime: '',
            species: 'fppf'
          }
        },
        list: [],
        total: 0,
        tableKey: 0,
        listLoading: false,
        temp: {},
        changeList: [],
        startObj: {}
      },

      textMap: {
        seeHistory: '粪便评分修改记录'
      },
      seeHistory: {
        dialogFormVisible: false, dialogStatus: '',
        total: 0, tableKey: 0, listLoading: false,
        getdataListParm: {
          name: 'getDungandbodyhistoryBar', page: 1, offset: 1, pagecount: 10, returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid'),
            barid: '',
            inputDatetime: '',
            time1: '',
            time2: ''
          }
        }
      },

      rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
      cellStyle: { padding: 0 + 'px' }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    changeDate() {
      this.getList()
    },
    getList() {
      this.table.listLoading = true
      GetDataByName(this.table.getdataListParm).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          this.table.list = response.data.list
          this.table.pageNum = response.data.pageNum
          this.table.pageSize = response.data.pageSize
          this.table.total = response.data.total
        } else {
          this.table.list = []
        }
        setTimeout(() => {
          this.table.listLoading = false
        }, 100)
      })
    },

    handleSearch() {
      console.log(this.table.getdataListParm.parammaps.changetime)

        if (this.table.getdataListParm.parammaps.changetime == '' || this.table.getdataListParm.parammaps.changetime == null ) {
        this.table.getdataListParm.parammaps.changetime = ''
      } else {
        this.table.getdataListParm.parammaps.changetime = parseTime(this.table.getdataListParm.parammaps.changetime, '{y}-{m}-{d}')
      }
      this.getList()
    },
    handleRefresh() {
      this.table.getdataListParm.parammaps.changetime = ''
      this.getList()
    },
    handleSeeHistory(row) {
      console.log(row)
      this.textMap.seeHistory = '粪便评分修改记录——栏舍：' + row.barname
      this.seeHistory.dialogFormVisible = true
      this.seeHistory.dialogStatus = 'seeHistory'

      this.seeHistory.getdataListParm.parammaps.species = 'fppf'
      this.seeHistory.getdataListParm.parammaps.barid = row.barids
      this.seeHistory.getdataListParm.parammaps.inputDatetime = ''
      this.seeHistory.getdataListParm.parammaps.time1 = ''
      this.seeHistory.getdataListParm.parammaps.time2 = ''
      this.getSeeHistoryList()
    },
    getSeeHistoryList() {
      this.seeHistory.listLoading = true
      GetDataByName(this.seeHistory.getdataListParm).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          this.seeHistory.list = response.data.list
          this.seeHistory.pageNum = response.data.pageNum
          this.seeHistory.pageSize = response.data.pageSize
          this.seeHistory.total = response.data.total
        } else {
          this.seeHistory.list = []
        }
        setTimeout(() => {
          this.seeHistory.listLoading = false
        }, 100)
      })
    },
    handleSearch2() {
      if (this.seeHistory.getdataListParm.parammaps.inputDatetime !== '' && this.seeHistory.getdataListParm.parammaps.inputDatetime !== null) {
        this.seeHistory.getdataListParm.parammaps.time1 = parseTime(this.seeHistory.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
        this.seeHistory.getdataListParm.parammaps.time2 = parseTime(this.seeHistory.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
      } else {
        this.seeHistory.getdataListParm.parammaps.inputDatetime = ''
        this.seeHistory.getdataListParm.parammaps.time1 = ''
        this.seeHistory.getdataListParm.parammaps.time2 = ''
      }
      this.seeHistory.getdataListParm.offset = 1
      this.getSeeHistoryList()
    },
    handleRefresh2() {
      this.seeHistory.getdataListParm.parammaps.time1 = ''
      this.seeHistory.getdataListParm.parammaps.time2 = ''
      this.seeHistory.getdataListParm.parammaps.inputDatetime = ''
      this.getSeeHistoryList()
    }
  }
}
</script>

<style  lang="scss" scoped>
 .search{margin-bottom: 10px;}
</style>
