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

update

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