<!--一次计量数据审核-->
<template>
  <div class="systemBase">
    <div>
      <div style="margin-top: 10px; border-bottom: 1px solid #d5d5d5">
        <el-form
          ref="searchData"
          :inline="true"
          :model="search"
          :rules="ruleValidate"
          style="padding-left: 12px"
        >
          <!-- <el-form-item label-width="70px" 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="baseSpotNo" label="计量点">
            <el-select
              v-model="search.baseSpotNo"
              clearable
              filterable
              collapse-tags
              size="small"
              style="width: 120px"
            >
              <el-option
                v-for="(item, index) in baseSpotNameItem"
                :key="index"
                :label="item.baseSpotName"
                :value="item.baseSpotNo"
              >
              </el-option>
            </el-select>
          </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, index) in matterNameItem"
                :key="index"
                :label="item.matterName"
                :value="item.matterNo"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <!-- <el-form-item prop="valueFlag" label="数据状态">
              <el-select v-model="search.valueFlag" clearable filterable collapse-tags size="small" style="width:120px">
                 <el-option v-for="(item,index) in valueFlagItem" :key="index" :label="item.valueFlag"
                  :value="item.valueFlag">
                 </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 class="common-operation-button-div">
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-check"
              @click="checkData"
              v-loading.fullscreen.lock="operateLoading"
              v-privilege="activeMenu + 'CHECK'"
              >审核</el-button
            >
            <el-button
              size="mini"
              type="danger"
              plain
              icon="el-icon-remove-outline"
              @click="unCheckData"
              v-loading.fullscreen.lock="operateLoading"
              v-privilege="activeMenu + 'UNCHECK'"
              >反审</el-button
            >
          </div>
        </div>
        <div class="common-table-div">
          <el-table
            v-loading="dataLoading"
            :row-class-name="tableRowClassName"
            ref="dataTable"
            highlight-current-row
            border
            :height="tableHeight"
            @current-change="handleCurrentChange"
            :summary-method="getSummaries"
            :data="table.list"
            :exchangeFilterMap="{
              weightType: {
                '0': '毛重',
                '1': '常规皮重',
                '2': '期限皮重',
                '3': '历史皮重',
                '4': '标识皮重',
                '5': '自重皮重',
              },
              meterMode: {
                '1': '远程计量',
                '2': '智能计量',
                '3': '手工录入',
                '4': '放行智能计量',
                '5': '滞后匹配',
              },
              valueFlag: { '0': '作废', '1': '作废', '3': '作废' },
              checkFlag: { '0': '未审', '1': '已审' },
            }"
            :icore-filter-flag="icoreFilterFlag"
          >
            <el-table-column
              type="index"
              label="序号"
              fixed="left"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="actualFirstNo"
              label="作业编号"
              min-width="110"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="predictionNo"
              label="预报编号"
              min-width="80"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="railwayNo"
              label="车号"
              min-width="80"
              align="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="railwayWorkNo"
              label="列车作业编号"
              min-width="120"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="matterName"
              label="物资名称"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="meterWeight"
              label="计量重量"
              min-width="100"
              align="right"
            >
              <template slot-scope="scope">
                {{ Math.floor((scope.row.meterWeight - 0) / 10) / 100 }}
              </template>
            </el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="meterBalanceWeight"
              label="结算重量"
              min-width="100"
              align="right"
            >
              <template slot-scope="scope">
                {{ Math.floor((scope.row.meterBalanceWeight - 0) / 10) / 100 }}
              </template>
            </el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="weightType"
              label="重量类型"
              min-width="100"
              align="left"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.weightType == 0">毛重</span>
                <span v-else-if="scope.row.weightType == 1">常规皮重</span>
                <span v-else-if="scope.row.weightType == 2">期限皮重</span>
                <span v-else-if="scope.row.weightType == 3">历史皮重</span>
                <span v-else-if="scope.row.weightType == 4">标识皮重</span>
                <span v-else-if="scope.row.weightType == 5">自重皮重</span>
              </template>
            </el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="shipmentNum"
              label="数量"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="baseSpotName"
              label="计量点"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="createTime"
              label="计量时间"
              min-width="160"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="createManName"
              label="计量员"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="meterClass"
              label="班次"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="meterGroup"
              label="班组"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="contractNo"
              label="合同号"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="batchNo"
              label="批次号"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="customerSupplierName"
              label="供应商"
              min-width="200"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="forwardingUnitName"
              label="发货单位"
              min-width="200"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="receivingUintName"
              label="收货单位"
              min-width="200"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="materialName"
              label="材质"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="specName"
              label="规格"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="bindCardNo"
              label="绑定卡号"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="loadPointName"
              label="卸货地点"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="sampleNo"
              label="取样编号"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="sampleVoucher"
              label="取样凭证"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="carrierUnitName"
              label="承运单位"
              min-width="200"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="meterTypeName"
              label="业务类型"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="meterMode"
              label="计量方式"
              min-width="100"
              align="left"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.meterMode == 1">远程计量</span>
                <span v-else-if="scope.row.meterMode == 2">智能计量</span>
                <span v-else-if="scope.row.meterMode == 3">手工录入</span>
                <span v-else-if="scope.row.meterMode == 4">放行智能计量</span>
                <span v-else-if="scope.row.meterMode == 5">滞后匹配</span>
              </template>
            </el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="checkFlag"
              min-width="100"
              label="审核状态"
              align="left"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.checkFlag == 0">未审</span>
                <span v-else-if="scope.row.checkFlag == 1">已审</span>
              </template>
            </el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="valueFlag"
              label="状态"
              min-width="100"
              align="left"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.valueFlag == 0">作废</span>
                <span v-else-if="scope.row.valueFlag == 1">有效</span>
                <span v-else-if="scope.row.valueFlag == 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,
      baseSpotNameItem: [],
      meterTypeNameItem: [],
      matterNameItem: [],
      valueFlagItem: [
        { valueFlag: '有效' },
        { valueFlag: '作废' },
        { valueFlag: '结净' }
      ],
      page: {
        pageSize: 100,
        pageNum: 1,
        totalPage: 0
      },
      page2: {
        pageSize: 100,
        pageNum: 1,
        totalPage: 0
      },
      table: {
        list: [],
        list2: [],
      },
      tableHeight: 0,
      multipleSelection: {},
      ruleValidate: {
        envDate: [{
          required: true,
          validator: this.endTimeVerify,
          trigger: 'blur'
        }],
        strDate: [{
          required: true,
          validator: this.strTimeVerify,
          trigger: 'blur'
        }]
      },
      search: {
        carNo: '',
        baseSpotName: '',
        baseSpotNo: '',
        meterTypeName: '',
        matterNo: '',
        valueFlag: '',
        strDate: '',
        envDate: '',
      },
      activeMenu: ''
    }
  },
  created () {
    this.tableHeight = (window.innerHeight - 220) > 400 ? window.innerHeight - 220 : 400
    this.activeMenu = window.top.localStorage.getItem('activeMenu')
  },
  mounted () {
    this.getDataList();
    this.getBaseSpotNameItem();
    // 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()
      }
    },
    getSummaries (param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "总计";
        }
        if (index === 1) {
          sums[index] = data.length;
        } else if (column.meterWeight === "meterWeight") {
          let val = 0;
          for (let i in data) {
            val = this.floatComputed(
              data[i].meterWeight ? data[i].meterWeight : 0,
              val,
              "+"
            );
          }
          sums[index] = val;
        } else if (column.property === "meterSortWeight") {
          let val = 0;
          for (let i in data) {
            val = this.floatComputed(
              data[i].meterSortWeight ? data[i].meterSortWeight : 0,
              val,
              "+"
            );
          }
          sums[index] = val;
        } else if (column.property === "meterBalanceWeight") {
          let val = 0;
          for (let i in data) {
            val = this.floatComputed(
              data[i].meterBalanceWeight ? data[i].meterBalanceWeight : 0,
              val,
              "+"
            );
          }
          sums[index] = val;
        }
      });
      return sums;
    },
    searchData () {
      this.$refs['searchData'].validate((valid) => {
        if (valid) {
          this.dataLoading = true;
          this.page.pageNum = 1;
          // this.search.valueFlag1 = this.search.valueFlag === '有效' ? 1 : this.search.valueFlag === '作废' ? 0 : this.search.valueFlag === '结净' ? 2 : ''
          if (isNaN(this.search.strDate) && !isNaN(Date.parse(this.search.strDate))) {
          } else {
            this.search.strDate = formatDate(this.search.strDate, 'yyyy-MM-dd HH:mm:ss')
          }
          if (isNaN(this.search.envDate) && !isNaN(Date.parse(this.search.envDate))) {
          } else {
            this.search.envDate = formatDate(this.search.envDate, 'yyyy-MM-dd HH:mm:ss')
          }
          this.axios.get('pass/systemBase/v1/meterworkrailwayactfirsts/selectAct' + '?pageNum=' + this.page.pageNum + '&pageSize=' + this.page.pageSize + '&carNo=' + this.search.carNo
            + '&baseSpotNo=' + this.search.baseSpotNo + '&meterTypeName=' + this.search.meterTypeName + '&matterNo=' + this.search.matterNo + '&valueFlag=1'
            + '&createTime1=' + this.search.strDate + '&createTime2=' + this.search.envDate)
            .then(res => {
              this.dataLoading = false;
              this.table.list = res.data.list;
              this.page.totalPage = res.data.total;
            }).catch(e => {
              this.dataLoading = false;
            });
        }
      })
    },
    checkData () {//审核
      if (this.multipleSelection.checkFlag === '1') {
        this.$message.warning('请选择状态为未审的数据！');
        return false;
      }
      this.axios.post('pass/systemBase/v1/meterworkrailwayactfirsts/audit', this.multipleSelection, { individualType: 'json' }).then(res => {
        if (res.code == '0' || res.code == '200') {
          this.$message.success('审核成功');
          this.getDataList();
        } else {
          this.$message.error(res.message)
        }
      }).catch(e => {
        this.$message.error(e.message)
      })
    },
    unCheckData () {//反审
      if (this.multipleSelection.checkFlag === '0') {
        this.$message.warning('请选择状态为已审的数据！');
        return false;
      }
      this.axios.post('pass/systemBase/v1/meterworkrailwayactfirsts/unaudit', this.multipleSelection, { individualType: 'json' }).then(res => {
        if (res.code == '0' || res.code == '200') {
          this.$message.success('反审成功');
          this.getDataList();
        } else {
          this.$message.error(res.message)
        }
      }).catch(e => {
        this.$message.error(e.message)
      })

    },
    handleCurrentChange (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/meterworkrailwayactfirsts/selectAct' + '?pageNum=' + this.page.pageNum + '&pageSize=' + this.page.pageSize + '&valueFlag=1')
        .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 '';
    },
    getBaseSpotNameItem () {
      this.axios.get('pass/systemBase/v1/meterbasespotinfos/noPage' + '?validFlag=1' + '&spotTypeNo=001002002&spotTypeName=轨道衡')
        .then(res => {
          this.baseSpotNameItem = res.data;
        })
    },
    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>