<!--
 * @Author: zwq
 * @Date: 2020-12-29 16:37:56
 * @LastEditors: lb
 * @LastEditTime: 2022-05-11 10:00:00
 * @Description:
-->
<template>
  <el-dialog
    :visible.sync="visible"
    :title="'btn.detail' | i18nFilter"
    class="dialog"
    width="45%"
    :close-on-click-modal="false"
    @close="close"
  >
    <!-- <small-title slot="title">{{ 'btn.detail' | i18nFilter }}</small-title> -->

    <el-row>
      <el-form ref="dataForm" :model="dataForm" :rules="rules" size="medium" label-width="100px" label-position="right">
        <el-row>
          <el-col :span="8">
            <el-form-item :label="$t('module.packingManage.PackingList.shelfId')">
              <!-- <el-input disabled>{{ dataForm.shelfName }}</el-input> -->
              <span class="el-form-item__label" style="font-size: 18px; font-weight: 700">
                {{ dataForm.shelfName }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('module.packingManage.PackingList.pl')">
              <span class="el-form-item__label">
                {{ dataForm.productionLineCode }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('module.packingManage.PackingList.orderNo')">
              <span class="el-form-item__label">{{ dataForm.orderCode }}</span>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item :label="$t('module.packingManage.PackingList.quantity')">
              <span class="el-form-item__label">{{ dataForm.quantity }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('module.packingManage.PackingList.customerName')">
              <span class="el-form-item__label">{{ dataForm.customerName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('module.packingManage.PackingList.finishTime')">
              <span class="el-form-item__label">
                {{ dataForm.endTime ? moment(dataForm.endTime).format('YYYY-MM-DD HH:mm:ss') : '' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item :label="$t('module.packingManage.PackingList.productsName')">
              <span class="el-form-item__label">{{ dataForm.productName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('module.packingManage.PackingList.productSize')">
              <span class="el-form-item__label">{{ dataForm.productSize }}</span>
            </el-form-item>
          </el-col>
        </el-row>

        <small-title :size="'md'" :no-padding="true">
          {{ $t('module.packingManage.PackingList.timeDetail') }}
        </small-title>

        <el-row>
          <base-table :table-config="tableProps" :table-data="dataForm.enterTimeList" />
        </el-row>
      </el-form>
    </el-row>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{ 'btn.cancel' | i18nFilter }}</el-button>
      <el-button type="primary" @click="handlePrint">{{ $t('module.packingManage.PackingList.print') }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
import i18n from '@/lang'
import moment from 'moment'
import BaseTable from '@/components/BaseTable'
import { getInfo } from '@/api/packing-manage/PackingList'
import { timeFormatter } from '@/filters'
import SmallTitle from '@/components/BaseDrawer/components/SmallTitle.vue'

const tableProps = [
  {
    prop: 'id',
    label: i18n.t('module.packingManage.PackingList.id')
  },
  {
    prop: 'enterTime',
    label: i18n.t('module.packingManage.PackingList.enterTime'),

    filter: timeFormatter
  },
  {
    prop: 'location',
    label: i18n.t('module.packingManage.PackingList.location')
  }
]

export default {
  components: { BaseTable, SmallTitle },
  data() {
    return {
      visible: false,
      dataForm: {
        id: 0,
        endTime: null,
        customerName: null,
        productName: null,
        quantity: null,
        startTime: null,
        orderCode: null,
        shelfName: null,
        enterTimeList: []
      },
      tableProps,
      listLoading: false,
      moment,
      rules: {}
    }
  },
  methods: {
    init(id) {
      this.dataForm.id = id || ''
      this.visible = true
      this.listLoading = true
      this.$nextTick(() => {
        if (this.dataForm.id) {
          getInfo({ id: this.dataForm.id }).then(res => {
            this.dataForm = res.data
            console.log(this.dataForm)
            this.listLoading = false
          })
        }
      })
    },
    handlePrint() {
      this.$emit('printDetail', this.dataForm)
    },
    close() {
      this.visible = false
    }
  }
}
</script>

<style scoped>
.info {
  display: inline-block;
  height: 100%;
  vertical-align: middle;
  line-height: 1;
}

.dialog >>> .el-dialog__body {
  padding: 30px 24px;
}
</style>
