//运输派单
<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="back">
        <i class="el-icon-back"></i>返回
      </el-button>
    </div>
    <div>
      <el-dialog
        title="车辆信息"
        :visible.sync="dialogTableVisible"
        :before-close="handleClose"
      >
        <el-input style="width:250px" v-model="truckText"></el-input>
        <el-button type="primary" @click="getCapacity">查询</el-button>
        <dilTable
          v-bind.sync="truck"
          @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>

    <div class="table">
      <mergeRowTable v-bind.sync="first" ref="table">
        <el-table-column fixed="right" label="操作" width="120">
          <template slot-scope="scope">
            <el-button
              @click="updateClick(scope)"
              type="text"
              size="small"
              v-if="
                scope.row.carStatus == '未接单' ||
                  scope.row.carStatus == '未进厂'
              "
            >
              修改
            </el-button>
            <el-button @click="deleteClick(scope)" type="text" size="small">
              关闭
            </el-button>
          </template>
        </el-table-column>
      </mergeRowTable>
    </div>
  </div>
</template>

<script>
import { getCookie } from '@/utils/util.js'
export default {
  data() {
    return {
      carrierUserId: '',
      //模态窗的框计算
      inputText: null,
      //车辆输入框
      truckText: null,
      //是否弹出对话框
      dialogTableVisible: false,
      //输入框的值
      input: '',
      //选项卡的当前选中的值
      activeName: 'first',
      //已下发的表格
      first: {
        requestUrl: '',
        comparison: 'orderNumber',
        orderNumber: [0, 1]
      },
      //车辆信息的表格
      truck: {
        requestUrl: '',
        // 控制显示当选列
        selectionType: 'radio'
      },
      //当前选中的订单id
      selectOrderId: null,
      //选中的车辆号
      capacityNumber: '',
      //选中的运力id
      capacityId: null,
      //是否关闭模态框
      drawer: false,
      //模态框从左往右打开
      direction: 'rtl',
      orderId: null,
      //区别点击的是添加运力，还是修改
      index: null
    }
  },
  created() {
    this.truck.requestUrl = '/api/v1/uc/getAllCapacityByCarrierLike?apiId=429'
    this.first.requestUrl =
      '/api/v1/oms/getDriverInfoForSale2?apiId=484&orderStatus=4' +
      '&saleOrderId=' +
      this.$route.params.saleOrderId
  },
  methods: {
    onclick() {
      this.first.requestUrl =
        '/api/v1/oms/getDriverInfoForSale2?apiId=484&orderStatus=4' +
        '&saleOrderId=' +
        this.$route.params.saleOrderId +
        '&con=' +
        this.input +
        '&i=' +
        new Date()
    },
    back() {
      this.$router.go(-1)
    },
    handleClose(done) {
      done()
      this.$message.info('取消修改运力')
    },
    getRequestUrl() {
      this.first.requestUrl =
        '/api/v1/oms/getDriverInfoForSale2?apiId=484&orderStatus=4' +
        '&saleOrderId=' +
        this.$route.params.saleOrderId +
        '&i=' +
        new Date()
    },
    getTruckRequestUrl() {
      this.truck.requestUrl =
        '/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=' +
        null +
        '&i=' +
        new Date()
    },
    currentRadioChange1(row) {
      console.log(row)
      this.capacityId = row.capacityId
    },
    //删除运输订单
    deleteClick(scope) {
      console.log(scope.row.orderNumber)
      let orderId = scope.row.orderNumber.substring(15)
      console.log(orderId)
      let map = {
        orderId: scope.row.orderId || orderId,
        userId: getCookie('userId')
      }
      this.$confirm('是否删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.axios.post('/api/v1/oms/closeOmstruckOrder', map).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: '已取消删除'
          })
        })
    },
    //修改运输订单
    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('修改运力失败')
          }
        })
    },
    handleClick(tab, event) {
      this.getRequestUrl()
    },
    Insert() {
      this.$router.push('addOldSporadicOrder')
    },
    getCapacity() {
      if (this.truckText != null) {
        if (getCookie('orgCode') == 'chengyunshang') {
          this.truck.requestUrl =
            '/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=' +
            getCookie('userId') +
            '&index=' +
            this.truckText
        } else {
          this.truck.requestUrl =
            '/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=' +
            null +
            '&index=' +
            this.truckText
        }
        this.truckText = null
      } else {
        if (getCookie('orgCode') == 'chengyunshang') {
          this.truck.requestUrl =
            '/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=' +
            getCookie('userId') +
            '&i=' +
            new Date()
        } else {
          this.truck.requestUrl =
            '/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=' +
            null +
            '&i=' +
            new Date()
        }
      }
    }
  }
}
</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;
  }
  .table {
    margin-left: 30px;
    margin-top: 10px;
  }
}
</style>
