
<template>
  <a-form
    ref="form"
    v-bind="formItemLayout"
    :form="form"
  >
    <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="原因">
      <a-textarea
        :rows="4"
        v-decorator="[
          'remark',
          {
            rules: [
              { required: true, message: '请输入详细的添加原因!', type: 'string' },
            ]
          }
        ]"
        placeholder="请输入详细的添加补差价原因" />
    </a-form-item>
  </a-form>
</template>

<script>
import { changeStatusTwo } from '@/api/organization'
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: {
    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>
