<template>
  <el-dialog visible :close-on-click-modal="false" :before-close="closeDialog" :title="$t('管理折扣')">
    <el-form ref="form" :model="form" label-width="80px" :rules="rules">
      
      
      <el-form-item :label="$t('旧全包价')" v-if="orderItem.charging">
        {{form.freight}} {{ currentMap[form.freightCurrency] }} / {{ unitMap[form.freightVolume] }}
      </el-form-item>
      <el-form-item :label="$t('新全包价')" style="width: 400px" prop="clearanceFreight"  v-if="orderItem.charging">
        <el-input v-model="form.freight" type="number" class="w-100" />
        {{ currentMap[form.freightCurrency] }} / {{ unitMap[form.freightVolume] }}
      </el-form-item>
      
    </el-form>
    <div class="page-title">审批流程</div>
    <work-flow xmlkey="special_apply" v-model="ccIdArr" />
    <div v-if="!form.applyStatus">
      <el-button type="primary" @click="handleSubmit">提交</el-button>
    </div>
    <div v-else>
      <el-button type="primary" @click="$router.push('/bpm/process-instance/detail?id=' + form.formId)">
        <dict-tag :type="DICT_TYPE.APPLY_STATUS" :value="form.applyStatus" />
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import {createOrderSpecial, getOrderSpecial} from "@/api/ecw/order"
import {getUnitList} from "@/api/ecw/unit"
import {getChannel, getChannelList} from "@/api/ecw/channel"
import { getCurrencyList } from '@/api/ecw/currency'
import { getProductType } from '@/api/ecw/productType'
import WorkFlow from '@/components/WorkFlow'
export default {
  name: "OrderSpecialDiscount",
  props: {
    order: Object,
    orderItem: Object,
    applyType: Number // 4是重货优惠5是泡货优惠
  },
  components: {
    WorkFlow
  },
  created() {
    // 查看详情,列表进来的
    this.getOrderSpecial()

  },
  data() {
    return {
      // applyType: 2, //1是优惠申请2是管理折扣3是佣金设置4是重货优惠5是泡货优惠
      ccIdArr: [],
      form: {
        
      },
      rules:{

      },
    }
  },
  watch:{
    ccIdArr(){
      this.$set(this.form, 'ccIds', this.ccIdArr.join(','))
    }
  },
  methods: {
    handleSubmit(){
      this.$refs.form.validate().then(res => {
        createOrderSpecial(Object.assign({}, this.form, {applyType: this.applyType})).then(res => {
          this.$message.success(this.$t('提交成功'))
          this.$emit('success')
        })
      })
    },
    getOrderSpecial(){
      getOrderSpecial(this.order.orderId, this.applyType, {}).then(r => {
        this.form = r.data
      })
    },
    closeDialog(){
      this.$emit('close')
    }
  }
}
</script>