<template>
  <a-modal
    :title="modalTitle"
    :width="400"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
  >
    <a-form :form="form">

      <a-form-item v-show="false">
        <a-input v-decorator="['id']" type="hidden"/>
      </a-form-item>

      <row-list :col="1">
        <row-item>

          <a-form-item
            label="车牌号"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-input
              v-decorator="['plateNumber']"/>
          </a-form-item>
        </row-item>
      </row-list>
    </a-form>
    <template slot="footer">
      <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
    </template>
  </a-modal>
</template>

<script>
import pick from 'lodash.pick'
import { updatePurchaseDispatchOrderInfo } from '@/api/purchase/purchase-dispatch-order'

export default {
  name: 'BasePurchaseDispatchContainerList',
  data () {
    return {
      confirmLoading: false,
      modalTitle: null,
      form: this.$form.createForm(this),
      visible: false

    }
  },
  props: {},
  created () {
    // 下拉框map
  },
  methods: {
    base (record) {
      this.visible = true
      const { form: { setFieldsValue } } = this
      this.modalTitle = '填写陆运信息'
      this.visible = true
      // 日期处理
      this.$nextTick(() => {
        setFieldsValue(Object.assign(pick(record, [
          'id',
          'plateNumber'
        ])))
      })
    },
    save () {
      const { form: { validateFieldsAndScroll } } = this
      this.confirmLoading = true
      validateFieldsAndScroll((errors, values) => {
        if (errors) {
          this.confirmLoading = false
          return
        }
        updatePurchaseDispatchOrderInfo(values).then(res => {
          this.handleCancel(values)
        })
      })
    },
    handleCancel (values) {
      this.visible = false
      this.confirmLoading = false
      this.form.resetFields()
      this.$emit('ok', values)
    }

  }
}
</script>
