// 提货单
<template>
  <div class="billOfLading">
    <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>
    <div class="tab">
      <dilTable v-bind.sync="option" ref="table">
        <el-table-column label="操作" fixed="right" width="200">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="detailclick(scope.row)">
              物资详情
            </el-button>
            <el-button type="text" size="mini" @click="configure(scope.row.orderId)">
              配置物资优先级
            </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/tms/getSaleOrderOnQueue?apiId=227",
      },
      //记录旧的row对象
      oldRow: "",
      //记录上一个展开的点击次数，单数为展开状态，复数为闭合状态
      oldRowCount: 1,
      tableHead: [
        {
          prop: "materialName",
          label: "物资名称",
          width: 150,
        },
        {
          prop: "specificationModel",
          label: "规格型号",
          width: 150,
        },
        {
          prop: "orderMaterialNumber",
          label: "物资件数",
          width: 100,
        },
      ],
      tableData: [],
    };
  },
  methods: {
    //   框计算
    onclick() {
      this.option.requestUrl = "/api/v1/tms/getSaleOrderOnQueue?apiId=227&con=" + this.inputText;
    },
    // 查看物资详情
    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.orderId);
    },
    // 根据运输订单id查询物资信息
    getMaterial(orderId) {
      this.axios
        .get("api/v1/tms/getMaterial?orderId=" + orderId)
        .then((res) => {
          this.tableData = res.data.data;
        });
    },
    // 跳转到配置物资优先顺序
    configure(orderId){
        this.$router.push("/bar1_billOfLadingAdd/"+orderId);
    }
  },
};
</script>
<style lang="scss" scoped>
.billOfLading {
  .top {
    width: 100%;
    height: 5rem;
    display: flex;
    align-items: center;
    padding-left: 2.5rem;
  }
}
</style>