<!--结净计量数据审核-->
<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="carNo" label="车号">
            <el-input
              v-model="search.carNo"
              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="searchDatas"
              v-loading.fullscreen.lock="operateLoading"
              v-privilege="activeMenu + 'SEARCH'"
              >查询</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <el-row>
        <el-col :span="24">
          <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-click="getImageList"
                ref="dataTable"
                highlight-current-row
                border
                :height="tableHeight"
                @current-change="handleCurrentChange"
                :data="table.list"
                :icore-filter-flag="icoreFilterFlag"
                :row-class-name="tableRowClassName"
                :exchangeFilterMap="{
                  uploadFlag: { '0': '未审核', '1': '未上传', '2': '已审核' },
                  grossMode: {
                    '1': '远程计量',
                    '2': '智能计量',
                    '3': '手工录入',
                    '4': '放行智能计量',
                    '5': '滞后匹配',
                  },
                  tareMode: {
                    '1': '远程计量',
                    '2': '智能计量',
                    '3': '手工录入',
                    '4': '放行智能计量',
                    '5': '滞后匹配',
                  },
                  netMode: { '1': '正常结净', '2': '匹配结净' },
                }"
              >
                <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"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="carNo"
                  label="车号"
                  min-width="80"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="trailerNo"
                  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="grossWeight"
                  label="毛重/t"
                  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="皮重/t"
                  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="净重/t"
                  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="addWeight"
                  label="附加重量/t"
                  min-width="100"
                  align="right"
                >
                  <template slot-scope="scope">
                    {{ Math.floor((scope.row.addWeight - 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="100"
                  label="毛重作业编号"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100"
                  prop="baseSpot1Name"
                  label="毛重计量点"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="160"
                  prop="grossTime"
                  label="毛重计量时间"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100"
                  prop="grossManName"
                  label="毛重计量员"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100"
                  prop="grossClass"
                  label="毛重班次"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100"
                  prop="grossGroup"
                  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"
                  min-width="100"
                  prop="contractNo"
                  label="合同号"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100"
                  prop="batchNo"
                  label="批次号"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="200"
                  prop="customerSupplierName"
                  label="供应商"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="200"
                  prop="forwardingUnitName"
                  label="发货单位"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="200"
                  prop="receivingUintName"
                  label="收货单位"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100"
                  prop="materialName"
                  label="材质"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100"
                  prop="specName"
                  label="规格"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100"
                  prop="loadPointName"
                  label="卸货地点"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100"
                  prop="sampleNo"
                  label="取样编号"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100"
                  prop="sampleVoucher"
                  label="取样凭证"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="200"
                  prop="carrierUnitName"
                  label="承运单位"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100"
                  prop="meterTypeName"
                  label="业务类型"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="80"
                  prop="uploadFlag"
                  label="审核状态"
                  align="left"
                >
                  <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>
        </el-col>
      </el-row>
      <div
        class="common-title-div"
        style="
          border-top: 1px solid #d5d5d5;
          margin-top: 10px;
          margin-bottom: 10px;
        "
      >
        毛重截图
      </div>
      <el-row>
        <div id="getBigImage">
          <ul>
            <li v-for="(item, index) in urlImage" :key="index">
              <img :src="item.image" width="97%" @click="imageChange" />
            </li>
          </ul>
        </div>
      </el-row>
      <div
        class="common-title-div"
        style="
          border-top: 1px solid #d5d5d5;
          margin-top: 10px;
          margin-bottom: 10px;
        "
      >
        皮重截图
      </div>
      <el-row>
        <div id="getBigImage2">
          <ul>
            <li v-for="(item, index) in urlImage2" :key="index">
              <img :src="item.image" width="97%" @click="imageChange2" />
            </li>
          </ul>
        </div>
      </el-row>
    </div>
  </div>
</template>
<script>
import { formatDate } from '@/utils/util.js';
import Viewer from 'viewerjs'
import 'viewerjs/dist/viewer.css'
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: {
        carNo: '',
        meterTypeName: '',
        matterNo: '',
        uploadFlag: '',
        strDate: formatDate(new Date()).slice(0, 10) + ' 00:00:00',
        envDate: formatDate(new Date()).slice(0, 10) + ' 23:59:59'
      },
      actualFirst: {},
      urlImage: [],
      urlImage2: [],
      ruleValidateSearch: {
        envDate: [{
          required: true,
          validator: this.endTimeVerify,
          trigger: 'blur'
        }],
        strDate: [{
          required: true,
          validator: this.strTimeVerify,
          trigger: 'blur'
        }]
      },
      activeMenu: '',
      matList: []
    }
  },
  components: {
    Viewer
  },
  created () {
    this.tableHeight = (window.innerHeight - 520) > 300 ? window.innerHeight - 520 : 300
    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.searchDatas()
    this.getMeterTypeNameItem()
  },
  methods: {
    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();
      }
    },
    getMatterName (val) {
      if (val) {
        this.matterNameItem = this.matList.filter(item => {
          if (item.matterName.indexOf(val) !== -1) {
            return true
          }
        }).slice(0, 300)
      } else {
        this.matterNameItem = [...this.matList].slice(0, 300)
      }
    },
    strTimeVerify (rule, value, callback) {
      if (this.search.envDate && !this.search.strDate) {
        callback(new Error('开始时间不能为空！'));
      } else {
        callback()
      }
    },
    getDataList () {
      this.dataLoading = true;
      this.axios.get('pass/systemBase/v1/meterworkcaractuals/' + '?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;
          if (this.table.list.length > 0) {
            this.$refs.dataTable.setCurrentRow(this.table.list[0])
            this.getImageList(this.table.list[0])
          }
        }).catch(e => {
          this.dataLoading = false;
        });
    },
    searchDatas () {
      this.page.pageNum = 1;
      this.searchData()
    },
    searchData () {
      this.$refs['searchData'].validate((valid) => {
        if (valid) {
          this.dataLoading = true;
          this.urlImage = []
          this.urlImage2 = []
          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/meterworkcaractuals/' + '?pageNum=' + this.page.pageNum + '&pageSize=' + this.page.pageSize + '&carNo=' + this.search.carNo
            + '&meterTypeName=' + this.search.meterTypeName + '&matterNo=' + this.search.matterNo + '&uploadFlag=' + this.search.uploadFlag1
            + '&netTime1=' + this.search.strDate + '&netTime2=' + this.search.envDate)
            .then(res => {
              this.dataLoading = false;
              this.table.list = res.data.list;
              this.page.totalPage = res.data.total;
              if (this.table.list.length > 0) {
                this.$refs.dataTable.setCurrentRow(this.table.list[0])
                this.getImageList(this.table.list[0])
              }
            }).catch(e => {
              this.dataLoading = false;
            });
        }
      })
    },
    imageChange (e) {
      if (e.target.nodeName == 'IMG') {
        this.initImageTools();
      }
    },
    initImageTools () {
      const ViewerDom = document.getElementById('getBigImage');

      const viewer = new Viewer(ViewerDom, {
        url: 'src',  //设置大图片的 url
        show: function () {
          viewer.update();
        },
        hide: function () { //在图片消失的时候销毁viewer
          viewer.destroy()
        }
      });
    },
    imageChange2 (e) {
      if (e.target.nodeName == 'IMG') {
        this.initImageTools2();
      }
    },
    initImageTools2 () {
      const ViewerDom = document.getElementById('getBigImage2');
      const viewer = new Viewer(ViewerDom, {
        url: 'src',  //设置大图片的 url
        show: function () {
          viewer.update();
        },
        hide: function () { //在图片消失的时候销毁viewer
          viewer.destroy()
        }
      });
    },
    getImageList (row) {
      this.actualFirst = row
      this.urlImage = []
      this.urlImage2 = []
      this.axios.get('pass/systemBase/v1/meterworkimages/getUrl' + '?actualFirstNo=C' + row.actualFirst1No)
        .then(res => {
          if (res.data !== null && res.data.length !== 0) {
            const imageList = res.data
            for (let i = 0; i < imageList.length; i++) {
              if (this.urlImage.length < res.data.length) {
                this.urlImage.push({ image: '' })
              }
              this.urlImage[i].image = '/weblib' + imageList[i]
            }
          }
        });
      this.axios.get('pass/systemBase/v1/meterworkimages/getUrl' + '?actualFirstNo=C' + row.actualFirst2No)
        .then(res => {
          if (res.data !== null && res.data.length !== 0) {
            const imageList = res.data
            for (let i = 0; i < imageList.length; i++) {
              if (this.urlImage2.length < res.data.length) {
                this.urlImage2.push({ image: '' })
              }
              this.urlImage2[i].image = '/weblib' + imageList[i]
            }
          }
        });
    },
    checkData () {//审核
      if (this.multipleSelection.uploadFlag === '1') {
        this.$message.warning('请选择状态为未审的数据！');
        return false;
      }
      this.axios.post('pass/systemBase/v1/meterworkcaractuals/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.uploadFlag === '0') {
        this.$message.warning('请选择状态为待上传的数据！');
        return false;
      }
      this.axios.post('pass/systemBase/v1/meterworkcaractuals/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)
      })
    },
    tableRowClassName ({
      row,
      rowIndex
    }) {
      if (row.uploadFlag === '2') {
        return 'error-row2';
      } else if (row.uploadFlag === '1') {
        return 'wait-row'
      }
      return '';
    },
    handleCurrentChange (val) {
      this.multipleSelection = val;
    },
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.searchData();
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.searchData();
    },
    getMatterNameItem () {
      this.axios.get('pass/systemBase/v1/meterbasematterinfos/noPage' + '?validFlag=1')
        .then(res => {
          this.matList = res.data;
          this.matterNameItem = [...res.data].slice(0, 300);
        })
    },
    getMeterTypeNameItem () {
      this.axios.get('pass/systemBase/v1/combaseinfos/noPage' + '?pBaseCode=001006' + '&validFlag=1')
        .then(res => {
          this.meterTypeNameItem = res.data;
        })
    }
  }
}
</script>
<style scoped>
</style>