<!--车辆核查登记管理-->
<template>
  <div class="systemBase">
    <div>
       <el-row>
         <el-col :span="12" style="border-right: 1px solid #d5d5d5;">
             <div style="margin-top: 10px;  border-bottom: 1px solid #d5d5d5;">
               <el-form ref="searchData" :inline="true" :model="search">
                  <el-form-item label-width="60px" prop="carNo" label="车号">
                   <el-input v-model="search.carNo" clearable size="small" style="width:120px" placeholder="请输入"></el-input>
                  </el-form-item>
                   <el-form-item prop="checkResult" label="核查结果">
                    <el-select v-model="search.checkResult"  clearable filterable collapse-tags size="small" style="width:120px">
                        <el-option v-for="(item,index) in checkResultItem" :key="index" :label="item.checkResult"
                         :value="item.checkResult">
                        </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label-width="20px">
                  <el-button icon="el-icon-search" type="primary" size="mini" @click="searchDatas" v-loading.fullscreen.lock="operateLoading" v-privilege="activeMenu + 'SEARCH'">查询</el-button>
                  </el-form-item>
                   </el-form>
               </div>
               <div style="margin-top: 10px;  border-bottom: 1px solid #d5d5d5;">
               <el-form :inline="true">
                   <el-form-item>
                      <div style="font-size: 14px; padding: 0px 20px;">车辆进厂核查登记管理
                      </div>
                  </el-form-item>
                  <el-form-item label-width="20px">
                  <el-button icon="el-icon-check" type="primary" size="mini" v-loading.fullscreen.lock="operateLoading"
                  @click="recoveryData" v-privilege="activeMenu + 'INCOMINGIN'">进厂核查</el-button>
                  </el-form-item>
                  <el-form-item label-width="20px">
                   <el-button size="mini" type="danger" plain icon="el-icon-remove-outline" v-loading.fullscreen.lock="operateLoading"
                   @click="discardData" v-privilege="activeMenu + 'ENTRY'">进厂撤销</el-button>
                  </el-form-item>
               </el-form>
                </div>
            <div class="common-table-div">
               <el-table ref="dataTable"  
                 border 
                 :height="tableHeight" 
                 highlight-current-row
                 @selection-change="handleSelectionChange"
                 :data="table.list" 
                 :exchangeFilterMap="{
                 'transportChemical':{'0':'否','1':'是'},
                 'waterBoxIsEmpty':{'0':'空','1':'非空'},
                 'checkResult':{'0':'正常','1':'异常'},
                 'valueFlag':{'0':'进厂核查','1':'出厂核查'}}"
                 :icore-filter-flag="icoreFilterFlag">
                 <el-table-column type="index" label="序号" fixed="left" align="center"></el-table-column>
                 <el-table-column type="selection" width="55" fixed="left" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="predictionNo" 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="mnemonicCode" label="挂号" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="driverName" label="司机姓名" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" prop="idNum" min-width="200px" label="身份证号" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="telNum" label="联系电话" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="customerSupplierName" label="供应商" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="transportChemical" label="可运危化品" align="center">
                   <template slot-scope="scope">
                     <span v-if="scope.row.transportChemical == 0">否</span>
                     <span v-else-if="scope.row.transportChemical == 1">是</span>
                   </template>
                 </el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="limitWeight" label="限载重量" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="tote" label="携带物" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="waterBoxIsEmpty" label="水箱为空" align="center">
                   <template slot-scope="scope">
                     <span v-if="scope.row.waterBoxIsEmpty == 0">空</span>
                     <span v-else-if="scope.row.waterBoxIsEmpty == 1">非空</span>
                   </template>
                 </el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="enterCheckManName" label="进厂核查人" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="enterCheckTime" label="进厂核查时间" align="center"></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="100px" prop="checkResult" label="核查结果" align="center">
                   <template slot-scope="scope">
                     <span v-if="scope.row.checkResult == 0">正常</span>
                     <span v-else-if="scope.row.checkResult == 1">异常</span>
                   </template>
                 </el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" prop="valueFlag" min-width="100px" label="状态" align="center">
                   <template slot-scope="scope">
                     <span v-if="scope.row.valueFlag == 0">进厂核查</span>
                     <span v-else-if="scope.row.valueFlag == 1">出厂核查</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 ref="editDiv" class="commom-edit-div" style="border-top: 1px solid #d5d5d5; margin-top: 10px">
               <el-form ref="baseData" :inline="true" label-width="95px" :rules="ruleValidateTable" :model="baseData">
                  <el-form-item prop="limitWeight" label="限载重量">
                   <el-input v-model="baseData.limitWeight" clearable size="small" style="width:120px" placeholder="请输入"></el-input>
                  </el-form-item>
                  <el-form-item prop="tote" label="携带物">
                   <el-input v-model="baseData.tote" clearable size="small" style="width:120px" placeholder="请输入"></el-input>
                  </el-form-item>
                   <el-form-item prop="waterBoxIsEmpty" label="水箱为空">
                      <el-select v-model="baseData.waterBoxIsEmpty"  filterable collapse-tags size="small" style="width:120px">
                          <el-option v-for="(item,index) in waterBoxIsEmptyItem" :key="index" :label="item.waterBoxIsEmpty"
                           :value="item.waterBoxIsEmpty">
                          </el-option>
                      </el-select>
                   </el-form-item>
                    <el-form-item prop="transportChemical" label="是否可运危化品">
                      <el-select v-model="baseData.transportChemical"  filterable collapse-tags size="small" style="width:120px">
                          <el-option v-for="(item,index) in transportChemicalItem" :key="index" :label="item.transportChemical"
                           :value="item.transportChemical">
                          </el-option>
                      </el-select>
                   </el-form-item>
                   <el-form-item prop="driverName" label="司机姓名">
                   <el-input v-model="baseData.driverName" clearable size="small" style="width:120px" placeholder="请输入"></el-input>
                  </el-form-item>
                  <el-form-item prop="idNum" label="身份证号">
                   <el-input v-model="baseData.idNum" clearable size="small" style="width:120px" placeholder="请输入"></el-input>
                  </el-form-item>
                   <el-form-item prop="telNum" label="联系电话">
                   <el-input v-model="baseData.telNum" clearable size="small" style="width:120px" placeholder="请输入"></el-input>
                  </el-form-item>
                   <el-form-item prop="checkResult" label="核查结果">
                      <el-select v-model="baseData.checkResult" filterable collapse-tags size="small" style="width:120px">
                          <el-option v-for="(item,index) in checkResultItem" :key="index" :label="item.checkResult"
                           :value="item.checkResult">
                          </el-option>
                      </el-select>
                   </el-form-item>
                  <el-form-item prop="memo" label="备注">
                   <el-input v-model="baseData.memo" clearable size="small" style="width:120px" placeholder="请输入"></el-input>
                  </el-form-item>
               </el-form>
             </div>
         </el-col>
         <el-col :span="12">
             <div style="margin-top: 10px;  border-bottom: 1px solid #d5d5d5;">
               <el-form ref="searchData2" :inline="true" :model="search2">
                  <el-form-item prop="carNo" label-width="60px" label="车号">
                   <el-input v-model="search2.carNo" clearable size="small" style="width:120px" placeholder="请输入"></el-input>
                  </el-form-item>
                   <el-form-item prop="checkResult" label="核查结果">
                    <el-select v-model="search2.checkResult"  clearable filterable collapse-tags size="small" style="width:120px">
                        <el-option v-for="(item,index) in checkResultItem" :key="index" :label="item.checkResult"
                         :value="item.checkResult">
                        </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label-width="20px">
                  <el-button icon="el-icon-search" type="primary" size="mini" @click="getDataList2" v-loading.fullscreen.lock="operateLoading" v-privilege="activeMenu + 'SEARCH2'">查询</el-button>
                  </el-form-item>
               </el-form>
             </div>
             <div style="margin-top: 10px;  border-bottom: 1px solid #d5d5d5;">
               <el-form :inline="true">
                  <el-form-item>
                      <div style="font-size: 14px; padding: 0px 20px;">车辆出厂核查登记管理
                      </div>
                  </el-form-item>
                  <el-form-item>
                  <el-button size="mini" type="primary" icon="el-icon-check" v-loading.fullscreen.lock="operateLoading"
                   @click="recoveryData2" v-privilege="activeMenu + 'FACTORYINS'">出厂核查</el-button>
                  </el-form-item>
                   <el-form-item label-width="20px">
                   <el-button size="mini" type="danger" plain icon="el-icon-remove-outline" v-loading.fullscreen.lock="operateLoading"
                   @click="discardData2" v-privilege="activeMenu + 'FACTORCAN'">出厂撤销</el-button>
                  </el-form-item>
               </el-form>
             </div>
            <div class="common-table-div">
               <el-table ref="dataTable2"  
                 border 
                 :height="tableHeight2" 
                 highlight-current-row
                 @selection-change="handleSelectionChange2"
                 :data="table.list2" 
                 :exchangeFilterMap="{
                 'transportChemical':{'0':'否','1':'是'},
                 'waterBoxIsEmpty':{'0':'空','1':'非空'},
                 'checkResult':{'0':'正常','1':'异常'},
                 'valueFlag':{'0':'进厂核查','1':'出厂核查'}}"
                 :icore-filter-flag="icoreFilterFlag">
                 <el-table-column type="index" label="序号" fixed="left" align="center"></el-table-column>
                 <el-table-column type="selection" width="55" fixed="left" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="predictionNo" 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="mnemonicCode" label="挂号" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="driverName" label="司机姓名" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" prop="idNum" min-width="200px" label="身份证号" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="telNum" label="联系电话" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="customerSupplierName" label="供应商" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="transportChemical" label="可运危化品" align="center">
                   <template slot-scope="scope">
                     <span v-if="scope.row.transportChemical == 0">否</span>
                     <span v-else-if="scope.row.transportChemical == 1">是</span>
                   </template>
                 </el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="limitWeight" label="限载重量" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="tote" label="携带物" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="waterBoxIsEmpty" label="水箱为空" align="center">
                   <template slot-scope="scope">
                     <span v-if="scope.row.waterBoxIsEmpty == 0">空</span>
                     <span v-else-if="scope.row.waterBoxIsEmpty == 1">非空</span>
                   </template>
                 </el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="leaveCheckManName" label="出厂核查人" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="leaveCheckTime" label="出厂核查时间" align="center"></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="100px" prop="checkResult" label="核查结果" align="center">
                   <template slot-scope="scope">
                     <span v-if="scope.row.checkResult == 0">正常</span>
                     <span v-else-if="scope.row.checkResult == 1">异常</span>
                   </template>
                 </el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" prop="valueFlag" min-width="100px" label="状态" align="center">
                   <template slot-scope="scope">
                     <span v-if="scope.row.valueFlag == 0">进厂核查</span>
                     <span v-else-if="scope.row.valueFlag == 1">出厂核查</span>
                   </template>
                 </el-table-column>
               </el-table>
             </div>
             <div class="common-foot-style">
              <el-pagination v-loading="dataLoading2" @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>
         </el-col>
       </el-row>
    </div>
  </div>
</template>
<script>
import {formatDate} from '@/utils/util.js';
  export default {
    data () {
      return {
        dataLoading: false,
        operateLoading: false,
        dataLoading2: false,
        operateLoading2: false,
        icoreFilterFlag: true,
        valueFlagItem: [
            {valueFlag:'进厂核查'},
            {valueFlag:'出厂核查'}
        ],
        checkResultItem: [
            {id:'0', checkResult:'正常'},
            {id:'1', checkResult:'异常'}
        ],
        transportChemicalItem: [
            {id:'0', transportChemical:'否'},
            {id:'1', transportChemical:'是'}
        ],
        waterBoxIsEmptyItem: [
          {id:'0', waterBoxIsEmpty:'空'},
          {id:'1', waterBoxIsEmpty:'非空'},
        ],
        page: {
          pageSize: 500,
          pageNum: 1,
          totalPage: 0
        },
        page2: {
          pageSize: 500,
          pageNum: 1,
          totalPage: 0
        },
        table: {
          list: [],
          list2: []
        },
        baseData: {
            limitWeight: '',
            waterBoxIsEmpty: '空',
            transportChemical: '否',
            driverName: '',
            idNum: '',
            telNum: '',
            checkResult: '正常',
            memo: '',
            tote: ''
        },
        search: {
            carNo: '',
            checkResult: ''
        },
        search2: {
            carNo: '',
            checkResult: ''
        },
        multipleSelection: [],
        multipleSelection2: [],
        tableHeight: 0,
        ruleValidateTable: {
          driverName: [{
            required: true,
            message: '该项不能为空',
            trigger: 'change'
          }],
          idNum: [{
            required: true,
            message: '该项不能为空',
            trigger: 'change'
          },
          {pattern:/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, 
          message: '你的身份证格式不正确' }],
          telNum: [
          {
            required: true,
            message: '该项不能为空',
            trigger: 'change'
          },
          {validator:function(rule,value,callback){
	            if(/^1[3456789]\d{9}$/.test(value) == false){
	                callback(new Error("请输入正确的手机号"));
	            }else{
	                callback();
	            }
	        }, trigger: 'blur'}],
        },
        ruleValidateTable2: {
          driverName: [{
            required: true,
            message: '该项不能为空',
            trigger: 'change'
          }],
          idNum: [{
            required: true,
            message: '该项不能为空',
            trigger: 'change'
          },
          {pattern:/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, 
          message: '你的身份证格式不正确' }],
          telNum: [
          {
            required: true,
            message: '该项不能为空',
            trigger: 'change'
          },
          {validator:function(rule,value,callback){
	            if(/^1[3456789]\d{9}$/.test(value) == false){
	                callback(new Error("请输入正确的手机号"));
	            }else{
	                callback();
	            }
	        }, trigger: 'blur'}],
        },
        activeMenu: ''
      }
    },
    created(){
      this.tableHeight = (window.innerHeight - 300) > 300 ? window.innerHeight - 300 : 300;
      this.tableHeight2 = (window.innerHeight - 180) > 420 ? window.innerHeight - 180 : 420;
      this.activeMenu = window.top.localStorage.getItem('activeMenu')
    },
    mounted () {
      this.getDataList()
      this.getDataList2()
    },
    methods: {
     getCode (code, arr, codeKey, nameKey) {
      if (!code) {
        return '';
      }
      let targetRow = arr.find(item => {
        return item[codeKey] === code;
      });
      return targetRow ? targetRow[nameKey] : '';
    },
    refresh () {
      this.baseData = {
            limitWeight: '',
            waterBoxIsEmpty: '空',
            transportChemical: '否',
            driverName: '',
            idNum: '',
            telNum: '',
            checkResult: '正常',
            memo: '',
            tote: ''
        }
        this.$refs['baseData'].resetFields();
    },
    recoveryData () {
       this.$refs['baseData'].validate((valid) => {
          if (valid) {
             if (this.multipleSelection.length !== 1) {
                  this.$message.warning('请选择一条您要进厂核查的数据！');
                  return;
             }
             this.multipleSelection[0].limitWeight = this.baseData.limitWeight;
             this.multipleSelection[0].waterBoxIsEmpty = this.getCode (this.baseData.waterBoxIsEmpty, this.waterBoxIsEmptyItem, 'waterBoxIsEmpty', 'id');
             this.multipleSelection[0].transportChemical = this.getCode (this.baseData.transportChemical, this.transportChemicalItem, 'transportChemical', 'id');
             this.multipleSelection[0].driverName = this.baseData.driverName;
             this.multipleSelection[0].idNum = this.baseData.idNum;
             this.multipleSelection[0].telNum = this.baseData.telNum;
             this.multipleSelection[0].checkResult = this.getCode (this.baseData.checkResult, this.checkResultItem, 'checkResult', 'id');
             this.multipleSelection[0].memo = this.baseData.memo;
             this.multipleSelection[0].tote = this.baseData.tote;
             this.axios.post('pass/systemBase/v1/meterworkcarchecks/incomeAndCheck', this.multipleSelection[0], {individualType: 'json'}).then(res=>{
               if (res.succeed) {
                  this.$message.success('进厂核查成功');
                  this.getDataList ();
                  this.refresh();
               }  else {
                this.$message.error(res.message)
               }
               }).catch(e => {
                this.$message.error(e.message)
              })
          }
       })
    },//进厂核查
    discardData () {
      if (this.multipleSelection.length < 1) {
        this.$message.warning('请选择您要进厂撤销的数据！');
        return;
      }
      this.axios.post('pass/systemBase/v1/meterworkcarchecks/incomeAndDelete', this.multipleSelection, {individualType: 'json'}).then(res => {
         if (res.succeed) {
           this.$message.success('进厂撤销成功');
           this.getDataList ();
        }  else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
    },//进厂撤销
    recoveryData2 () {
       if (this.multipleSelection2.length !== 1) {
            this.$message.warning('请选择一条您要出厂核查的数据！');
            return;
       }
       this.axios.post('pass/systemBase/v1/meterworkcarchecks/outcomeAndCheck', this.multipleSelection2[0], {individualType: 'json'}).then(res=>{
         if (res.succeed) {
            this.$message.success('出厂核查成功');
            this.getDataList2 ();
         }  else {
          this.$message.error(res.message)
         }
         }).catch(e => {
          this.$message.error(e.message)
        })
    },//出厂核查
    discardData2 () {
      if (this.multipleSelection2.length < 1) {
        this.$message.warning('请选择您要出厂撤销的数据！');
        return;
      }
      this.axios.post('pass/systemBase/v1/meterworkcarchecks/outcomeAndDelete', this.multipleSelection2, {individualType: 'json'}).then(res => {
         if (res.succeed) {
           this.$message.success('出厂撤销成功');
           this.getDataList2 ();
        }  else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
    },//出厂撤销
      handleSelectionChange (val) {
        this.multipleSelection = val;
      },
      pageSizeChange (size) {
        this.page.pageSize = size;
        this.getDataList();
      },
      pageCurrentChange (index) {
        this.page.pageNum = index;
        this.getDataList();
      },
      handleSelectionChange2 (val) {
        this.multipleSelection2 = val;
      },
      pageSizeChange2 (size) {
        this.page2.pageSize = size;
        this.getDataList2();
      },
      pageCurrentChange2 (index) {
        this.page2.pageNum = index;
        this.getDataList2();
      },
      searchDatas () {
          this.page.pageNum = 1;
          this.getDataList()
      },
      getDataList () {
        this.dataLoading = true;
        this.search.checkResult1 = this.search.checkResult === '正常' ? '0':this.search.checkResult === '异常'?'1':''
        this.axios.get('pass/systemBase/v1/meterworkcarchecks/relationIn' + '?pageNum=' + this.page.pageNum + '&pageSize=' + this.page.pageSize +
        '&carNo=' + this.search.carNo + '&checkResult=' + this.search.checkResult1)
          .then(res => {
            this.dataLoading = false;
            this.table.list = res.data.list;
            this.page.totalPage = res.data.total;
          }).catch(e => {
            this.dataLoading = false;
          });
      },
      getDataList2 () {
        this.dataLoading2 = true;
        this.search2.checkResult1 = this.search2.checkResult === '正常' ? '0':this.search2.checkResult === '异常'?'1':''
        this.axios.get('pass/systemBase/v1/meterworkcarchecks/relationOut' + '?pageNum=' + this.page2.pageNum + '&pageSize=' + this.page2.pageSize +
        '&carNo=' + this.search2.carNo + '&checkResult=' + this.search2.checkResult1)
          .then(res => {
            this.dataLoading2 = false;
            this.table.list2 = res.data.list;
            this.page2.totalPage = res.data.total;
          }).catch(e => {
            this.dataLoading2 = false;
          });
      }
    },
  }
</script>
<style scoped>
</style>