<template>
  <div class="orderDetailData">
    <div v-show="!isSingle" style="position: relative;padding-right: 90px;">
      <TopTab :orderIdList='orderIdList' :orderId="orderId" @emitFun='toggleName' />
      <el-button type="primary" plain size="small"
        style="position: absolute;right: 0; top: 0;height: 48px;font-size: 14px;" @click="returnOrderManage"><svg-icon
          icon-class="return" /> 返回</el-button>
    </div>
    <div class="box1">
      <div class="boxTitle">
        <span class="blueTitle"></span>
        <span>订单编码: {{ orderMsg.code }}</span>
      </div>
      <el-button v-show="isSingle" type="primary" plain size="small" style="float: right;"
        @click="returnOrderManage"><svg-icon icon-class="return" /> 返回</el-button>
      <div style="padding-left: 14px;">
        <el-row>
          <el-col :span='4'>
            <div class="blodTip">订单名</div>
            <div class="lightTip">{{ orderMsg.name }}</div>
          </el-col>
          <el-col :span='4'>
            <div class="blodTip">产品名称</div>
            <div class="lightTip" :title='orderMsg.productName'>{{ orderMsg.productName }}</div>
          </el-col>
          <el-col :span='4'>
            <div class="blodTip">产品规格</div>
            <div class="lightTip">{{ orderMsg.specifications }}</div>
          </el-col>
          <el-col :span='4'>
            <div class="blodTip">创建时间</div>
            <div class="lightTip">{{ parseTime(orderMsg.createTime) }}</div>
          </el-col>
          <el-col :span='4'>
            <div class="blodTip">计划开始时间</div>
            <div class="lightTip">{{ parseTime(orderMsg.planStartTime) }}</div>
          </el-col>
          <el-col :span='4'>
            <div class="blodTip">计划完成时间</div>
            <div class="lightTip">{{ parseTime(orderMsg.planFinishTime) }}</div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span='4'>
            <div class="blodTip">计划加工数量</div>
            <div class="lightTip">{{ orderMsg.planQuantity }}</div>
          </el-col>
          <el-col :span='4'>
            <div class="blodTip">加工平方数(平方米)</div>
            <div class="lightTip">{{ orderMsg.planArea }}</div>
          </el-col>
          <el-col :span='4'>
            <div class="blodTip">预计用时(时)</div>
            <div class="lightTip">{{ orderMsg.expectTime }}</div>
          </el-col>
          <el-col :span='4'>
            <div class="blodTip">状态</div>
            <div class="lightTip">{{ getDictDataLabel(DICT_TYPE.ORDER_STATUS, orderMsg.status) }}</div>
          </el-col>
          <el-col :span='4'>
            <div class="blodTip">实际开始时间</div>
            <div class="lightTip">{{ parseTime(orderMsg.startProduceTime) }}</div>
          </el-col>
          <el-col :span='4'>
            <div class="blodTip">实际完成时间</div>
            <div class="lightTip">{{ parseTime(orderMsg.finishProduceTime) }}</div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span='4'>
            <div class="blodTip">实际生产数量</div>
            <div class="lightTip">{{ orderMsg.actualQuantity }}</div>
          </el-col>
          <el-col :span='4'>
            <div class="blodTip">完成比%</div>
            <div class="lightTip">{{ orderMsg.completeProp }}</div>
          </el-col>
          <el-col :span='4'>
            <div class="blodTip">废片数量</div>
            <div class="lightTip">{{ orderMsg.nokQuantity }}</div>
          </el-col>
        </el-row>
      </div>
    </div>
    <div class="box2">
      <div class="boxTitle">
        <span class="blueTitle"></span>
        <span>工单信息</span>
      </div>
      <!-- 列表 -->
      <base-table :page="queryParams.pageNo" :limit="queryParams.pageSize" :table-props="tableProps1"
        :table-data="list1" :max-height="tableH" />
    </div>
  </div>
</template>
<script>
import { parseTime } from '@/utils/ruoyi'
import { publicFormatter } from '@/utils/dict'
import { getProcessFlowList } from '@/api/base/orderManage'
import TopTab from './components/topTab'
const tableProps1 = [
  {
    prop: 'issueTime',
    label: '下发时间',
    filter: parseTime,
    minWidth: 160
  },
  {
    prop: 'name',
    label: '工单名',
    minWidth: 160,
    showOverflowtooltip: true
  },
  {
    prop: 'code',
    label: '工单编码',
    minWidth: 150
  },
  {
    prop: 'roomNameDict',
    label: '负责车间',
    minWidth: 150,
    filter: publicFormatter('workshop')
  },
  {
    prop: 'planAssignmentQuantity',
    label: '计划分配数量',
    width: 110
  },
  {
    prop: 'actualAssignmentQuantity',
    label: '实际分配数量',
    width: 110
  },
  {
    prop: 'actualArea',
    label: '加工平方数',
    width: 100
  },
  {
    prop: 'status',
    label: '状态',
    filter: publicFormatter('work_order_status')
  },
  {
    prop: 'startProduceTime',
    label: '开始时间',
    filter: parseTime,
    minWidth: 160
  },
  {
    prop: 'finishProduceTime',
    label: '结束时间',
    filter: parseTime,
    minWidth: 160
  },
  {
    prop: 'productLineNames',
    label: '关联产线',
    filter: (val) => val ? val.join(',') : '',
    showOverflowtooltip: true
  },
  {
    prop: 'workers',
    label: '负责人',
    showOverflowtooltip: true
  },
  {
    prop: 'remark',
    label: '备注',
    showOverflowtooltip: true
  }
]
import { orderDetail, getOrderList } from '@/api/base/orderManage'
export default {
  name: 'OrderDetailData',
  data() {
    return {
      orderId: '',
      orderIdList: [], //订单监控跳转过来
      isSingle: true,//单个详情，false是多个详情
      tableProps1,
      list1: [],
      tableH: this.tableHeight(420),
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 500
      },
      orderMsg: {},
      processFlowName: ''
    }
  },
  components: { TopTab },
  mounted() {
    window.addEventListener('resize', () => {
      this.tableH = this.tableHeight(510) / 2
    })
    if (this.$route.query.orderIdString && this.$route.query.orderIdString !== 'undefined') {
      getOrderList({ ids: this.$route.query.orderIdString }).then(res => {
        this.orderIdList = res.data.map(item => {
          return {
            id: item.id,
            name: item.name
          }
        })
        this.orderId = this.orderIdList[0].id
        this.getMsg()
      })
      this.isSingle = false
      console.log('aaaaa')
    } else {
      this.orderId = this.$route.query.orderId
      this.isSingle = true
      this.getMsg()
      console.log('bbbbbbbbbb')
    }
  },
  methods: {
    getMsg() {
      orderDetail({
        id: this.orderId
      }).then(res => {
        this.orderMsg = res.data
        this.list1 = res.data.coreWorkOrderRespVOS
        // 工艺
        getProcessFlowList().then(res => {
          let arr = res.data || []
          if (arr.length > 0) {
            arr.map(item => {
              if (item.id === this.orderMsg.processFlowId) {
                this.processFlowName = item.name
              }
            })
          }
        })
      })
    },
    // 返回
    returnOrderManage() {
      this.$router.go(-1)
    },
    // 切换tab获取订单详情
    toggleName(val) {
      this.orderId = val
      this.getMsg()
    }
  }
}
</script>
<style lang='scss' scoped>
.orderDetailData {
  background-color: rgb(242, 244, 249);

  .box1,
  .box2 {
    background-color: #fff;
    border-radius: 9px;
  }

  .box2 {
    height: calc(100vh - 351px);
    padding: 12px 16px 0;
    margin-top: 8px;
  }

  .box1 {
    height: 215px;
    padding: 16px 16px 0 16px;

    .blodTip {
      height: 16px;
      font-size: 14px;
      font-weight: 600;
      color: rgba(0, 0, 0, 0.85);
      margin-bottom: 8px;
    }

    .lightTip {
      height: 16px;
      font-size: 14px;
      font-weight: 400;
      color: rgba(102, 102, 102, 0.75);
      margin-bottom: 12px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }

  .boxTitle {
    display: inline-block;
    font-size: 16px;
    font-weight: 400;
    color: #000000;
    margin: 0 10px 20px 0;
  }

  .blueTitle {
    content: '';
    display: inline-block;
    width: 4px;
    height: 18px;
    background-color: #0B58FF;
    border-radius: 1px;
    margin-right: 8px;
    vertical-align: bottom;
  }
}
</style>