//运输派单
<template>
  <div class="transportOrder">
    <div class="transportOrder_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="Insert" v-if="activeName == 'first'">
        <i class="el-icon-plus"></i>新增
      </el-button>
    </div>
    <el-dialog title="车辆信息" :visible.sync="dialogTableVisible" :before-close="handleClose">
    <dilTable
          v-bind.sync="truck"
          @radio-change="currentRadioChange1"
        ></dilTable>
    <span slot="footer" class="dialog-footer">
    <el-button @click="cancelUpdate()">取 消</el-button>
    <el-button type="primary" @click="updateTruckCapacity()">确 定</el-button>
    </span>
    </el-dialog>
    <div class="transportOrder_bottom">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="未接收" name="first">
          <dilTable v-bind.sync="first">
            <el-table-column
            fixed="right"
            label="操作"
            width="100"
          >
            <template slot-scope="scope">
               <el-button @click="updateClick(scope)" type="text" size="small">
                修改
              </el-button>
             <el-button @click="deleteClick(scope)" type="text" size="small">
                删除
              </el-button>
            </template>
          </el-table-column>
          </dilTable>
        </el-tab-pane>
        <!-- 已接收 -->
        <el-tab-pane label="已接收" name="Received">
          <dilTable v-bind.sync="Received">
            <el-table-column
            fixed="right"
            label="操作"
            width="100"
          >
            <template slot-scope="scope">
              <el-button @click="deleteClick(scope)" type="text" size="small">
                关闭
              </el-button>
            </template>
          </el-table-column>      
          </dilTable>
        </el-tab-pane>
         <!-- 已完成 -->
        <el-tab-pane label="已完成" name="completed">
          <dilTable v-bind.sync="completed">
          </dilTable>
        </el-tab-pane>
      </el-tabs>
    </div> 
  </div>
</template>

<script>
import { getCookie } from "@/utils/util.js";
export default {
  data() {
    return {
      carrierUserId:'',
      //模态窗的框计算
      inputText: null,
      //是否弹出对话框
      dialogTableVisible: false,
      //输入框的值
      input: "",
      //选项卡的当前选中的值
      activeName: "first",
      //已下发的表格
      first: {
        requestUrl:"",
      },
      completed:{
        requestUrl:"",
      },
      //车辆信息的表格
      truck: {
        requestUrl: "/api/v1/oms/getCapacityAndDriverList?apiId=246&carrierId=" + '',
        // 控制显示当选列
        selectionType: "radio",
      },
      Received:{
        requestUrl: "",
      },
      //物资信息的数据
      tableData: [],
      //物资信息的表头
      tableHead: [
        {
          prop: "materialName",
          label: "物资名称",
          width: 200,
        },
        {
          prop: "materialModel",
          label: "规格型号",
          width: 200,
        },
        {
          prop: "weightNum",
          label: "物资数量",
          width: 200,
        },
      ],
      //当前选中的订单id
      selectOrderId: null,
      //选中的车辆号
      capacityNumber: "",
      //选中的运力id
      capacityId: null,
      orderId:null,
      //是否关闭模态框
      drawer: false,
      //模态框从左往右打开
      direction: "rtl",
      //多选的选中的订单id
      selectionList: [],
      //区别点击的是添加运力，还是修改
      index: null,
    };
  },
  created(){
       if (getCookie("orgCode") == "chengyunshang") {
      this.truck.requestUrl =
        "/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=" +
        getCookie("userId");
      }else {
      this.truck.requestUrl =
        "/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=" + null;
      }
      if(getCookie('orgCode') == "chengyunshang"){
        this.first.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=4&carrierId=" + getCookie("userId") ,
        this.Received.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=5&carrierId=" + getCookie("userId"),
        this.completed.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=2&carrierId=" + getCookie("userId")
      }else if(getCookie("orgCode") == "dagangadmin" || getCookie("orgCode") == "zidonghuabu"){
        this.first.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=4"
        this.Received.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=5"
        this.completed.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=2"
      }else{
        this.first.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=4&userId=" + getCookie("orgCode")
        this.Received.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=5&userId=" + getCookie("orgCode")
        this.completed.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=2&userId=" + getCookie("orgCode")
      }    
  },
  
  methods: {
    handleClose(done){
      done()
      this.$message.info("取消修改运力")
    },
    cancelUpdate(){
      this.dialogTableVisible = false
      this.$message.info("取消修改运力")
    },
    getRequestUrl(){
      if(getCookie('orgCode') == "chengyunshang"){
        this.first.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=4&carrierId=" + getCookie("userId") + "&test=" + new Date(),
        this.Received.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=5&carrierId=" + getCookie("userId") + "&test=" + new Date()
        this.completed.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=2&carrierId=" + getCookie("userId") + "&test=" + new Date()
      
      }else if(getCookie("orgCode") == "dagangadmin" || getCookie("orgCode") == "zidonghuabu"){
        this.first.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=4&test=" + new Date()
        this.Received.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=5&test=" + new Date()
        this.completed.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=2&test=" + new Date()
      }else{
        this.first.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=4&userId=" + getCookie("orgCode") + "&test=" + new Date()
        this.Received.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=5&userId=" + getCookie("orgCode") + "&test=" + new Date()
        this.completed.requestUrl =  "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=2&userId=" + getCookie("orgCode") + "&test=" + new Date()     
      }
    },
    //删除运输订单
    deleteClick(scope){
      this.$confirm('是否删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
            this.axios
            .post("/api/v1/oms/closeOmstruckOrder?orderId=" + scope.row.orderId)
            .then((res) => {
              if (res.data.code == 200) {
                this.$message({
                  type: "success",
                  message: "删除成功!",
                });     
                this.getRequestUrl()
              } else {
                this.$message({
                  message: "删除失败",
                  type: "warning",
                });
              }
            });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
      console.log(scope.row.orderId)
    },
    //修改运输订单
    updateClick(scope){
      this.getTruckRequestUrl()
      this.orderId = scope.row.orderId
      this.dialogTableVisible = true
      console.log(scope.row.orderId)
    },
    updateTruckCapacity(){
        if(this.capacityId == null){
            this.$message.error("未选中运力")
            return
        }
        this.axios.post("/api/v1/oms/updateCapacityId",{
          capacityId:this.capacityId,
          orderId :this.orderId
        }).then((res) =>{
          if(res.data.code == "200"){
            this.$message.success("修改运力成功")
            this.getRequestUrl()
            this.dialogTableVisible = false
          }else{
            this.$message.error("修改运力失败")
          }
        })
    },
    getTruckRequestUrl(){
        if (getCookie("orgCode") == "chengyunshang") {
      this.truck.requestUrl =
        "/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=" +
        getCookie("userId") + "&test=" + new Date();
      } else {
      this.truck.requestUrl =
        "/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=" + null +  "&test=" + new Date();
      }
    },
    currentRadioChange1(row){
      console.log(row)
      this.capacityId = row.capacityId
    },
    
    onclick(){
      console.log("dianji")
    },
    handleClick(tab, event) {
      this.getRequestUrl()
    },
    // 查看物资详情
    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.materialDetails(row.orderId);
    },
    //查看当前订单的物资信息
    materialDetails(orderId) {
      this.axios
        .post("/api/v1/uc/getOrderMaterialMesByOrderId/" + orderId)
        .then((res) => {
          if (res.data.code == "200") {
            this.tableData = res.data.data;
          }
        });
    },
    Insert(){
      this.$router.push("addMornThanTransportOrder")
    }
  },
};
</script>

<style lang="scss">

.transportOrder {
  .transportOrder_top {
    width: 100%;
    height: 100px;
    display: flex;
    align-items: center;
    padding-left: 50px;
    .el-input{
  width: 20%;
}
  }
  .drawer_top {
    width: 100%;
    height: 50px;
    padding-left: 20px;
    display: flex;
    align-items: center;
  }
}
</style>