<template>
  <!-- 装车作业页面 -->
  <div class="homeworkPath">
    <div class="top">
      <el-input placeholder="请输入内容" v-model="inputText" clearable>
      </el-input>
      <el-button type="primary" class="btn" @click="onclick">
        <i class="el-icon-search"></i>查询
      </el-button>
    </div>
    <dilTable v-bind.sync="option" ref="table">
      <el-table-column fixed="right" label="操作" align="center" width="100">
        <template slot-scope="scope">
          <el-button @click="detailclick(scope.row)" type="text" size="small">
            查看物资信息
          </el-button>
        </template>
      </el-table-column>
      <!-- 物资详情下拉框 -->
      <el-table-column type="expand" width="1">
        <template slot-scope="props">
          <el-form label-position="center" inline class="demo-table-expand">
            <div v-if="false">{{ props }}</div>
            <div>
              <dilTable v-bind.sync="option1"></dilTable>
            </div>
          </el-form>
        </template>
      </el-table-column>
    </dilTable>
  </div>
</template>


<script>
export default {
  name: "wagonload",
  data() {
    return {
      inputText: "",
      option: {
        // 表格请求数据的地址
        requestUrl: "/api/v1/tms/getTmstrainWagonLoad?apiId=203&resultType=4",
      },
      //记录旧的row对象
      oldRow: "",
      //记录上一个展开的点击次数，单数为展开状态，复数为闭合状态
      oldRowCount: 1,
      option1: {
        requestUrl: "",
      },
    };
  },

  methods: {
    // 查看物资详情
    detailclick(row) {
      // 记录重复点击次数
      if (this.oldRow === row) {
        this.oldRowCount += 1;
      }
      // 切换当前详情表
      this.$refs.table.toggleRowExpansion(row);
      // 打开前关闭上一个详情表
      if (this.oldRow != "") {
        if (this.oldRow != row) {
          if (this.oldRowCount % 2 === 1) {
            this.$refs.table.toggleRowExpansion(this.oldRow);
          } else {
            this.oldRowCount = 1;
          }
        } else {
          this.oldRow = null;
          return;
        }
      }
      // 重置上一个点击对象
      this.oldRow = row;
      this.getMaterial(row.resultId);
    },
    getMaterial(resultId) {
      this.option1.requestUrl =
        "/api/v1/tms/getMaterialAndCarByLoadingId?apiId=259&loadingId=" + resultId;
    },
    onclick() {
      this.option.requestUrl =
        "/api/v1/tms/getTmstrainWagonLoad?apiId=203&resultType=4&con=" +
        this.inputText;
    },
    btnclick() {
      this.$router.push("/addWagonLoad");
    },
    click(resultId) {
      this.$router.push("/editWagonLoad/" + resultId);
    },
    deleteclick(scope) {
      let resultId = scope;
      this.$confirm("是否删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.$axios
            .post(
              "/api/v1/tms/deleteTmstrainLoadingResultByResultId?resultId=" +
                resultId
            )
            .then(() => {
              this.$router.go(0);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消删除!",
          });
        });
    },
  },
};
</script>
<style lang='scss'>
.homeworkPath {
  .top {
    padding: 1.25rem 1.875rem;
  }
}
</style>
