<template>
  <div class="associated-order">
    <h1 class="title">
      互斥订单-{{orderDetails.orderNo}}
    </h1>
    <el-divider></el-divider>
    <orde-details-form  :details ="orderDetails" ></orde-details-form>
    <el-divider></el-divider>
    <el-form inline label-width="100px">
      <el-form-item label="订单号"><div class="content">
        <el-input v-model="params.relateOrderId"></el-input>
      </div></el-form-item>
      <el-form-item><div class="content">
        <el-button @click="getList">查询</el-button>
      </div></el-form-item>
    </el-form>
    <el-divider></el-divider>
    <div style="display: flex;align-items: center;">
      <h1 class="title">
        已加入互斥订单列表
      </h1>
      <div style="flex: 1;margin-left: 20px;">
        <el-button :disabled="multipleSelection.length === 0" type="primary" @click="batchGuanlianOrderByOrderId(multipleSelection.map(e =>({orderId:orderId,mutualOrderId:e.orderId})))" >批量移出</el-button>
      </div>
      <div>
        <el-button type="primary" @click="$router.push('/order/not-mutex-order/'+ orderId)" >添加互斥订单</el-button>
      </div>
    </div>
    <el-table :data="list"  @selection-change="handleSelectionChange" >
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column type="index" label="序号"></el-table-column>
      <el-table-column label="订单号" prop="orderNo"></el-table-column>
      <el-table-column label="唛头" prop="marks"></el-table-column>
      <el-table-column label="货物数据"></el-table-column>
      <el-table-column label="入仓时间" prop="remarks"></el-table-column>
      <el-table-column label="状态" prop="status" >
        <template v-slot:default="scope">
          <dict-tag :value="scope.row.status" :type="DICT_TYPE.ORDER_STATUS" ></dict-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作人"></el-table-column>
      <el-table-column label="操作时间" prop="createTime"></el-table-column>
      <el-table-column label="操作">
        <template v-slot:default='scope'>
          <el-button type="text"  @click ="guanlianOrderByOrderId(scope.row.orderId)">
            移出
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
//关联订单
import ordeDetailsForm from "@/views/ecw/order/components/ordeDetailsForm";
import {getOrder} from "@/api/ecw/order";
import {
  deleteBatchGuanlianOrderByOrderId,
  deleteGuanlianOrderByOrderId,
  guanlianList,
} from "@/api/ecw/mutexOrder";
import {getDictDatas,DICT_TYPE} from '@/utils/dict'
export default {
  name: "mutexOrder",
  props:{
    orderId:[String,Boolean]
  },
  components:{
    ordeDetailsForm
  },
  data(){
    return {
      orderDetails:{},
      params:{
        orderId:undefined,
        mutualOrderId:undefined
      },
      list:[],
      DICT_TYPE,
      getDictDatas,
      multipleSelection:[]
    }
  },
  created() {
    this.params.orderId = this.orderId;
    this.getList();
    getOrder(this.orderId).then( r =>{
      if(r.code === 0){
        this.orderDetails = r.data;
      }
    })
  },
  methods:{
    getList(){
      guanlianList(this.params).then(r => {
        if(r.code === 0){
          this.list = r.data
        }
      })
    },
    guanlianOrderByOrderId(id){
      deleteGuanlianOrderByOrderId({orderId:this.orderId,mutualOrderId:id}).then(r =>{
        if(r.code === 0){
          this.getList()
          this.$message.success('操作成功');
        }
      })
    },
    batchGuanlianOrderByOrderId(val){
      deleteBatchGuanlianOrderByOrderId(val).then(r => {
        this.getList()
        this.$message.success('操作成功');
        this.multipleSelection = []
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    }
  },

}
</script>

<style scoped lang="scss">
.associated-order{
  padding: 20px;
  box-sizing: border-box;
  .title{
    font-size: 30px;
    font-weight: 600;
  }
}
</style>
