<template>
  <a-modal
    centered
    class="modalBox"
    :footer="null"
    :maskClosable="false"
    title="发货"
    v-model="isShow"
    @cancle="isShow=false"
    :width="1000">
    <a-form
      id="logistics-form"
      :form="form"
      ref="form"
      v-bind="formItemLayout"
      @submit="handleSubmit">
      <h4>物流信息：</h4>
      <a-form-item label="快递公司" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
        <span>{{ formData.expressName }}</span>
      </a-form-item>
      <a-form-item label="运单编号" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
        <span>{{ formData.expressNum }}</span>
      </a-form-item>
      <h4>收货人信息：</h4>
      <a-form-item label="收货人姓名" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
        <span>{{ formData.receiverName }}</span>
      </a-form-item>
      <a-form-item label="收货人电话" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
        <span>{{ formData.receiverPhone }}</span>
      </a-form-item>
      <a-form-item :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol" label="收货人地址">
        <span>{{ formData.receiveAddress }}</span>
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script>
import { VSelect } from '@/components'
import { getLuckyDrawWinDetail } from '@/api/luckyDraw.js'
import { expressCompanyQuery } from '@/api/order.js'
export default {
  name: 'GoodsLogistics',
  components: { VSelect },
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    // 列id
    itemId: {
      type: String || Number,
      default: ''
    }
  },
  data () {
    return {
      form: this.$form.createForm(this),
      formItemLayout: {
        labelCol: { span: 4 },
        wrapperCol: { span: 16 }
      },
      formData: {
        expressName: undefined, //  快递公司
        expressNum: '', //  运单编号
        receiverName: '', // 收货人名称
        receiverPhone: '', // 收货人电话
        receiveAddress: '' //  详细地址
      },
      addrProvinceList: [], //  省下拉
      addrCityList: [], //  市下拉
      addrDistrictList: [], //  区下拉
      isShow: this.openModal, //  是否填写物流信息
      expressCompany: [] //  快递公司
    }
  },
  mounted () {
    this.getExpressCompany()
  },
  methods: {
    //  物流信息  保存
    handleSubmit (e) {
      e.preventDefault()
      this.form.validateFields((err, values) => {
        if (!err) {
          this.$emit('submit', values.formData)
        }
      })
    },
    //  获取快递公司
    getExpressCompany () {
      expressCompanyQuery({}).then(res => {
        if (res.status == 200) {
          this.expressCompany = res.data
        } else {
          this.expressCompany = []
        }
      })
    },
    // 获取获奖用户信息
    getCustomerInfo () {
      getLuckyDrawWinDetail({ id: this.itemId }).then(res => {
        if (res.status == 200) {
          this.formData = res.data
		  // console.log(this.formData, 'lkllllllll')
        }
      })
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (val) {
      if (!val) {
        this.$emit('close')
        this.form.resetFields()
      } else {
        if (this.itemId) {
          this.getCustomerInfo()
        }
      }
    }
  }
}
</script>

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