
<template>
  <a-form
    ref="form"
    v-bind="formItemLayout"
    :form="form"
  >
    <a-form-item label="收货人名">
      <a-input
        v-decorator="[
          'no1',
          {
            rules: [
              { required: true, message: `请选择收货人名!`, type: 'string' },
            ]
          }
        ]"
        :placeholder="`请选择收货人名!`"
      />
    </a-form-item>
    <a-form-item label="收货地址">
      <a-input
        v-decorator="[
          'no2',
          {
            rules: [
              { required: true, message: `请选择收货地址!`, type: 'string' },
            ]
          }
        ]"
        :placeholder="`请选择收货地址!`"
      />
    </a-form-item>
    <a-form-item label="购买数量">
      <a-input
        v-decorator="[
          'no3',
          {
            rules: [
              { required: true, message: `请选择购买数量!`, type: 'string' },
            ]
          }
        ]"
        :placeholder="`请选择购买数量!`"
      />
    </a-form-item>
    <a-form-item label="发货方式">
      <a-select
        @change="typeChange"
        v-decorator="[
          'status',
          {
            rules: [
              { required: true, message: `请选择发货方式!`, type: 'string' }
            ]
          }
        ]"
        :placeholder="`请选择发货方式!`">
        <a-select-option value="online">线上发货</a-select-option>
        <a-select-option value="offline">线下自提</a-select-option>
      </a-select>
    </a-form-item>
    <a-form-item label="快递类型" v-if="currentType === 'online'">
      <a-select
        v-decorator="[
          'tpe',
          {
            rules: [
              { required: true, message: `请选择快递类型!`, type: 'string' }
            ]
          }
        ]"
        :placeholder="`请选择快递类型!`">
        <a-select-option value="shunfeng">顺丰速递</a-select-option>
        <a-select-option value="yunda">韵达快递</a-select-option>
      </a-select>
    </a-form-item>
    <a-form-item label="快递单号" v-if="currentType === 'online'">
      <a-input
        v-decorator="[
          'no',
          {
            rules: [
              { required: true, message: `请选择快递单号!`, type: 'string' },
            ]
          }
        ]"
        :placeholder="`请选择快递单号!`"
      />
    </a-form-item>
    <a-form-item
      label="自提时间"
      v-if="currentType === 'offline'"
    >
      <a-date-picker
        v-decorator="[
          'time',
          {
            rules: [
              { required: true, message: `请选择自提时间!` },
            ]
          }
        ]"
        :placeholder="`请选择自提时间!`"
        style="width: 100%" />
    </a-form-item>
  </a-form>
</template>

<script>
import { changeStatusTwo } from '@/api/organization'
import moment from 'moment'
export default {
  name: 'EditSend',
  props: {
    item: {
      type: Object,
      default: () => {
          return {}
        }
    }
  },
  data: () => ({
    formItemLayout: {
      labelCol: { span: 6 },
      wrapperCol: { span: 14 }
    },
    loading: false,
    currentType: ''
  }),
  beforeCreate () {
    this.form = this.$form.createForm(this)
  },
  methods: {
    moment,
    onOk () {
      return new Promise(resolve => {
        this.form.validateFields((errors, values) => {
          if (!errors) {
            const params = {
              status: values.status
            }
            changeStatusTwo(this.item.order_item_id, params).then((res) => {
              this.$notification.success({
                message: '成功',
                description: '修改成功'
              })
              resolve(true)
            }).catch((err) => {
              this.$notification.error({
                message: '失败',
                description: err.message
              })
              resolve(false)
            })
          }
        })
      })
    },
    // 切换发货方式(线上发货 自提发货)
    typeChange (e) {
      this.currentType = e
    }
  }
}
</script>

<style scoped>

</style>
