<!--车辆黑名单管理-->
<template>
  <div class="systemBase common-container-deriction">
    <div class="common-title-div">
      <el-form
        ref="searchData2"
        :inline="true"
        :model="searchForm"
        style="padding-left: 12px"
      >
        <el-form-item>
          <div style="font-size: 16px; padding: 0px 20px">车辆黑名单管理</div>
        </el-form-item>
        <el-form-item prop="carNo" label="车号">
          <el-input
            v-model="searchForm.carNo"
            clearable
            size="small"
            style="width: 120px"
            placeholder="请输入"
          ></el-input>
        </el-form-item>
        <el-form-item label-width="20px">
          <el-button
            icon="el-icon-search"
            type="primary"
            size="mini"
            @click="getDataList"
            v-loading.fullscreen.lock="operateLoading"
            >查询</el-button
          >
          <el-button
            icon="el-icon-circle-plus-outline"
            type="primary"
            size="mini"
            v-loading.fullscreen.lock="operateLoading"
            @click="addData"
            v-privilege="activeMenu + 'ADD'"
            >新增</el-button
          >
          <el-button
            icon="el-icon-edit"
            type="primary"
            size="mini"
            v-loading.fullscreen.lock="operateLoading"
            @click="modifyData"
            v-privilege="activeMenu + 'UPDATE'"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="danger"
            plain
            icon="el-icon-remove-outline"
            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-form-item>
      </el-form>
    </div>
    <div class="common-table-div">
      <el-table
        v-loading="dataLoading"
        @row-click="rowChange"
        ref="dataTable"
        :row-class-name="tableRowClassName"
        highlight-current-row
        border
        :height="tableHeight"
        @selection-change="handleSelectionChange"
        :data="table.list"
        :exchangeFilterMap="{ valueFlag: { '1': '无效', '0': '有效' } }"
        :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
          sortable
          :show-overflow-tooltip="true"
          min-width="80px"
          prop="carNo"
          label="车号"
          align="center"
        ></el-table-column>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          min-width="80px"
          prop="carOwnerName"
          label="车主姓名"
          align="center"
        ></el-table-column>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          min-width="80px"
          prop="carDriverName"
          label="驾驶员"
          align="center"
        ></el-table-column>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          min-width="120px"
          prop="carUnderUnit"
          label="隶属单位"
          align="center"
        ></el-table-column>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          min-width="200px"
          prop="punishReason"
          label="处罚原因"
          align="center"
        ></el-table-column>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          min-width="200px"
          prop="punishResult"
          label="处罚结果"
          align="center"
        ></el-table-column>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          prop="valueFlag"
          width="60px"
          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-column
          sortable
          :show-overflow-tooltip="true"
          min-width="200px"
          prop="memo"
          label="备注"
          align="center"
        ></el-table-column>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          min-width="80px"
          prop="createManName"
          label="创建人"
          align="center"
        ></el-table-column>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          min-width="160px"
          prop="createTime"
          label="创建时间"
          align="center"
        ></el-table-column>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          min-width="80px"
          prop="updateManName"
          label="修改人"
          align="center"
        ></el-table-column>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          min-width="160px"
          prop="updateTime"
          label="修改时间"
          align="center"
        ></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 ref="editTitle" class="common-title-div" style="border-top: 1px solid #d5d5d5;">编辑区
    </div> -->
    <div
      ref="editDiv"
      class="commom-edit-div"
      style="border-top: 1px solid #d5d5d5; margin-top: 10px"
    >
      <el-form
        ref="baseData"
        label-width="80px"
        :inline="true"
        :rules="ruleValidate"
        :model="baseData"
      >
        <el-form-item prop="carNo" label="车号">
          <el-input
            v-model="baseData.carNo"
            size="small"
            clearable
            placeholder="请输入"
            style="width: 150px"
          ></el-input>
        </el-form-item>
        <el-form-item prop="carDriverName" label="驾驶员">
          <el-input
            v-model="baseData.carDriverName"
            size="small"
            clearable
            placeholder="请输入"
            style="width: 150px"
          ></el-input>
        </el-form-item>
        <el-form-item prop="carOwnerName" label="车主姓名">
          <el-input
            v-model="baseData.carOwnerName"
            size="small"
            clearable
            placeholder="请输入"
            style="width: 150px"
          ></el-input>
        </el-form-item>
        <el-form-item prop="carUnderUnit" label="隶属单位">
          <el-input
            v-model="baseData.carUnderUnit"
            size="small"
            clearable
            placeholder="请输入"
            style="width: 150px"
          ></el-input>
        </el-form-item>
        <el-form-item prop="punishReason" label="处罚原因">
          <el-input
            v-model="baseData.punishReason"
            size="small"
            clearable
            placeholder="请输入"
            style="width: 150px"
          ></el-input>
        </el-form-item>
        <el-form-item prop="punishResult" label="处罚结果">
          <el-input
            v-model="baseData.punishResult"
            size="small"
            clearable
            placeholder="请输入"
            style="width: 150px"
          ></el-input>
        </el-form-item>
        <el-form-item prop="memo" label="备注">
          <el-input
            v-model="baseData.memo"
            size="small"
            clearable
            placeholder="请输入"
            style="width: 150px"
          ></el-input>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import {
  meterbasecarblacelists
} from '../../../utils/api.js';
import {
  Delete,
  Recovery,
  add,
  modify,
  discard
} from '../../../utils/httpRequest.js';
import pinyinUtils from '../../../utils/pinyin/pinyinUtils.js'
export default {
  data () {
    return {
      dataLoading: false,
      operateLoading: false,
      icoreFilterFlag: true,
      baseData: {
        carNo: '',
        carDriverName: '',
        carOwnerName: '',
        carUnderUnit: '',
        punishReason: '',
        punishResult: '',
        memo: ''
      },
      page: {
        pageSize: 500,
        pageNum: 1,
        totalPage: 0
      },
      table: {
        list: []
      },
      multipleSelection: [],
      tableHeight: 0,
      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'
        }],
        punishReason: [{
          required: true,
          message: '处罚原因不能为空',
          trigger: 'change'
        }],
        punishResult: [{
          required: true,
          message: '处罚结果不能为空',
          trigger: 'change'
        }]
      },
      activeMenu: '',
      searchForm: {
        carNo: ''
      }
    }
  },
  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();
  },
  methods: {
    rowChange (row, column, event) {
      let row1 = Object.assign({}, row)
      this.baseData = row1;
    },
    addData () {
      let _this = this;
      _this.$refs['baseData'].validate((valid) => {
        if (valid) {
          _this.operateLoading = true;
          let baseDataAdd = {};
          baseDataAdd.carNo = _this.baseData.carNo
          baseDataAdd.carDriverName = _this.baseData.carDriverName
          baseDataAdd.carOwnerName = _this.baseData.carOwnerName
          baseDataAdd.carUnderUnit = _this.baseData.carUnderUnit
          baseDataAdd.punishReason = _this.baseData.punishReason
          baseDataAdd.punishResult = _this.baseData.punishResult
          baseDataAdd.memo = _this.baseData.memo
          add(meterbasecarblacelists, baseDataAdd, (e) => {
            _this.operateLoading = false;
            _this.getDataList();
            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(meterbasecarblacelists + _this.baseData.blacelistNo + '/', _this.baseData, (e) => {
            _this.operateLoading = false;
            _this.getDataList();
            if (!e) {
              _this.$refs['baseData'].resetFields && _this.$refs['baseData'].resetFields();
            }
          })
        }
      });
    },
    recoveryData () {
      let _this = this;
      _this.operateLoading = true;
      Recovery(meterbasecarblacelists + 'Recovery', _this.multipleSelection, (e) => {
        _this.operateLoading = false;
        if (!e) {
          _this.getDataList();
        }
      });
    },
    // deleteData () {
    //   this.$confirm('确定删除选中的计量组件信息？', {
    //       confirmButtonText: '确定',
    //       cancelButtonText: '取消'
    //     })
    //     .then(() => {
    //       this.operateLoading = true;
    //       Delete(meterbasecarblacelists, this.multipleSelection, (e) => {
    //         this.operateLoading = false;
    //         if (!e) {
    //           this.getDataList();
    //         }
    //       })
    //     })
    //     .catch(action => {
    //       this.$message({
    //         type: 'info',
    //         message: action === 'cancel' ? '放弃保存并离开页面' : '停留在当前页面'
    //       })
    //     });
    // },
    abolishData () {
      let _this = this;
      _this.operateLoading = true;
      discard(meterbasecarblacelists + 'abolish', _this.multipleSelection, (e) => {
        _this.operateLoading = false;
        if (!e) {
          _this.getDataList();
        }
      });
    },
    handleSelectionChange (val) {
      this.multipleSelection = val;
    },
    getTableHeight (dom) {
      return (window.innerHeight - dom.offsetTop);
    },
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.getDataList();
    },

    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.getDataList(2);
    },
    getDataList (flag = 1) {
      if (flag === 1) {
        this.page.pageNum = 1
      }
      this.dataLoading = true;
      this.axios.get(meterbasecarblacelists + '?pageNum=' + this.page.pageNum + '&pageSize=' + this.page.pageSize + '&carNo=' + this.searchForm.carNo)
        .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 !== '0') {
        return 'error-row2';
      }
      return '';
    }
    // myBlur() {
    //   if (this.baseData.customerSupplierName) {
    //     this.baseData.mnemonicCode = pinyinUtils.initial(this.baseData.customerSupplierName);
    //   }
    // }
  }
}
</script>
<style scoped>
.el-select {
  width: 100%;
}
</style>
