<!--
@name: 托盘管理-编辑
@author: 李恒
@time: 2022-06-22 16:21:34
-->
<template>
  <p-spin :spinning="spinning">
    <p-card>
      <div slot="title" style="display: flex; align-items: center; cursor: pointer" @click="backPage">
        <a-icon type="arrow-left" style="color: #1990ff" class="mr-10"/>
        修改-{{ typeTitle }}
      </div>
      <div slot="extra">
        <p-button type="primary" @click="onSave">确认修改</p-button>
      </div>
      <p-form-model ref='formTarget' :label-col='{ span: 8 }' :model='form' :wrapper-col='{ span: 16 }'
                    class='plg-grid-from'
      >
        <a-row>
          <a-col :span='8' :xxl='6'>
            <p-form-model-item label='下传批次号码'>
              <p-input v-model='form.downloadBatchNumber' disabled/>
            </p-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span='8' :xxl='6'>
            <p-form-model-item label='仓配中心'>
              <p-input v-model='form.dcCode' disabled/>
            </p-form-model-item>
          </a-col>
          <a-col :span='8' :xxl='6'>
            <p-form-model-item label='仓库名称'>
              <p-input v-model='form.warehouseName' disabled/>
            </p-form-model-item>
          </a-col>
          <a-col :span='8' :xxl='6'>
            <p-form-model-item label='货主'>
              <p-input v-model='form.cargoOwnerName' disabled/>
            </p-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span='8' :xxl='6'>
            <p-form-model-item label='商品编码'>
              <p-input v-model='form.itemCode' disabled/>
            </p-form-model-item>
          </a-col>
          <a-col :span='8' :xxl='6'>
            <p-form-model-item label='商品名称'>
              <p-input v-model='form.itemName' disabled/>
            </p-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span='8' :xxl='6'>
            <p-form-model-item label='批号'>
              <p-input v-model='form.manufacturerLotNum' disabled/>
            </p-form-model-item>
          </a-col>
          <a-col :span='8' :xxl='6'>
            <p-form-model-item label='生产日期'>
              <p-input v-model='form.productionDate' disabled/>
            </p-form-model-item>
          </a-col>
          <a-col :span='8' :xxl='6'>
            <p-form-model-item label='有效期至'>
              <p-input v-model='form.expiredDate' disabled/>
            </p-form-model-item>
          </a-col>
          <a-col :span='8' :xxl='6'>
            <p-form-model-item label='数量'>
              <p-input v-model='form.pieceQty' disabled/>
            </p-form-model-item>
          </a-col>
          <a-col :span='8' :xxl='6'>
            <p-form-model-item label='状态'>
              <p-input v-model='form.statusName' disabled/>
            </p-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span='8' :xxl='6' v-if="form.type==='2'">
            <p-form-model-item label='监管码'>
              <p-input v-model='form.supervisionCode' disabled/>
            </p-form-model-item>
          </a-col>
          <a-col :span='8' :xxl='6'>
            <p-form-model-item label='源容器号'>
              <p-input v-model='form.contanerCode' disabled/>
            </p-form-model-item>
          </a-col>
          <a-col :span='8' :xxl='6'>
            <p-form-model-item label='目标容器号'>
              <p-input v-model='form.newContanerCode'/>
            </p-form-model-item>
          </a-col>
        </a-row>
      </p-form-model>
    </p-card>
  </p-spin>
</template>

<script>
import {save} from './api'

export default {
  props: {
    type: '',
    editData: {
      type: Object,
      default: () => ({})
    },
  },
  data() {
    return {
      spinning: false,
      form: {},
    }
  },
  mounted() {
    this.form = {...this.editData}
  },
  computed: {
    typeTitle() {
      const {type: businessType} = this.editData
      if (businessType === '1') return '托盘'
      if (businessType === '2') return '监管码'
      return '托盘管理'
    }
  },
  methods: {
    backPage() {
      this.$emit('back')
    },
    // 保存
    onSave() {
      const {newContanerCode} = this.form
      if (!newContanerCode) return this.$message.warn('请输入目标托盘号')
      this.$confirm({
        content: '是否确定提交?',
        onOk: () => {
          return save({...this.form, newContanerCode}).then((res) => {
            this.spinning = false
            if (res.success) {
              this.$message.success(res.message)
              this.$emit('back')
            } else {
              this.$message.warn(res.message)
            }
          }).finally(() => {
            this.spinning = false
          })
        },
      })
    }
  },
}
</script>

<style lang='less'>
</style>