<template>
  <!-- 请车作业页面 -->
  <div class="trainTransport">
     <div class="search" style="display:flex;margin: 10px;">
        <!-- <el-input
          placeholder="请输入"
          v-model="input"
          style="margin: 10px; width:10%"
          clearable
        ></el-input> -->
       <el-date-picker style="margin: 10px;" v-model="startTime" type="datetime" placeholder="起始日期"></el-date-picker>
      <el-date-picker style="margin: 10px;" v-model="endTime" type="datetime" placeholder="结束日期"></el-date-picker>
        <el-button
          type="primary"
          class="btn"
          @click="onclick"
          style="margin: 10px;"
        >
          <i class="el-icon-search"></i>查询
        </el-button>
        <el-button class="btn" style="margin: 10px;" type="primary" @click="insertClick">
          <i class="el-icon-plus"></i>新增
        </el-button>
      </div>
      <dilTable v-bind.sync="option" ref="table">
          <el-table-column fixed="right" label="操作" width="120">
            <template slot-scope="scope">
              <el-button
                @click="updateClick(scope.row.resultId)"
                type="text"
                size="small"
              >
                修改
              </el-button>
              <el-button
                @click="deleteClick(scope.row)"
                type="text"
                size="small"
              >
                删除
              </el-button>
            </template>
          </el-table-column>
        </dilTable>
  </div>
</template>

<script>
import { sjTime } from "@/utils/sharedJsFile";
export default {
  name: "inplantTMS",
  data() {
    return {
      input: "",
      startTime:null,
      endTime:null,
      option: {
        // 表格请求数据的地址
        requestUrl: ""
      },
    };
  },
  created() {
    this.onclick();
  },
  methods: {
    checkDate(){
      if(this.startTime&&this.endTime&&this.startTime<this.endTime){
        return true;
      }else{
        return false;
      }
    },
    onclick() {
      if (this.checkDate()) {
        this.option.requestUrl =
          "/api/v1/tms/getAllPleaseResult?apiId=509&con=" + this.input
          +"&i="+new Date()
          +"&startTime="+sjTime(this.startTime)
          +"&endTime="+sjTime(this.endTime);
      } else {
        this.option.requestUrl =
          "/api/v1/tms/getAllPleaseResult?apiId=509&con=" +this.input
          +"&i="+new Date();
      }
    },
    // 删除
    deleteClick(row) {
      this.$confirm("是否删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(() => {
          let map={
            resultId:row.resultId,
            deleted:1
          }
          this.axios
            .post("/api/v1/tms/editPleaseResult",map)
            .then(() => {
              this.$message({
                type: "success",
                message: "删除成功!"
              });
              this.onclick();
            });
        })  
    },
    //新增
    insertClick() {
      this.$router.push("/addWagonPlease/");
    },
    //修改
    updateClick(resultId) {
      this.$router.push("/editWagonPlease/" + resultId);
    }
  }
};
</script>

<style lang="scss">
.trainTransport {
  .top {
    padding: 1.25rem 0.375rem;
    .el-input {
      width: 20%;
      margin-right: 1.25rem;
    }
  }
}
</style>
