<template>
  <!-- 销售化产焦炭派车页面 -->
  <div class="salePlan">
    <div class="top">
      <span class="text">订单时间：</span>
      <el-date-picker
        v-model="startTime"
        type="datetime"
        placeholder="选择日期"
        style="width:200px"
      >
      </el-date-picker>
      <span class="text">至</span>
      <el-date-picker
        v-model="endTime"
        type="datetime"
        placeholder="选择日期"
        style="width:200px"
      >
      </el-date-picker>
      <el-input
        placeholder="请输入内容"
        v-model="input"
        style="width:250px"
        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">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <!-- 已审批 -->
        <el-tab-pane label="已审批" name="four">
          <dilTable v-bind.sync="option4" ref="table" :pageSize="200">
            <el-table-column fixed="right" label="操作" width="180">
              <template slot-scope="scope">
                <el-button
                  @click="sendClick(scope.row.saleOrderId)"
                  type="text"
                  size="small"
                  >派车</el-button
                >
                <el-button
                  @click="addClick(scope.row.saleOrderId)"
                  type="text"
                  size="small"
                  >排车</el-button
                >
                <el-button
                  @click="checkSaleOrderDetails(scope.row.saleOrderId)"
                  type="text"
                  size="small"
                  >运单详情</el-button
                >
              </template>
            </el-table-column>
          </dilTable>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>
<script>
import { sjTime } from "@/utils/sharedJsFile";
export default {
  name: "saleOrder",
  data() {
    return {
      endTime: null,
      startTime: null,
      startDate: new Date().getTime() - 3600 * 1000 * 24 * 85,
      endDate: new Date(),
      activeName: "four",
      input: "",
      option4: {
        // 表格请求数据的地址
        requestUrl:
          "/api/v1/ams/getSaleOrderListBySaleCompanyes?apiId=475&shipperId=2"
        // &startDate="+sjTime(new Date().getTime() - 3600 * 1000 * 24 * 85)+"&endDate="+sjTime(new Date()),
      }
    };
  },
  methods: {
    checkSaleOrderDetails(saleOrderId) {
      console.log(saleOrderId);
      this.$router.push("saleOrderOODetails/" + saleOrderId);
    },
    refresh() {
      this.$router.go(0);
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    onclick() {
      let startTime = null;
      let endTime = null;
      if (this.startTime && this.endTime) {
        startTime = sjTime(this.startTime);
        endTime = sjTime(this.endTime);
      }
      this.option4.requestUrl =
        "/api/v1/ams/getSaleOrderListBySaleCompanyes?apiId=475&shipperId=2&con=" +
        this.input +
        "&startTime=" +
        startTime +
        "&endTime=" +
        endTime +
        "&i=" +
        new Date();
    },
    seeclick(saleOrderId) {
      this.$router.push("/saleOrderDetail/" + saleOrderId);
    },
    click(saleOrderId) {
      this.$router.push("/editSaleOrder/" + saleOrderId);
    },
    addClick(saleOrderId) {
      this.$router.push("/addSaleOrderArrange/" + saleOrderId);
    },
    sendClick(saleOrderId) {
      this.$router.push("/addSaleOrderSend/" + 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;
        });
    },

    // -------查看物资详情 (财务已审批)
    detailclick1(row) {
      // 记录重复点击次数
      if (this.oldRow1 === row) {
        this.oldRowCount1 += 1;
      }
      // 切换当前详情表
      this.$refs.table1.toggleRowExpansion(row);
      // 打开前关闭上一个详情表
      if (this.oldRow1 != "") {
        if (this.oldRow1 != row) {
          if (this.oldRowCount1 % 2 === 1) {
            this.$refs.table1.toggleRowExpansion(this.oldRow1);
          } else {
            this.oldRowCount1 = 1;
          }
        } else {
          this.oldRow1 = null;
          return;
        }
      }
      // 重置上一个点击对象
      this.oldRow1 = row;
      // 根据销售订单id查询物资信息
      this.axios
        .post("/api/v1/ams/getSaleMaterialList?saleOrderId=" + row.saleOrderId)
        .then(res => {
          this.tableData1 = res.data.data;
        });
    },

    // -------查看物资详情 (已上报)
    detailclick2(row) {
      // 记录重复点击次数
      if (this.oldRow2 === row) {
        this.oldRowCount2 += 1;
      }
      // 切换当前详情表
      this.$refs.table2.toggleRowExpansion(row);
      // 打开前关闭上一个详情表
      if (this.oldRow2 != "") {
        if (this.oldRow2 != row) {
          if (this.oldRowCount2 % 2 === 1) {
            this.$refs.table2.toggleRowExpansion(this.oldRow2);
          } else {
            this.oldRowCount2 = 1;
          }
        } else {
          this.oldRow2 = null;
          return;
        }
      }
      // 重置上一个点击对象
      this.oldRow2 = row;
      // 根据销售订单id查询物资信息
      this.axios
        .post("/api/v1/ams/getSaleMaterialList?saleOrderId=" + row.saleOrderId)
        .then(res => {
          this.tableData2 = 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/getSaleMaterialList?saleOrderId=" + row.saleOrderId)
        .then(res => {
          this.tableData3 = res.data.data;
        });
    },

    // 上传
    uploadclick(saleOrderId) {
      this.$confirm("是否上传", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "上传成功!"
          });
          this.axios
            .post("/api/v1/ams/uploadSaleOrder?saleOrderId=" + saleOrderId)
            .then(() => {
              this.$router.go(0);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消上传!"
          });
        });
    },
    //删除
    deleteclick(scope) {
      let saleOrderId = scope;
      this.$confirm("是否删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!"
          });
          this.axios
            .post(
              "/api/v1/ams/deleteAmsSaleOrderBySaleOrderId?saleOrderId=" +
                saleOrderId
            )
            .then(() => {
              this.$router.go(0);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消删除!"
          });
        });
    }
  }
};
</script>
<style lang="scss" scoped>
.salePlan {
  .top {
    margin-left: 20px;
    margin-top: 20px;
  }
  .table {
    margin-left: 20px;
    margin-top: 20px;
  }
}
</style>
