红包配置修改
This commit is contained in:
parent
36ce6caf67
commit
a19066ef70
@ -35,43 +35,106 @@
|
||||
:value="item.platform.platform_id"
|
||||
/>
|
||||
</el-select>
|
||||
|
||||
<el-alert
|
||||
type="warning"
|
||||
title="红包金额单位:元,保留两位小数,概率单位:%"
|
||||
class="mgb-20"
|
||||
>
|
||||
</el-alert>
|
||||
<!-- 概率表 -->
|
||||
<el-collapse v-model="activeNames">
|
||||
<!-- 红包金额表 -->
|
||||
<h3>红包金额配置</h3>
|
||||
<el-form
|
||||
ref="cashForm"
|
||||
:model="cashForm"
|
||||
style="width: 100%"
|
||||
label-width="100px"
|
||||
class="mgt-20 mgb-20"
|
||||
>
|
||||
<el-form-item
|
||||
label="[1]红包金额"
|
||||
prop="Cash_1"
|
||||
:rules="cashRules"
|
||||
>
|
||||
<el-input
|
||||
v-model="cashForm.Cash_1"
|
||||
style="width: 70%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
label="[2]红包金额"
|
||||
prop="Cash_2"
|
||||
:rules="cashRules"
|
||||
>
|
||||
<el-input
|
||||
v-model="cashForm.Cash_2"
|
||||
style="width: 70%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
label="[3]红包金额"
|
||||
prop="Cash_3"
|
||||
:rules="cashRules"
|
||||
>
|
||||
<el-input
|
||||
v-model="cashForm.Cash_3"
|
||||
style="width: 70%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
label="[4]红包金额"
|
||||
prop="Cash_4"
|
||||
:rules="cashRules"
|
||||
>
|
||||
<el-input
|
||||
v-model="cashForm.Cash_4"
|
||||
style="width: 70%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
label="[5]红包金额"
|
||||
prop="Cash_5"
|
||||
:rules="cashRules"
|
||||
>
|
||||
<el-input
|
||||
v-model="cashForm.Cash_5"
|
||||
style="width: 70%"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
</el-form>
|
||||
|
||||
<!-- 红包金额表 end -->
|
||||
|
||||
<!-- 概率配置 -->
|
||||
<h3>概率配置</h3>
|
||||
<el-collapse
|
||||
v-model="activeNames"
|
||||
v-if="allRE.length > 0"
|
||||
>
|
||||
<el-collapse-item
|
||||
:name="index"
|
||||
v-for="(item, index) in redEnvelopeList"
|
||||
v-for="(item, index) in allRE"
|
||||
:key="index"
|
||||
>
|
||||
<template slot="title">
|
||||
{{ `[${index+1}]红包:${item.cash}`}}
|
||||
<svg-icon
|
||||
style="margin-right: 20px;"
|
||||
icon-class="del"
|
||||
@click.stop="delRE(index)"
|
||||
/>
|
||||
{{ `次数:${item.id}`}}
|
||||
</template>
|
||||
|
||||
<el-form
|
||||
:ref="`redEnvelopeForm${index}`"
|
||||
:ref="`PRForm${index}`"
|
||||
:model="item"
|
||||
style="width: 100%"
|
||||
label-width="100px"
|
||||
class="mgt-20 mgb-20"
|
||||
>
|
||||
|
||||
<el-form-item
|
||||
label="红包金额"
|
||||
prop="cash"
|
||||
:rules="cashRules"
|
||||
>
|
||||
<el-input
|
||||
v-model="item.cash"
|
||||
style="width: 70%"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item
|
||||
:label="`获得概率${idx + 1}`"
|
||||
:label="`红包[${idx + 1}]概率`"
|
||||
:prop="`prList[${idx}].pr`"
|
||||
v-for="(p, idx) in item.prList"
|
||||
:key="idx"
|
||||
@ -87,13 +150,23 @@
|
||||
|
||||
</el-collapse>
|
||||
|
||||
<!-- 概率表 end-->
|
||||
|
||||
<div
|
||||
class="tip mgt-20 mgb-20"
|
||||
v-else
|
||||
>
|
||||
暂无配置,请添加配置
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<el-button
|
||||
class="mgt-20"
|
||||
type="success"
|
||||
@click="addRE"
|
||||
v-if="permEdit"
|
||||
>新增</el-button>
|
||||
<el-button
|
||||
class="mgt-20"
|
||||
type="primary"
|
||||
@click="saveRECfg"
|
||||
@click="saveAllIV"
|
||||
v-if="permEdit"
|
||||
>保存</el-button>
|
||||
<el-button
|
||||
@ -108,6 +181,7 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
<script>
|
||||
import { mapGetters } from 'vuex'
|
||||
import { getGame } from '@/api/games'
|
||||
@ -129,17 +203,49 @@ export default {
|
||||
permEdit: false,
|
||||
permPublish: false,
|
||||
hasList: false,
|
||||
RECfg: [],
|
||||
|
||||
// form
|
||||
redEnvelopeList: [],
|
||||
cashForm: {
|
||||
Cash_1: '0.00',
|
||||
Cash_2: '0.00',
|
||||
Cash_3: '0.00',
|
||||
Cash_4: '0.00',
|
||||
Cash_5: '0.00'
|
||||
},
|
||||
cashRules: [
|
||||
{ required: true, message: '请填写红包金额', trigger: 'blur' },
|
||||
{ pattern: /\d+.\d{2}/, message: '红包金额格式:6.66', trigger: 'blur' }
|
||||
{
|
||||
pattern: /^\d+.\d{2}$/,
|
||||
message: '红包金额格式:6.66',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
prRules: [
|
||||
{ required: true, message: '请填写红包获得概率', trigger: 'blur' }
|
||||
],
|
||||
activeNames: []
|
||||
PRForm: {},
|
||||
activeNames: [],
|
||||
defaultSetting: {
|
||||
id: 0,
|
||||
prList: [
|
||||
{
|
||||
pr: 0
|
||||
},
|
||||
{
|
||||
pr: 0
|
||||
},
|
||||
{
|
||||
pr: 0
|
||||
},
|
||||
{
|
||||
pr: 0
|
||||
},
|
||||
{
|
||||
pr: 0
|
||||
}
|
||||
]
|
||||
},
|
||||
allRE: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -156,83 +262,19 @@ export default {
|
||||
this.userInfo.permissions.includes(`${this.uid}-publish`) ||
|
||||
this.userInfo.permissions.includes(`games-writeable`)
|
||||
this.getGameInfo(this.getGameSettings)
|
||||
|
||||
this.redEnvelopeList = this.generateREList()
|
||||
},
|
||||
watch: {
|
||||
allRE: {
|
||||
handler: function(nVal) {
|
||||
nVal.map((item, index) => {
|
||||
item.id = index + 1
|
||||
})
|
||||
},
|
||||
immediate: true,
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// common
|
||||
generateREList() {
|
||||
const result = []
|
||||
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const prList = []
|
||||
for (let j = 0; j < 10; j++) {
|
||||
prList.push({
|
||||
pr: 0
|
||||
})
|
||||
}
|
||||
result.push({
|
||||
cash: 0,
|
||||
prList: prList
|
||||
})
|
||||
}
|
||||
return result
|
||||
},
|
||||
resolveREConfig(settings) {
|
||||
for (let i = 0; i < settings.length; i++) {
|
||||
const setting = settings[i]
|
||||
if (setting.key === 'red_envelope') {
|
||||
this.RECfg = JSON.parse(setting.value)
|
||||
this.hasList = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.hasList) {
|
||||
this.$message.warning('当前无红包配置,请填写!')
|
||||
return
|
||||
}
|
||||
|
||||
this.RECfg.map(item => {
|
||||
let REIdx
|
||||
for (const key in item) {
|
||||
if (item.hasOwnProperty(key)) {
|
||||
if (key.startsWith('Cash_')) {
|
||||
REIdx = this.resolveREIndex(key)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
this.redEnvelopeList[REIdx].cash = item[`Cash_${REIdx + 1}`]
|
||||
this.redEnvelopeList[REIdx].prList[item.id - 1] = {
|
||||
pr: item[`Percent_${REIdx + 1}`]
|
||||
}
|
||||
})
|
||||
|
||||
this.redEnvelopeList = JSON.parse(JSON.stringify(this.redEnvelopeList))
|
||||
},
|
||||
resolveREIndex(str) {
|
||||
const reg = /Cash_(\d+)/
|
||||
const result = reg.exec(str)
|
||||
return result ? result[1] - 1 : ''
|
||||
},
|
||||
formRECfg() {
|
||||
const result = []
|
||||
|
||||
this.redEnvelopeList.map((item, index) => {
|
||||
item.prList.map((p, idx) => {
|
||||
const cashKey = `Cash_${index + 1}`
|
||||
const percentKey = `Percent_${index + 1}`
|
||||
result.push({
|
||||
id: idx + 1,
|
||||
[cashKey]: parseFloat(item.cash).toFixed(2),
|
||||
[percentKey]: parseFloat(p.pr)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
this.RECfg = result
|
||||
},
|
||||
getGameInfo(cb) {
|
||||
getGame({ uid: this.uid })
|
||||
.then(res => {
|
||||
@ -273,42 +315,150 @@ export default {
|
||||
}
|
||||
this.cfgs = data.records
|
||||
this.hasList = false
|
||||
this.resolveREConfig(this.cfgs)
|
||||
this.resolveRE(this.cfgs)
|
||||
})
|
||||
},
|
||||
resolveRE(settings) {
|
||||
for (let i = 0; i < settings.length; i++) {
|
||||
const setting = settings[i]
|
||||
|
||||
if (setting.key === 'red_envelope') {
|
||||
const data = setting.value
|
||||
? this.parseData(JSON.parse(setting.value))
|
||||
: {}
|
||||
|
||||
this.allRE = data.allRE || []
|
||||
this.cashForm = data.cashForm || {}
|
||||
this.hasList = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!this.hasList) this.allRE = []
|
||||
},
|
||||
changePlatform() {
|
||||
this.getGameSettings()
|
||||
},
|
||||
changeType() {
|
||||
this.getGameSettings()
|
||||
},
|
||||
updateACList() {
|
||||
addRE() {
|
||||
const defaultSetting = JSON.parse(JSON.stringify(this.defaultSetting))
|
||||
defaultSetting.id = this.allRE.length
|
||||
this.activeNames.push(this.allRE.length)
|
||||
this.allRE.push(defaultSetting)
|
||||
},
|
||||
delRE(index) {
|
||||
this.$confirm('是否要删除该项红包配置?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
.then(() => {
|
||||
this.allRE.splice(index, 1)
|
||||
this.$message.success('删除成功!')
|
||||
})
|
||||
.catch(() => {
|
||||
this.$message.info('已取消删除!')
|
||||
})
|
||||
},
|
||||
formData(data) {
|
||||
const result = []
|
||||
const cashList = [
|
||||
this.cashForm.Cash_1,
|
||||
this.cashForm.Cash_2,
|
||||
this.cashForm.Cash_3,
|
||||
this.cashForm.Cash_4,
|
||||
this.cashForm.Cash_5
|
||||
]
|
||||
data.map(item => {
|
||||
const percentList = []
|
||||
|
||||
item.prList.map(p => {
|
||||
percentList.push(parseFloat(p.pr))
|
||||
})
|
||||
|
||||
result.push({
|
||||
id: item.id,
|
||||
cashList: cashList,
|
||||
percentList: percentList
|
||||
})
|
||||
})
|
||||
return JSON.stringify(result)
|
||||
},
|
||||
parseData(data) {
|
||||
const result = {}
|
||||
const cashList = data[0].cashList
|
||||
|
||||
result.cashList = cashList
|
||||
result.allRE = []
|
||||
|
||||
data.map(item => {
|
||||
const prList = []
|
||||
|
||||
item.percentList.map(p => {
|
||||
prList.push({ pr: p })
|
||||
})
|
||||
|
||||
result.allRE.push({
|
||||
id: item.id,
|
||||
prList: prList
|
||||
})
|
||||
})
|
||||
|
||||
result.cashForm = {
|
||||
Cash_1: cashList[0],
|
||||
Cash_2: cashList[1],
|
||||
Cash_3: cashList[2],
|
||||
Cash_4: cashList[3],
|
||||
Cash_5: cashList[4]
|
||||
}
|
||||
|
||||
return result
|
||||
},
|
||||
updateREList() {
|
||||
const data = this.formData(this.allRE)
|
||||
if (!this.hasList) {
|
||||
this.cfgs.push({
|
||||
key: 'red_envelope',
|
||||
title: '红包配置',
|
||||
type: 'string',
|
||||
value: JSON.stringify(this.RECfg)
|
||||
value: data
|
||||
})
|
||||
return
|
||||
}
|
||||
for (let i = 0; i < this.cfgs.length; i++) {
|
||||
if (this.cfgs[i].key === 'red_envelope') {
|
||||
this.cfgs[i].value = JSON.stringify(this.RECfg)
|
||||
this.cfgs[i].value = data
|
||||
break
|
||||
}
|
||||
}
|
||||
},
|
||||
saveRECfg() {
|
||||
this.formRECfg()
|
||||
|
||||
saveAllIV() {
|
||||
if (this.allRE.length === 0) {
|
||||
this.$confirm('当前无邀请项,是否清空?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
.then(() => {
|
||||
this.updateREList()
|
||||
this.saveSettings()
|
||||
})
|
||||
.catch(() => {
|
||||
this.$message.info('已取消保存!')
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const validArr = []
|
||||
for (let i = 0; i < this.redEnvelopeList.length; i++) {
|
||||
validArr.push(this.validForm(`redEnvelopeForm${i}`))
|
||||
for (let i = 0; i < this.allRE.length; i++) {
|
||||
validArr.push(this.validForm(`PRForm${i}`, false))
|
||||
}
|
||||
validArr.push(this.validForm(`cashForm`, true))
|
||||
Promise.all(validArr)
|
||||
.then(() => {
|
||||
this.updateACList()
|
||||
this.updateREList()
|
||||
this.saveSettings()
|
||||
})
|
||||
.catch(err => {
|
||||
@ -316,12 +466,20 @@ export default {
|
||||
this.$message.error('请按要求填写表单')
|
||||
})
|
||||
},
|
||||
validForm(formName) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.$refs[formName][0].validate(valid => {
|
||||
valid ? resolve() : reject()
|
||||
validForm(formName, isSingle) {
|
||||
if (isSingle) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.$refs['cashForm'].validate(valid => {
|
||||
valid ? resolve() : reject()
|
||||
})
|
||||
})
|
||||
})
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.$refs[formName][0].validate(valid => {
|
||||
valid ? resolve() : reject()
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
saveSettings() {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user