<template>
  <!-- 订单获取关联单 -->
  <el-dialog title="关联单" visible :before-close="closeDialog" :close-on-click-modal="false" width="95%" append-to-body>
    <el-table :data="list">
     <el-table-column
       width="55">
     </el-table-column>
     <el-table-column type="index" :label="$t('序号')"></el-table-column>
     <el-table-column :label="$t('订单号')" prop="orderBackVO.orderNo"></el-table-column>
     <el-table-column :label="$t('唛头')" prop="orderBackVO.marks"></el-table-column>
     <el-table-column :label="$t('货物数据')">
       <template v-slot="{row}">
        <div>
          {{row.orderBackVO.costVO.totalNum}}{{$t('箱')}}
        </div>
         <div>
          {{row.orderBackVO.costVO.totalVolume}}m³
        </div>
         <div>
          {{row.orderBackVO.costVO.totalWeight}}KG
        </div>
       </template>
     </el-table-column>
     <el-table-column :label="$t('入仓时间')" prop="orderBackVO.rucangTime">
       <template v-slot="{row}">
         {{parseTime(row.orderBackVO.rucangTime)}}
       </template>
     </el-table-column>
     <el-table-column :label="$t('状态')" prop="status" >
       <template v-slot:default="scope">
        {{scope.row.orderBackVO.statusMsg}}
       </template>
     </el-table-column>
     <el-table-column :label="$t('操作人')" prop="creator">
       <template v-slot="{row}">
         {{(userList.find( i => row.creator == i.id) || {}).nickname}}
       </template>
     </el-table-column>
     <el-table-column :label="$t('操作时间')">
       <template v-slot="{row}">
         {{parseTime(row.createTime)}}
       </template>
     </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="params.page" :limit.sync="params.rows"
              @pagination="getList" />
  </el-dialog>
</template>
<script>
import { getOrder, getOrderWarehouseIn } from "@/api/ecw/order";
import { guanlianList } from "@/api/ecw/associatedOrder";
import {listSimpleUsers} from "@/api/system/user";
import WarehouseRecordDetail from '@/views/ecw/order/warehousing/components/WarehouseRecordDetail.vue'
import { parseTime } from "@/utils/ruoyi";
export default {
  filters: { parseTime },
   components: {
    WarehouseRecordDetail
  },
  props: {
    order: Object, // order 和 orderId 二选一
    orderId: Number,
    orderItemId: Number,
  },
  data() {
    return {
      orderDetail: null,
      warehouseList: null,
      list:[],
      userList:[],
      total:0,
      params:{
        orderId:undefined,
        relateOrderNo:undefined,
        page:1,
        rows:10
      },
    };
  },
  computed: {
    info() {
      return this.orderDetail || this.order;
    },
    orderItem() {
      if (!this.info) return null;
      return this.info.orderItemVOList.find(
        (item) => item.orderItemId == this.orderItemId
      );
    },
    warehouseItem() {
      if (!this.warehouseList) return [];
      return (
        this.warehouseList.find(
          (item) => item.orderItemId == this.orderItemId
        ) || []
      );
    },
  },

  created() {
    this.show = true;
    this.params.orderId = this.orderItemId;
    this.getList();
    listSimpleUsers().then(r => this.userList = r.data)
  },
  methods: {
    closeDialog() {
      this.show = false;
      this.$emit("close");
    },
    getList(){
      guanlianList(this.params).then(r => {
        if(r.code === 0){
          this.list = r.data.list;
          this.total = r.data.total;
        }
      })
    },
    getOrderWarehouseIn() {
      getOrderWarehouseIn(this.info.orderId).then((res) => {
        this.warehouseList = res.data;
      });
    },
  },
};
</script>
