<!--期限皮重数据维护-->
<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 clearable v-model="search.carNo" placeholder="请输入" size="small" 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 + 'DELETE'">废除</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-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="80" prop="carNo" label="车号" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="80" prop="meterWeight" label="皮重（kg）" align="right"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120" prop="baseSpotName" label="皮重计量点" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120" prop="meterName" label="皮重计量员" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160" prop="meterTime" label="皮重计量时间" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160" prop="startTime" label="有效开始时间" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160" prop="endTime" label="有效结束时间" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160" prop="warnTime" label="提醒留皮时间" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120" prop="upWeight" label="上一次皮重（kg）" align="right"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120" prop="avgWeight" label="平均皮重（kg）" align="right"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120" prop="meterNum" label="皮重次数" align="right"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="80" 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>
</template>

<script>
  import {
    meterbasetermtaredatas
  } from '../../../utils/api.js';
  import {
    discardOne,
    RecoveryOne
    // add,
    // modify
  } from '../../../utils/httpRequest.js';
  export default {
    data () {
      return {
        dataLoading: false,
        operateLoading: false,
        icoreFilterFlag: true,
        tableHeight: 0,
        // valueFlagIndex: 0,
        // valueFlag: [
        //   {id: '0', name: '服役'},
        //   {id: '1', name: '停役'}
        // ],
        // baseData: {
        //   carNo: '',
        //   carDriverName: '',
        //   carOwnerName: '',
        //   carUnderUnit: '',
        //   memo: ''
        // },
        page: {
          pageSize: 500,
          pageNum: 1,
          totalPage: 0
        },
        table: {
          list: []
        },
        // multipleSelection: {},
        // ruleValidate: {
        //   carNo: [{
        //     required: true,
        //     message: '车号不能为空',
        //     trigger: 'change'
        //   }],
        //   carDriverName: [{
        //     required: true,
        //     message: '驾驶员不能为空',
        //     trigger: 'change'
        //   }],
        //   carOwnerName: [{
        //     required: true,
        //     message: '车主姓名不能为空',
        //     trigger: 'change'
        //   }],
        //   carUnderUnit: [{
        //     required: true,
        //     message: '隶属单位不能为空',
        //     trigger: 'change'
        //   }]
        // },
        search: {
          carNo: ''
        },
        activeMenu: ''
      }
    },
    created () {
      this.tableHeight = (window.innerHeight - 220) > 400 ? window.innerHeight - 220 : 400;
      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) {
        let row1 = Object.assign ({}, row)
        this.baseData = row1;
      },
      // baseDataClear () {
      //   this.baseData.carNo = '';
      //   this.baseData.carDriverName = '';
      //   this.baseData.carOwnerName = '';
      //   this.baseData.carUnderUnit = '';
      //   this.baseData.memo = '';
      // },
      searchDatas () {
        this.page.pageNum = 1;
        this.searchData()
      },
      searchData () {
        this.dataLoading = true;
        this.icoreFilterFlag = false
        this.axios.get(meterbasetermtaredatas + 'like/?pageNum=' + this.page.pageNum + '&pageSize=' + this.page.pageSize +
            '&carNo=' + this.search.carNo)
          .then(res => {
            this.icoreFilterFlag = true
            this.dataLoading = false;
            this.table.list = res.data.list;
            this.page.totalPage = res.data.total;
          }).catch(e => {
            this.icoreFilterFlag = true
            this.dataLoading = false;
          });
      },
      // addData () {
      //   let _this = this;
      //   _this.$refs['baseData'].validate((valid) => {
      //     if (valid) {
      //       _this.operateLoading = true;
      //       add (meterbasetermtaredatas, _this.baseData, (e) => {
      //         _this.operateLoading = false;
      //         _this.getDataList();
      //         _this.baseDataClear();
      //         if (!e) {
      //           _this.$refs['baseData'].resetFields && _this.$refs['baseData'].resetFields();
      //         }
      //       })
      //     }
      //   });
      // },
      // modifyData () {
      //   let _this = this;
      //   _this.$refs['baseData'].validate((valid) => {
      //     if (valid) {
      //       _this.operateLoading = true;
      //       modify (meterbasetermtaredatas + _this.baseData.carNo + '/', _this.baseData, (e) => {
      //         _this.operateLoading = false;
      //         _this.getDataList();
      //         _this.baseDataClear();
      //         if (!e) {
      //           _this.$refs['baseData'].resetFields && _this.$refs['baseData'].resetFields();
      //         }
      //       })
      //     }
      //   });
      // },
      recoveryData () {
        let _this = this;
        _this.operateLoading = true;
        RecoveryOne(meterbasetermtaredatas + 'Recovery', _this.multipleSelection, (e) => {
          _this.operateLoading = false;
          if (!e) {
            _this.getDataList();
          }
        });
      },
      abolishData () {
        let _this = this;
        _this.operateLoading = true;
        discardOne(meterbasetermtaredatas + 'abolish', _this.multipleSelection, (e) => {
          _this.operateLoading = false;
          if (!e) {
            _this.getDataList();
          }
        });
      },
      // deleteData () {
      //   this.$confirm('确定删除选中的客运车辆？', {
      //       confirmButtonText: '确定',
      //       cancelButtonText: '取消'
      //     })
      //     .then(() => {
      //       this.operateLoading = true;
      //       Delete(meterbasetermtaredatas, this.multipleSelection, (e) => {
      //         this.operateLoading = false;
      //         if (!e) {
      //           this.getDataList();
      //         }
      //       })
      //     })
      //     .catch(action => {
      //       this.$message({
      //         type: 'info',
      //         message: action === 'cancel' ? '放弃保存并离开页面' : '停留在当前页面'
      //       })
      //     });
      // },
      handleCurrentChange (val) {
        this.multipleSelection = val;
      },
      getTableHeight (dom) {
        return (window.innerHeight - dom.offsetTop);
      },
      pageSizeChange (size) {
        this.page.pageSize = size;
        // this.getDataList();
        this.searchData()
      },

      pageCurrentChange (index) {
        this.page.pageNum = index;
        // this.getDataList();
        this.searchData()
      },
      getDataList () {
        this.dataLoading = true;
        this.axios.get(meterbasetermtaredatas + '?pageNum=' + this.page.pageNum + '&pageSize=' + this.page.pageSize)
          .then(res => {
            this.dataLoading = false;
            this.table.list = res.data.list;
            this.page.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>
