<!--结净计量数据查询-->
<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"
              size="small"
              clearable
              style="width: 120px"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label-width="70px" prop="minusManName" label="扣重人">
            <el-input
              v-model="search.minusManName"
              size="small"
              clearable
              style="width: 120px"
              placeholder="请输入"
            ></el-input>
          </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="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
              type="primary"
              size="mini"
              @click="searchData"
              v-loading.fullscreen.lock="operateLoading"
              v-privilege="activeMenu + 'SEARCH'"
              >查询</el-button
            >
          </el-form-item>
          <el-form-item label-width="20px">
            <el-button
              type="primary"
              size="mini"
              :loading="reduceLoading"
              @click="dataReduce"
              v-privilege="activeMenu + 'REDUCE'"
              >扣杂</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" style="display: flex">
              结净计量数据查询 （
              <div
                style="
                  width: 12px;
                  height: 12px;
                  background-color: #000000;
                  color: #000000;
                  margin-top: 5px;
                "
              ></div>
              待审核
              <div
                style="
                  width: 12px;
                  height: 12px;
                  background-color: rgb(0, 116, 10);
                  color: rgb(0, 116, 10);
                  margin-left: 5px;
                  margin-top: 5px;
                "
              ></div>
              待上传
              <div
                style="
                  width: 12px;
                  height: 12px;
                  background-color: red;
                  color: red;
                  margin-left: 5px;
                  margin-top: 5px;
                "
              ></div>
              已上传）
            </div>
            <div class="common-table-div" id="topTable">
              <el-table
                id="excelTable"
                v-loading="dataLoading"
                @row-click="getRow"
                ref="dataTable"
                highlight-current-row
                border
                :height="tableHeight"
                :summary-method="getSum"
                show-summary
                :data="table.list"
                :row-class-name="tableRowClassName"
                :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="isFixed"
                  align="center"
                ></el-table-column>
                <!-- <el-table-column type="selection" width="55" align="center" :fixed="isFixed"></el-table-column> -->
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="actualNo"
                  label="流水号"
                  min-width="80"
                  align="left"
                  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="carNo"
                  label="车号"
                  min-width="80"
                  fixed="left"
                  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="indexMatterName"
                  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="grossWeight"
                  label="毛重(kg)"
                  min-width="100"
                  align="right"
                >
                </el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="tareWeight"
                  label="皮重(kg)"
                  min-width="100"
                  align="right"
                >
                </el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="netWeight"
                  label="净重(kg)"
                  min-width="100"
                  align="right"
                >
                </el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="addWeight"
                  min-width="120"
                  label="扣杂/附加重量(kg)"
                  align="left"
                ></el-table-column>
                <!-- <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="addWeight"
                  label="附加重量(kg)"
                  min-width="100"
                  align="right"
                >
                </el-table-column> -->
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="minusManName"
                  label="扣重人"
                  min-width="100"
                  align="left"
                >
                </el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="minusTime"
                  label="扣重时间"
                  min-width="100"
                  align="left"
                >
                </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="minusMemo"
                  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="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
                  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="80"
                  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>
        </el-col>
      </el-row>
      <!-- 扣重数据编辑区域 -->
      <div
        ref="editTitle"
        class="common-title-div"
        style="margin-top: 20px; border-top: 1px solid #d5d5d5"
      >
        洁净计量数据扣重区域
      </div>
      <div ref="editDiv" class="commom-edit-div">
        <el-form
          ref="baseData"
          label-width="80px"
          :inline="true"
          :rules="ruleValidateTable1"
          :model="baseData"
        >
          <el-form-item prop="grossWeight" label="毛重(kg)">
            <el-input
              v-model="baseData.grossWeight"
              clearable
              type="text"
              size="mini"
              disabled
              style="width: 120px"
            ></el-input>
          </el-form-item>
          <el-form-item prop="tareWeight" label="皮重(kg)">
            <el-input
              v-model="baseData.tareWeight"
              clearable
              type="text"
              size="mini"
              disabled
              style="width: 120px"
            ></el-input>
          </el-form-item>
          <el-form-item prop="netWeight" label="净重(kg)">
            <el-input
              v-model="baseData.netWeight"
              clearable
              type="text"
              size="mini"
              disabled
              style="width: 120px"
            ></el-input>
          </el-form-item>
          <el-form-item prop="addWeight" label="扣杂/附加重量(kg)" label-width="130px">
            <el-input
              v-model="baseData.addWeight"
              clearable
              type="text"
              size="mini"
              style="width: 120px"
            ></el-input>
          </el-form-item>
          <el-form-item prop="minusMemo" label="扣重备注">
            <el-input
              v-model="baseData.minusMemo"
              clearable
              type="text"
              size="mini"
              style="width: 330px"
            ></el-input>
          </el-form-item>
          <el-form-item label-width="0">
            <span style="color: red"
              >当扣杂/附加重量初始值不为空时，请在原有数值上进行扣杂操作</span
            >
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
import { formatDate } from "@/utils/util.js";
import {
  getCookie
} from '@/utils/util.js';
import {
  cookieUserId,
  cookieUserName
} from '@/config/config.js';
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
import { recordChange } from '~/utils/utils'

export default {
  data () {
    let numberCheck = (rule, value, callback) => {
      if (/^(-?\d+)(\.\d+)?$/.test(value - 0) == false) {
        callback(new Error("重量需要为数值"));
      } else {
        callback();
      }
    };
    return {
      indexMatterName: "",
      dataLoading: false,
      operateLoading: false,
      icoreFilterFlag: true,
      meterTypeNameItem: [],
      matterNameItem: [],
      uploadFlagItem: [
        { uploadFlag: "待审核" },
        { uploadFlag: "待上传" },
        { uploadFlag: "已上传" },
      ],
      page: {
        pageSize: 100,
        pageNum: 1,
        totalPage: 0,
      },
      isFixed: "left",
      table: {
        list: [],
      },
      multipleSelection: [],
      tableHeight: 0,
      search: {
        carNo: "",
        minusManName: '',
        matterNo: "",
        strDate: "",
        envDate: "",
      },
      ruleValidateSearch: {
        envDate: [
          {
            required: true,
            validator: this.endTimeVerify,
            trigger: "blur",
          },
        ],
        strDate: [
          {
            required: true,
            validator: this.strTimeVerify,
            trigger: "blur",
          },
        ]
      },
      baseData: {
        addWeight: "", // 扣杂
        netWeight: '',   // 净重
        grossWeight: '', // 毛重
        tareWeight: '', // 皮重
        minusMemo: "", // 扣重备注
        id: "", // 数据主键id
      },
      baseDataCache: {
        addWeight: "", // 扣杂
        netWeight: '', // 净重
        grossWeight: '', // 毛重
        tareWeight: '', // 皮重
        minusMemo: "", // 扣重备注
        id: "", // 数据主键id
      },
      ruleValidateTable1: {
        addWeight: [
          {
            validator: numberCheck,
            message: "扣杂需要为数值",
            trigger: "change",
          },
        ]
      },
      reduceLoading: false,
      activeMenu: "",
      matList: [],
      spotNameList: [],
      judgeTypeList: [],
      selectRow: {}
    };
  },
  created () {
    this.tableHeight =
      window.innerHeight - 320 > 400 ? window.innerHeight - 320 : 400;
    this.search.envDate = formatDate(new Date(), "yyyy-MM-dd") + " 23:59:59";
    this.search.strDate = formatDate(new Date(), "yyyy-MM-dd") + " 00:00:00";
    this.activeMenu = window.top.localStorage.getItem("activeMenu");
    this.getSpotList()
  },
  mounted () {
    this.getMatterNameItem(); // 物资名称
    // this.getMeterTypeNameItem() // 业务类型
    // 不进行默认查询
    // this.searchData()
  },
  methods: {
    getSpotList () {
      this.axios
        .get(
          "pass/systemBase/v1/meterbasespotinfos/noPage" +
          "?validFlag=1&spotTypeName=汽车衡"
        )
        .then((res) => {
          this.spotNameList = [...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();
      }
    },
    getSum ({ columns, data }) {
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计";
        }
        const values = data.map((item) => Number(item[column.property]));
        if (!values.every((value) => isNaN(value))) {
          if (
            (column.property === "grossWeight") |
            (column.property === "tareWeight") |
            (column.property === "netWeight") |
            (column.property === "addWeight")
          ) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value) && value - 0 !== 0) {
                return this.floatComputed1(prev, curr, "+");
              } else {
                return prev;
              }
            }, 0);
          }
        }
      });
      return sums;
    },
    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();
      }
    },
    searchData (flag = 1) {
      if (flag === 1) {
        this.page.pageNum = 1;
      }
      // 时间不能为空
      // if (this.search.strDate === "" || this.search.envDate === "") {
      //   return this.$message.error("时间不能为空");
      // }
      // 车号或者流水号其中一个需要有值
      if (this.search.carNo === "" && this.search.actualNo === "") {
        return this.$message.error("车号或者流水号不能全部为空");
      }
      this.$refs["searchData"].validate((valid) => {
        if (valid) {
          this.dataLoading = true;
          if (this.search.strDate !== "" && this.search.envDate !== "") {
            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/selectView" +
              "?pageNum=" +
              this.page.pageNum +
              "&pageSize=" +
              this.page.pageSize +
              "&carNo=" +
              this.search.carNo +
              "&matterNo=" +
              this.search.matterNo +
              "&netTime1=" +
              this.search.strDate +
              "&netTime2=" +
              this.search.envDate + `&minusManName=${this.search.minusManName}`
            )
            .then((res) => {
              this.dataLoading = false;
              this.table.list = res.data.list;
              this.page.totalPage = res.data.total;
            })
            .catch((e) => {
              this.dataLoading = false;
            });
        }
      });
    },
    floatComputed1 (arg1, arg2, sign) {
      if (!arg1) {
        arg1 = 0;
      }
      if (!arg2) {
        arg2 = 0;
      }
      let val1 = arg1 + "";
      let val2 = arg2 + "";
      let rate = 1;
      let rate1 = 1;
      let rate2 = 1;
      if (val1.indexOf(".") < 0) {
        rate1 = 0;
      } else {
        rate1 = val1.length - val1.indexOf(".") - 1;
      }
      if (val2.indexOf(".") < 0) {
        rate2 = 0;
      } else {
        rate2 = val2.length - val2.indexOf(".") - 1;
      }
      rate = rate2;
      val2 = val2.replace(".", "");
      val1 = val1.replace(".", "");
      if (rate1 > rate2) {
        rate = rate1;
        for (let i = 0; i < rate1 - rate2; i++) {
          val2 = val2 + "0";
        }
      } else {
        for (let i = 0; i < rate2 - rate1; i++) {
          val1 = val1 + "0";
        }
      }
      let rateNum = Math.pow(10, rate);
      if (sign === "-") {
        return (Number(val1) - Number(val2)) / rateNum;
      }
      if (sign === "+") {
        return (Number(val1) + Number(val2)) / rateNum;
      }
      if (sign === "*") {
        return (Number(val1) * Number(val2)) / (rateNum * rateNum);
      }
      if (sign === "/") {
        // 默认保留4位
        let num = 0;
        if (Number(val1) - 0 !== 0 && Number(val2) - 0 !== 0) {
          num = Number(val1) / Number(val2) + "";
          if (num.split(".").length > 0) {
            if (num[1].length > 4) {
              num = num.toFixed(4);
            }
          }
        }
        return num;
      }
      return null;
    },
    // 行点击
    getRow (val) {
      this.baseData.addWeight = val.addWeight;
      this.baseData.minusMemo = val.minusMemo;
      this.baseData.netWeight = val.netWeight;
      this.baseData.grossWeight = val.grossWeight;
      this.baseData.tareWeight = val.tareWeight;
      this.baseData.id = val.id;
      this.selectRow = { ...val }
    },
    // 扣重
    dataReduce () {
      if (!this.baseData.id || this.baseData.id === "") {
        return this.$message.warning("请先点选要进行扣重的数据");
      }
      this.$refs.baseData.validate(async (valid) => {
        if (!valid) return this.$message.error("请规范填写数据");
        this.reduceLoading = true;
        let dataList = [
          {
            updateManNo: userId,
            updateManName: userName,
            actualNo: this.selectRow.actualNo,
            predictionNo: this.selectRow.predictionNo,
            actualFirst1No: this.selectRow.actualFirst1No,
            actualFirst2No: this.selectRow.actualFirst2No,
            carNo: this.selectRow.carNo,
            meterTypeName: this.selectRow.meterTypeName,
            meterTypeNo: this.selectRow.meterTypeNo,
            matterName: this.selectRow.matterName,
            matterNo: this.selectRow.matterNo,
            customerSupplierName: this.selectRow.customerSupplierName,
            customerSupplierNo: this.selectRow.customerSupplierNo,
            forwardingUnitName: this.selectRow.forwardingUnitName,
            forwardingUnitNo: this.selectRow.forwardingUnitNo,
            receivingUintName: this.selectRow.receivingUintName,
            receivingUintNo: this.selectRow.receivingUintNo,
            ...this.baseData,
            minusManName: userName,
            minusManNo: userId,
            minusTime: formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss')
          }
        ]
        const { oldStr, newStr } = recordChange(this.selectRow, dataList[0])
        const logList = [{
          createManNo: userId,
          createManName: userName,
          operationPage: '洁净计量数据扣杂',
          operationFunction: '洁净扣杂',
          operationId: this.selectRow.id,
          operationPredictionNo: this.selectRow.predictionNo,
          operationCarnNo: this.selectRow.carNo,
          operationBeforeFix: oldStr,
          operationAfterFix: newStr
        }]
        const res = await this.axios.post('pass/systemBase/v1/meterworkcaractuals/batchUpdateCar', dataList, { individualType: 'json' });
        if (res.status = "succeed") {
          const log = await this.axios.post('pass/systemBase/v1/meterbaseoperationlogs/addList', [...logList], { individualType: 'json' })
          if (!log.succeed) {
            this.$message.error('修改日志保存失败');
          }
          this.baseData = { ...this.baseDataCache };
          this.$message.success('扣重成功')
          this.searchData();
          this.selectRow = {}
        } else {
          this.$message.error(data.message);
        }
        this.reduceLoading = false;
      });
    },
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.searchData();
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.searchData(2);
    },
    tableRowClassName ({ row, rowIndex }) {
      if (row.uploadFlag === "2") {
        return "error-row2";
      } else if (row.uploadFlag === "1") {
        return "wait-row";
      }
      return "";
    },
    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;
        });
    },
  },
  watch: {
    'baseData.addWeight': function (newVal) {
      console.log(newVal)
      if (!/^(-?\d+)(\.\d+)?$/.test(newVal - 0)) {
        return this.$message.error('扣重需要为数值')
      }
      // 计算净重
      let netWeight = this.floatComputed1(this.selectRow.grossWeight - 0, this.selectRow.tareWeight - 0, '-')
      this.baseData.netWeight = this.floatComputed1(netWeight, newVal, '-')
    }
  }
};
</script>

<style scoped>
.small-font {
  font-size: 7px;
  -webkit-transform-origin-x: 0;
  -webkit-transition: scale(0.58);
}
</style>