// 公开抢单
<template>
  <div class="steel_inbound">
    <div class="sache">
      <el-input
        placeholder="请输入内容"
        v-model="inputText"
        clearable>
      </el-input>
      <el-button type="primary" class="btn" @click="onclick1">
        <i class="el-icon-search"></i>查询
      </el-button>
    </div>
    <div class="table">
      <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="50">
        <template slot-scope="scope">
          <el-button @click="Grab(scope)" type="text" size="small">
            抢单
          </el-button>
        </template>
      </el-table-column>
      </dilTable>
		</el-tab-pane>
     	<el-tab-pane label="已抢单" name="second">
				<dilTable v-bind.sync="second">
          <el-table-column fixed="right" label="操作" width="50">
            <template slot-scope="scope">
          <el-button @click="dispatch(scope) ,handleBtnClick1() " type="text" size="small">
            派单
          </el-button>
            </template>
      </el-table-column>
      </dilTable>
      <el-drawer title="司机排班信息表" :visible.sync="drawer" :direction="direction" :before-close="handleClose"
				:modal="false" size="30%" style="margin-top: 5.625rem;">
        <el-input placeholder="请输入内容" v-model="input"  style="margin-top:10px;margin-left:20px" clearable> </el-input>
      <el-button type="primary" class="btn" @click="onclick()"  style="margin-bottom:15px">
        <i class="el-icon-search"></i>查询
      </el-button>
				<dilTable v-bind.sync="third" @radio-change="currentRadioChange"></dilTable>
				<div style=" margin-left: 25rem;">
					<el-button type="primary" @click="makeSure">派发</el-button>
				</div>
			</el-drawer>
		</el-tab-pane>
    </el-tabs>
    
    </div>
  </div>
</template>

<script>
export default {
  data(){
    return{
      drawer: false,
			direction: 'rtl',
      activeName: "first",
      inputText:"",
      dispatchId:null,
      input:"",
      first:{
        // first请求数据的地址
        requestUrl: "/api/v1/ams/getPCDispatchSaleOrderList?apiId=242&dispatchType=1",
      },
      second:{
        requestUrl:"/api/v1/ams/selectDispatchSaleOrderList?apiId=233&carrierId=1",
      },
      third:{
        requestUrl:"/api/v1/oms/getCapacityAndDriverList?apiId=246",
        selectionType: "radio",
				mapList: []      
      }
    }
  },
  methods:{
      handleClick(tab, event) {
      console.log(tab, event);
    },
    onclick1(){
       if(this.activeName == "first"){
        this.option1.requestUrl = "/api/v1/ams/getPCDispatchSaleOrderList?apiId=242&con=" + this.input;
      }else if
        (this.activeName == "second"){
        this.option2.requestUrl = "/api/v1/ams/selectDispatchSaleOrderList?apiId=233&carrierId=1&con=" + this.input;
      }
    },
    dispatch(scope){
      this.dispatchId = scope.row.dispatchId
    },
    handleBtnClick1(){

				this.drawer=true
			},
      currentRadioChange(selection) {
				this.mapList = selection
        console.log(this.mapList)
			},
    onclick() {
        this.third.requestUrl =
        "/api/v1/oms/getCapacityAndDriverList?apiId=246&con=" + this.input;
      },
      makeSure(){
        this.$confirm("是否派发","提示",{
          confirmButtonText:"确定",
          cancelButtonText:"取消",
          type:"warning",
          center:true,
        })
        .then(() => {
        this.axios.post("/api/v1/oms/addAppTruckOrder?orderType=" + 1 + 
        "&carrierId="+ 1 +"&dispatchId=" + this.dispatchId 
        + "&capacityNumber=" + this.mapList.capacityNumber)
        .then((res) => {
          if(res.data.code == 200){
            this.$message({
              type:"success",
              message:"派单成功！",
            });
            this.$router.go(0);
          } else {
            this.$message({
                  message: "删除失败",
                  type: "warning",
                });
          }
        })
        }) .catch(() => {
          this.$message({
            type: "info",
            message: "派发操作已取消!",
          });
        });
       
      },
  	Grab(scope){
      console.log(scope)
      this.$confirm("是否抢单", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.axios
            .post("/api/v1/ams/lockDispatchSaleOrder?dispatchId="+ scope.row. dispatchId+"&carrierId=" + 1)
            .then((res) => {
              if (res.data.code == 200) {
                this.$message({
                  type: "success",
                  message: "抢单成功!",
                });     
                this.$router.go(0);
              } else {
                this.$message({
                  message: "删除失败",
                  type: "warning",
                });
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "删除操作已取消!",
          });
        });
    },
  }
}
</script>

<style lang="scss" scode>
.steel_inbound{
  .sache{
    padding: 1.25rem 0.375rem;
    .el-input {
      width: 20%;
      margin-right: 1.25rem;
    }
  }
}
</style>