// 分派计划
<template>
  <div class="inwardOrder">
    <div class="sache">
      <el-input
        placeholder="可查询车牌号、物资、装卸货点"
        v-model="inputText"
        clearable
      >
      </el-input>
      <span>订单时间：</span>
      <el-date-picker
        v-model="startTime"
        type="datetime"
        placeholder="选择日期"
        style="width:220px"
      >
      </el-date-picker>
      <span>至</span>
      <el-date-picker
        v-model="endTime"
        type="datetime"
        placeholder="选择日期"
        style="width:220px"
      >
      </el-date-picker>
      <el-button type="primary" class="btn" @click="onClick">
        <i class="el-icon-search"></i>查询
      </el-button>
    </div>
    <!-- 车辆信息 -->
    <el-dialog
      title="车辆信息"
      :visible.sync="dialogTableVisible"
      :before-close="handleClose"
    >
      <el-input v-model="truckInput" style="width:250px"></el-input>
      <el-button type="primary" @click="clickTruck">查询</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>
    <template>
      <div>
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="待接收" name="first">
            <dilTable v-bind.sync="first" ref="table">
              <el-table-column fixed="right" label="操作" width="120">
                <template slot-scope="scope">
                  <el-button type="text" size="mini" @click="updatePlan(scope)">
                    修改
                  </el-button>
                  <el-button
                    type="text"
                    size="mini"
                    @click="deleteClick(scope)"
                  >
                    删除
                  </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="80">
                <template slot-scope="scope">
                  <el-button
                    type="text"
                    size="mini"
                    @click="deleteClick(scope)"
                  >
                    关闭
                  </el-button>
                </template>
              </el-table-column>
            </dilTable>
          </el-tab-pane>
          <el-tab-pane label="已完成" name="third">
            <dilTable v-bind.sync="third"> </dilTable>
          </el-tab-pane>
        </el-tabs>
      </div>
    </template>
  </div>
</template>
<script>
import { getCookie } from '@/utils/util.js'
import { sjTime } from '@/utils/sharedJsFile'
export default {
  data() {
    return {
      startTime: null,
      endTime: null,
      inputText: null,
      truckInput: null,
      userCarrierId: '',
      //是否弹出对话框
      dialogTableVisible: false,
      first: {},
      //车辆信息的表格
      truck: {
        requestUrl:
          '/api/v1/oms/getCapacityAndDriverList?apiId=246&carrierId=' + '',
        // 控制显示当选列
        selectionType: 'radio'
      },
      //选中的运力id
      capacityId: null,
      activeName: 'first',
      second: {
        requestUrl: ''
      },
      third: {
        requestUrl: ''
      }
    }
  },
  created() {
    if (getCookie('orgCode') == 'chengyunshang') {
      this.first.requestUrl =
        '/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=4&carrierId=' +
        getCookie('userId')
      this.second.requestUrl =
        '/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=5&carrierId=' +
        getCookie('userId')
      this.third.requestUrl =
        '/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=2&carrierId=' +
        getCookie('userId')
    } else {
      this.first.requestUrl =
        '/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=4'
      this.second.requestUrl =
        '/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=5'
      this.third.requestUrl =
        '/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=2'
    }
  },
  methods: {
    onClick() {
      console.log('dks')
      let orgCode = null
      let startTime = null
      let endTime = null
      if (this.startTime && this.endTime) {
        startTime = sjTime(this.startTime)
        endTime = sjTime(this.endTime)
      }
      if (getCookie('orgCode') == 'chengyunshang') {
        orgCode = getCookie('userId')
      }
      if (this.activeName == 'first') {
        this.first.requestUrl =
          '/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=4&orgCode=' +
          orgCode +
          '&con=' +
          this.inputText +
          '&startTime=' +
          startTime +
          '&endTime=' +
          endTime +
          '&i=' +
          new Date()
      } else if (this.activeName == 'second') {
        this.second.requestUrl =
          '/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=5&orgCode=' +
          orgCode +
          '&con=' +
          this.inputText +
          '&startTime=' +
          startTime +
          '&endTime=' +
          endTime +
          '&i=' +
          new Date()
      } else {
        this.third.requestUrl =
          '/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=2&orgCode=' +
          orgCode +
          '&con=' +
          this.inputText +
          '&startTime=' +
          startTime +
          '&endTime=' +
          endTime +
          '&i=' +
          new Date()
      }
    },
    getRequest() {
      if (getCookie('orgCode') == 'chengyunshang') {
        this.first.requestUrl =
          '/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=4&carrierId=' +
          getCookie('userId') +
          '&i=' +
          new Date()
        this.second.requestUrl =
          '/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=5&carrierId=' +
          getCookie('userId') +
          '&i=' +
          new Date()
        this.third.requestUrl =
          '/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=2&carrierId=' +
          getCookie('userId') +
          '&i=' +
          new Date()
      } else {
        this.first.requestUrl =
          '/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=4' +
          '&i=' +
          new Date()
        this.second.requestUrl =
          '/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=5' +
          '&i=' +
          new Date()
        this.third.requestUrl =
          '/api/v1/oms/getInwardOrderList?apiId=260&orderStatus=2' +
          '&i=' +
          new Date()
      }
    },
    handleClick() {
      this.getRequest()
    },
    handleClose(done) {
      done()
      this.$message.info('取消修改运力')
    },
    currentRadioChange1(row) {
      console.log(row)
      this.capacityId = row.capacityId
    },
    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()
      }
    },
    //修改运输订单
    updatePlan(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.dialogTableVisible = false
            this.getRequest()
          } else {
            this.$message.error('修改运力失败')
            this.dialogTableVisible = false
            this.getRequest()
          }
        })
    },
    clickTruck() {
      this.truck.requestUrl =
        '/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=' +
        null +
        '&index=' +
        this.truckInput
    },
    //删除运输订单
    deleteClick(scope) {
      let map = {
        orderId: scope.row.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.getRequest()
            } else {
              this.$message({
                message: '删除失败',
                type: 'warning'
              })
            }
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    }
  }
}
</script>
<style lang="scss">
.inwardOrder {
  margin-top: 20px;
  margin-left: 20px;
  .sache {
    .el-input {
      width: 20%;
      margin-right: 1.25rem;
    }
  }
}
</style>
