<!--静态轨道衡结净计量数据查询-->
<template>
  <div class="systemBase">
    <div>
      <div style="margin-top: 10px; border-bottom: 1px solid #d5d5d5">
        <el-form
          ref="searchData"
          :inline="true"
          :model="search"
          :rules="ruleValidateSearch"
        >
          <el-form-item label-width="70px" prop="railwayNo" label="车号">
            <el-input
              v-model="search.railwayNo"
              clearable
              size="small"
              style="width: 120px"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item prop="meterTypeName" label="业务类型">
            <el-select
              v-model="search.meterTypeName"
              clearable
              filterable
              collapse-tags
              size="small"
              style="width: 120px"
            >
              <el-option
                v-for="(item, index) in meterTypeNameItem"
                :key="index"
                :label="item.baseName"
                :value="item.baseName"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="matterNo" label="物资名称">
            <el-select
              v-model="search.matterNo"
              clearable
              filterable
              collapse-tags
              size="small"
              style="width: 120px"
              :filter-method="getMatterName"
            >
              <el-option
                v-for="item in matterNameItem"
                :key="item.matterNo"
                :label="item.matterName"
                :value="item.matterNo"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="uploadFlag" label="数据状态">
            <el-select
              v-model="search.uploadFlag"
              clearable
              filterable
              collapse-tags
              size="small"
              style="width: 120px"
            >
              <el-option
                v-for="(item, index) in uploadFlagItem"
                :key="index"
                :label="item.uploadFlag"
                :value="item.uploadFlag"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="strDate" label="开始时间">
            <el-date-picker
              v-model="search.strDate"
              clearable
              type="datetime"
              style="width: 180px"
              placeholder="选择日期"
              size="small"
            ></el-date-picker>
          </el-form-item>
          <el-form-item prop="envDate" label="结束时间">
            <el-date-picker
              v-model="search.envDate"
              clearable
              type="datetime"
              style="width: 180px"
              placeholder="选择日期"
              size="small"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label-width="20px">
            <el-button
              icon="el-icon-search"
              type="primary"
              size="mini"
              @click="searchData"
              v-loading.fullscreen.lock="operateLoading"
              v-privilege="activeMenu + 'SEARCH'"
              >查询</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <div style="border-right: 1px solid #d5d5d5">
        <div class="common-title-div">结净计量数据</div>
        <div class="common-table-div">
          <el-table
            v-loading="dataLoading"
            ref="dataTable"
            highlight-current-row
            border
            :height="tableHeight"
            @selection-change="handleSelectionChange"
            :data="table.list"
            :exchangeFilterMap="{
              uploadFlag: { '0': '待审核', '1': '待上传', '2': '已上传' },
              grossMode: {
                '1': '远程计量',
                '2': '智能计量',
                '3': '手工录入',
                '4': '放行智能计量',
                '5': '滞后匹配',
              },
              tareMode: {
                '1': '远程计量',
                '2': '智能计量',
                '3': '手工录入',
                '4': '放行智能计量',
                '5': '滞后匹配',
              },
              netMode: { '1': '正常结净', '2': '匹配结净' },
            }"
            :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"
              fixed="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="predictionNo"
              label="预报编号"
              min-width="80"
              align="left"
              fixed="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="railwayNo"
              label="车号"
              min-width="80"
              align="left"
              fixed="left"
            ></el-table-column>
            <!-- <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="railwayCarriageNo"
              label="车厢序号"
              min-width="80"
              align="left"
            ></el-table-column> -->
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="matterName"
              label="物资名称"
              min-width="120"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="contractNo"
              min-width="120"
              label="合同号"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="batchNo"
              min-width="120"
              label="批次号"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="customerSupplierName"
              min-width="200"
              label="供应商"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="forwardingUnitName"
              min-width="200"
              label="发货单位"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="receivingUintName"
              min-width="200"
              label="收货单位"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="memo"
              min-width="120"
              label="备注"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="grossWeight"
              label="毛重"
              min-width="100"
              align="right"
            >
              <template slot-scope="scope">
                {{ Math.floor((scope.row.grossWeight - 0) / 10) / 100 }}
              </template>
            </el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="tareWeight"
              label="皮重"
              min-width="100"
              align="right"
            >
              <template slot-scope="scope">
                {{ Math.floor((scope.row.tareWeight - 0) / 10) / 100 }}
              </template>
            </el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="netWeight"
              label="净重"
              min-width="100"
              align="right"
            >
              <template slot-scope="scope">
                {{ Math.floor((scope.row.netWeight - 0) / 10) / 100 }}
              </template>
            </el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="meterNum"
              min-width="110"
              label="数量"
              align="right"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="actualFirst1No"
              min-width="120"
              label="毛重作业编号"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="baseSpot1Name"
              min-width="120"
              label="毛重计量点"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="grossTime"
              min-width="160"
              label="毛重计量时间"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="grossManName"
              min-width="120"
              label="毛重计量员"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="grossClass"
              min-width="120"
              label="毛重班次"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="grossGroup"
              min-width="120"
              label="毛重班组"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="100"
              prop="grossMode"
              label="毛重计量方式"
              align="left"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.grossMode == 1">远程计量</span>
                <span v-else-if="scope.row.grossMode == 2">智能计量</span>
                <span v-else-if="scope.row.grossMode == 3">手工录入</span>
                <span v-else-if="scope.row.grossMode == 4">放行智能计量</span>
                <span v-else-if="scope.row.grossMode == 5">滞后匹配</span>
              </template>
            </el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="100"
              prop="actualFirst2No"
              label="皮重作业编号"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="100"
              prop="baseSpot2Name"
              label="皮重计量点"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="160"
              prop="tareTime"
              label="皮重计量时间"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="100"
              prop="tareManName"
              label="皮重计量员"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="100"
              prop="netClass"
              label="皮重班次"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="100"
              prop="tareGroup"
              label="皮重班组"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="100"
              prop="tareMode"
              label="皮重计量方式"
              align="left"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.tareMode == 1">远程计量</span>
                <span v-else-if="scope.row.tareMode == 2">智能计量</span>
                <span v-else-if="scope.row.tareMode == 3">手工录入</span>
                <span v-else-if="scope.row.tareMode == 4">放行智能计量</span>
                <span v-else-if="scope.row.tareMode == 5">滞后匹配</span>
              </template>
            </el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="100"
              prop="netSpot3Name"
              label="净重计量点"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="160"
              prop="netTime"
              label="净重计量时间"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="100"
              prop="netManName"
              label="净重计量员"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="100"
              prop="netClass"
              label="净重班次"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="100"
              prop="netGroup"
              label="净重班组"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="100"
              prop="netMode"
              label="结净方式"
              align="left"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.netMode == 1">正常结净</span>
                <span v-else-if="scope.row.netMode == 2">匹配结净</span>
              </template>
            </el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="station"
              label="发站"
              min-width="200"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="arrival"
              label="到站"
              min-width="200"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="materialName"
              min-width="120"
              label="材质"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="specName"
              min-width="120"
              label="规格"
              align="left"
            ></el-table-column>
            <!-- <el-table-column :show-overflow-tooltip="true" prop="" label="绑定卡号" min-width="100" align="left"></el-table-column> -->
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="loadPointName"
              min-width="120"
              label="卸货地点"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="sampleNo"
              min-width="120"
              label="取样编号"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="sampleVoucher"
              min-width="120"
              label="取样凭证"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="carrierUnitName"
              min-width="200"
              label="承运单位"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="meterTypeName"
              min-width="120"
              label="业务类型"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="uploadFlag"
              min-width="120"
              label="状态"
              align="center"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.uploadFlag == 0">待审核</span>
                <span v-else-if="scope.row.uploadFlag == 1">待上传</span>
                <span v-else-if="scope.row.uploadFlag == 2">已上传</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="[50, 100, 200, 400]"
            :page-size="page.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page.totalPage"
          >
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { formatDate } from '@/utils/util.js';
export default {
  data () {
    return {
      dataLoading: false,
      operateLoading: false,
      icoreFilterFlag: true,
      meterTypeNameItem: [],
      matterNameItem: [],
      uploadFlagItem: [
        { uploadFlag: '待审核' },
        { uploadFlag: '待上传' },
        { uploadFlag: '已上传' }
      ],
      page: {
        pageSize: 100,
        pageNum: 1,
        totalPage: 0
      },
      table: {
        list: []
      },
      multipleSelection: [],
      tableHeight: 0,
      search: {
        railwayNo: '',
        meterTypeName: '',
        matterNo: '',
        uploadFlag: '',
        strDate: '',
        envDate: ''
      },
      ruleValidateSearch: {
        envDate: [{
          required: true,
          validator: this.endTimeVerify,
          trigger: 'blur'
        }],
        strDate: [{
          required: true,
          validator: this.strTimeVerify,
          trigger: 'blur'
        }]
      },
      activeMenu: ''
    }
  },
  created () {
    this.tableHeight = (window.innerHeight - 220) > 400 ? window.innerHeight - 220 : 400
    this.search.envDate = new Date()
    this.search.strDate = new Date(new Date().setDate(new Date().getDate() - 7))
    this.activeMenu = window.top.localStorage.getItem('activeMenu')
  },
  mounted () {
    this.getDataList();
    // this.getMatterNameItem();
    this.getMeterTypeNameItem()
  },
  methods: {
    getMatterName (val) {
      this.axios.get('pass/systemBase/v1/meterbasematterinfos/noPage' + '?validFlag=1' + '&matterName=' + val)
        .then(res => {
          this.matterNameItem = res.data;
        })
    },
    endTimeVerify (rule, value, callback) {
      if (this.search.strDate && !this.search.envDate) {
        callback(new Error('结束时间不能为空！'));
      } else if (this.search.envDate) {
        if (Date.parse(this.search.envDate) > Date.parse(this.search.strDate)) {
          callback();
        } else {
          callback(new Error('结束时间不得早于开始时间！'));
        }
      } else {
        callback();
      }
    },
    strTimeVerify (rule, value, callback) {
      if (this.search.envDate && !this.search.strDate) {
        callback(new Error('开始时间不能为空！'));
      } else {
        callback()
      }
    },
    searchData () {
      this.$refs['searchData'].validate((valid) => {
        if (valid) {
          this.dataLoading = true;
          this.page.pageNum = 1;
          this.search.uploadFlag1 = this.search.uploadFlag === '待审核' ? 0 : this.search.uploadFlag === '待上传' ? 1 : this.search.uploadFlag === '已上传' ? 2 : ''
          this.search.strDate = formatDate(this.search.strDate, 'yyyy-MM-dd HH:mm:ss')
          this.search.envDate = formatDate(this.search.envDate, 'yyyy-MM-dd HH:mm:ss')
          this.axios.get('pass/systemBase/v1/meterworkrailwayactuals/selectView' + '?pageNum=' + this.page.pageNum + '&pageSize=' + this.page.pageSize + '&railwayNo=' + this.search.railwayNo
            + '&meterTypeName=' + this.search.meterTypeName + '&matterNo=' + this.search.matterNo + '&uploadFlag=' + this.search.uploadFlag1
            + '&netTime1=' + this.search.strDate + '&netTime2=' + this.search.envDate + '&flag=0')
            .then(res => {
              this.dataLoading = false;
              this.table.list = res.data.list;
              this.page.totalPage = res.data.total;
            }).catch(e => {
              this.dataLoading = false;
            });
        }
      })
    },
    handleSelectionChange (val) {
      this.multipleSelection = val;
    },
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.getDataList();
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.getDataList();
    },
    getDataList () {
      this.dataLoading = true;
      this.axios.get('pass/systemBase/v1/meterworkrailwayactuals/selectDiff' + '?pageNum=' + this.page.pageNum + '&pageSize=' + this.page.pageSize + '&flag=0')
        .then(res => {
          this.dataLoading = false;
          this.table.list = res.data.list;
          this.page.totalPage = res.data.total;
        }).catch(e => {
          this.dataLoading = false;
        });
    },
    getMatterNameItem () {
      this.axios.get('pass/systemBase/v1/meterbasematterinfos/noPage' + '?validFlag=1')
        .then(res => {
          this.matterNameItem = res.data;
        })
    },
    getMeterTypeNameItem () {
      this.axios.get('pass/systemBase/v1/combaseinfos/noPage' + '?pBaseCode=001006' + '&validFlag=1')
        .then(res => {
          this.meterTypeNameItem = res.data;
        })
    }
  }
}
</script>

<style scoped>
</style>