// 运输路线
<template>
  <div class="steel_inbound">
    <div class="top">
      <!-- 框计算 -->
      <el-input placeholder="请输入内容" class="input" v-model="inputText" clearable>
      </el-input>
      <el-button type="primary" class="btn" @click="onclick">
        <i class="el-icon-search"></i>查询
      </el-button>
      <el-button type="primary" class="btn1" @click="AddClick">
        <i class="el-icon-plus"></i>新增
      </el-button>
    </div>
    <div class="tab">
      <dilTable v-bind.sync="option" ref="table">
        <el-table-column label="操作">
          <template slot-scope="scope">
            <!-- <el-button
              type="text"
              size="mini"
              @click="transitRouteUpdata(scope.row.lineId)"
              >修改</el-button
            > -->
            <el-button
              size="mini"
              type="text"
              @click="transitRouteDetail(scope.row)"
              >路线详情</el-button
            >
            <el-button
              size="mini"
              type="text"
              @click="transitRouteDelete(scope.row.lineId)"
              >删除</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>
                <el-table :data="tableData" border >
                  <el-table-column
                    v-for="(item, i) in tableHead"
                    :key="i"
                    :prop="item.prop"
                    :label="item.label"
                    :width="item.width"
                  ></el-table-column>
                </el-table>
              </div>
            </el-form>
          </template>
        </el-table-column>
      </dilTable>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 框计算的输入框的值
      inputText: "",
      // 表格渲染的表头及数据
      option: {
        requestUrl: "/api/v1/rms/getAllLineDesk?apiId=249",
      },
      countNumber: 0,
      //记录旧的row对象
      oldRow: "",
      //记录上一个展开的点击次数，单数为展开状态，复数为闭合状态
      oldRowCount: 1,
      tableHead: [
        {
          prop: "enfactoryGatepostName",
          label: "进门门岗",
          width: 150,
        },
        {
          prop: "outfactoryGatepostName",
          label: "出门门岗",
          width: 150,
        },
        {
          prop: "grossNumber",
          label: "计毛汽车衡",
          width: 150,
        },
        {
          prop: "tareNumber",
          label: "计皮汽车衡",
          width: 150,
        },
      ],
      tableData: [],
    };
  },
  methods: {
    initialization(lineId, num) {
      this.axios
        .post("/api/v1/rms/getCountNumber?lineId=" + lineId)
        .then((res) => {
          if (res.data.code == "200") {
            if (res.data.data > 0) {
              this.$message({
                showClose: true,
                message: "此路线已经和运输订单关联,不能进行修改!",
                type: "warning",
              });
            } else {
              if (num == 2) {
                this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning",
                })
                  .then(() => {
                    this.axios
                      .post("/api/v1/rms/updateRmsLine", { lineId: lineId })
                      .then((res) => {
                        if ((res.data.code = "200")) {
                          this.$message({
                            type: "success",
                            message: "删除成功!",
                          });
                          this.$router.go(0);
                        }
                      });
                  })
                  .catch(() => {
                    this.$message({
                      type: "info",
                      message: "已取消删除",
                    });
                  });
              } else if (num == 1) {
                this.$router.push({
                  path: "/transitRouteAdd/" + lineId,
                });
              }
            }
          }
        });
    },
    // 框计算查询按钮
    onclick() {
      this.option.requestUrl =
        "/api/v1/rms/getAllLineDesk?apiId=249&con=" + this.inputText;
    },
    // 跳转新增运输路线页面
    AddClick() {
      this.$router.push({
        path: "/transitRouteAdd/0",
      });
    },
    // -------查看线路详情
    transitRouteDetail(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.lineId);
    },
    // 根据线路id查询物资信息
    getMaterial(lineId) {
      this.axios
        .post("/api/v1/rms/getGateCalculateMes?lineId="+lineId)
        .then((res) => {
          var lineInfo = [];
          if(res.data.data!=null){
            lineInfo.push(res.data.data);
          }
          this.tableData = lineInfo;
        });
    },
    //跳转修改界面
    transitRouteUpdata(lineId) {
      this.initialization(lineId, 1);
    },
    //删除本条运输路线
    transitRouteDelete(lineId) {
      this.initialization(lineId, 2);
    },
  },
};
</script>
<style lang="scss">
.steel_inbound{
  .top{
    width: 100%;
    height: 100px;
    display: flex;
    align-items: center;
    padding-left: 30px;
    .input{
      width: 250px;
    }
    .btn{
      margin: 20px;
    }
  }
}

</style>