<!--修改-提成和额外金额-->
<template>
  <q-dialog v-model="persistent" content-class="bg-grey-1" persistent transition-show="scale" transition-hide="scale">
    <q-card style="width: 400px;max-width:500px;padding:0 20px;">
      <q-card-section>
        <div class="text-h6">{{commonTitle}}</div>
      </q-card-section>
      <template v-if="type==1">
        <q-input filled stack-label :dense="false" v-model="msg.CommissionMoney" ref="CommissionMoney"
            class="col-6 q-pb-lg" label="提成金额" :rules="[val => !!val || '请填写提成金额']" />
      </template>
      <template v-if="type==2">
        <q-input filled stack-label :dense="false" v-model="msg.ExtraRewardMoney" ref="ExtraRewardMoney"
            class="col-6 q-pb-lg" label="额外奖励" :rules="[val => !!val || '请填写额外奖励']" />
        <q-input filled stack-label :dense="false" v-model="msg.ExtraDeductMoney" ref="ExtraDeductMoney"
            class="col-6 q-pb-lg" label="额外扣除" :rules="[val => !!val || '请填写额外扣除']" />
      </template>
      <q-card-actions align="right" class="bg-white">
        <q-btn label="取消" flat color="grey-10" style="font-weight:400 !important" @click="closeRemarkForm" />
        <q-btn label="保存" color="accent" class="q-px-md" style="font-weight:400 !important" @click="saveMoney" />
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>
<script>
  import {
    UpdateOrderCommission,
  } from '../../api/sale/sale'
  export default {
    props: {
      data: {
        type: Object,
        default: null,
      },
      type: {
        type: Number,
        default: 0,
      }
    },
    data() {
      return {
        persistent: true,
        commonTitle: '',
        msg: {
          OrderId: 0, //订单id
          Type: 1, //类型 1提成 2额外金额
          CommissionMoney: '', //提成金额
          ExtraRewardMoney: 0, //额外奖励
          ExtraDeductMoney: 0 //额外扣除
        }
      }
    },
    created() {},
    mounted() {
        this.msg.OrderId = this.data.OrderId;
        this.msg.Type = this.type;
      if (this.type == 1) {
        this.commonTitle = '修改提成'
        this.msg.CommissionMoney = this.data.CommissionMoney;
      }
      if(this.type==2){
        this.commonTitle = '修改额外奖励'
        this.msg.CommissionMoney = 0;
        this.msg.ExtraRewardMoney = this.data.ExtraRewardMoney;
        this.msg.ExtraDeductMoney = this.data.ExtraDeductMoney;
      }
    },
    methods: {
      //关闭弹窗
      closeRemarkForm() {
        this.persistent = false;
        this.$emit('close');
      },
      //保存修改
      saveMoney() {
        if (this.type == 1) {
          if (this.msg.CommissionMoney == '') {
            this.$q.notify({
              icon: 'negative',
              color: 'accent',
              timeout: 2000,
              message: '请填写提成金额',
              position: 'top'
            })
            return
          }
        }
        if(this.type == 2){
          if (this.msg.ExtraRewardMoney == '') {
            this.$q.notify({
              icon: 'negative',
              color: 'accent',
              timeout: 2000,
              message: '请填写额外奖励',
              position: 'top'
            })
            return
          }
         if (this.msg.ExtraDeductMoney === '') {
            this.$q.notify({
              icon: 'negative',
              color: 'accent',
              timeout: 2000,
              message: '请填写额外扣除',
              position: 'top'
            })
            return
          }
        }
        UpdateOrderCommission(this.msg).then(res => {
          if (res.Code == 1) {
            this.$q.notify({
              icon: 'iconfont icon-chenggong',
              color: 'accent',
              timeout: 2000,
              message: '修改成功！',
              position: 'top'
            })
          }
          this.$emit('success');
        })
      }
    }
  }

</script>
