<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">
        <a-select
          id="logistics-expressName"
          allowClear
          v-decorator="[
            'formData.expressName',
            { initialValue: formData.expressName,
              rules: [{ required: true, message: '请选择快递公司' }] },
          ]"
          placeholder="请选择快递公司"
        >
          <a-select-option v-for="(item,index) in expressCompany" :key="index" :value="item.expressName">
            {{ item.expressName }}
          </a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item label="运单编号" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
        <a-input
          id="logistics-expressNum"
          :maxLength="30"
          v-decorator="[
            'formData.expressNum',
            { initialValue: formData.expressNum, getValueFromEvent: $filterEmpty, rules: [{ required: true, message: '请输入运单编号' }] }
          ]"
          placeholder="请输入运单编号(最多30个字符)"
          allowClear />
      </a-form-item>
      <h4>收货人信息：</h4>
      <a-form-item label="收货人姓名" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
        <a-input
          id="network-edit-name"
          :maxLength="30"
          v-decorator="[
            'formData.receiverName',
            { initialValue: formData.receiverName, getValueFromEvent: $filterEmpty, rules: [{ required: true, message: '请输入收货人姓名' }] }
          ]"
          placeholder="请输入收货人姓名(最多30个字符)"
          allowClear />
      </a-form-item>
      <a-form-item label="收货人电话" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
        <a-input
          id="network-edit-name"
          :maxLength="11"
          type="number"
          v-decorator="[
            'formData.receiverPhone',
            { initialValue: formData.receiverPhone, getValueFromEvent: $filterEmpty, rules: [
              { required: true, message: '请输入收货人电话' },
              {pattern: /^[1][0-9]{10}$/, message: '请输入正确的收货人电话' }] }
          ]"
          placeholder="请输入收货人电话"
          allowClear />
      </a-form-item>
      <a-form-item :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol" label="收货人地址">
        <a-input
          id="network-edit-address"
          :maxLength="100"
          v-decorator="[
            'formData.receiveAddress',
            { initialValue: formData.receiveAddress, getValueFromEvent: $filterEmpty, rules: [{ required: true, message: '请输入详细地址' }] }
          ]"
          placeholder="请输入详细地址(最多100个字符)"
          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="isShow=false" style="margin-left: 15px" id="logistics-close">取消</a-button>
      </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) {
          // console.log(res, 'rrrrrr')
		  this.formData = Object.assign({}, res.data)
        }
      })
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (val) {
      if (!val) {
        this.$emit('close')
      } else {
        this.form.resetFields()
        if (this.itemId) {
          this.getCustomerInfo()
        }
      }
    }
  }
}
</script>

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