<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">
      <div class="form_box" style="margin-right: 10rem">
        <dil-form :formId="255" v-model="form1" ref="from1"></dil-form>
      </div>
    </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, isNumber } from "@/utils/sharedJsFile";
import { getCookie } from "@/utils/util.js";
export default {
  components: { PageTitle },
  data() {
    return {
      form1: {},
      option: {
        // 表格请求数据的地址
        requestUrl: "/api/v1/tms/getWagonNo/3?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),
        resultRemark: this.form1.resultRemark,
        resultType: 3,
      };
      console.log(tmstrainWagonUnloadResult);
      if (
        tmstrainWagonUnloadResult.wagonNoList == null ||
        tmstrainWagonUnloadResult.resultArrivalDate == null ||
        tmstrainWagonUnloadResult.resultUnloadTime == null
      )
       this.$message.error("存在空值！");
      else
        this.axios
          .post(
            "/api/v1/tms/insertTmstrainWagonUnLoadResult",
            tmstrainWagonUnloadResult
          )
          .then((res) => {
            if ((res.data.code = "200")) {
              this.$message({
                type: "success",
                message: "新增成功!",
              });
              this.$router.go(-1);
            }else{
               ({ type: "failed", message: "新增失败!" });
            }

            
          });
    },
    // 取消
    cancel() {
      this.$router.go(-1);
    },
  },
};
</script>
<style lang='scss' scoped>
.addWagonLoad {
  .form {
    display: flex;
    .form_box {
      width: 320px;
      margin-left: 35%;
      margin-top: 30px;
      margin-right: 22px;
      .el-form {
        .preview-group {
          .el-form-item {
            .el-form-item__label {
              display: inline-block;
              width: 70px !important;
            }
            .el-form-item__content {
              .el-select {
                width: 250px;
              }
              .el-input {
                width: 220px;
              }
              .el-textarea {
                .el-textarea__inner {
                  display: block;
                  resize: vertical;
                  padding: 5px 13px;
                  line-height: 1.5;
                  width: 70%;
                  border-radius: 4px;
                  margin-left: 56px;
                  margin-top: -25px;
                }
              }
            }
          }
        }
      }
    }
  }
  .button-box {
    margin-top: 50px;
    margin-left: 600px;
  }
}
</style>