<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>
    <div class="table">
      <mergeRowTable v-bind.sync="option4" ref="table">
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button
              @click="steelSendClick(scope.row.saleOrderId)"
              type="text"
              size="small"
              >钢材派车</el-button
            >
          </template>
        </el-table-column>
      </mergeRowTable>
    </div>
  </div>
</template>
<script>
import { getCookie } from "@/utils/util.js";
export default {
  name: "saleOrder",
  data() {
    return {
      activeName: "four",
      drawer: false,
      input: "",
      index: "",
      carrierId: null,
      carrierName: null,
      option4: {
        // 表格请求数据的地址
        requestUrl: "",
        comparison: "saleNumber",
        columnIndexs: [0, 1, 2, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15]
      },
      mapList: [],
      mapItemList: [],
      //(销售公司已审批)
      tableData: []
    };
  },
  created() {
    this.initUrl();
  },
  methods: {
    initUrl() {
      if (getCookie("orgCode") == "chengyunshang") {
        this.option4.requestUrl =
          "/api/v1/ams/getSaleOrderListToCarrier?apiId=467&carrierSsoId=" +
          getCookie("userId");
      } else {
        this.option4.requestUrl =
          "/api/v1/ams/getSaleOrderListToCarrier?apiId=467&carrierSsoId=" +
          null;
      }
    },
    refresh() {
      this.$router.go(0);
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    onclick() {
      if (getCookie("orgCode") == "chengyunshang") {
        if (this.activeName == "four") {
          this.option4.requestUrl =
            "/api/v1/ams/getSaleOrderListToCarrier?apiId=467&carrierSsoId=" +
            getCookie("userId") +
            "&con=" +
            this.input;
        }
      } else {
        if (this.activeName == "four") {
          this.option4.requestUrl =
            "/api/v1/ams/getSaleOrderListToCarrier?apiId=467&con=" +
            this.input +
            "&carrierSsoId=" +
            "";
        }
      }
    },
    seeclick(saleOrderId) {
      this.$router.push("/saleOrderDetail/" + saleOrderId);
    },
    steelSendClick(saleOrderId) {
      this.$router.push("/addSaleOrderSteelSendCarrier/" + saleOrderId);
    },
    // -------查看物资详情 (已审批)
    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/getSaleMaterialList?saleOrderId=" + row.saleOrderId)
        .then(res => {
          this.tableData = 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>
