<template>
  <a-modal
    centered
    class="modalBox"
    :footer="null"
    :maskClosable="false"
    title="物流信息"
    v-model="isShow"
    @cancle="isShow=false"
    :width="1000">
    <a-form
      id="goodsLogistics-form"
      :form="form"
      ref="form"
      v-bind="formItemLayout"
      @submit="handleSubmit">
      <a-form-item label="快递公司" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
        <v-select
          ref="company"
          code="ADVERT_POSITION"
          allowClear
          id="logistics-company"
          placeholder="请选择快递公司"
          v-decorator="['formData.company', { initialValue: formData.company, rules: [{ required: true, message: '请选择快递公司' }] }]"
        ></v-select>
      </a-form-item>
      <a-form-item label="运单编号" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
        <a-input
          id="logistics-orderNo"
          :maxLength="30"
          v-decorator="[
            'formData.orderNo',
            { initialValue: formData.orderNo, getValueFromEvent: $filterEmpty, rules: [{ required: true, message: '请输入运单编号(最多30个字符)' }] }
          ]"
          placeholder="请输入运单编号(最多30个字符)"
          allowClear />
      </a-form-item>
      <a-form-item :wrapper-col="{ span: 12, offset: 6 }" style="text-align: center;">
        <a-button type="primary" html-type="submit" id="logistics-submit" style="margin-right: 15px">保存</a-button>
        <a-button @click="close" style="margin-left: 15px" id="logistics-close">取消</a-button>
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script>
import { VSelect } from '@/components'
export default {
  name: 'GoodsLogistics',
  components: { VSelect },
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      form: this.$form.createForm(this),
      formItemLayout: {
        labelCol: { span: 4 },
        wrapperCol: { span: 16 }
      },
      formData: {
        company: null, //  快递公司
        orderNo: '' //  运单编号
      },
      isShow: this.openModal //  是否填写物流信息
    }
  },
  methods: {
    //  物流信息  保存
    handleSubmit (e) {
      e.preventDefault()
      const _this = this
      this.form.validateFields((err, values) => {
        if (!err) {
          this.$emit('success')
        }
      })
    },
    //  取消
    close () {
      this.isShow = false
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (val) {
      if (!val) {
        this.$emit('close')
      }
    }
  }
}
</script>

<style lang="less" scoped>
</style>
