<template>
  <el-dialog
    :visible.sync="visible"
    v-bind="modalOptions"
    append-to-body
  >
    <el-form
      ref="formData"
      :model="formData"
      size="mini"
      label-position="left"
      label-suffix=":"
      label-width="200px"
    >
      <!-- 平台消费金活动分佣规则信息 -->
      <el-form-item label="规则ID" prop="ruleId">
        {{ formData.ruleId || '--' }}
      </el-form-item>
      <el-form-item label="活动ID" prop="activityId">
        {{ formData.activityId || '--' }}
      </el-form-item>
      <el-form-item label="关联活动" prop="activityName">
        {{ formData.activityName || '--' }}
      </el-form-item>
      <el-form-item label="活动类型" prop="activityType">
        <span v-if="formData.activityType === 5">消费金</span>
        <span v-else-if="formData.activityType === 6">组合活动</span>
        <span v-else>--</span>
      </el-form-item>
      <el-form-item label="团长规则" prop="leadersRule">
        <span v-if="formData.leadersRule === 1">比例</span>
        <span v-else-if="formData.leadersRule === 2">金额</span>
        <span v-else>--</span>
      </el-form-item>
      <el-form-item label="直接团长规则" prop="leadersMoney">
        {{ formData.leadersMoney }}
      </el-form-item>
      <el-form-item label="间接团长规则" prop="leadersInMoney">
        {{ formData.leadersInMoney }}
      </el-form-item>
      <el-form-item label="合伙人规则" prop="partnerRule">
        <span v-if="formData.partnerRule === 1">比例</span>
        <span v-else-if="formData.partnerRule === 2">金额</span>
        <span v-else>--</span>
      </el-form-item>
      <el-form-item label="直接合伙人规则" prop="partnerMoney">
        {{ formData.partnerMoney }}
      </el-form-item>
      <el-form-item label="间接合伙人规则" prop="partnerInMoney">
        {{ formData.partnerInMoney }}
      </el-form-item>
      <el-form-item label="加盟商规则" prop="franchiseeRule">
        <span v-if="formData.franchiseeRule === 1">比例</span>
        <span v-else-if="formData.franchiseeRule === 2">金额</span>
        <span v-else>--</span>
      </el-form-item>
      <el-form-item label="加盟商佣金规则" prop="franchiseeMoney">
        {{ formData.franchiseeMoney }}
      </el-form-item>
      <el-form-item label="社区店规则" prop="communityRule">
        <span v-if="formData.communityRule === 1">比例</span>
        <span v-else-if="formData.communityRule === 2">金额</span>
        <span v-else>--</span>
      </el-form-item>
      <el-form-item label="社区店佣金规则" prop="communityMoney">
        {{ formData.communityMoney }}
      </el-form-item>
      <el-form-item label="代理商规则" prop="agentRule">
        <span v-if="formData.agentRule === 1">比例</span>
        <span v-else-if="formData.agentRule === 2">金额</span>
        <span v-else>--</span>
      </el-form-item>
      <el-form-item label="代理商佣金规则" prop="agentMoney">
        {{ formData.agentMoney }}
      </el-form-item>
      <el-form-item label="分佣来源" prop="sourceType">
        <span v-if="formData.sourceType === 1">订单金额</span>
        <span v-else-if="formData.sourceType === 2">赠送代金券</span>
        <span v-else-if="formData.sourceType === 3">消费金</span>
        <span v-else>--</span>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        {{ formData.createTime || '--' }}
      </el-form-item>
      <el-form-item label="更新时间" prop="updateTime">
        {{ formData.updateTime || '--' }}
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import { getByIdPlatformBeeRule } from '@/api/commissionAllocation/gradeCommission'

export default {
  name: 'DetailModal',
  data() {
    return {
      modalOptions: {
        closeOnClickModal: false,
        width: '800px',
        title: '查看平台消费金活动分佣规则详情'
      },
      visible: false,
      formData: {
        ruleId: '',
        activityId: '',
        activityName: '',
        activityType: '',
        leadersRule: '',
        leadersMoney: '',
        leadersInMoney: '',
        partnerRule: '',
        partnerMoney: '',
        partnerInMoney: '',
        franchiseeRule: '',
        franchiseeMoney: '',
        communityRule: '',
        communityMoney: '',
        agentRule: '',
        agentMoney: '',
        sourceType: '',
        createTime: '',
        updateTime: ''
      }
    }
  },
  methods: {
    handleClose() {
      this.visible = false
    },
    handleOpen(params = {}) {
      this.formData = Object.assign(this.$options.data().formData, params)
      if (params.ruleId) {
        this.getInfo(params.ruleId)
      }
      this.visible = true
    },
    async getInfo(id) {
      const loading = this.$loading({ text: '加载中' })
      try {
        const res = await getByIdPlatformBeeRule({ id })
        this.formData = Object.assign(this.$options.data().formData, res.data, {
          ruleId: res.data.ruleId || '',
          activityId: res.data.activityId || '',
          activityName: res.data.activityName || '',
          activityType: res.data.activityType || '',
          leadersRule: res.data.leadersRule || '',
          leadersMoney: res.data.leadersMoney,
          leadersInMoney: res.data.leadersInMoney,
          partnerRule: res.data.partnerRule || '',
          partnerMoney: res.data.partnerMoney,
          partnerInMoney: res.data.partnerInMoney,
          franchiseeRule: res.data.franchiseeRule || '',
          franchiseeMoney: res.data.franchiseeMoney,
          communityRule: res.data.communityRule || '',
          communityMoney: res.data.communityMoney,
          agentRule: res.data.agentRule || '',
          agentMoney: res.data.agentMoney,
          sourceType: res.data.sourceType || '',
          createTime: res.data.createTime || '',
          updateTime: res.data.updateTime || ''
        })
      } finally {
        loading.close()
      }
    }
  }
}
</script>

