Commission.vue 11.1 KB
Newer Older
1
<template>
dragondean@qq.com's avatar
dragondean@qq.com committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
  <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('商品类型')">
        <span>{{ $l(productType, 'title') }}</span>
      </el-form-item>
      <el-form-item :label="$t('商品名称')">
        <span>{{ orderItem.prodTitleZh }}</span>
      </el-form-item>
      <el-form-item :label="$t('英文名称')">
        <span>{{ orderItem.prodTitleEn }}</span>
      </el-form-item>
      <el-form-item :label="$t('线路')">
<dict-tag :type="DICT_TYPE.TRANSPORT_TYPE" :value="order.transportId" />
        {{ channel ? $l(channel, 'title') : '' }}
        {{$t("从【{departureName}】发往【{objectiveName}", {departureName: $l(order.logisticsInfoDto, 'startTitle'), objectiveName: $l(order.logisticsInfoDto, 'destTitle')})}}
      </el-form-item>
      <el-form-item :label="$t('是否预付')">
        <dict-tag :type="DICT_TYPE.ECW_YESNO" :value="orderItem.isPayAdvance" />
      </el-form-item>
      
      <el-row v-if="!orderItem.charging">
        <el-col :span="12">
          <el-form-item :label="$t('运费')">
25 26 27
            <!-- {{orderItem.oneSeaFreight}} -->
            {{originPrice}}
            {{ currencyMap[orderItem.seaFreightCurrency] }} / {{ unitMap[orderItem.seaFreightVolume] }}
28
          </el-form-item>
dragondean@qq.com's avatar
dragondean@qq.com committed
29 30 31
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('清关费')">
dragondean@qq.com's avatar
dragondean@qq.com committed
32
            {{orderItem.oneClearanceFreight}} {{ currencyMap[orderItem.clearanceFreightCurrency] }} / {{ unitMap[orderItem.clearanceFreightVolume] }}
33
          </el-form-item>
dragondean@qq.com's avatar
dragondean@qq.com committed
34 35 36 37
        </el-col>
      </el-row>
      
      <el-form-item :label="$t('全包价')" v-if="orderItem.charging">
dragondean@qq.com's avatar
dragondean@qq.com committed
38
        {{orderItem.oneSeaFreight}} {{ currencyMap[orderItem.seaFreightCurrency] }} / {{ unitMap[orderItem.seaFreightVolume] }}
dragondean@qq.com's avatar
dragondean@qq.com committed
39 40 41 42 43 44 45 46
      </el-form-item>

      <el-form-item :label="$t('佣金类型')" prop="commissionType">
        <dict-selector :type="DICT_TYPE.COMMISSION_TYPE" v-model="form.commissionType" form-type="radio" formatter="number" />
      </el-form-item>

      <!-- 明佣或者明佣+暗佣才显示 -->
      <el-form-item label="明佣佣金" v-if="form.commissionType == 1 || form.commissionType == 3">
47
        <el-input v-model="form.lightCommissionAmount" type="number" placeholder="" class="w-100"></el-input>
dragondean@qq.com's avatar
dragondean@qq.com committed
48 49 50 51
        {{ currencyMap[orderItem.seaFreightCurrency] }} / {{ unitMap[orderItem.seaFreightVolume] }}
      </el-form-item>

      <!-- 明佣+暗佣才显示 -->
dragondean@qq.com's avatar
dragondean@qq.com committed
52
      <el-form-item label="暗佣佣金" v-if="form.commissionType == 3" prop="shadeCommissionAmount" :rules="{validator: shadeCommissionValidator, message: '暗佣设置错误', trigger: 'blur'}">
53
        <el-input v-model="form.shadeCommissionAmount" placeholder="" type="number" class="w-100"></el-input>
dragondean@qq.com's avatar
dragondean@qq.com committed
54
        {{ currencyMap[orderItem.seaFreightCurrency] }} / {{ unitMap[orderItem.seaFreightVolume] }}
dragondean@qq.com's avatar
dragondean@qq.com committed
55 56 57 58 59
      </el-form-item>

      <!-- 无佣金不显示 -->
      <div class="pl-50" v-if="form.commissionType != 0">
        <div v-if="form.commissionType != 2">{{$l(orderItem, 'prodTitle')}}</div>
60

dragondean@qq.com's avatar
dragondean@qq.com committed
61 62
        <!-- 明佣+暗佣显示 -->
        <div v-if="form.commissionType == 3">
63 64 65 66
          {{$t('成本价')}}
          <!-- {{Decimal(form.freight || orderItem.oneSeaFreight).minus(form.shadeCommissionAmount)}}  -->
          {{ costPrice }}
          {{ currencyMap[form.freightCurrency] }} / {{ unitMap[form.freightVolume] }}
dragondean@qq.com's avatar
dragondean@qq.com committed
67 68 69 70 71 72 73 74
        </div>
        
        <!-- 暗佣显示 -->
        <div v-if="form.commissionType == 2">
          {{$l(orderItem, 'prodTitle')}}
          <template v-if="darkCommission">
            {{$t('暗佣')}}{{darkCommission}} {{ currencyMap[form.freightCurrency] }} / {{ unitMap[form.freightVolume] }}
          </template>
75
          <el-link type="primary" @click.native="$router.push('/customer/customerCommission?customerId=' + order.customerId)">{{$t('去设置')}}</el-link>
dragondean@qq.com's avatar
dragondean@qq.com committed
76 77
        </div>

78 79 80 81 82 83 84 85 86 87
        <div  v-if="form.commissionType == 1 || form.commissionType == 3">
          {{$t('销售价')}}
          <!-- {{Decimal(form.freight || orderItem.oneSeaFreight).plus(form.lightCommissionAmount) }} --> 
          {{salePrice}}
          {{ currencyMap[form.freightCurrency] }} / {{ unitMap[form.freightVolume] }}</div>
        <div v-if="form.commissionType == 3">
          {{$t('实际佣金返点')}}
          {{form.shadeCommissionAmount + form.lightCommissionAmount }}
          {{ currencyMap[form.freightCurrency] }} / {{ unitMap[form.freightVolume] }}
        </div>
dragondean@qq.com's avatar
dragondean@qq.com committed
88 89 90 91 92
      </div>
      
    </el-form>
    <div class="page-title">审批流程</div>
    <work-flow xmlkey="commission_config" v-model="ccIdArr" />
dragondean@qq.com's avatar
dragondean@qq.com committed
93
    <div v-if="form.applyStatus != 1">
94
      <el-button type="primary" @click="handleSubmit" :disabled="!submitable">提交</el-button>
dragondean@qq.com's avatar
dragondean@qq.com committed
95 96 97 98 99
    </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>
dragondean@qq.com's avatar
dragondean@qq.com committed
100 101
      <el-button type="primary" @click="cancelAudit">取消审核</el-button>
      <el-button type="default" @click="closeDialog">返回</el-button>
dragondean@qq.com's avatar
dragondean@qq.com committed
102 103
    </div>
  </el-dialog>
104 105 106
</template>

<script>
dragondean@qq.com's avatar
dragondean@qq.com committed
107 108 109
import {createOrderSpecial, getOrderSpecial} from "@/api/ecw/order"
import {getUnitList} from "@/api/ecw/unit"
import {getChannel} from "@/api/ecw/channel"
110
import { getCurrencyList } from '@/api/ecw/currency'
dragondean@qq.com's avatar
dragondean@qq.com committed
111 112 113
import { getProductType } from '@/api/ecw/productType'
import WorkFlow from '@/components/WorkFlow'
import {getDarkReturnCommission} from '@/api/ecw/customerCommission'
dragondean@qq.com's avatar
dragondean@qq.com committed
114
import Decimal from 'decimal.js'
dragondean@qq.com's avatar
dragondean@qq.com committed
115
import {cancelProcessInstance} from '@/api/bpm/processInstance'
116
import { number } from "echarts/lib/export"
117
export default {
dragondean@qq.com's avatar
dragondean@qq.com committed
118 119 120 121 122
  name: "OrderSpecialCommission",
  props: {
    order: Object,
    orderItem: Object,
  },
123 124 125 126
  components: {
    WorkFlow
  },
  data() {
dragondean@qq.com's avatar
dragondean@qq.com committed
127 128 129 130 131 132 133
    let shadeCommissionValidator = (rule, value, callback) => {
        if (!Number(value)) return callback(new Error('请输入有效数字'))
        let reg = /((^[1-9]\d*)|^0)(\.\d*){0,1}$/;
        if (!reg.test(value)) return callback(new Error('请输入有效数字'));
        if(Number(value) > this.originPrice) return callback(new Error('暗佣不能超过运费'))
        callback();
    }
134
    return {
dragondean@qq.com's avatar
dragondean@qq.com committed
135
      shadeCommissionValidator,
dragondean@qq.com's avatar
dragondean@qq.com committed
136 137
      applyType: 3, // 1是优惠申请2是管理折扣3是佣金设置4是重货优惠5是泡货优惠
      unitList:[],
138
      currencyList:[],
dragondean@qq.com's avatar
dragondean@qq.com committed
139 140 141 142 143 144 145 146 147 148 149 150
      ccIdArr: [],
      form: {
        type: 3
      },
      rules:{
        seaFreight      : {required: true, message: '运费不能为空'},
        clearanceFreight: {required: true, message: '清关费不能为空'}
      },
      productType: null,
      channel: null,
      darkCommission: null
    }
151
  },
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
  computed: {
    // 是否可以提交
    submitable(){
      let submitable = false;
      [
        ['orgLightCommissionAmount', 'lightCommissionAmount'],
        ['orgShadeCommissionAmount', 'shadeCommissionAmount'],
        ['commissionType', 'orgCommissionType']
      ].forEach(item => {
        if(this.form[item[0]] != this.form[item[1]]){
          submitable = true
        }
      })
      return submitable
    },
    // 根据渠道id显示渠道名
    getChannelNameById(){
      return channelId => {
        const s = this.channelList.find(item => item.channelId == channelId) ?. nameZh
        return s ? '' + s + '' : ''
      }
    },
    currencyMap(){
      let map = {}
      this.currencyList.forEach(item => {
        map[item.id] = this.$l(item, 'title')
      })
      return map
    },
    unitMap(){
      let map = {}
      this.unitList.forEach(item => {
        map[item.id] = this.$l(item, 'title')
      })
      return map
    },
    // 原价
    originPrice(){
      if(!this.form.orgFreight) return 0
191
        return Decimal(this.form.orgFreight).minus(parseFloat(this.form.orgLightCommissionAmount) || 0)
192 193 194
    },
    // 成本价
    costPrice(){
195
      
196
      if(!this.originPrice) return 0
197
      return Decimal(this.originPrice).minus(parseFloat(this.form.shadeCommissionAmount) || 0)
198 199 200 201
    },
    // 销售价
    salePrice(){
      if(!this.originPrice) return 0
202
      return Decimal(this.originPrice).plus(parseFloat(this.form.lightCommissionAmount) || 0)
203 204 205 206
    }
  },
  
  
dragondean@qq.com's avatar
dragondean@qq.com committed
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
  watch:{
    ccIdArr(){
      this.$set(this.form, 'ccIds', this.ccIdArr.join(','))
    },
    'form.commissionType'(val, old){
      if(typeof old !='undefined' && old != val){
        this.$set(this.form, 'lightCommissionAmount', 0)
        this.$set(this.form, 'shadeCommissionAmount', 0)
      }
      
      
      // 暗佣需要查询暗佣设置
      if(val == 2){
        this.getCommission()
      }
222 223
    }
  },
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
  created() {
    // 查看详情,列表进来的
    this.getOrderSpecial()

    getUnitList().then(res => this.unitList = res.data)
    getCurrencyList().then(res => this.currencyList = res.data)

    getProductType(this.orderItem.prodType).then(res => {
      this.productType = res.data
    })
    if(this.order.channelId){
      getChannel(this.order.channelId).then(res => {
        this.channel = res.data
      })
    }
  },
dragondean@qq.com's avatar
dragondean@qq.com committed
240
  methods: {
dragondean@qq.com's avatar
dragondean@qq.com committed
241
    Decimal(n){
dragondean@qq.com's avatar
dragondean@qq.com committed
242
      if(!n) return Decimal
dragondean@qq.com's avatar
dragondean@qq.com committed
243 244
      return new Decimal(n)
    },
dragondean@qq.com's avatar
dragondean@qq.com committed
245 246 247 248 249 250 251
    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')
        })
      })
252
    },
dragondean@qq.com's avatar
dragondean@qq.com committed
253 254 255 256 257 258 259 260 261 262
    getOrderSpecial(){
      getOrderSpecial(this.order.orderId, this.applyType, {orderItemId: this.orderItem.orderItemId}).then(r => {
        this.form = r.data
      })
    },
    /* getProductTypeNameById(id){
      return this.$l(this.productTypeList.find(e => e.id === id), 'title')
    }, */
    closeDialog(){
      this.$emit('close')
263
    },
dragondean@qq.com's avatar
dragondean@qq.com committed
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
    getCommission(){
        getDarkReturnCommission({
          customerId: this.order.customerId,
          customsType: this.order.customsType,
          darkCurrency: this.orderItem.seaFreightCurrency,
          darkUnit: this.order.seaFreightVolume,
          departureId: this.order.departureVO.departureId,
          objectiveId: this.order.objectiveVO.objectiveId,
          productAttr: this.orderItem.prodAttrIds.split(',').filter(item => item && item != ''),
          productType: this.orderItem.prodType,
          transportId: this.order.transportId,
          type: 2, // 暗佣
        }).then(res => {
          this.darkCommission = res.data?.darkCommission
        })
dragondean@qq.com's avatar
dragondean@qq.com committed
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
    },
    cancelAudit(){
      this.$prompt(this.$t('请输入取消原因?'), this.$t("取消审批"), {
        type: 'warning',
        confirmButtonText: this.$t("确定"),
        cancelButtonText: this.$t("取消"),
        inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/, // 判断非空,且非空格
        inputErrorMessage: this.$t("取消原因不能为空"),
      }).then(({ value }) => {
        return cancelProcessInstance(this.form.formId, value);
      }).then(() => {
        this.$modal.msgSuccess(this.$t("取消成功"));
        this.closeDialog()
      })
    },
294 295 296
  }
}
</script>