<!--历史皮重数据维护-->
<template>
  <div class="systemBase common-container-deriction">
    <div class="common-title-div" style="height: 45px;">
      <el-row>
        <el-col :span="1">
          <div style="line-height: 28px;text-align: right;margin-right: 5px;font-size:14px">
            车号
          </div>
        </el-col>
        <el-col :span="3">
          <el-input v-model="search.carNo" clearable placeholder="请输入" size="mini" style="" />
        </el-col>
        <el-button style="margin-left: 10px;" icon="el-icon-search" type="primary" size="mini"
        @click="searchDatas" v-loading.fullscreen.lock="operateLoading" v-privilege="activeMenu + 'SEARCH'">查询</el-button>
        <el-button size="mini" type="danger" icon="el-icon-remove-outline" plain
        v-loading.fullscreen.lock="operateLoading" @click="abolishData" v-privilege="activeMenu + 'ABOLISH'">废除</el-button>
        <el-button size="mini" type="primary" icon="el-icon-check"
        v-loading.fullscreen.lock="operateLoading" @click="recoveryData" v-privilege="activeMenu + 'RECOVERY'">启用</el-button>
      </el-row>
    </div>
    <div class="common-table-div">
      <el-table ref="dataTable" border :height="tableHeight" @current-change="handleCurrentChange" :data="table.list" highlight-current-row
      :exchangeFilterMap="{'valueFlag':{'1':'无效','0':'有效'}}"
      :icore-filter-flag="icoreFilterFlag" @row-click="getDataList2"
      :row-class-name="tableRowClassName">
        <el-table-column type="index" label="序号" fixed="left" align="center"></el-table-column>
        <!-- <el-table-column type="selection" width="55" align="center"></el-table-column> -->
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="dataNo" label="数据编号" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="carNo" label="车号" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="meterWeight" label="皮重（kg）" align="right"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="baseSpotName" label="皮重计量点" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="meterName" label="皮重计量员"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="meterTime" label="皮重计量时间" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="upWeight" label="上一次皮重（kg）" align="right"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="avgWeight" label="平均皮重（kg）" align="right"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="meterNum" label="皮重次数" align="right"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="valueFlag" label="状态" align="center">
          <template slot-scope="scope">
              <span v-if="scope.row.valueFlag == 1">无效</span>
              <span v-else-if="scope.row.valueFlag == 0">有效</span>
            </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="common-foot-style">
        <el-pagination v-loading="dataLoading" @size-change="pageSizeChange" @current-change="pageCurrentChange"
          :current-page="page.pageNum" :page-sizes="[100, 500, 1000]" :page-size="page.pageSize" layout="total, sizes, prev, pager, next, jumper"
          :total="page.totalPage">
        </el-pagination>
    </div>
    <div class="common-table-div">
      <div class="common-title-div">皮重明细
      </div>
      <el-table ref="dataTable2" border :height="tableHeight"  :data="table.list2" highlight-current-row
      :icore-filter-flag="icoreFilterFlag">
        <el-table-column type="index" label="序号" fixed="left" align="center"></el-table-column>
        <!-- <el-table-column type="selection" width="55" align="center"></el-table-column> -->
        <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="detailNo" label="数据编号" align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="actualFirstNo" label="作业编号" align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="meterWeight" label="皮重（kg）" align="right"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="carNo" label="车号" align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="baseSpotName" label="计量点"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="meterName" label="计量员" align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="meterTime" label="计量时间" align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="meterOrder" label="计量次序" align="right"></el-table-column>
      </el-table>
    </div>
    <div class="common-foot-style">
        <el-pagination v-loading="dataLoading" @size-change="pageSizeChange2" @current-change="pageCurrentChange2"
          :current-page="page2.pageNum" :page-sizes="[100, 500, 1000]" :page-size="page2.pageSize" layout="total, sizes, prev, pager, next, jumper"
          :total="page2.totalPage">
        </el-pagination>
    </div>
  </div>
</template>
<script>
 import {
    meterbasehistaredatas,
    meterbasehistaredetails
  } from '../../../utils/api.js';
  import {
    discardOne,
    RecoveryOne
  } from '../../../utils/httpRequest.js';
  export default {
    data () {
      return {
        dataLoading: false,
        operateLoading: false,
        icoreFilterFlag: true,
        page: {
          pageSize: 500,
          pageNum: 1,
          totalPage: 0
        },
        page2: {
          pageSize: 500,
          pageNum: 1,
          totalPage: 0
        },
        table: {
          list: [],
          list2: []
        },
        // multipleSelection: {},
        tableHeight: 0,
        search: {
          carNo: ''
        },
        firstRow: {},
        activeMenu: ''
      }
    },
    created () {
      this.tableHeight = (window.innerHeight - 220)/2 > 200 ? (window.innerHeight - 220)/2 : 200;
      this.activeMenu = window.top.localStorage.getItem('activeMenu')
    },
    mounted () {
      // this.tableHeight = this.getTableHeight(this.$refs['dataTable'].$el) - 80;
      this.getDataList();
      // this.getDataList2();
    },
    methods: {
      rowChange (row, column, event) {
        this.baseData = Object.assign ({}, row);
      },
      searchDatas () {
        this.page.pageNum = 1;
        this.searchData()
      },
      searchData () {
        this.dataLoading = true;
        this.axios.get(meterbasehistaredatas + 'like/?pageNum=' + this.page.pageNum + '&pageSize=' + this.page.pageSize +
            '&carNo=' + this.search.carNo)
          .then(res => {
            this.dataLoading = false;
            this.table.list = res.data.list;
            if (res.data.list.length > 0){
              this.$refs.dataTable.setCurrentRow(res.data.list[0])
              this.getDataList2(res.data.list[0])
            } else {
              this.table.list2 = []
            }
            this.page.totalPage = res.data.total;
          }).catch(e => {
            this.dataLoading = false;
          });
      },
      recoveryData () {
        let _this = this;
        _this.operateLoading = true;
        RecoveryOne(meterbasehistaredatas + 'Recovery', _this.multipleSelection, (e) => {
          _this.operateLoading = false;
          if (!e) {
            _this.getDataList();
          }
        });
      },
      abolishData () {
        let _this = this;
        _this.operateLoading = true;
        discardOne(meterbasehistaredatas + 'abolish', _this.multipleSelection, (e) => {
          _this.operateLoading = false;
          if (!e) {
            _this.getDataList();
          }
        });
      },
      handleCurrentChange (val) {
        this.multipleSelection = val;
      },
      getTableHeight (dom) {
        return (window.innerHeight - dom.offsetTop);
      },
      pageSizeChange (size) {
        this.page.pageSize = size;
        this.searchData()
      },

      pageCurrentChange (index) {
        this.page.pageNum = index;
        this.searchData()
      },
      pageSizeChange2 (size) {
        this.page2.pageSize = size;
        this.getDataList2(this.firstRow);
      },

      pageCurrentChange2 (index) {
        this.page2.pageNum = index;
        this.getDataList2(this.firstRow);
      },
      getDataList () {
        this.dataLoading = true;
        this.axios.get(meterbasehistaredatas + '?pageNum=' + this.page.pageNum + '&pageSize=' + this.page.pageSize)
          .then(res => {
            this.dataLoading = false;
            this.table.list = res.data.list;
            if (res.data.list.length > 0){
              this.$refs.dataTable.setCurrentRow(res.data.list[0])
              this.getDataList2(res.data.list[0])
            } else {
              this.table.list2 = []
            }
            this.page.totalPage = res.data.total;
          }).catch(e => {
            this.dataLoading = false;
          });
      },
      getDataList2 (row) {
        this.firstRow = row
        this.dataLoading = true;
        this.axios.get(meterbasehistaredetails + '?pageNum=' + this.page2.pageNum + '&pageSize=' + this.page2.pageSize + '&carNo=' + row.carNo)
          .then(res => {
            this.dataLoading = false;
            this.table.list2 = res.data.list;
            this.page2.totalPage = res.data.total;
          }).catch(e => {
            this.dataLoading = false;
          });
      },
      tableRowClassName ({
        row,
        rowIndex
      }) {
        if (row.valueFlag == '1') {
          return 'error-row2';
        }
        return '';
      }
    }
  }
</script>
<style scoped>
  .el-select {
    width: 100%;
  }
</style>
