123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <template>
- <el-dialog :visible.sync="visible" v-bind="modalOptions">
- <el-form ref="formData" :model="formData" :rules="formRules" size="mini" label-suffix=":" label-width="150px">
- <el-form-item label="关联活动" prop="activityId">
- <el-select
- v-model="formData.activityId" size="mini" placeholder="请选择关联活动" filterable
- @change="(e) => formData.activityName = activityList.find(i => i.currencyId === e).currencyName"
- >
- <el-option
- v-for="(item, index) in activityList" :key="item.currencyId"
- :label="`${item.currencyName}(${item.currencyId})`" :value="item.currencyId"
- />
- </el-select>
- </el-form-item>
- <el-form-item label="活动类型" prop="activityType">
- <el-select v-model="formData.activityType" size="mini" placeholder="请选择活动类型">
- <el-option label="499" :value="1" />
- <el-option label="商圈" :value="2" />
- <el-option label="爆品" :value="3" />
- <el-option label="消费金" :value="4" />
- </el-select>
- </el-form-item>
- <el-form-item label="团长规则" prop="leadersRule">
- <el-select v-model="formData.leadersRule" size="mini" placeholder="请选择团长规则">
- <el-option label="比例" :value="1" />
- <el-option label="金额" :value="2" />
- </el-select>
- </el-form-item>
- <el-form-item label="直接团长规则" prop="leadersMoney">
- <el-input v-model="formData.leadersMoney" placeholder="请输入直接团长规则" style="width: 150px;">
- <template #append>
- <div v-if="formData.leadersRule === 1">%</div>
- <div v-else-if="formData.leadersRule === 2">元</div>
- </template>
- </el-input>
- </el-form-item>
- <el-form-item label="间接团长规则" prop="leadersInMoney">
- <el-input v-model="formData.leadersInMoney" placeholder="请输入间接团长规则" style="width: 150px;">
- <template #append>
- <div v-if="formData.leadersRule === 1">%</div>
- <div v-else-if="formData.leadersRule === 2">元</div>
- </template>
- </el-input>
- </el-form-item>
- <el-form-item label="合伙人规则" prop="partnerRule">
- <el-select v-model="formData.partnerRule" size="mini" placeholder="请选择合伙人规则">
- <el-option label="比例" :value="1" />
- <el-option label="金额" :value="2" />
- </el-select>
- </el-form-item>
- <el-form-item label="直接合伙人规则" prop="partnerMoney">
- <el-input v-model="formData.partnerMoney" placeholder="请输入直接合伙人规则" style="width: 150px;">
- <template #append>
- <div v-if="formData.partnerRule === 1">%</div>
- <div v-else-if="formData.leadersRule === 2">元</div>
- </template>
- </el-input>
- </el-form-item>
- <el-form-item label="间接合伙人规则" prop="partnerInMoney">
- <el-input v-model="formData.partnerInMoney" placeholder="请输入间接合伙人规则" style="width: 150px;">
- <template #append>
- <div v-if="formData.partnerRule === 1">%</div>
- <div v-else-if="formData.leadersRule === 2">元</div>
- </template>
- </el-input>
- </el-form-item>
- <el-form-item label="分佣来源" prop="sourceType">
- <el-select v-model="formData.sourceType" size="mini" placeholder="请选择分佣来源">
- <el-option label="订单金额" :value="1" />
- <el-option label="赠送代金券" :value="2" />
- <el-option label="消费金" :value="3" />
- </el-select>
- </el-form-item>
- </el-form>
- <template #footer>
- <span class="dialog-footer">
- <el-button size="mini" @click="handleClose">取 消</el-button>
- <el-button type="primary" size="mini" @click="handleSubmit">确 定</el-button>
- </span>
- </template>
- </el-dialog>
- </template>
- <script>
- import { getAllPlatformBeeCurrency, getByIdPlatformBeeRule, savePlatformBeeRule, priceControlUpdatePlan } from '@/api/commissionAllocation/gradeCommission'
- export default {
- name: 'EditModal',
- components: {
- },
- data() {
- return {
- modalOptions: {
- closeOnClickModal: false,
- width: '820px',
- title: ''
- },
- visible: false,
- activityList: [],
- formData: {
- ruleId: '',
- activityId: '',
- activityType: '',
- leadersRule: '',
- leadersMoney: '',
- leadersInMoney: '',
- partnerRule: '',
- partnerMoney: '',
- partnerInMoney: '',
- sourceType: ''
- },
- formRules: {
- activityId: [
- { required: true, message: '缺少活动' }
- ],
- activityType: [
- { required: true, message: '请选择活动' }
- ],
- leadersRule: [
- { required: true, message: '请选择团长规则' }
- ],
- leadersMoney: [
- { required: false, message: '请输入直接团长规则' },
- { pattern: /^0\.\d{0,2}$|^[1-9]\d*\.\d{0,2}$|^[1-9]\d*$/, message: '数值有误' } // >0的数字, 最多2位小数正则
- ],
- leadersInMoney: [
- { required: false, message: '请输入间接团长规则' },
- { pattern: /^0\.\d{0,2}$|^[1-9]\d*\.\d{0,2}$|^[1-9]\d*$/, message: '数值有误' }
- ],
- partnerRule: [
- { required: true, message: '请选择合伙人规则' }
- ],
- partnerMoney: [
- { required: false, message: '请输入直接合伙人规则' },
- { pattern: /^0\.\d{0,2}$|^[1-9]\d*\.\d{0,2}$|^[1-9]\d*$/, message: '数值有误' }
- ],
- partnerInMoney: [
- { required: false, message: '请输入间接合伙人规则' },
- { pattern: /^0\.\d{0,2}$|^[1-9]\d*\.\d{0,2}$|^[1-9]\d*$/, message: '数值有误' }
- ],
- sourceType: [
- { required: true, message: '请选择分佣来源' }
- ]
- }
- }
- },
- methods: {
- handleClose() {
- this.visible = false
- },
- async initList() {
- const res = await getAllPlatformBeeCurrency({})
- this.activityList = res.data
- },
- handleOpen(params = {}) {
- this.modalOptions.title = params.ruleId ? '编辑平台消费金活动分佣规则' : '添加平台消费金活动分佣规则'
- this.formData = Object.assign(this.$options.data().formData, params, {
- ruleId: params.ruleId || '',
- activityId: params.activityId || '',
- activityName: params.activityName || '',
- activityType: params.activityType || '',
- leadersRule: params.leadersRule || '',
- leadersMoney: (params.leadersRule === 1) && (typeof params.leadersMoney === 'number') ? params.leadersMoney * 100 : params.leadersMoney,
- leadersInMoney: (params.leadersRule === 1) && (typeof params.leadersInMoney === 'number') ? params.leadersInMoney * 100 : params.leadersInMoney,
- partnerRule: params.partnerRule || '',
- partnerMoney: (params.partnerRule === 1) && (typeof params.partnerMoney === 'number') ? params.partnerMoney * 100 : params.partnerMoney,
- partnerInMoney: (params.partnerRule === 1) && (typeof params.partnerInMoney === 'number') ? params.partnerInMoney * 100 : params.partnerInMoney,
- sourceType: params.sourceType || ''
- })
- this.visible = true
- this.initList()
- if (params.ruleId) {
- this.getInfo(params.ruleId)
- } else {
- this.$refs.formData && this.$refs.formData.resetFields()
- }
- },
- 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.leadersRule === 1) && (typeof res.data.leadersMoney === 'number') ? res.data.leadersMoney * 100 : res.data.leadersMoney,
- leadersInMoney: (res.data.leadersRule === 1) && (typeof res.data.leadersInMoney === 'number') ? res.data.leadersInMoney * 100 : res.data.leadersInMoney,
- partnerRule: res.data.partnerRule || '',
- partnerMoney: (res.data.partnerRule === 1) && (typeof res.data.partnerMoney === 'number') ? res.data.partnerMoney * 100 : res.data.partnerMoney,
- partnerInMoney: (res.data.partnerRule === 1) && (typeof res.data.partnerInMoney === 'number') ? res.data.partnerInMoney * 100 : res.data.partnerInMoney,
- sourceType: res.data.sourceType || ''
- })
- this.$nextTick(() => {
- this.$refs.formData && this.$refs.formData.validate()
- })
- } finally {
- loading.close()
- }
- },
- handleSubmit() {
- this.$refs.formData.validate(async (valid) => {
- if (valid) {
- const loading = this.$loading({ text: '提交中,请稍候……' })
- try {
- const { leadersRule, partnerRule, leadersMoney, leadersInMoney, partnerMoney, partnerInMoney, ...otps } = this.formData
- const params = {
- leadersMoney: leadersRule === 1 ? leadersMoney / 100 : leadersMoney,
- leadersInMoney: leadersRule === 1 ? leadersInMoney / 100 : leadersInMoney,
- partnerMoney: partnerRule === 1 ? partnerMoney / 100 : partnerMoney,
- partnerInMoney: partnerRule === 1 ? partnerInMoney / 100 : partnerInMoney,
- ...otps
- }
- this.formData.ruleId ? await priceControlUpdatePlan(params) : await savePlatformBeeRule(params)
- loading.close()
- this.$message({ message: `${this.formData.ruleId ? '编辑' : '添加'}成功!`, type: 'success' })
- this.$emit('success')
- this.visible = false
- } catch (e) {
- loading.close()
- } finally {
- loading.close()
- }
- } else {
- this.$message({ message: '请输入相关信息', type: 'warning' })
- return false
- }
- })
- }
- }
- }
- </script>
|