<template>
  <!-- 销售订单页面 -->
  <div class="salePlan">
    <div class="top">
      <el-input placeholder="请输入内容" v-model="input" clearable> </el-input>
      <el-button type="primary" class="btn" @click="onclick">
        <i class="el-icon-search"></i>查询
      </el-button>
      <el-button type="primary" @click="refresh">
        <i class="el-icon-refresh"></i>刷新
      </el-button>
    </div>
    <el-dialog
      title="承运商信息"
      :visible.sync="dialogTableVisible"
      :before-close="handleClose"
    >
      <el-input style="width: 250px" v-model="carrierText"></el-input>
      <el-button type="primary" @click="getCarrier">查询</el-button>
      <dilTable
        v-bind.sync="carrierOption"
        @radio-change="currentRadioChange1"
      ></dilTable>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogTableVisible = false">取 消</el-button>
        <el-button type="primary" @click="updateTruckCapacity()"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <div class="table">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <!-- 未授权 -->
        <el-tab-pane label="未授权" name="four">
          <mergeRowTable v-bind.sync="option4" ref="table">
            <el-table-column fixed="right" label="操作" width="180">
              <template slot-scope="scope">
                <el-button
                  @click="empowerCarrierClick(scope.row.saleOrderMaterialId)"
                  type="text"
                  size="small"
                  >授权承运商</el-button
                >
                <el-button
                  @click="steelSendClick(scope.row.saleOrderMaterialId)"
                  type="text"
                  size="small"
                  >钢材派车</el-button
                >
              </template>
            </el-table-column>
          </mergeRowTable>
        </el-tab-pane>

        <!-- 未派车 -->
        <el-tab-pane label="未派车" name="five">
          <mergeRowTable v-bind.sync="option0" ref="table0">
            <el-table-column fixed="right" label="操作" width="160">
              <template slot-scope="scope">
                <el-button
                  @click="updateCarrier(scope)"
                  type="text"
                  size="small"
                  >修改承运商授权</el-button
                >
              </template>
            </el-table-column>
          </mergeRowTable>
        </el-tab-pane>
        <!-- 已派车 -->
        <el-tab-pane label="已派车" name="first">
          <mergeRowTable v-bind.sync="option" ref="table3"> </mergeRowTable>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>
<script>
export default {
  name: "saleOrder",
  data() {
    return {
      carrierText: null,
      dialogTableVisible: false,
      activeName: "four",
      drawer: false,
      input: "",
      index: "",
      carrierId: null,
      carrierName: null,
      option: {
        // 表格请求数据的地址
        requestUrl: "/api/v1/ams/getHaveCarTruckNoList?apiId=466",
        comparison: "saleOrderMaterialId",
        columnIndexs: [0, 1, 2, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15]
      },
      option2: {
        // 表格请求数据的地址
        requestUrl: "/api/v1/ams/getSaleOrderReportedes?apiId=408"
      },
      option3: {
        // 表格请求数据的地址
        requestUrl: "/api/v1/ams/getAmsSaleOrderApprovedes?apiId=409"
      },
      option4: {
        // 表格请求数据的地址
        requestUrl: "/api/v1/ams/getSteelTruckNoList?apiId=411",
        comparison: "saleOrderMaterialId",
        columnIndexs: [0, 1, 2, 3, 4, 8, 9, 10, 11, 12, 13, 14, 15]
      },
      option0: {
        // 表格请求数据的地址
        requestUrl: "/api/v1/ams/getNoCarTruckNoList?apiId=466",
        comparison: "saleOrderMaterialId",
        columnIndexs: [0, 1, 2, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15]
      },
      carrierOption: {
        requestUrl: "/api/v1/uc/getCarrierListByLike?apiId=412",
        selectionType: "radio"
      },
      mapList: [],
      mapItemList: []
    };
  },
  methods: {
    getRequestUrl() {
      this.option.requestUrl =
        "/api/v1/ams/getHaveCarTruckNoList?apiId=466&i=" + new Date();
      this.option4.requestUrl =
        "/api/v1/ams/getSteelTruckNoList?apiId=411&i=" + new Date();
      this.option0.requestUrl =
        "/api/v1/ams/getNoCarTruckNoList?apiId=466&i=" + new Date();
    },
    handleClose() {},
    updateCarrier(scope) {
      // console.log(scope.row);
      this.saleOrderMaterialId = scope.row.saleOrderMaterialId;
      this.dialogTableVisible = true;
    },
    currentRadioChange1(row) {
      console.log(row);
      this.carrierId = row.carrierId;
    },
    getCarrier() {
      this.carrierOption.requestUrl =
        "/api/v1/uc/getCarrierListByLike?apiId=412&index=" + this.carrierText;
    },
    //修改承运商授权
    updateTruckCapacity() {
      let map = {
        carrierId: this.carrierId,
        saleOrderMaterialId: this.saleOrderMaterialId
      };
      this.axios.post("/api/v1/ams/updateTruckNoCarrier", map).then(res => {
        if (res.data.code == "200") {
          this.$message.success("修改授权成功");
          this.getRequestUrl();
          this.dialogTableVisible = false;
        }
      });
    },
    refresh() {
      this.getRequestUrl();
    },

    handleClick(tab, event) {
      console.log(tab, event);
    },
    onclick() {
      if (this.activeName == "four") {
        this.option4.requestUrl =
          "/api/v1/ams/getSteelTruckNoList?apiId=411&con=" + this.input;
        // console.log("aaaa" + this.input);
      } else if (this.activeName == "five") {
        this.option0.requestUrl =
          "/api/v1/ams/getNoCarTruckNoList?apiId=466&con=" + this.input;
      } else if (this.activeName == "first") {
        this.option.requestUrl =
          "/api/v1/ams/getHaveCarTruckNoList?apiId=466&con=" + this.input;
      }
    },
    seeclick(saleOrderId) {
      this.$router.push("/saleOrderDetail/" + saleOrderId);
    },
    empowerCarrierClick(saleOrderMaterialId) {
      this.$router.push("/saleOrderSteelEmpower/" + saleOrderMaterialId);
    },
    steelSendClick(saleOrderMaterialId) {
      this.$router.push("/addSaleOrderSteelSend/" + saleOrderMaterialId);
    },
    // -------查看物资详情 (已审批)
    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;
      // 根据销售订单id查询物资信息
      this.axios
        .post(
          "/api/v1/ams/getTruckNoMaterialList?saleOrderMaterialId=" +
            row.saleOrderMaterialId
        )
        .then(res => {
          this.tableData = res.data.data;
        });
    },

    // -------查看物资详情 (已派车)
    detailclick3(row) {
      // 记录重复点击次数
      if (this.oldRow3 === row) {
        this.oldRowCount3 += 1;
      }
      // 切换当前详情表
      this.$refs.table3.toggleRowExpansion(row);
      // 打开前关闭上一个详情表
      if (this.oldRow3 != "") {
        if (this.oldRow3 != row) {
          if (this.oldRowCount3 % 2 === 1) {
            this.$refs.table3.toggleRowExpansion(this.oldRow3);
          } else {
            this.oldRowCount3 = 1;
          }
        } else {
          this.oldRow3 = null;
          return;
        }
      }
      // 重置上一个点击对象
      this.oldRow3 = row;
      // 根据销售订单id查询物资信息
      this.axios
        .post(
          "/api/v1/ams/getTruckNoMaterialList?saleOrderMaterialId=" +
            row.saleOrderMaterialId
        )
        .then(res => {
          this.tableData3 = res.data.data;
        });
    },

    // -------查看物资详情 (未派车)
    detailclick0(row) {
      // 记录重复点击次数
      if (this.oldRow0 === row) {
        this.oldRowCount0 += 1;
      }
      // 切换当前详情表
      this.$refs.table0.toggleRowExpansion(row);
      // 打开前关闭上一个详情表
      if (this.oldRow0 != "") {
        if (this.oldRow0 != row) {
          if (this.oldRowCount0 % 2 === 1) {
            this.$refs.table0.toggleRowExpansion(this.oldRow0);
          } else {
            this.oldRowCount0 = 1;
          }
        } else {
          this.oldRow0 = null;
          return;
        }
      }
      // 重置上一个点击对象
      this.oldRow0 = row;
      // 根据销售订单id查询物资信息
      this.axios
        .post(
          "/api/v1/ams/getTruckNoMaterialList?saleOrderMaterialId=" +
            row.saleOrderMaterialId
        )
        .then(res => {
          this.tableData0 = res.data.data;
        });
    }
  }
};
</script>
<style lang="scss" scoped>
.salePlan {
  .top {
    margin-left: 20px;
    margin-top: 20px;
    .el-input {
      width: 20%;
      margin-right: 1.25rem;
    }
  }
  .table {
    margin-left: 20px;
    margin-top: 20px;
  }
}
</style>
