<!--动轨手工录数-->
<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 prop="strDate" label="开始时间">
            <el-date-picker
              v-model="search.strDate"
              clearable
              type="datetime"
              style="width: 180px"
              placeholder="选择日期"
              @change="dateChange('search', 'strDate', search.strDate)"
              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"
              @change="dateChange('search', 'envDate', search.envDate)"
              placeholder="选择日期"
              size="small"
            ></el-date-picker>
          </el-form-item>
          <el-form-item prop="baseSpotName" label="计量点">
            <el-select
              v-model="search.baseSpotName"
              filterable
              collapse-tags
              size="small"
              style="width: 120px"
              @change="spotChange"
            >
              <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 label-width="20px">
            <el-button
              icon="el-icon-search"
              type="primary"
              size="mini"
              @click="searchForcastData"
              v-privilege="activeMenu + 'QUERY'"
              >查询</el-button
            >
            <el-button
              icon="el-icon-circle-plus-outline"
              type="primary"
              size="mini"
              @click="showAddDialog"
              v-privilege="activeMenu + 'QUERY'"
              >新增</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <div style="border-right: 1px solid #d5d5d5">
        <el-row>
          <el-col :span="12">
            <div class="common-title-div">预报数据</div>
            <div class="common-table-div">
              <el-table
                v-loading="dataLoading"
                ref="dataTable"
                highlight-current-row
                border
                :height="tableHeight2"
                @current-change="forecastCurrentChange"
                :icore-filter-flag="icoreFilterFlag"
                :data="forcastList"
              >
                <el-table-column
                  type="index"
                  label="序号"
                  fixed="left"
                  align="center"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="predictionNo"
                  label="预报编号"
                  min-width="120"
                  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="matterName"
                  label="物资名称"
                  min-width="120"
                  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="meterTypeName"
                  min-width="100"
                  label="业务类型"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="memo"
                  min-width="100"
                  label="备注"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="railwayTypeName"
                  min-width="100"
                  label="轨道衡类型"
                  align="left"
                ></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-if="scope.row.valueFlag == 1">未使用</span>
                    <span v-else-if="scope.row.valueFlag == 2">已使用</span>
                    <span v-else-if="scope.row.valueFlag == 3">已作废</span>
                    <span v-else-if="scope.row.valueFlag == 4">正使用</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="[100, 500, 1000]"
                :page-size="page.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="page.totalPage"
              >
              </el-pagination>
            </div> -->
          </el-col>
          <el-col :span="12">
            <div class="common-title-div">期限皮重数据</div>
            <div class="common-table-div">
              <el-table
                v-loading="dataLoading2"
                ref="dataTable2"
                highlight-current-row
                border
                :height="tableHeight2"
                @current-change="handleCurrentChange2"
                :icore-filter-flag="icoreFilterFlag"
                :data="tareTypeList"
              >
                <el-table-column
                  type="index"
                  label="序号"
                  fixed="left"
                  align="center"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="210px"
                  prop="tareTypeName"
                  label="重量类型"
                  align="center"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100px"
                  prop="railwayWeight"
                  label="重量"
                  align="right"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100px"
                  prop="railwayType"
                  label="火车类型"
                  align="center"
                >
                  <template slot-scope="scope">
                    <span v-if="scope.row.railwayType == 0">内部车辆</span>
                    <span v-else-if="scope.row.railwayType == 1">外部车辆</span>
                  </template>
                </el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100px"
                  prop="railwayTypeName"
                  label="轨道类型名称"
                  align="center"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100px"
                  prop="startTime1"
                  label="有效开始时间"
                  align="center"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100px"
                  prop="endTime1"
                  label="有效结束时间"
                  align="center"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100px"
                  prop="termValidity"
                  label="有效期(天)"
                  align="right"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100px"
                  prop="createManName"
                  label="创建人姓名"
                  align="center"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="160px"
                  prop="createTime"
                  label="创建人时间"
                  align="center"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="100px"
                  prop="updateManName"
                  label="修改人姓名"
                  align="center"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  min-width="160px"
                  prop="updateTime"
                  label="修改人时间"
                  align="center"
                ></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>
        <el-row>
          <el-col :span="24">
            <div
              style="
                margin-top: 10px;
                padding-top: 10px;
                border-bottom: 1px solid #d5d5d5;
                border-top: 1px solid #d5d5d5;
              "
            >
              <el-form
                ref="search2"
                :inline="true"
                :model="search2"
                :rules="ruleValidateSearch2"
              >
                <el-form-item label-width="80px">
                  <div style="font-size: 16px; padding: 0px 20px">净重数据</div>
                </el-form-item>
                <el-form-item prop="strDate" label="开始时间">
                  <el-date-picker
                    v-model="search2.strDate"
                    clearable
                    type="datetime"
                    style="width: 180px"
                    placeholder="选择日期"
                    @change="dateChange('search2', 'strDate', search2.strDate)"
                    size="small"
                  ></el-date-picker>
                </el-form-item>
                <el-form-item prop="envDate" label="结束时间">
                  <el-date-picker
                    v-model="search2.envDate"
                    clearable
                    type="datetime"
                    @change="dateChange('search2', 'envDate', search2.envDate)"
                    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="searchNetData"
                    >查询</el-button
                  >
                </el-form-item>
                <el-form-item label-width="20px">
                  <el-button
                    type="danger"
                    plain
                    icon="el-icon-remove-outline"
                    size="mini"
                    @click="unCleanData"
                    v-privilege="activeMenu + 'RELIEVE'"
                    >解除</el-button
                  >
                </el-form-item>
              </el-form>
            </div>
            <div class="common-table-div">
              <el-table
                v-loading="dataLoading3"
                ref="dataTable3"
                highlight-current-row
                border
                :height="tableHeight"
                @selection-change="handleSelectionChange"
                :data="netDataList"
                :exchangeFilterMap="{
                  uploadFlag: { '0': '待审核', '1': '待上传', '2': '已上传' },
                  grossMode: {
                    '1': '远程计量',
                    '2': '智能计量',
                    '3': '手工录入',
                    '4': '放行智能计量',
                    '5': '滞后匹配',
                  },
                  tareMode: {
                    '1': '远程计量',
                    '2': '智能计量',
                    '3': '手工录入',
                    '4': '放行智能计量',
                    '5': '滞后匹配',
                  },
                  netMode: { '1': '正常结净', '2': '匹配结净' },
                }"
                :icore-filter-flag="true"
              >
                <el-table-column
                  type="index"
                  label="序号"
                  fixed="left"
                  align="center"
                ></el-table-column>
                <el-table-column
                  type="selection"
                  width="55"
                  align="center"
                  fixed="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="predictionNo"
                  label="预报编号"
                  min-width="120"
                  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="matterName"
                  label="物资名称"
                  min-width="120"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="forwardingUnitName"
                  min-width="120"
                  label="发货单位"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="receivingUintName"
                  min-width="120"
                  label="收货单位"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="grossWeight"
                  label="毛重"
                  min-width="100"
                  align="right"
                >
                  <template slot-scope="scope">
                    {{ Math.floor((scope.row.grossWeight - 0) / 10) / 100 }}
                  </template>
                </el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="tareWeight"
                  label="皮重"
                  min-width="100"
                  align="right"
                >
                  <template slot-scope="scope">
                    {{ Math.floor((scope.row.tareWeight - 0) / 10) / 100 }}
                  </template>
                </el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="netWeight"
                  label="净重"
                  min-width="100"
                  align="right"
                >
                  <template slot-scope="scope">
                    {{ Math.floor((scope.row.netWeight - 0) / 10) / 100 }}
                  </template>
                </el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="waterNum"
                  label="水分"
                  min-width="100"
                  align="right"
                >
                </el-table-column>
                <!-- <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="dryWeight"
                  label="干重"
                  min-width="100"
                  align="right"
                >
                  <template slot-scope="scope">
                    {{ Math.floor((scope.row.dryWeight - 0) / 10) / 100 }}
                  </template>
                </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"
                  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="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="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="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="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="meterTypeName"
                  min-width="120"
                  label="业务类型"
                  align="left"
                ></el-table-column>
                <el-table-column
                  sortable
                  :show-overflow-tooltip="true"
                  prop="uploadFlag"
                  min-width="120"
                  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="page3.pageNum"
                :page-sizes="[50, 100, 200, 400]"
                :page-size="page3.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="page3.totalPage"
              >
              </el-pagination>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <!-- 实绩新增弹窗 -->
    <el-dialog
      @close="closeDialog"
      :visible.sync="showFlag"
      customClass="weight-input-wrap"
      title="计量数据录入"
      width="700px"
      :close-on-click-modal="false"
    >
      <el-form
        ref="formObj"
        label-width="70px"
        :inline="true"
        :model="formObj"
        :rules="rules"
      >
        <el-form-item prop="matterName" label="物资名称">
          <el-input
            type="text"
            size="mini"
            v-model="formObj.matterName"
            disabled
          ></el-input>
        </el-form-item>
        <el-form-item prop="forwardingUnitName" label="发货单位">
          <el-input
            type="text"
            size="mini"
            v-model="formObj.forwardingUnitName"
            disabled
          ></el-input>
        </el-form-item>
        <el-form-item prop="receivingUintName" label="收货单位">
          <el-input
            type="text"
            size="mini"
            v-model="formObj.receivingUintName"
            disabled
          ></el-input>
        </el-form-item>
        <el-form-item prop="grossWeight" label="毛重">
          <el-input
            v-model="formObj.grossWeight"
            size="small"
            type="number"
            style="width: 160px"
          ></el-input>
        </el-form-item>
        <el-form-item prop="tareWeight" label="期限皮重">
          <el-input
            v-model="formObj.tareWeight"
            size="small"
            type="number"
            style="width: 160px"
          ></el-input>
        </el-form-item>
        <el-form-item prop="netWeight" label="净重">
          <el-input
            v-model="formObj.netWeight"
            size="small"
            type="number"
            style="width: 160px"
          ></el-input>
        </el-form-item>
        <el-form-item prop="createTime" label="毛重时间">
          <el-date-picker
            v-model="formObj.createTime"
            clearable
            type="datetime"
            style="width: 180px"
            placeholder="选择日期"
            @change="dateChange('formObj', 'createTime', formObj.createTime)"
            size="small"
          ></el-date-picker>
        </el-form-item>
        <el-form-item prop="insertNum" label="新增条数">
          <el-input
            v-model="formObj.insertNum"
            size="small"
            type="number"
            style="width: 160px"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="primary" size="mini" @click="createData"
          >确定</el-button
        >
        <el-button size="mini" type="default" @click="closeDialog"
          >取消</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getCookie, formatDate } from '@/utils/util.js';
import { cookieUserId, cookieUserName } from '@/config/config.js'
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
  data () {
    return {
      dataLoading: false,
      dataLoading2: false,
      dataLoading3: false,
      icoreFilterFlag: false,
      page: {
        pageSize: 100,
        pageNum: 1,
        totalPage: 0
      },
      page2: {
        pageSize: 100,
        pageNum: 1,
        totalPage: 0
      },
      page3: {
        pageSize: 100,
        pageNum: 1,
        totalPage: 0
      },
      forcastList: [],
      tableHeight: 430,
      tableHeight2: 140,
      dataList: {},
      search: {
        strDate: formatDate(new Date(), 'yyyy-MM-dd') + ' 00:00:00',
        envDate: formatDate(new Date(), 'yyyy-MM-dd') + ' 23:59:59',
        baseSpotName: '选矿计检站动态衡',
        baseSpotNo: '00025',
        railwayTypeName: '动态轨道衡'
      },
      search2: {
        railwayNo: '',
        strDate: formatDate(new Date(), 'yyyy-MM-dd') + ' 00:00:00',
        envDate: formatDate(new Date(), 'yyyy-MM-dd') + ' 23:59:59'
      },
      // 预报查询表单验证规则对象
      ruleValidateSearch: {
        envDate: [{
          required: true,
          validator: this.endTimeVerify,
          trigger: 'blur'
        }],
        strDate: [{
          required: true,
          validator: this.strTimeVerify,
          trigger: 'blur'
        }]
      },
      // 动轨实绩查询表单验证规则对象
      ruleValidateSearch2: {
        envDate: [{
          required: true,
          validator: this.endTimeVerify2,
          trigger: 'blur'
        }],
        strDate: [{
          required: true,
          validator: this.strTimeVerify2,
          trigger: 'blur'
        }]
      },
      activeMenu: '',
      matterNameItem: [],
      sdrList: [],
      rcvList: [],
      baseSpotNameItem: [], // 计量点数据
      netList: [], // 净重勾选数据
      forcastRow: {},
      tareTypeList: [], // 期限皮重数据
      netDataList: [],
      formObj: {
        matterName: '',
        forwardingUnitName: '',
        receivingUintName: '',
        grossWeight: '',
        tareWeight: '',
        netWeight: '',
        insertNum: 0,
        railwayModelName: '补录'
      }, // 数据新增对象
      formObjCache: {
        matterName: '',
        forwardingUnitName: '',
        receivingUintName: '',
        grossWeight: '',
        tareWeight: '',
        netWeight: '',
        insertNum: 0,
        railwayModelName: '补录'
      }, // 数据新增对象
      showFlag: false,
      rules: {
        grossWeight: [{ required: true, message: '毛重不能为空', trigger: 'blur' }],
        tareWeight: [{ required: true, message: '皮重不能为空', trigger: 'blur' }],
        netWeight: [{ required: true, message: '净重不能为空', trigger: 'blur' }],
        matterName: [{ required: true, message: '物资不能为空', trigger: 'blur' }],
        forwardingUnitName: [{ required: true, message: '发货单位不能为空', trigger: 'blur' }],
        receivingUintName: [{ required: true, message: '收货单位不能为空', trigger: 'blur' }]
      },
      avgGross: 0
    }
  },
  created () {
    this.activeMenu = window.top.localStorage.getItem('activeMenu')
  },
  mounted () {
    this.init();
  },
  methods: {
    async init () {
      this.searchForcastData();
      this.searchNetData();
      await this.getBaseSpotNameItem();
      this.getDynamicTareType();
    },
    // 查询预报数据
    async searchForcastData (flag = 1) {
      if (flag === 1) {
        this.page.pageNum = 1
      }
      // 判断计量点是砂石还是选矿
      let memo = this.search.baseSpotName.indexOf('砂石') !== -1 ? '0' : '1'
      if (memo === 1 && (this.search.strDate - 0 === 0 || this.search.envDate - 0 === '')) {
        return this.$message.error('开始结束时间不能为空')
      }
      let strTime = memo === '0' ? '' : this.search.strDate;
      let endTime = memo === '0' ? '' : this.search.envDate;
      let paramStr = `startTime=${strTime}&endTime=${endTime}&memo=${memo}&railwayTypeName=动态轨道衡`
      const { data: res } = await this.axios.get(`pass/systemBase/v1/prerailwayscales/doQueryByCar?${paramStr}`)
      // console.log(res, '预报查询数据')
      if (res) {
        this.forcastList = [...res]
      } else {
        this.forcastList = []
      }
      this.getDynamicTareType()
    },
    // 获取动轨期限皮重
    async getDynamicTareType () {
      const { data: res } = await this.axios.get(`pass/systemBase/v1/meterbaserailwayweights/?railwayTypeName=动态轨道衡&valueFlag=0&tareType=${this.search.baseSpotNo}`)
      // console.log(res, '期限皮重类型数据')
      if (res && res.list) {
        this.tareTypeList = [...res.list]
      } else {
        this.tareTypeList = []
      }
    },
    // 查询动轨补录净重数据
    async searchNetData (flag = 1) {
      if (flag === 1) {
        this.page3.pageNum = 1
      }
      const { data: res } = await this.axios.get('pass/systemBase/v1/meterworkrailwayactuals/selectDiff' + '?pageNum=' + this.page3.pageNum + '&pageSize=' + this.page3.pageSize
        + '&createTime1=' + this.search2.strDate + '&createTime2=' + this.search2.envDate + `&flag=1&grossMode=3`)
      // console.log(res, '洁净数据查询返回结果')
      if (res && res.list) {
        this.netDataList = [...res.list]
        this.page3.totalPage = res.total - 0
      } else {
        this.netDataList = [];
        this.page3.totalPage = 0;
      }
    },
    // 获取计量点数据
    getBaseSpotNameItem () {
      this.axios.get('pass/systemBase/v1/meterbasespotinfos/noPage' + '?validFlag=1' + '&spotTypeNo=001002002')
        .then(res => {
          let spotData = res.data ? res.data.filter(i => i.baseSpotName.indexOf('动态') !== -1) : [];
          this.baseSpotNameItem = [...spotData];
        })
    },
    // 手工录入计量数据
    async createData () {
      const valid = this.$refs.formObj.validate().catch(() => false)
      if (!valid) return this.$message.error('请规范填写数据')
      if (this.formObj.insertNum - 0 === 0 || !(/^[1-9]\d*$/.test(this.formObj.insertNum))) {
        return this.$message.error('新增条数需要为大于0的整数')
      }
      // 构建请求参数
      let spotItem = this.baseSpotNameItem.find(b => b.baseSpotName === this.search.baseSpotName)
      // 预报实体
      let forecastObj = { ...this.forcastRow }
      // 期限皮重实体
      let tareObj = { ...this.tareRow }
      let netList = []
      for (let i = 0; i < this.formObj.insertNum; i++) {
        // 一次实绩
        let actualObj = {
          ...this.formObj,
          railwayCarriageNo: i + 1,
          meterWeight: this.formObj.grossWeight,
          baseSpotName: this.search.baseSpotName,
          baseSpotNo: spotItem.baseSpotNo,
          createManName: userName,
          createManNo: userId,
          createTime: this.formObj.createTime,
          railwayModelName: '补录',
          meterGroup: 'BL',
          id: null
        }
        netList.push(actualObj)
      }
      let paramObj = {
        one: { ...forecastObj },
        two: [...netList],
        three: { ...tareObj }
      }

      const data = await this.axios.post('pass/systemBase/v1/meterworkrailwayactfirsts/doAddMotoriaWf', paramObj, { individualType: 'json' })
      console.log(data, '新增返回结果')
      if (data.status === 'succeed') {
        this.$message.success('新增成功')
        this.init()
        this.closeDialog()
      } else {
        this.$message.error('新增失败')
      }
    },
    spotChange (val) {
      console.log(val)
      console.log(this.baseSpotNameItem)
      if (val) {
        let spotItem = this.baseSpotNameItem.find(b => b.baseSpotName === val)
        this.search.baseSpotNo = spotItem.baseSpotNo
      }
    },
    dateChange (formName, valName, val) {
      if (formName === 'search') {
        this.search[valName] = formatDate(val)
      } else if (formName === 'formObj') {
        this.formObj[valName] = formatDate(val)
      } else {
        this.search2[valName] = formatDate(val)
      }
    },
    // 净重数据多选
    handleSelectionChange (val) {
      this.netList = [...val]
    },
    // 预报当前行选中
    forecastCurrentChange (val) {
      this.forcastRow = { ...val }
    },
    handleCurrentChange2 (val) {
      this.tareRow = { ...val }
    },
    //解除
    unCleanData () {
      if (this.netList.length < 1) {
        this.$message.warning('请选择您要解除结净的数据！');
        return false;
      }
      this.axios.post('pass/systemBase/v1/meterworkrailwayactuals/removeDt', this.netList, { individualType: 'json' }).then(res => {
        if (res.code == '0' || res.code == '200') {
          this.$message.success('解除成功');
          this.init();
        } else {
          this.$message.error(res.message)
        }
      }).catch(e => {
        this.$message.error(e.message)
      })
    },
    // 根据选中预报数据查询前7天平均重量
    async getAverageWgt (row) {
      let item = this.baseSpotNameItem.find(t => t.baseSpotName === this.search.baseSpotName)
      // 获取当前时间以及七天前时间
      let dateNow = formatDate(new Date(), 'yyyy-MM-dd') + ' 00:00:00';
      let earlyDate = formatDate(new Date(new Date().getTime() - 7 * 24 * 3600 * 1000), 'yyyy-MM-dd') + ' 23:59:59';
      let param = {
        startTime: earlyDate,
        endTime: dateNow,
        matterNo: row.matterNo,
        netSpot3No: item.baseSpotNo
      }
      const { data: res } = await this.axios.post('pass/systemBase/v1/meterworkrailwayactuals/getTareAvg', param, { individualType: 'json' })
      this.avgGross = res - 0
    },
    closeDialog () {
      this.showFlag = false
      this.formObj = { ...this.formObjCache }
    },
    // 显示新增弹窗
    async showAddDialog () {
      if (JSON.stringify(this.forcastRow) === '{}') {
        return this.$message.error('请点选要新增计量数据的预报')
      }
      if (JSON.stringify(this.tareRow) === '{}') {
        return this.$message.error('请点选要新增计量数据的期限皮重')
      }
      await this.getAverageWgt(this.forcastRow)
      this.formObj = { ...this.formObj, ...this.forcastRow }
      this.formObj.grossWeight = this.avgGross - 0
      this.formObj.tareWeight = Math.floor((this.tareRow.railwayWeight - 0) / 10) / 100 // 转换为吨
      this.showFlag = true
    },
    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()
      }
    },
    endTimeVerify2 (rule, value, callback) {
      if (this.search2.strDate !== '' && this.search2.envDate === '') {
        callback(new Error('结束时间不能为空！'));
      } else if (this.search2.envDate) {
        if (Date.parse(this.search2.envDate) > Date.parse(this.search2.strDate)) {
          callback();
        } else {
          callback(new Error('结束时间不得早于开始时间！'));
        }
      } else {
        callback();
      }
    },
    strTimeVerify2 (rule, value, callback) {
      if (this.search2.envDate !== '' && this.search2.strDate === '') {
        callback(new Error('开始时间不能为空！'));
      } else {
        callback()
      }
    },
    pageSizeChange (size) {
      this.page.pageSize = size
      this.searchNetData()
    },
    pageCurrentChange (index) {
      this.page.pageNum = index
      this.searchNetData(2)
    }
  },
  watch: {
    'formObj.grossWeight': {
      handler: function (val) {
        let reg = /^(-?\d+)(\.\d+)?$/
        if (reg.test(val - 0)) {
          this.formObj.netWeight = this.floatComputed(val - 0, this.formObj.tareWeight - 0, '-')
        }
      }
    },
    'formObj.tareWeight': {
      handler: function (val) {
        let reg = /^(-?\d+)(\.\d+)?$/
        if (reg.test(val - 0)) {
          this.formObj.netWeight = this.floatComputed(this.formObj.grossWeight - 0, val - 0, '-')
        }
      }
    }
  }
}
</script>

<style scoped>
</style>