<!--一次计量数据维护-->
<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"
          style="padding-left: 12px"
        >
          <!-- <el-form-item label-width="70px" prop="railwayNo" label="车号">
            <el-input
              v-model="search.railwayNo"
              clearable
              size="small"
              style="width: 120px"
              placeholder="请输入"
            ></el-input>
          </el-form-item> -->
          <el-form-item prop="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="getMatterName2"
            >
              <el-option
                v-for="item in matterNameItem2"
                :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="searchData"
              v-loading.fullscreen.lock="operateLoading"
              v-privilege="activeMenu + 'SEARCH'"
              >查询</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <div style="border-right: 1px solid #d5d5d5">
        <div class="common-title-div">
          一次计量数据维护
          <div class="common-operation-button-div">
            <el-button
              icon="el-icon-circle-plus-outline"
              type="primary"
              size="mini"
              @click="addData"
              v-loading.fullscreen.lock="operateLoading"
              v-privilege="activeMenu + 'ADD'"
              >新增</el-button
            >
            <el-button
              icon="el-icon-edit"
              type="primary"
              size="mini"
              @click="modifyData"
              v-loading.fullscreen.lock="operateLoading"
              v-privilege="activeMenu + 'UPDATE'"
              >修改</el-button
            >
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-check"
              @click="enableData"
              v-loading.fullscreen.lock="operateLoading"
              v-privilege="activeMenu + 'RECOVERY'"
              >启用</el-button
            >
            <el-button
              size="mini"
              type="danger"
              plain
              icon="el-icon-remove-outline"
              @click="discardData"
              v-loading.fullscreen.lock="operateLoading"
              v-privilege="activeMenu + 'ABOLISH'"
              >废除</el-button
            >
          </div>
        </div>
        <div class="common-table-div">
          <el-table
            v-loading="dataLoading"
            @row-click="rowChange"
            :row-class-name="tableRowClassName"
            ref="dataTable"
            highlight-current-row
            border
            :height="tableHeight"
            @current-change="handleCurrentChange"
            :summary-method="getSummaries"
            :data="table.list"
            :exchangeFilterMap="{
              weightType: {
                '0': '毛重',
                '1': '常规皮重',
                '2': '期限皮重',
                '3': '历史皮重',
                '4': '标识皮重',
                '5': '自重皮重',
              },
              meterMode: {
                '1': '远程计量',
                '2': '智能计量',
                '3': '手工录入',
                '4': '放行智能计量',
                '5': '滞后匹配',
              },
              valueFlag: { '0': '作废', '1': '作废', '3': '作废' },
            }"
            :icore-filter-flag="icoreFilterFlag"
          >
            <el-table-column
              type="index"
              label="序号"
              fixed="left"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="actualFirstNo"
              label="作业编号"
              min-width="110"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="predictionNo"
              label="预报编号"
              min-width="80"
              align="left"
            ></el-table-column>
            <!-- <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="railwayNo"
              label="车号"
              min-width="80"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="railwayCarriageNo"
              label="车厢序号"
              min-width="80"
              align="left"
            ></el-table-column> -->
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="railwayCarriageNo"
              label="列车作业编号"
              min-width="120"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="matterName"
              label="物资名称"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="meterWeight"
              label="计量重量"
              min-width="100"
              align="right"
            >
              <template slot-scope="scope">
                {{ Math.floor((scope.row.meterWeight - 0) / 10) / 100 }}
              </template>
            </el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="meterSortWeight"
              label="分检重量"
              min-width="100"
              align="right"
            >
              <template slot-scope="scope">
                {{ Math.floor((scope.row.meterSortWeight - 0) / 10) / 100 }}
              </template>
            </el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="meterBalanceWeight"
              label="结算重量"
              min-width="100"
              align="right"
            >
              <template slot-scope="scope">
                {{ Math.floor((scope.row.meterBalanceWeight - 0) / 10) / 100 }}
              </template>
            </el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="weightType"
              label="重量类型"
              min-width="100"
              align="left"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.weightType == 0">毛重</span>
                <span v-else-if="scope.row.weightType == 1">常规皮重</span>
                <span v-else-if="scope.row.weightType == 2">期限皮重</span>
                <span v-else-if="scope.row.weightType == 3">历史皮重</span>
                <span v-else-if="scope.row.weightType == 4">标识皮重</span>
                <span v-else-if="scope.row.weightType == 5">自重皮重</span>
              </template>
            </el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="shipmentNum"
              label="数量"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="baseSpotName"
              label="计量点"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="createTime"
              label="计量时间"
              min-width="160"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="createManName"
              label="计量员"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="meterClass"
              label="班次"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="meterGroup"
              label="班组"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="forwardingUnitName"
              label="发货单位"
              min-width="200"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="receivingUintName"
              label="收货单位"
              min-width="200"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="bindCardNo"
              label="绑定卡号"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="sampleNo"
              label="取样编号"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="sampleVoucher"
              label="取样凭证"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="meterTypeName"
              label="业务类型"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="meterMode"
              label="计量方式"
              min-width="100"
              align="left"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.meterMode == 1">远程计量</span>
                <span v-else-if="scope.row.meterMode == 2">智能计量</span>
                <span v-else-if="scope.row.meterMode == 3">手工录入</span>
                <span v-else-if="scope.row.meterMode == 4">放行智能计量</span>
                <span v-else-if="scope.row.meterMode == 5">滞后匹配</span>
              </template>
            </el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="valueFlag"
              label="状态"
              min-width="100"
              align="left"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.valueFlag == 0">作废</span>
                <span v-else-if="scope.row.valueFlag == 1">有效</span>
                <span v-else-if="scope.row.valueFlag == 2">结净</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="common-foot-style">
          <el-pagination
            v-loading="dataLoading"
            @size-change="pageSizeChange"
            @current-change="pageCurrentChange"
            :current-page="page.pageNum"
            :page-sizes="[50, 100, 200, 400]"
            :page-size="page.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page.totalPage"
          >
          </el-pagination>
        </div>
      </div>
    </div>
    <div class="common-title-div" style="margin-bottom: 10px">
      计量数据编辑区
    </div>
    <el-form
      ref="baseData"
      :inline="true"
      label-width="70px"
      :rules="ruleValidateTable"
      :model="baseData"
    >
      <el-form-item prop="meterTypeName" label="业务类型">
        <el-select
          v-model="baseData.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="meterSortWeight" label="分检重量">
        <el-input
          v-model="baseData.meterSortWeight"
          clearable
          style="width: 120px"
          size="small"
          placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item prop="forwardingUnitName" label="发货单位">
        <el-select
          v-model="baseData.forwardingUnitName"
          clearable
          filterable
          collapse-tags
          size="small"
          style="width: 120px"
        >
          <el-option
            v-for="item in forwardingUnitNameItem"
            :key="item.customerSupplierNo"
            :label="item.customerSupplierName"
            :value="item.customerSupplierName"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item prop="meterMode" label="计量方式">
        <el-select
          v-model="baseData.meterMode"
          clearable
          filterable
          collapse-tags
          size="small"
          style="width: 120px"
        >
          <el-option
            v-for="(item, index) in meterModeItem"
            :key="index"
            :label="item.meterMode"
            :value="item.meterMode"
          >
          </el-option>
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item prop="railwayNo" label="车      号">
            <el-input v-model="baseData.railwayNo" size="small" style="width:120px" placeholder="请输入"></el-input>
          </el-form-item> -->
      <el-form-item prop="meterWeight" label="计量重量">
        <el-input
          v-model="baseData.meterWeight"
          clearable
          size="small"
          style="width: 120px"
          placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item prop="meterGroup" label="班     组">
        <el-select
          v-model="baseData.meterGroup"
          clearable
          filterable
          collapse-tags
          size="small"
          style="width: 120px"
        >
          <el-option
            v-for="(item, index) in meterGroupItem"
            :key="index"
            :label="item.meterGroup"
            :value="item.meterGroup"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="receivingUintName" label="收货单位">
        <el-select
          v-model="baseData.receivingUintName"
          clearable
          filterable
          collapse-tags
          size="small"
          style="width: 120px"
        >
          <el-option
            v-for="item in receivingUintNameItem"
            :key="item.customerSupplierName"
            :label="item.customerSupplierName"
            :value="item.customerSupplierName"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="weightType" label="重量类型">
        <el-select
          v-model="baseData.weightType"
          clearable
          filterable
          collapse-tags
          size="small"
          style="width: 120px"
        >
          <el-option
            v-for="(item, index) in weightTypeItem"
            :key="index"
            :label="item.weightType"
            :value="item.weightType"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="baseSpotName" label="计量点">
        <el-select
          v-model="baseData.baseSpotName"
          clearable
          filterable
          collapse-tags
          size="small"
          style="width: 120px"
        >
          <el-option
            v-for="(item, index) in baseSpotNameItem"
            :key="index"
            :label="item.baseSpotName"
            :value="item.baseSpotName"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="matterName" label="物资名称">
        <el-select
          v-model="baseData.matterName"
          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.matterName"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="shipmentNum" label="计量数量">
        <el-input
          v-model="baseData.shipmentNum"
          clearable
          size="small"
          style="width: 120px"
          placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item prop="meterClass" label="班     次">
        <el-select
          v-model="baseData.meterClass"
          clearable
          filterable
          collapse-tags
          size="small"
          style="width: 120px"
        >
          <el-option
            v-for="(item, index) in meterClassItem"
            :key="index"
            :label="item.meterClass"
            :value="item.meterClass"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item prop="customerSupplierName" label="供应商">
        <el-select
          v-model="baseData.customerSupplierName"
          clearable
          filterable
          collapse-tags
          size="small"
          style="width: 120px"
        >
          <el-option
            v-for="(item, index) in customerSupplierNameItem"
            :key="index"
            :label="item.customerSupplierName"
            :value="item.customerSupplierName"
          >
          </el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item prop="railwayWorkNo" label="列车作业">
        <el-input
          v-model="baseData.railwayWorkNo"
          clearable
          style="width: 120px"
          size="small"
          placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item prop="createTime" label="计量时间">
        <el-date-picker
          v-model="baseData.createTime"
          clearable
          type="datetime"
          placeholder="选择日期"
          size="small"
        ></el-date-picker>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { formatDate } from '@/utils/util.js';
export default {
  data () {
    return {
      dataLoading: false,
      dataLoading2: false,
      operateLoading: false,
      icoreFilterFlag: true,
      actualFirst: {},
      baseSpotNameItem: [],//计量点
      meterTypeNameItem: [],
      matterNameItem: [],
      matterNameItem2: [],
      valueFlagItem: [
        { valueFlag: '有效' },
        { valueFlag: '作废' },
        { valueFlag: '结净' }
      ],
      materialNameItem: [],//材质
      forwardingUnitNameItem: [],//发货单位
      meterModeItem: [
        { id: '1', meterMode: '远程计量' },
        { id: '2', meterMode: '智能计量' },
        { id: '3', meterMode: '手工录入' },
        { id: '4', meterMode: '放行智能计量' },
        { id: '5', meterMode: '滞后匹配' }
      ],//计量方式
      meterGroupItem: [
        { meterGroup: '甲' },
        { meterGroup: '乙' },
        { meterGroup: '丙' },
        { meterGroup: '丁' }
      ],//班组
      specNameItem: [],//规格
      receivingUintNameItem: [],//收货单位
      weightTypeItem: [
        { id: '0', weightType: '毛重' },
        { id: '1', weightType: '常规皮重' },
        { id: '2', weightType: '期限皮重' },
        { id: '3', weightType: '历史皮重' },
        { id: '4', weightType: '标识皮重' },
        { id: '5', weightType: '自重皮重' }
      ],//重量类型
      meterClassItem: [
        { meterClass: '白班' },
        { meterClass: '中班' },
        { meterClass: '晚班' },
        { meterClass: '常白班' }
      ],//班次
      loadPointNameItem: [],//卸货地点
      carrierUnitNameItem: [],//承运单位
      customerSupplierNameItem: [],//供应商
      utensilNameItem: [],//器具名称
      utensilUtensilNameItem: [],//器具属性
      page: {
        pageSize: 100,
        pageNum: 1,
        totalPage: 0
      },
      page2: {
        pageSize: 100,
        pageNum: 1,
        totalPage: 0
      },
      table: {
        list: [],
        list2: []
      },
      baseData: {
        predictionNo: '',
        meterTypeName: '',
        addWeight: '',
        contractNo: '',
        materialName: '',
        forwardingUnitName: '',
        meterMode: '远程计量',
        meterWeight: '',
        meterGroup: '甲',
        batchNo: '',
        specName: '',
        receivingUintName: '',
        weightType: '毛重',
        baseSpotName: '',
        matterName: '',
        shipmentNum: '',
        meterClass: '白班',
        createTime: '',
        loadPointName: '',
        carrierUnitName: '',
        customerSupplierName: '',
        railwayWorkNo: '',
        railwayCarriageNo: ''
      },
      multipleSelection: {},
      tableHeight: 0,
      search: {
        railwayNo: '',
        baseSpotNo: '',
        meterTypeName: '',
        matterNo: '',
        valueFlag: '',
        strDate: '',
        envDate: '',
      },
      ruleValidateSearch: {
        envDate: [{
          required: true,
          validator: this.endTimeVerify,
          trigger: 'blur'
        }],
        strDate: [{
          required: true,
          validator: this.strTimeVerify,
          trigger: 'blur'
        }]
      },
      ruleValidateTable: {
        meterTypeName: [{
          required: true,
          message: '该项不能为空',
          trigger: 'change'
        }],
        baseSpotName: [{
          required: true,
          message: '该项不能为空',
          trigger: 'change'
        }],
        createTime: [{
          required: true,
          message: '该项不能为空',
          trigger: 'change'
        }]
      },
      activeMenu: '',
      matList: []
    }
  },
  created () {
    this.tableHeight = (window.innerHeight - 100) / 2 > 400 ? window.innerHeight - 100 : 400;
    this.activeMenu = window.top.localStorage.getItem('activeMenu')
  },
  mounted () {
    this.getDataList();
    this.getBaseSpotNameItem();
    this.getMatterNameItem();
    // this.getCarrierUnitNameItem();
    // this.getLoadPointNameItem();
    // this.getCustomerSupplierNameItem();
    this.getMeterTypeNameItem();
    // this.getMaterialNameItem();//材质
    // this.getSpecNameItem();//规格
    this.getForwardingUnitNameItem();//收发货单位
    // this.getReceivingUintNameItem();//收货单位
  },
  methods: {
    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)
      }
    },
    getMatterName2 (val) {
      if (val) {
        this.matterNameItem2 = this.matList.filter(item => {
          if (item.matterName.indexOf(val) !== -1) {
            return true
          }
        }).slice(0, 300)
      } else {
        this.matterNameItem2 = this.matList.slice(0, 300)
      }
    },
    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 === "quantity") {
          let val = 0;
          for (let i in data) {
            val = this.floatComputed(
              data[i].quantity ? data[i].quantity : 0,
              val,
              "+"
            );
          }
          sums[index] = val;
        } else if (column.property === "factweight") {
          let val = 0;
          for (let i in data) {
            val = this.floatComputed(
              data[i].factweight ? data[i].factweight : 0,
              val,
              "+"
            );
          }
          sums[index] = val;
        }
      });
      return sums;
    },
    getCode (code, arr, codeKey, nameKey) {
      if (!code) {
        return '';
      }
      let targetRow = arr.find(item => {
        return item[codeKey] === code;
      });
      return targetRow ? targetRow[nameKey] : '';
    },
    endTimeVerify (rule, value, callback) {
      if (this.search.strDate && !this.search.envDate) {
        callback(new Error('结束时间不能为空！'));
      } else if (this.search.envDate) {
        if (Date.parse(this.search.envDate) > Date.parse(this.search.strDate)) {
          callback();
        } else {
          callback(new Error('结束时间不得早于开始时间！'));
        }
      } else {
        callback();
      }
    },
    strTimeVerify (rule, value, callback) {
      if (this.search.envDate && !this.search.strDate) {
        callback(new Error('开始时间不能为空！'));
      } else {
        callback()
      }
    },
    refresh () {
      this.baseData = {
        predictionNo: '',
        meterTypeName: '',
        addWeight: '',
        contractNo: '',
        materialName: '',
        forwardingUnitName: '',
        railwayNo: '',
        meterMode: '远程计量',
        railwayNo: '',
        meterWeight: '',
        meterGroup: '甲',
        batchNo: '',
        specName: '',
        receivingUintName: '',
        contractNo: '',
        weightType: '毛重',
        baseSpotName: '',
        matterName: '',
        shipmentNum: '',
        meterClass: '白班',
        createTime: '',
        carrierUnitName: '',
        customerSupplierName: '',
        railwayWorkNo: '',
        railwayCarriageNo: ''
      }
      // this.baseData.matterName = this.matterNameItem[0].matterName
      // this.baseData.carrierUnitName = this.carrierUnitNameItem[0].carrierUnitName
      // this.baseData.loadPointName = this.loadPointNameItem[0].loadPointName
      this.baseData.baseSpotName = this.baseSpotNameItem[0].baseSpotName
      // this.baseData.customerSupplierName = this.customerSupplierNameItem[0].customerSupplierName
      // this.baseData.meterTypeName = this.meterTypeNameItem[0].baseName
      // this.baseData.materialName = this.materialNameItem[0].baseName
      // this.baseData.specName = this.specNameItem[0].baseName
      // this.baseData.receivingUintName = this.receivingUintNameItem[0].companyName
      // this.baseData.forwardingUnitName = this.forwardingUnitNameItem[0].companyName
      this.$refs['baseData'].resetFields();
    },
    addData () {
      this.$refs['baseData'].validate((valid) => {
        if (valid) {
          let baseDataAdd = {}
          baseDataAdd.meterTypeName = this.baseData.meterTypeName
          baseDataAdd.meterTypeName = this.baseData.meterTypeName
          baseDataAdd.addWeight = this.baseData.addWeight
          baseDataAdd.materialName = this.baseData.materialName
          baseDataAdd.forwardingUnitName = this.baseData.forwardingUnitName
          baseDataAdd.railwayNo = this.baseData.railwayNo
          baseDataAdd.meterWeight = this.baseData.meterWeight
          baseDataAdd.meterGroup = this.baseData.meterGroup
          baseDataAdd.batchNo = this.baseData.batchNo
          baseDataAdd.specName = this.baseData.specName
          baseDataAdd.receivingUintName = this.baseData.receivingUintName
          baseDataAdd.contractNo = this.baseData.contractNo
          baseDataAdd.baseSpotName = this.baseData.baseSpotName
          baseDataAdd.matterName = this.baseData.matterName
          baseDataAdd.shipmentNum = this.baseData.shipmentNum
          baseDataAdd.meterClass = this.baseData.meterClass
          baseDataAdd.createTime = this.baseData.createTime
          baseDataAdd.carrierUnitName = this.baseData.carrierUnitName
          baseDataAdd.customerSupplierName = this.baseData.customerSupplierName
          baseDataAdd.railwayWorkNo = this.baseData.railwayWorkNo
          baseDataAdd.railwayCarriageNo = this.baseData.railwayCarriageNo
          baseDataAdd.meterMode = this.getCode(this.baseData.meterMode, this.meterModeItem, 'meterMode', 'id')
          baseDataAdd.weightType = this.getCode(this.baseData.weightType, this.weightTypeItem, 'weightType', 'id')
          baseDataAdd.baseSpotNo = this.getCode(this.baseData.baseSpotName, this.baseSpotNameItem, 'baseSpotName', 'baseSpotNo')
          baseDataAdd.meterTypeNo = this.getCode(this.baseData.meterTypeName, this.meterTypeNameItem, 'baseName', 'baseCode')
          baseDataAdd.matterNo = this.getCode(this.baseData.matterName, this.matterNameItem, 'matterName', 'matterNo')
          baseDataAdd.loadPointNo = this.getCode(this.baseData.loadPointName, this.loadPointNameItem, 'loadPointName', 'loadPointNo')
          baseDataAdd.carrierUnitNo = this.getCode(this.baseData.carrierUnitName, this.carrierUnitNameItem, 'carrierUnitName', 'carrierUnitNo')
          baseDataAdd.customerSupplierNo = this.getCode(this.baseData.customerSupplierName, this.customerSupplierNameItem, 'customerSupplierName', 'customerSupplierNo')
          baseDataAdd.materialNo = this.getCode(this.baseData.materialName, this.materialNameItem, 'baseName', 'baseCode')
          baseDataAdd.specNo = this.getCode(this.baseData.specName, this.specNameItem, 'baseName', 'baseCode')
          baseDataAdd.forwardingUnitNo = this.getCode(this.baseData.forwardingUnitName, this.forwardingUnitNameItem, 'companyName', 'companyNo')
          baseDataAdd.receivingUintNo = this.getCode(this.baseData.receivingUintName, this.receivingUintNameItem, 'companyName', 'companyNo')
          baseDataAdd.railwayTypeNo = '001019002'
          baseDataAdd.railwayTypeName = '动态轨道衡'
          this.axios.post('pass/systemBase/v1/meterworkrailwayactfirsts/add', baseDataAdd, { individualType: 'json' }).then(res => {
            if (res.succeed) {
              this.$message.success('新增成功');
              this.getDataList();
              this.refresh();
            } else {
              this.baseData.meterMode = this.getCode(this.baseData.meterMode, this.meterModeItem, 'id', 'meterMode')
              this.baseData.weightType = this.getCode(this.baseData.weightType, this.weightTypeItem, 'id', 'weightType')
              this.$message.error(res.message)
            }
          }).catch(e => {
            this.baseData.meterMode = this.getCode(this.baseData.meterMode, this.meterModeItem, 'id', 'meterMode')
            this.baseData.weightType = this.getCode(this.baseData.weightType, this.weightTypeItem, 'id', 'weightType')
            this.$message.error(e.message)
          })
        }
      })
    },
    modifyData () {
      this.$refs['baseData'].validate((valid) => {
        if (valid) {
          this.baseData.meterMode = this.getCode(this.baseData.meterMode, this.meterModeItem, 'meterMode', 'id')
          this.baseData.weightType = this.getCode(this.baseData.weightType, this.weightTypeItem, 'weightType', 'id')
          this.baseData.baseSpotNo = this.getCode(this.baseData.baseSpotName, this.baseSpotNameItem, 'baseSpotName', 'baseSpotNo')
          this.baseData.meterTypeNo = this.getCode(this.baseData.meterTypeName, this.meterTypeNameItem, 'baseName', 'baseCode')
          this.baseData.matterNo = this.getCode(this.baseData.matterName, this.matList, 'matterName', 'matterNo')
          this.baseData.loadPointNo = this.getCode(this.baseData.loadPointName, this.loadPointNameItem, 'loadPointName', 'loadPointNo')
          this.baseData.carrierUnitNo = this.getCode(this.baseData.carrierUnitName, this.carrierUnitNameItem, 'carrierUnitName', 'carrierUnitNo')
          this.baseData.customerSupplierNo = this.getCode(this.baseData.customerSupplierName, this.customerSupplierNameItem, 'customerSupplierName', 'customerSupplierNo')
          this.baseData.materialNo = this.getCode(this.baseData.materialName, this.materialNameItem, 'baseName', 'baseCode')
          this.baseData.specNo = this.getCode(this.baseData.specName, this.specNameItem, 'baseName', 'baseCode')
          this.baseData.forwardingUnitNo = this.getCode(this.baseData.forwardingUnitName, this.forwardingUnitNameItem, 'companyName', 'companyNo')
          this.baseData.receivingUintNo = this.getCode(this.baseData.receivingUintName, this.receivingUintNameItem, 'companyName', 'companyNo')
          this.axios.post('pass/systemBase/v1/meterworkrailwayactfirsts/update', this.baseData, { individualType: 'json' }).then(res => {
            if (res.succeed) {
              this.$message.success('修改成功');
              this.getDataList();
              this.refresh();
            } else {
              this.baseData.meterMode = this.getCode(this.baseData.meterMode, this.meterModeItem, 'id', 'meterMode')
              this.baseData.weightType = this.getCode(this.baseData.weightType, this.weightTypeItem, 'id', 'weightType')
              this.$message.error(res.message)
            }
          }).catch(e => {
            this.baseData.meterMode = this.getCode(this.baseData.meterMode, this.meterModeItem, 'id', 'meterMode')
            this.baseData.weightType = this.getCode(this.baseData.weightType, this.weightTypeItem, 'id', 'weightType')
            this.$message.error(e.message)
          })
        }
      })
    },
    enableData () {
      if (JSON.stringify(this.multipleSelection) == "{}") {
        this.$message.warning('请选择您要启用的数据！');
        return;
      }
      if (this.multipleSelection.valueFlag === '1') {
        this.$message.warning('请选择状态为无效的数据！');
        return false;
      }
      this.axios.post('pass/systemBase/v1/meterworkrailwayactfirsts/recover', this.multipleSelection, { individualType: 'json' }).then(res => {
        if (res.succeed) {
          this.$message.success('启用成功');
          this.getDataList();
          //  this.refresh();
          //  this.refresh2();
        } else {
          this.$message.error(res.message)
        }
      }).catch(e => {
        this.$message.error(e.message)
      })
    },
    discardData () {
      if (JSON.stringify(this.multipleSelection) == "{}") {
        this.$message.warning('请选择您要废除的数据！');
        return;
      }
      if (this.multipleSelection.valueFlag === '0') {
        this.$message.warning('请选择状态为有效的数据！');
        return false;
      }
      this.axios.post('pass/systemBase/v1/meterworkrailwayactfirsts/abolish', this.multipleSelection, { individualType: 'json' }).then(res => {
        if (res.succeed) {
          this.$message.success('作废成功');
          this.getDataList();
          //  this.refresh();
          //  this.refresh2();
        } else {
          this.$message.error(res.message)
        }
      }).catch(e => {
        this.$message.error(e.message)
      })
    },
    handleSelectionChange (val) {
      this.multipleSelection = val;
    },
    rowChange (row, column, event) {
      this.baseData = Object.assign({}, row);
      this.axios.get('pass/systemBase/v1/meterbasematterinfos/noPage' + '?validFlag=1' + '&matterNo=' + this.baseData.matterNo)
        .then(res => {
          this.matterNameItem = res.data;
        })
      this.baseData.meterMode = this.getCode(this.baseData.meterMode, this.meterModeItem, 'id', 'meterMode')
      this.baseData.weightType = this.getCode(this.baseData.weightType, this.weightTypeItem, 'id', 'weightType')
    },
    searchData () {
      this.$refs['searchData'].validate((valid) => {
        if (valid) {
          this.dataLoading = true;
          this.page.pageNum = 1;
          this.search.valueFlag1 = this.search.valueFlag === '有效' ? 1 : this.search.valueFlag === '作废' ? 0 : this.search.valueFlag === '结净' ? 2 : ''
          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/meterworkrailwayactfirsts/selectAct' + '?pageNum=' + this.page.pageNum + '&pageSize=' + this.page.pageSize + '&railwayNo=' + this.search.railwayNo
            + '&baseSpotNo=' + this.search.baseSpotNo + '&meterTypeName=' + this.search.meterTypeName + '&matterNo=' + this.search.matterNo + '&valueFlag=' + this.search.valueFlag1
            + '&createTime1=' + this.search.strDate + '&createTime2=' + this.search.envDate)
            .then(res => {
              this.dataLoading = false;
              this.table.list = res.data.list;
              this.page.totalPage = res.data.total;
            }).catch(e => {
              this.dataLoading = false;
            });
        }
      })
    },
    handleCurrentChange (val) {
      this.multipleSelection = val;
    },
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.getDataList();
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.getDataList();
    },
    getDataList () {
      this.dataLoading = true;
      this.axios.get('pass/systemBase/v1/meterworkrailwayactfirsts/selectAct' + '?pageNum=' + this.page.pageNum + '&pageSize=' + this.page.pageSize)
        .then(res => {
          this.dataLoading = false;
          this.table.list = res.data.list;
          this.page.totalPage = res.data.total;
        }).catch(e => {
          this.dataLoading = false;
        });
    },
    tableRowClassName ({
      row,
      rowIndex
    }) {
      if (row.valueFlag === '0') {
        return 'error-row2';
      }
      return '';
    },
    getBaseSpotNameItem () {
      this.axios.get('pass/systemBase/v1/meterbasespotinfos/noPage' + '?validFlag=1' + '&spotTypeNo=001002002&spotTypeName=轨道衡')
        .then(res => {
          let data = res.data.filter(item => item.baseSpotName.indexOf('动') !== -1);
          this.baseSpotNameItem = data;
          this.baseData.baseSpotName = data[0].baseSpotName;
        })
    },
    async getMatterNameItem () {
      let param = {
        pageNum: 1,
        pageSize: 1000,
        validFlag: '1',
        memo: '动态轨道衡'
      }
      let { data: res } = await this.axios.post('pass/systemBase/v1/meterbasematterinfos/listLike', param, { individualType: 'json' })
      console.log(res, '动轨用物料数据')
      this.matList = [...res.list]
      this.matterNameItem = this.matList.slice(0, 300)
      this.matterNameItem2 = this.matList.slice(0, 300)
    },
    getCarrierUnitNameItem () {
      this.axios.get('pass/systemBase/v1/meterbasecarrierunits/noPage' + '?validFlag=1')
        .then(res => {
          this.carrierUnitNameItem = res.data;
        })
    },
    getLoadPointNameItem () {
      this.axios.get('pass/systemBase/v1/meterbaseloadpoints/noPage' + '?validFlag=1')
        .then(res => {
          this.loadPointNameItem = res.data;
        })
    },
    getCustomerSupplierNameItem () {
      this.axios.get('pass/systemBase/v1/meterbasecustomersuppliers/noPage' + '?validFlag=1')
        .then(res => {
          this.customerSupplierNameItem = res.data;
        })
    },
    getMeterTypeNameItem () {
      this.axios.get('pass/systemBase/v1/combaseinfos/noPage' + '?pBaseCode=001006' + '&validFlag=1')
        .then(res => {
          this.meterTypeNameItem = res.data;
          this.baseData.meterTypeName = res.data[0].baseName;
        })
    },
    getMaterialNameItem () {
      this.axios.get('pass/systemBase/v1/combaseinfos/noPage' + '?pBaseCode=001017' + '&validFlag=1')
        .then(res => {
          this.materialNameItem = res.data;
        })
    },
    getSpecNameItem () {
      this.axios.get('pass/systemBase/v1/combaseinfos/noPage' + '?pBaseCode=001018' + '&validFlag=1')
        .then(res => {
          this.specNameItem = res.data;
        })
    },
    getForwardingUnitNameItem () {
      this.axios.get('pass/systemBase/v1/meterbasecustomersuppliers/like/?pageNum=1&PageSize=1000&memo=动态轨道衡')
        .then(res => {
          console.log(res)
          // 发货单位
          let rcvList = res.data.list.filter(item => item.customerSupplierType - 0 === 0);
          let sdrList = res.data.list.filter(item => (item.customerSupplierType - 0 === 1 || item.customerSupplierType - 0 === 2))
          this.forwardingUnitNameItem = [...sdrList];
          this.receivingUintNameItem = [...rcvList];
        })
    }
  }
}
</script>

<style scoped>
</style>