<template>
<div>
  <el-dialog :before-close="()=>{
    clearFrom();$emit('update:show',false)
  }" center width="80%"  :visible.sync="show">
    <div class="content">
      <el-form label-width="180px" label-position="left">
        <el-form-item label="特殊要求">
         <dict-selector v-if="show" v-model="form.advanceType" formType="radio" :type="DICT_TYPE.ORDER_SPECIAL_NEEDS" ></dict-selector>
        </el-form-item>
        <el-form-item label="特殊要求备注"><el-input  type="textarea" style="width: 300px;" v-model="form.todoDetail"></el-input></el-form-item>
        <el-form-item label="内陆运费垫付预计金额" v-if="form.advanceType == 6">
          <el-input style="width: 300px;" v-model="form.transFee">
            <div style="width: 100px;" slot="append" >
              <dict-selector   v-model="form.transCurrency"  :type="DICT_TYPE.COMMISSION_CURRENCY_TYPE" ></dict-selector>
            </div>
          </el-input>
        </el-form-item>
        <el-form-item label="付款类型" v-if="form.advanceType == 6">
         <div style="width: 300px;">
           <dict-selector v-model="form.payType"  :type="DICT_TYPE.PAYMENT_TYPE" ></dict-selector>
         </div>
        </el-form-item>
      </el-form>
    </div>
    <div  slot="footer" class="dialog-footer">
      <el-button @click="submit">提交</el-button>
      <el-button @click="clearFrom();$emit('update:show',false)">取消</el-button>
    </div>
  </el-dialog>
</div>
</template>

<script>
import { getDictDatas, DICT_TYPE } from '@/utils/dict';
import {specialNeedCreate} from "@/api/ecw/order";
export default {
  name: "specialNeeds",
  created() {
    this.clearFrom()
  },
  props:{
    orderId:{
      type:[String,Number],
    },
    show:Boolean,
  },
  data(){
    return{
      getDictDatas,
      DICT_TYPE,
      form:{},
    }
  },
  methods:{
    clearFrom(){
      this.form = {
        advanceType:undefined,
        advanceWho: undefined,
        payType: undefined,
        todoDetail: undefined,
        transCurrency: undefined,
        transFee: undefined
      }
    },
    submit(){
      specialNeedCreate([{orderId:this.orderId, ...this.form}]).then(r=>{
        if(r.code === 0){
          this.clearFrom();
          this.$emit('update:show',false)
          this.$emit('determine')
          this.$message.success('提交成功');
        }
      })
    },
  },
  watch:{
    'form.advanceType'(val){
      this.form.transFee = undefined;
      this.form.transCurrency = undefined;
      this.form.payType = undefined;
    }
  }
}
</script>

<style scoped lang="scss">

</style>
