Commit c4336ef6 authored by 秦海涛's avatar 秦海涛

update

parent ce15a779
import moment from 'moment' import moment from 'moment'
import schema from 'async-validator'; import schema from 'async-validator';
import { descriptor, formatValidator } from './validate'; import {
descriptor,
formatValidator
} from './validate';
import { import {
getActivityDetail, getActivityDetail,
saveActivityInfo, saveActivityInfo,
...@@ -16,13 +19,13 @@ var validator = new schema(descriptor); ...@@ -16,13 +19,13 @@ var validator = new schema(descriptor);
Component({ Component({
data: { data: {
labelCol: { fixedSpan: 5 }, labelCol: {
fixedSpan: 5
},
id: '', id: '',
startTime: '', startTime: '',
endTime: '', endTime: '',
rule: '', taskList: [
prizeInfoList: [],
taskList:[
// { // {
// type: "beMembership",//会员 // type: "beMembership",//会员
// value: 20,//完成任务获得值 // value: 20,//完成任务获得值
...@@ -86,7 +89,7 @@ Component({ ...@@ -86,7 +89,7 @@ Component({
value: '', value: '',
}, },
beMembership: { beMembership: {
value:'', value: '',
checked: false checked: false
}, },
sign: { sign: {
...@@ -122,7 +125,7 @@ Component({ ...@@ -122,7 +125,7 @@ Component({
jumpLink: { jumpLink: {
title: "", title: "",
taskRateType: 3, taskRateType: 3,
link: "",//跳转链接 link: "", //跳转链接
times: 3, times: 3,
value: '', value: '',
checked: false checked: false
...@@ -137,7 +140,9 @@ Component({ ...@@ -137,7 +140,9 @@ Component({
}, },
props: {}, props: {},
didMount() { didMount() {
const { id } = this.$page.$router.params const {
id
} = this.$page.$router.params
if (id) { if (id) {
this.getActivityInfo(id) this.getActivityInfo(id)
} }
...@@ -146,13 +151,22 @@ Component({ ...@@ -146,13 +151,22 @@ Component({
// 获取id活动信息 // 获取id活动信息
async getActivityInfo(activityId) { async getActivityInfo(activityId) {
try { try {
const { success, data, message } = await getActivityDetail({ activityId }) const {
success,
data,
message
} = await getActivityDetail({
activityId
})
if (!success) { if (!success) {
this.showFailToast(message); this.showFailToast(message);
return; return;
} }
let { prizeInfoList, ...rest } = data; let {
prizeInfoList,
...rest
} = data;
this.setData({ this.setData({
...rest, ...rest,
...@@ -169,8 +183,12 @@ Component({ ...@@ -169,8 +183,12 @@ Component({
} }
}, },
onChange(e) { onChange(e) {
const { value } = e.detail; const {
const { name } = e.target.dataset; value
} = e.detail;
const {
name
} = e.target.dataset;
this.setData({ this.setData({
[name]: value [name]: value
}) })
...@@ -182,12 +200,12 @@ Component({ ...@@ -182,12 +200,12 @@ Component({
}, },
setDataByKey(name, val) { setDataByKey(name, val) {
const keys = name.split('.'); const keys = name.split('.');
if(keys.length === 1) { if (keys.length === 1) {
this.setData({ this.setData({
[keys[0]]: val [keys[0]]: val
}) })
} }
if(keys.length === 2) { if (keys.length === 2) {
let targetKey = this.data[keys[0]]; let targetKey = this.data[keys[0]];
targetKey[keys[1]] = val; targetKey[keys[1]] = val;
let newVal = Object.assign({}, targetKey) let newVal = Object.assign({}, targetKey)
...@@ -195,7 +213,7 @@ Component({ ...@@ -195,7 +213,7 @@ Component({
[keys[0]]: newVal [keys[0]]: newVal
}) })
} }
if(keys.length === 3) { if (keys.length === 3) {
let targetKey = this.data[keys[0]]; let targetKey = this.data[keys[0]];
targetKey[keys[1]][keys[2]] = val; targetKey[keys[1]][keys[2]] = val;
let newVal = Object.assign({}, targetKey) let newVal = Object.assign({}, targetKey)
...@@ -205,13 +223,21 @@ Component({ ...@@ -205,13 +223,21 @@ Component({
} }
}, },
onTaskInputChange(e) { onTaskInputChange(e) {
const { name } = e.target.dataset; const {
const { value } = e.detail; name
} = e.target.dataset;
const {
value
} = e.detail;
this.setDataByKey(name, value); this.setDataByKey(name, value);
}, },
onCheckChange(e) { onCheckChange(e) {
const { name } = e.target.dataset; const {
const { value } = e.detail; name
} = e.target.dataset;
const {
value
} = e.detail;
this.setDataByKey(name, value); this.setDataByKey(name, value);
}, },
onTaskChange(data, key) { onTaskChange(data, key) {
...@@ -225,7 +251,9 @@ Component({ ...@@ -225,7 +251,9 @@ Component({
}) })
}, },
onTimeChange(timeRange, error) { onTimeChange(timeRange, error) {
const { formState } = this.data; const {
formState
} = this.data;
this.setData({ this.setData({
timeRange, timeRange,
...@@ -253,9 +281,11 @@ Component({ ...@@ -253,9 +281,11 @@ Component({
validator.validate(data, (errors, fields) => { validator.validate(data, (errors, fields) => {
console.log('errors', errors); console.log('errors', errors);
console.log('fields', fields); console.log('fields', fields);
const { formState } = _this.data; const {
formState
} = _this.data;
_this.setFormTips(formState, errors, target) _this.setFormTips(formState, errors, target)
if(errors) { if (errors) {
resolve(false); resolve(false);
} else { } else {
resolve(true); resolve(true);
...@@ -271,7 +301,7 @@ Component({ ...@@ -271,7 +301,7 @@ Component({
Object.keys(formState).forEach(key => { Object.keys(formState).forEach(key => {
let error = errors.filter(v => target ? v.field === target && v.field === key : v.field === key).length && errors.filter(v => v.field === key)[0]; let error = errors.filter(v => target ? v.field === target && v.field === key : v.field === key).length && errors.filter(v => v.field === key)[0];
// 时间实时校验 // 时间实时校验
if(key === 'timeRange' && formState[key].status === 'error') { if (key === 'timeRange' && formState[key].status === 'error') {
return return
} }
newValidator[key] = { newValidator[key] = {
...@@ -290,11 +320,11 @@ Component({ ...@@ -290,11 +320,11 @@ Component({
async onSubmit() { async onSubmit() {
const isValidForm = await this.validateForm(this.data); const isValidForm = await this.validateForm(this.data);
// console.log(this.formatActivityParams(this.data)) // console.log(this.formatActivityParams(this.data))
if(!isValidForm) return; if (!isValidForm) return;
console.log('成功') console.log('成功')
...@@ -327,40 +357,29 @@ Component({ ...@@ -327,40 +357,29 @@ Component({
activityId = '', activityId = '',
startTime, startTime,
endTime, endTime,
rule,
title,
subtitle,
logoImg,
prizeInfoList,
taskList, taskList,
taskMap, taskMap,
commandTitle, <% for(var i = 0; i < configList.length; ++i) {%>
commandImg, <%- !taskKeys.includes(configList[i].key) && configList[i].key !== 'label' ? configList[i].key + ',' : '' %><% } %>
beenInvitedText,
} = params; } = params;
return { return {
id, id,
activityId, activityId,
title,
subtitle,
logoImg,
startTime: new Date(startTime).getTime(), startTime: new Date(startTime).getTime(),
endTime: new Date(endTime).getTime(), endTime: new Date(endTime).getTime(),
rule, // prizeInfoList: this.formatPrizeList(prizeInfoList),
prizeInfoList: this.formatPobalityPrizeList(prizeInfoList),
taskList: this.formatTaskMapToList(taskMap), taskList: this.formatTaskMapToList(taskMap),
commandTitle, <% for(var i = 0; i < configList.length; ++i) {%>
commandImg, <%- !taskKeys.includes(configList[i].key) && configList[i].key !== 'label' ? configList[i].key + ',' : '' %><% } %>
beenInvitedText
} }
}, },
// taskMap转化taskList // taskMap转化taskList
formatTaskMapToList(taskMap) { formatTaskMapToList(taskMap) {
let list = []; let list = [];
Object.keys(taskMap).forEach(type => { Object.keys(taskMap).forEach(type => {
if(!taskMap[type].checked) return; if (!taskMap[type].checked) return;
let task = { let task = {
...taskMap[type], ...taskMap[type],
type type
...@@ -378,13 +397,16 @@ Component({ ...@@ -378,13 +397,16 @@ Component({
return taskMap return taskMap
}, },
// 补足谢谢参与类型 // 补足谢谢参与类型
formatPobalityPrizeList(prizeInfoList = []) { formatPrizeList(prizeInfoList = []) {
let totalPercent = prizeInfoList.reduce((total, next) => { let totalPercent = prizeInfoList.reduce((total, next) => {
return total = addFloat(total, +next.probablity) return total = addFloat(total, +next.probablity)
}, 0) }, 0)
// 排名类型不含谢谢参与 // 排名类型不含谢谢参与
if(prizeInfoList[0].rank) return prizeInfoList; if (prizeInfoList[0].rank) return prizeInfoList;
let prizeInfoListCopy = prizeInfoList.concat().map((v, index) => ({ ...v, level: index })); let prizeInfoListCopy = prizeInfoList.concat().map((v, index) => ({
...v,
level: index
}));
if (totalPercent < 100) { if (totalPercent < 100) {
let thanksType = { let thanksType = {
...@@ -400,85 +422,23 @@ Component({ ...@@ -400,85 +422,23 @@ Component({
this.backList() this.backList()
}, },
onInputChange(e) { onInputChange(e) {
let { detail: { value }, let {
currentTarget: { dataset } detail: {
value
},
currentTarget: {
dataset
}
} = e } = e
let { name } = dataset
this.setData({ [name]: value })
},
onChangeByDataName(val, dataName) {
this.setDataByKey(dataName, val)
},
// 选择奖品弹窗
handlerShowPrize(evt) {
const {
prizeInfoList
} = this.data
let { let {
name name
} = evt.target.dataset } = dataset
if (name === 'edit') { this.setData({
this.setData({ [name]: value
showPrize: true, })
prizeDialogData: evt.target.dataset.x,
prizeDialogEdit: true,
hasEditPrize: true
})
} else {
if (prizeInfoList.length >= 20) {
this.showFailToast('最多创建20个奖励配置')
return false
}
this.setData({
showPrize: true,
prizeDialogData: {},
prizeDialogEdit: false,
hasEditPrize: false
})
}
}, },
//生成规则 onChangeByDataName(val, dataName) {
generateRule() { this.setDataByKey(dataName, val)
const {
title,
startTime,
endTime,
prizeInfoList
} = this.data;
if (title && startTime && endTime && prizeInfoList.length) {
let bool = true;
prizeInfoList.forEach(i => {
if (!i.image || !i.name) {
bool = false
}
})
if (!bool) {
this.showFailToast('请检查奖品配置是否正确')
return
}
console.log({
title,
startTime: startTime,
endTime: endTime,
prizeInfoList
}, 'time');
generateRule({
title,
startTime: new Date(startTime).getTime(),
endTime: new Date(endTime).getTime(),
prizeInfoList
}).then(res => {
if (res.success) {
this.setData({
rule: res.data,
hasEditChangePrize: false
})
}
})
} else {
this.showFailToast('请填写完整信息')
}
}, },
onCloseDialog(data) { onCloseDialog(data) {
......
import { TASK_RATE_TYPE } from '../const'
import flatten from 'lodash/flatten'
import { rankTableValidator } from "../../../utils/validate"; import { rankTableValidator } from "../../../utils/validate";
// 使用 async-validator 校验 // 使用 async-validator 校验
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment