<template>
  <el-dialog :title="$t('订单转异')" :before-close="()=>{$emit('update:showException',false)}" center
             :visible.sync="showException">
    <el-form ref="transmutationForm" :model="params" label-width="200">
      <el-form-item prop="exceptionType" :rules="{ required:true,message:'至少选择一个转异原因'}"
                    :label="$t('原因类型')">
        <el-select v-model="params.exceptionType" placeholder="至少选择一个转异原因">
          <el-option v-for="dict in this.getDictDatas(DICT_TYPE.CONS_EXCEPTION_TYPE)"
                     :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('附件')">
        <image-upload v-model="params.exceptionUrls"></image-upload>
      </el-form-item>
      <el-form-item :label="$t('详细信息')">
        <el-input v-model="params.exceptionRemark" :rows="8" type="textarea"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">{{ $t("确 定") }}</el-button>
      <el-button @click="$emit('update:showException',false)">{{ $t("取 消") }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
import imageUpload from "@/components/ImageUpload/index.vue"
import { createConsException } from "@/api/ecw/consException"
import { getSpecialListByConsId } from "@/api/ecw/consSpecialNeed"

export default {
  name: "transmutation",
  components: { imageUpload },
  props: {
    id: Number,
    showException: Boolean
  },
  data() {
    return {
      params: {
        exceptionType: null,
        exceptionUrls: [],
        exceptionRemark: null
      }
    }
  },
  methods: {
    submitForm() {
      this.$refs.transmutationForm.validate(validate => {
        if (validate) {
          var param = {
            consId: this.id,
            exceptionType: this.params.exceptionType,
            exceptionRemark: this.params.exceptionRemark,
            exceptionUrls: this.params.exceptionUrls.length ? this.params.exceptionUrls.split(",") : [],
            mediaBusinessType: 1,
            exceptionStatus: 0
          }
          createConsException(param).then(response => {
            this.$emit("update:showException", false)
            this.$emit("determine")
            this.$modal.msgSuccess("新增成功")
          })
        }
      })
    }
  },
  watch: {
    showException(val) {
      if (val) {

      } else {
        this.params = {
          exceptionType: null,
          exceptionUrls: [],
          exceptionRemark: null
        }
      }
    }
  }
}
</script>

<style scoped>

</style>
