<!--一次计量数据审核-->
<template>
  <div class="systemBase">
    <div>
      <div style="margin-top: 10px; border-bottom: 1px solid #d5d5d5">
        <el-form
          ref="searchData1"
          :inline="true"
          :model="search"
          :rules="ruleValidate"
        >
          <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 in matterNameItem"
                :key="item.matterNo"
                :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="searchDatas"
              v-loading.fullscreen.lock="operateLoading"
              v-privilege="activeMenu + 'SEARCH'"
              >查询</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <el-row>
        <el-col :span="18">
          <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"
                :summary-method="getSummaries"
                show-summary
                @current-change="getMeasurementData"
                :data="table.list"
                @row-click="getDataList2"
                :exchangeFilterMap="{
                  valueFlag: { '0': '作废', '1': '有效', '2': '洁净' },
                  checkFlag: { '0': '未审', '1': '已审' },
                  weightType: {
                    '0': '毛重',
                    '1': '常规皮重',
                    '2': '期限皮重',
                    '3': '历史皮重',
                    '4': '标识皮重',
                    '5': '自重皮重',
                  },
                }"
                :icore-filter-flag="icoreFilterFlag"
              >
                <el-table-column
                  type="index"
                  label="序号"
                  fixed="left"
                  align="center"
                ></el-table-column>
                <!-- <el-table-column type="selection" width="55" align="center"></el-table-column> -->
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  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="center"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="carNo"
                  label="车号"
                  min-width="80"
                  align="center"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="trailerNo"
                  label="挂号"
                  min-width="80"
                  align="center"
                ></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="meterWeight"
                  label="重量(T)"
                  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="meterNum"
                  min-width="110"
                  label="数量"
                  align="right"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="addWeight"
                  min-width="100"
                  label="附加重量(T)"
                  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="weightType"
                  label="重量类型"
                  min-width="100"
                  align="center"
                >
                  <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="baseSpotName"
                  min-width="100"
                  label="计量点"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="createTime"
                  min-width="160"
                  label="计量时间"
                  align="center"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="createManName"
                  min-width="100"
                  label="计量员"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="meterClass"
                  min-width="100"
                  label="班次"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="meterGroup"
                  min-width="100"
                  label="班组"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="contractNo"
                  min-width="100"
                  label="合同号"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="batchNo"
                  min-width="100"
                  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="materialName"
                  min-width="100"
                  label="材质"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="specName"
                  min-width="100"
                  label="规格"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="bindCardNo"
                  min-width="100"
                  label="绑定卡号"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="loadPointName"
                  min-width="100"
                  label="卸货地点"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="sampleNo"
                  min-width="100"
                  label="取样编号"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="sampleVoucher"
                  min-width="100"
                  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="100"
                  label="业务类型"
                  align="left"
                ></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="状态"
                  width="60"
                  min-width="100"
                  align="center"
                >
                  <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>
        </el-col>
        <el-col :span="6">
          <div class="common-title-div">附加重量</div>
          <div class="common-table-div">
            <el-table
              v-loading="dataLoading2"
              :row-class-name="tableRowClassName"
              ref="dataTable2"
              highlight-current-row
              border
              :height="tableHeight"
              :summary-method="getSummaries2"
              show-summary
              :data="table.list2"
              :icore-filter-flag="icoreFilterFlag"
            >
              <el-table-column
                type="index"
                label="序号"
                fixed="left"
                align="center"
              ></el-table-column>
              <!-- <el-table-column type="selection" width="55" align="center"></el-table-column> -->
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="utensilNo"
                label="器具编号"
                min-width="110"
                align="center"
              ></el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="utensilName"
                label="器具名称"
                min-width="80"
                align="left"
              ></el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="utensilWeight"
                label="器具重量(T)"
                min-width="120"
                align="right"
              >
                <template slot-scope="scope">
                  {{ Math.floor((scope.row.utensilWeight - 0) / 10) / 100 }}
                </template>
              </el-table-column>
              <el-table-column
                sortable
                :show-overflow-tooltip="true"
                prop="utensilUtensilName"
                label="器具属性"
                min-width="80"
                align="left"
              ></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="[50, 100, 200, 400]"
              :page-size="page2.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="page2.totalPage"
            >
            </el-pagination>
          </div>
        </el-col>
      </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>
    </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,
      dataLoading2: false,
      operateLoading: false,
      icoreFilterFlag: true,
      actualFirst: '',
      measurementData: '',
      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,
      ruleValidate: {
        envDate: [{
          required: true,
          validator: this.endTimeVerify,
          trigger: 'blur'
        }],
        strDate: [{
          required: true,
          validator: this.strTimeVerify,
          trigger: 'blur'
        }]
      },
      search: {
        carNo: '',
        baseSpotNo: '',
        meterTypeName: '',
        matterNo: '',
        valueFlag: '',
        strDate: '',
        envDate: '',
      },
      urlImage: [],
      activeMenu: '',
      matList: []
    }
  },
  components: {
    Viewer
  },
  created () {
    this.tableHeight = (window.innerHeight - 320) > 200 ? window.innerHeight - 320 : 200
    this.activeMenu = window.top.localStorage.getItem('activeMenu')
  },
  mounted () {
    // this.getDataList();
    this.searchDatas();
    this.getBaseSpotNameItem();
    this.getMatterNameItem();
    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()
      }
    },
    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.property === "meterWeight") {
          let val = 0;
          for (let i in data) {
            val = this.floatComputed(
              data[i].meterWeight ? Math.floor((data[i].meterWeight - 0) / 10) / 100 : 0,
              val,
              "+"
            );
          }
          sums[index] = val;
        } else if (column.property === "meterNum") {
          let val = 0;
          for (let i in data) {
            val = this.floatComputed(
              data[i].meterNum ? data[i].meterNum - 0 : 0,
              val,
              "+"
            );
          }
          sums[index] = val;
        }
      });
      return sums;
    },
    getSummaries2 (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.property === "utensilWeight") {
          let val = 0;
          for (let i in data) {
            val = this.floatComputed(
              data[i].utensilWeight ? Math.floor((data[i].utensilWeight - 0) / 10) / 100 : 0,
              val,
              "+"
            );
          }
          sums[index] = val;
        }
      });
      return sums;
    },
    checkData () {//审核
      if (this.measurementData.checkFlag === '1') {
        this.$message.warning('请选择状态为未审的数据！');
        return false;
      }
      this.axios.post('pass/systemBase/v1/meterworkcaractualfirsts/audit', this.measurementData, { individualType: 'json' }).then(res => {
        if (res.code == '0' || res.code == '200') {
          this.$message.success('审核成功');
          // this.getDataList();
          this.searchDatas();
        } else {
          this.$message.error(res.message)
        }
      }).catch(e => {
        this.$message.error(e.message)
      })
    },
    unCheckData () {//反审
      if (this.measurementData.checkFlag === '0') {
        this.$message.warning('请选择状态为已审的数据！');
        return false;
      }
      this.axios.post('pass/systemBase/v1/meterworkcaractualfirsts/unaudit', this.measurementData, { individualType: 'json' }).then(res => {
        if (res.code == '0' || res.code == '200') {
          this.$message.success('反审成功');
          // this.getDataList();
          this.searchDatas();
        } else {
          this.$message.error(res.message)
        }
      }).catch(e => {
        this.$message.error(e.message)
      })

    },
    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()
        }
      });
    },
    getMeasurementData (val) {
      this.measurementData = val
      this.getDataList2(val)
      this.getImageList(val)
    },
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.searchData()
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.searchData()
    },
    pageSizeChange2 (size) {
      this.page2.pageSize = size;
      this.getDataList2(this.actualFirst);
    },
    pageCurrentChange2 (index) {
      this.page2.pageNum = index;
      this.getDataList2(this.actualFirst);
    },
    getDataList () {
      this.dataLoading = true;
      this.axios.get('pass/systemBase/v1/meterworkcaractualfirsts/' + '?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;
          if (this.table.list.length > 0) {
            this.$refs.dataTable.setCurrentRow(this.table.list[0])
            this.getDataList2(this.table.list[0])
            this.getImageList(this.table.list[0])
          }
        }).catch(e => {
          this.dataLoading = false;
        });
    },
    getImageList (row) {
      this.actualFirst = row
      if (row === undefined || row === null) {
        this.urlImage = []
        return
      }
      this.axios.get('pass/systemBase/v1/meterworkimages/getUrl' + '?actualFirstNo=C' + row.actualFirstNo)
        .then(res => {
          if (res.data !== null && res.data.length !== 0) {
            const imageList = res.data
            for (let i = 0; i < res.data.length; i++) {
              if (this.urlImage.length < res.data.length) {
                this.urlImage.push({ image: '' })
              }
              this.urlImage[i].image = '/weblib' + res.data[i]
              //  this.urlImage2.push(imageList[i])
            }
          }
          // this.$nextTick(() => {
          //       this.initImageTools();
          //    });
        });
    },
    getDataList2 (row) {
      this.actualFirst = row
      if (row === undefined || row === null) {
        this.table.list2 = []
        return
      }
      this.dataLoading2 = true;
      this.axios.get('pass/systemBase/v1/meterworkaddweights/' + '?pageNum=' + this.page2.pageNum + '&pageSize=' + this.page2.pageSize + '&actualFirstNo=' + row.actualFirstNo)
        .then(res => {
          this.dataLoading2 = false;
          this.table.list2 = res.data.list;
          this.page2.totalPage = res.data.total;
        }).catch(e => {
          this.dataLoading2 = false;
        });
    },
    searchDatas () {
      this.page.pageNum = 1;
      this.searchData()
    },
    searchData () {
      this.$refs['searchData1'].validate((valid) => {
        if (valid) {
          this.dataLoading = true;
          // 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.urlImage = []
          this.table.list2 = []
          this.axios.get('pass/systemBase/v1/meterworkcaractualfirsts/' + '?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;
              if (this.table.list.length > 0) {
                this.$refs.dataTable.setCurrentRow(this.table.list[0])
                this.getDataList2(this.table.list[0])
                this.getImageList(this.table.list[0])
              }
            }).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')
        .then(res => {
          this.baseSpotNameItem = res.data;
        })
    },
    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>