<template>
  <!-- 添加车皮卸车实绩 -->
  <div class="addWagonLoad">
    <page-title>新增</page-title>

    <div class="main">
      <el-divider content-position="left">选择已装车实绩</el-divider>
    </div>

    <div>
      <dilTable
        v-bind.sync="option"
        ref="table"
        @selection-change="selectionChange"
      >
      </dilTable>
    </div>

    <el-divider content-position="left">车皮卸车实绩</el-divider>
     <div class="form-box" style="margin-right: 10rem">
        <dil-form :formId="255" v-model="form1" ref="from1"></dil-form>
      </div>
    <div class="button-box">
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="makeSure">确定</el-button>
    </div>
    
  </div>
</template>

<script>
import PageTitle from "@/components/Page/Title";
// import { sjTime } from "@/utils/sharedJsFile";
export default {
  components: { PageTitle },
  data() {
    return {
      form1: {},
       option: {
        // 表格请求数据的地址
        requestUrl:
          "/api/v1/tms/getWagonNo/2?apiId=213",
        // 控制显示当选列
        selectionType: "select",
      },
      value: undefined,
      list: [],
    };
  },
  mounted() {},
  methods: {
    selectionChange(selection){
      this.list = [];
      selection.forEach(e => {
        this.list.push(
          {
            resultWagonNo:e.resultWagonNo,
            resultId:e.resultId,
            purchaseOrderId: e.purchaseOrderId,
            unloadingPointId: e.unloadingPointId,
          })
      });
    },
    // 确定
    makeSure() {
      let tmstrainWagonUnloadResult = {
        wagonNoList: this.list,
        resultArrivalDate: sjTime(this.form1.resultArrivalDate),
        resultUnloadTime: sjTime(this.form1.resultUnloadTime),
        unloadingPointId: this.form1.unloadingPointId,
        resultBigTicketWeight: this.form1.resultBigTicketWeight,
        resultRailHorizontalWeight: this.form1.resultRailHorizontalWeight,
        resultRemark: this.form1.resultRemark,
        resultType: 2
      };
      console.log(tmstrainWagonUnloadResult);
      if (tmstrainWagonUnloadResult.wagonNoList==null
      ||tmstrainWagonUnloadResult.resultArrivalDate==null||
      tmstrainWagonUnloadResult.resultUnloadTime==null||
      tmstrainWagonUnloadResult.unloadingPointId==null||
      tmstrainWagonUnloadResult.resultBigTicketWeight==null||
      tmstrainWagonUnloadResult.resultRailHorizontalWeight==null
      ) this.$message.error("存在空值！");
      else
      this.axios
        .post(
          "/api/v1/tms/insertTmstrainWagonUnLoadResult",
          tmstrainWagonUnloadResult
        )
        .then(() => {
          this.$message({
            type: "success",  
            message: "新增成功!",
          });
          this.$router.go(-1);
        });
    },
    // 取消
    cancel() {
      this.$router.go(-1);
    },
  },
};
</script>
<style lang='scss' scoped>
// @import "@/styles/TMS/addWagonUnLoed.scss";
</style>