<template>
<div>
  <el-dialog :before-close="()=>{$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="advanceType" multiple formType="checkbox" :type="DICT_TYPE.ORDER_SPECIAL_NEEDS" ></dict-selector>
        </el-form-item>
        <el-form-item label="特殊要求备注"><el-input  type="textarea" style="width: 300px;" v-model="todoDetail"></el-input></el-form-item>
        <el-form-item v-for="(item,index) in  this.getDictDatas(this.DICT_TYPE.ORDER_SPECIAL_NEEDS)" v-if="advanceType.indexOf(item.value) > -1" :key="item.value" :label="item.label + '预计金额'">
          <el-input style="width: 300px;" v-model="specialNeedsList[index].transFee">
            <div style="width: 100px;" slot="append" >
              <dict-selector   v-model="specialNeedsList[index].transCurrency"  :type="DICT_TYPE.COMMISSION_CURRENCY_TYPE" ></dict-selector>
            </div>
          </el-input>
        </el-form-item>
        <el-form-item label="付款类型">
          <dict-selector placeholder="请选择付款类型"  v-model="payType"  :type="DICT_TYPE.PAYMENT_TYPE" ></dict-selector>
        </el-form-item>
      </el-form>
    </div>
    <div  slot="footer" class="dialog-footer">
      <el-button @click="submit">提交</el-button>
      <el-button @click="$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",
  props:{
    orderId:{
      type:[String,Number],
    },
    show:Boolean,
  },
  data(){
    return{
      getDictDatas,
      DICT_TYPE,
      form:{},
      advanceType:[],
      specialNeedsList:[],
      todoDetail:'',
      payType:''
    }
  },
  methods:{
    submit(){
      this.specialNeedsList.forEach(i => {
        i.todoDetail = this.todoDetail
        i.payType = this.payType
      })
      let p = this.specialNeedsList.filter(i => this.advanceType.indexOf(i.advanceType) > -1)
      specialNeedCreate(p).then(r=>{
        if(r.code === 0){
          this.$emit('update:show',false)
          this.$emit('determine')
          this.$message.success('提交成功');
        }
      })
    },
  },
  watch:{
    show(val){
      if(val){
         this.getDictDatas(this.DICT_TYPE.ORDER_SPECIAL_NEEDS).forEach(r => {
             this.specialNeedsList.push({
               advanceType:r.value,
               orderId:this.orderId,
               transFee:'',//预计金额
               transCurrency:'',//运输费币种
               })
         })
      }else {
        this.specialNeedsList = []
        this.advanceType = []
      }
    }
  }
}
</script>

<style scoped lang="scss">

</style>
