<!--分检预报关联火车实绩直接生成汽车实绩-->
<template>
  <div class="systemBase">
    <el-form
      ref="searchData1"
      :inline="true"
      :model="searchFParam"
      style="padding: 8px 0 0 12px"
      label-width="70px"
    >
      <el-form-item label="汽车号" label-width="60px">
        <el-input
          type="text"
          size="mini"
          style="width: 110px;"
          clearable
          v-model.trim="searchFParam.carNo"
        ></el-input>
      </el-form-item>
      <el-form-item label="火车号" label-width="60px">
        <el-input
          type="text"
          size="mini"
          clearable
          style="width: 110px;"
          v-model.trim="searchFParam.railwayNo"
        ></el-input>
      </el-form-item>
      <el-form-item label="开始时间">
        <el-date-picker
          type="datetime"
          size="mini"
          style="width: 180px;"
          v-model="searchFParam.startTime"
          @change="dateChange(searchFParam.startTime, 'startTime', 'searchFParam')"
          clearable
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间">
        <el-date-picker
          type="datetime"
          size="mini"
          style="width: 180px;"
          v-model="searchFParam.endTime"
          @change="dateChange(searchFParam.endTime, 'endTime', 'searchFParam')"
          clearable
        ></el-date-picker>
      </el-form-item>
      <el-form-item label-width="10px">
        <el-button type="primary" size="mini" @click="searchDatas(1)"
          >查询</el-button
        >
      </el-form-item>
    </el-form>
    <el-row>
      <el-col :span="12">
        <div style="border: 1px solid #d5d5d5; padding: 10px 0 10px 10px">
          <div style="font-size: 17px">分检预报信息 <span style="color: red;">(只会查询出未使用的分检预报)</span></div>
        </div>
        <div class="common-table-div">
          <el-table
            v-loading="dataLoading2"
            ref="dataTable"
            highlight-current-row
            border
            :height="tableHeight"
            @row-click="handleSelectionChange2"
            :data="table.list"
            :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"
              min-width="100"
              prop="carNo"
              label="车号"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="railwayNo"
              min-width="100"
              label="火车号"
              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="contractNo"
              label="合同号"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="batchNo"
              min-width="110"
              label="批次号"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="customerSupplierName"
              min-width="160"
              label="供应商"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="forwardingUnitName"
              min-width="160"
              label="发货单位"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="receivingUintName"
              min-width="160"
              label="收货单位"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="specName"
              min-width="100"
              label="规格"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="shipmentGrossWeight"
              min-width="100"
              label="发运毛重"
              align="right"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="shipmentNetWeight"
              min-width="100"
              label="发运净重"
              align="right"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="shipmentNum"
              min-width="100"
              label="发运数量"
              align="right"
            ></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
          style="
            border: 1px solid #d5d5d5;
            padding: 10px 0 10px 10px;
            border-left: none;
          "
        >
          <div style="font-size: 17px">火车计量数据</div>
        </div>
        <div class="common-table-div">
          <el-table
            v-loading="dataLoading"
            @row-click="rowChange"
            ref="dataTable"
            highlight-current-row
            border
            :height="tableHeight"
            :data="table.list2"
            :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"
              min-width="100"
              prop="railwayNo"
              label="火车号"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="railwayNo"
              min-width="100"
              label="火车号"
              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="contractNo"
              label="合同号"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="batchNo"
              min-width="110"
              label="批次号"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="customerSupplierName"
              min-width="160"
              label="供应商"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="forwardingUnitName"
              min-width="160"
              label="发货单位"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="receivingUintName"
              min-width="160"
              label="收货单位"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="specName"
              min-width="100"
              label="规格"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="grossWeight"
              label="毛重"
              min-width="100"
              align="left"
            >
              <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="left"
            >
              <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="left"
            >
              <template slot-scope="scope">
                {{ Math.floor((scope.row.netWeight - 0) / 10) / 100 }}
              </template>
            </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="[100, 500, 1000]"
            :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="border-right: 1px solid #d5d5d5">
          <div class="common-title-div">
            <el-form :inline="true">
              <el-form-item label-width="80px"><span style="font-size: 17px">汽车计量数据</span></el-form-item>
              <el-form-item label="汽车号">
                <el-input
                  type="text"
                  size="mini"
                  style="width: 110px;"
                  clearable
                  v-model.trim="searchCParam.carNo"
                ></el-input>
              </el-form-item>
              <el-form-item label="火车号">
                <el-input
                  type="text"
                  size="mini"
                  clearable
                  style="width: 110px;"
                  v-model.trim="searchCParam.railwayNo"
                ></el-input>
              </el-form-item>
              <el-form-item label="开始时间">
                <el-date-picker
                  type="datetime"
                  size="mini"
                  style="width: 180px;"
                  v-model="searchCParam.startTime"
                  @change="dateChange(searchCParam.startTime, 'startTime', 'searchCParam')"
                  clearable
                ></el-date-picker>
              </el-form-item>
              <el-form-item label="结束时间">
                <el-date-picker
                  type="datetime"
                  size="mini"
                  style="width: 180px;"
                  v-model="searchCParam.endTime"
                  @change="dateChange(searchCParam.endTime, 'endTime', 'searchCParam')"
                  clearable
                ></el-date-picker>
              </el-form-item>
              <el-form-item label-width="20px">
                <el-button
                  type="primary"
                  size="mini"
                  @click="getMatchData(1)"
                  >查询</el-button
                >
              </el-form-item>
              <el-form-item label-width="20px">
                <el-button
                  icon="el-icon-circle-plus-outline"
                  type="primary"
                  size="mini"
                  @click="addData"
                  v-privilege="activeMenu + 'MOVE'"
                  >转移</el-button
                >
              </el-form-item>
              <!-- <el-form-item label-width="20px">
                <el-button
                  size="mini"
                  type="danger"
                  plain
                  icon="el-icon-remove-outline"
                  @click="abolishData"
                  v-privilege="activeMenu + 'ABOLISH'"
                  >作废</el-button
                >
              </el-form-item> -->
            </el-form>
          </div>
        </div>
        <div class="common-table-div">
          <el-table
            v-loading="dataLoading3"
            ref="dataTable"
            highlight-current-row
            border
            :height="tableHeight"
            @selection-change="handleSelectionChange3"
            :data="table.list3"
            :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"
              min-width="100"
              prop="carNo"
              label="车号"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="railwayNo"
              min-width="100"
              label="火车号"
              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="contractNo"
              label="合同号"
              min-width="100"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="batchNo"
              min-width="110"
              label="批次号"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="customerSupplierName"
              min-width="160"
              label="供应商"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="forwardingUnitName"
              min-width="160"
              label="发货单位"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="receivingUintName"
              min-width="160"
              label="收货单位"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="specName"
              min-width="100"
              label="规格"
              align="left"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="shipmentGrossWeight"
              min-width="100"
              label="发运毛重"
              align="right"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              prop="shipmentNetWeight"
              min-width="100"
              label="发运净重"
              align="right"
            ></el-table-column>
          </el-table>
        </div>
        <div class="common-foot-style">
          <el-pagination
            v-loading="dataLoading3"
            @size-change="pageSizeChange3"
            @current-change="pageCurrentChange3"
            :current-page="page3.pageNum"
            :page-sizes="[100, 500, 1000]"
            :page-size="page3.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page3.totalPage"
          >
          </el-pagination>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { getCookie, formatDate } from '@/utils/util.js';
import { cookieUserId, cookieUserName } from '@/config/config.js'

export default {
  data () {
    return {
      icoreFilterFlag: true,
      dataLoading: false,
      dataLoading2: false,
      dataLoading3: false,
      multipleSelection: {},
      multipleSelection2: [],
      multipleSelection3: [],
      table: {
        list: [],
        list2: [],
        list3: []
      },
      searchForm: {
        countTypeName: '',
        mainTypeName: ''
      },
      searchFParam: {
        carNo: '',
        railwayNo: '',
        startTime: '',
        endTime: ''
      },
      searchCParam: {
        carNo: '',
        railwayNo: '',
        startTime: '',
        endTime: ''
      },
      page: {
        pageSize: 100,
        pageNum: 1,
        totalPage: 0
      },
      page2: {
        pageSize: 100,
        pageNum: 1,
        totalPage: 0
      },
      page3: {
        pageSize: 100,
        pageNum: 1,
        totalPage: 0
      },
      activeMenu: '',
      orgTree: [],
      multipleSelection1: [],
      selectedData: {},
      userName: '',
      userId: '',
      forecastSelection: {},
      trainSelection: {}
    }
  },
  async created () {
    this.tableHeight = (window.innerHeight - 290) / 2 > 250 ? (window.innerHeight - 290) / 2 : 250
    this.activeMenu = window.top.localStorage.getItem('activeMenu')
  },
  mounted () {
    this.userName = getCookie(cookieUserName);
    this.userId = getCookie(cookieUserId);
  },
  methods: {
    // 查询分检预报数据
    getForecastData (flag) {
      if (flag === 1) {
        this.page.pageNum = 1
      }
      if (this.searchFParam.railwayNo - 0 === 0) {
        return this.$message.error('请先输入火车号再进行查询')
      }
      this.axios.get(`pass/systemBase/v1/pretrackscales/?pageNum=${this.page.pageNum}&pageSize=${this.page.pageSize}&predictionType=3&valueFlag=1&railwayNo=${this.searchFParam.railwayNo}&carNo=${this.searchFParam.carNo}&createTime1=${this.searchFParam.startTime}&createTime2=${this.searchFParam.endTime}`)
        .then(res => {
          this.table.list = [...res.data.list];
        })
    },
    // 分别查询三张表的数据
    async searchDatas () {
      this.getForecastData(1)
      this.getTrainData(1)
    },
    // 分页查询火车计量数据
    getTrainData (flag) {
      if (flag === 1) {
        this.page2.pageNum = 1
      }
      if (this.searchFParam.railwayNo - 0 === 0) {
        return this.$message.error('请先输入火车号再进行查询')
      }
      this.axios.get(`pass/systemBase/v1/meterworkrailwayactuals/selectDiff?pageNum=${this.page2.pageNum}&pageSize=${this.page2.pageSize}&railwayNo=${this.searchFParam.railwayNo}&flag=0&valueFlag=0&uploadFlag=0&createTime1=${this.searchFParam.startTime}&createTime2=${this.searchFParam.endTime}`)
        .then(res => {
          if (res && res.data && res.data.list.length > 0) {
            this.table.list2 = [...res.data.list]
            this.page2.totalPage = res.data.total
          } else {
            this.table.list2 = []
            this.page2.totalPage = res.data.total
          }
        })
    },
    // 查询汽车实绩数据
    async getMatchData (flag) {
      if (flag === 1) {
        this.page3.pageNum = 1
      }
      const res = await this.axios.get(`pass/systemBase/v1/meterworkcaractuals/selectView?pageNum=${this.page3.pageNum}&pageSize=${this.page3.pageSize}&railwayNo=${this.searchCParam.railwayNo}&carNo=${this.searchCParam.carNo}&netTime1=${this.searchCParam.startTime}&netTime2=${this.searchCParam.endTime}`)
      if (res && res.data && res.data.list.length > 0) {
        this.table.list3 = [...res.data.list]
        this.page3.totalPage = res.data.total
      } else {
        this.table.list3 = []
        this.page3.totalPage = res.data.total
      }
    },
    rowChange (val) {
      this.trainSelection = val
    },
    // 物料数据表格多选回调
    handleSelectionChange2 (val) {
      this.forecastSelection = val
    },
    // 关联数据多选回调
    handleSelectionChange3 (val) {
      this.multipleSelection3 = [...val]
    },
    // 添加关联数据
    addData () {
      if (JSON.stringify(this.forecastSelection) === '{}') {
        this.$message.warning('请点选分检预报数据！');
        return;
      }
      if (JSON.stringify(this.trainSelection) === '{}') {
        this.$message.warning('请点选火车计量数据！');
        return;
      }
      let linkList = []
      // 要进行重量转移的分检预报预报号和火车计量数据主键构建参数
      let param = {
        id1: this.forecastSelection.predictionNo,
        id2: this.trainSelection.actualNo
      }
      this.axios.post(`pass/systemBase/v1/meterworkcaractuals/conversionTrainToCar?predictionNo=${this.forecastSelection.predictionNo}&actualNo=${this.trainSelection.actualNo}`, { individualType: 'json' }).then(res => {
        if (res.succeed) {
          this.$message.success(res.message);
          this.searchDatas();
          this.getMatchData();
        } else {
          this.$message.error(res.message);
        }
      }).catch(e => {
        this.$message.error(e.message)
      })
    },
    // 作废数据
    abolishData () {
      let ids = ''
      if (this.multipleSelection3.length < 1) {
        this.$message.warning('请选择要作废的汽车计量数据！');
        return;
      }
      // 将所有选中的关联数据的id拼接成一个由逗号分隔的字符串
      this.multipleSelection3.forEach((item, index) => {
        if (index !== this.multipleSelection3.length - 1) {
          ids += item.id + ','
        } else {
          ids += item.id
        }
      })
      this.axios.delete(`pass/systemBase/v1/meterbasehistarecountds/${ids}`).then(res => {
        // console.log(res, '删除的返回结果')
        if (res.succeed) {
          this.$message.success(res.message);
          this.searchDatas()
        } else {
          this.$message.error(res.message)
        }
      }).catch(e => {
        this.$message.error(e.message)
      })
    },
    // 页大小变化回调
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.getForecastData(1);
    },
    // 页跳转变化回调
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.getForecastData();
    },
    // 页大小变化回调
    pageSizeChange2 (size) {
      this.page2.pageSize = size;
      this.getTrainData(1);
    },
    // 页跳转变化回调
    pageCurrentChange2 (index) {
      this.page2.pageNum = index;
      this.getTrainData();
    },
    // 页大小变化回调
    pageSizeChange3 (size) {
      this.page2.pageSize = size;
      this.getUnloadRoleData(1);
    },
    // 页跳转变化回调
    pageCurrentChange3 (index) {
      this.page2.pageNum = index;
      this.getUnloadRoleData();
    },
    dateChange (val, valName, formName) {
      if (formName === 'searchFParam') {
        this.searchFParam[valName] = formatDate(val, 'yyyy-MM-dd HH:mm:ss')
      } else {
        this.searchCParam[valName] = formatDate(val, 'yyyy-MM-dd HH:mm:ss')
      }
      console.log(this.searchCParam[valName])
    }
  }
}
</script>
<style scoped>
</style>