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

feat: config Temp

parent 3db47e60
......@@ -4,7 +4,7 @@
"pages/cmp/index/index"
],
"window": {
"defaultTitle": "店铺漂流记商家后台"
"defaultTitle": "<%=appName%>"
},
"plugins": {
"myPlugin": {
......
......@@ -3,14 +3,14 @@ export default {
requestType: "ams",
// app环境
env: "online", // online 线上 test 测试
env: "test", // online 线上 test 测试
// 默认云函数名称
cloudFnName: 'backstage',
// 小程序appId
appId: "3000000002099934",
appId: "<%=appId%>",
// 配置应用appID, 权益插件用
bizCode: "3000000003498711",
bizCode: "<%=bizCode%>",
};
.edit-container {
background-color: #fff;
}
.edit-title {
font-size: 12px;
font-weight: 400;
color: rgba(153, 153, 153, 1);
}
.edit-title_my {
color:rgba(51,134,241,1);
}
.edit-breadcrumb {
padding: 20px 24px;
border-bottom: 2px solid rgba(240, 242, 245, 1);
}
.edit-title-separate {
margin: 0 5px;
font-weight: 900;
}
.edit-content {
padding: 20px;
}
.edit-content-form-item {
width: 100%;
}
.submit-btn {
margin: 20px 0 0 80px;
}
.submit-btn Button {
margin-left: 20px;
}
\ No newline at end of file
<view class="edit-container">
<view class="edit-breadcrumb">
<text class="edit-title edit-title_my" onTap="backList">我的活动</text>
<text class="edit-title edit-title-separate">/</text>
<text class="edit-title">{{activityId ? '编辑' : '新建'}} 「 <%=appName%> 」 活动</text>
</view>
<view class="edit-content">
<form class="edit-content-form" inline="true" labelTextAlign="right" labelCol="{{labelCol}}">
<% for(var i = 0; i < configList.length; ++i) {%>
<%=configList[i]%><% } %>
<view class="submit-btn">
<button onTap="onSubmit" type="primary">确定</button>
<button>取消</button>
</view>
</form>
</view>
\ No newline at end of file
import moment from 'moment'
import schema from 'async-validator';
import { descriptor, formatValidator } from './validate';
import {
getActivityDetail,
saveActivityInfo
} from '/api'
import {
addFloat
} from '/utils/helper'
const THANKS_TYPE = 5
var validator = new schema(descriptor);
/**
*
* 1.任务相关
* 体力值 power
* 参与次数 gameTimes
* 粮食(牧草、水滴等) food
* 金币 coins
* 道具(炸弹、复活卡等) tools
*
*/
Component({
data: {
labelCol: {
fixedSpan: 5
},
id: '',
title: '',
subtitle: '',
startTime: '',
endTime: '',
timeRange: [],
rule: '',
isEnd: false,
isStart: false,
originalStartTime: '',
limitValue: '',
prizeInfoList: [],
prizeDialogData: {},
commandTitle: '',
beenInvitedText: '',
formState: formatValidator(validator.rules)
},
props: {},
didMount() {
const { id } = this.$page.$router.params
if (id) {
this.getActivityInfo(id)
}
},
methods: {
// 获取id活动信息
async getActivityInfo(activityId) {
try {
const { success, data, message } = await getActivityDetail({ activityId })
if (!success) {
this.showFailToast(message);
return;
}
let { prizeInfoList, ...rest } = data;
this.setData({
...rest,
timeRange: [+rest.startTime, +rest.endTime],
originalStartTime: +rest.startTime,
isStart: +rest.startTime < Date.now(),
isEnd: +rest.endTime < Date.now(),
prizeInfoList: prizeInfoList && prizeInfoList.length > 0 ? prizeInfoList : this.data.prizeInfoList
})
} catch (error) {
console.log(error, 'err')
}
},
onChange(e) {
const { value } = e.detail;
const { name } = e.target.dataset;
this.setData({
[name]: value
})
},
onConfigInputChange(e) {
this.setData({
limitValue: e.detail.value
})
},
onTimeChange(timeRange, error) {
const { formState } = this.data;
this.setData({
timeRange,
startTime: timeRange[0],
endTime: timeRange[1],
formState: {
...formState,
timeRange: {
status: error ? 'error' : 'success',
message: error || ''
}
}
})
},
validateForm(data, target) {
const _this = this;
return new Promise((resolve, reject) => {
validator.validate(data, (errors, fields) => {
const { formState } = _this.data;
_this.setFormTips(formState, errors, target)
if(errors) {
resolve(false);
} else {
resolve(true);
}
// validation passed
});
})
},
setFormTips(formState, errors, target) {
errors = errors || []
let newValidator = {};
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') {
return
}
newValidator[key] = {
status: error ? 'error' : 'success',
message: error ? error.message : ''
}
})
this.setData({
formState: newValidator
})
},
// 提交信息
async onSubmit() {
const {
id,
activityId,
startTime,
endTime,
rule,
prizeInfoList,
joinTimesEveryday,
joinNeedCredits
} = this.data
const isValidForm = await this.validateForm(this.data);
if(!isValidForm) return;
console.log('成功')
return;
if (!prizeInfoList.length) {
this.setDataTips('prizeTipsInfo', 'error', '请至少添加一个奖品配置')
}
if (prizeInfoList.length) {
let totalPercent = prizeInfoList.reduce((total, next) => {
return total = addFloat(total, +next.probablity)
}, 0)
if (totalPercent > 100) {
this.setDataTips('prizeTipsInfo', 'error', '奖品的中奖概率相加不能超过100')
} else {
this.setDataTips('prizeTipsInfo', 'success', '')
}
}
if (joinTimesEveryday !== '' && joinTimesEveryday >= 0 && joinTimesEveryday <= 99 && Number.isInteger(+joinTimesEveryday)) {
this.setDataTips('joinTimesEverydayTipsInfo', 'success', '')
} else {
this.setDataTips('joinTimesEverydayTipsInfo', 'error', '请输入正确的每日可参与次数(0-99)')
}
if (joinNeedCredits !== '' && joinNeedCredits > 0 && joinNeedCredits <= 999 && Number.isInteger(+joinNeedCredits)) {
this.setDataTips('joinNeedCreditsTipsInfo', 'success', '')
} else {
this.setDataTips('joinNeedCreditsTipsInfo', 'error', '请输入正确的购买盲盒消耗积分(1-999)')
}
this.setData({
ruleTipsInfo: !rule
})
const {
prizeTipsInfo,
ruleTipsInfo,
timeRangeTipInfo,
joinTimesEverydayTipsInfo,
joinNeedCreditsTipsInfo
} = this.data
if (
prizeTipsInfo.status === "error" ||
ruleTipsInfo ||
timeRangeTipInfo.status === 'error' ||
joinTimesEverydayTipsInfo.status === 'error' ||
joinNeedCreditsTipsInfo.status === 'error'
) {
this.showFailToast('请检查信息是否全部填写正确')
return
} else {
const params = this.formatActivityParams(this.data)
saveActivityInfo(params)
.then(res => {
if (res.success) {
this.goToActivityList()
} else {
this.showFailToast(res.message)
}
}).catch(err => {
console.log(err)
})
}
},
showFailToast(text) {
my.showToast({
type: 'fail',
content: text
})
},
// 格式化参数
formatActivityParams({
activityId,
startTime,
endTime,
rule,
joinTimesEveryday,
joinNeedCredits,
prizeInfoList
}) {
// 补足谢谢参与类型
let totalPercent = prizeInfoList.reduce((total, next) => {
return total = addFloat(total, +next.probablity)
}, 0)
let prizeInfoListCopy = prizeInfoList.concat()
if (totalPercent < 100) {
let thanksType = {
type: THANKS_TYPE,
name: '谢谢参与',
probablity: 100 - totalPercent
}
prizeInfoListCopy.push(thanksType)
}
return {
activityId,
startTime: new Date(startTime).getTime(),
endTime: new Date(endTime).getTime(),
rule,
prizeInfoList: prizeInfoListCopy.map((v, index) => ({ ...v, level: index })),
joinTimesEveryday,
joinNeedCredits
}
},
cancleEdit() {
this.goToActivityList()
},
onInputChange(e) {
let { detail: { value },
currentTarget: { dataset }
} = e
let { name } = dataset
this.setData({ [name]: value })
},
// 选择奖品弹窗
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
})
}
},
onCloseDialog(data) {
switch (data) {
case "group":
this.setData({
showGroup: false
})
return
case "prize":
this.setData({
showPrize: false,
prizeDialogData: {}
})
return
case "baby":
this.setData({
showBaby: false
})
return
case "link":
this.setData({
showLink: false
})
return
}
},
backList() {
this.$page.$router.push("/activity/list");
},
// 更新奖品名次
onUpdateLevel(data, type) {
let dataSourceCopy
if (type || type === 0) {
dataSourceCopy = this.data.prizeInfoList.reduce((s, i, index) => {
if (index === type) {
return s = [...s, data]
} else {
return s = [...s, i]
}
}, [])
} else {
dataSourceCopy = [].concat(this.data.prizeInfoList, data)
}
this.setData({
prizeInfoList: dataSourceCopy
})
}
},
})
\ No newline at end of file
{
"component": true,
"usingComponents": {
"tb-label": "/components/form/tb-label/tb-label",
"tb-input": "/components/form/tb-input/tb-input",
"tb-config-input": "/components/form/tb-config-input/tb-config-input",
"tb-range-picker": "/components/form/tb-range-picker/tb-range-picker",
"tb-rule": "/components/form/tb-rule/tb-rule",
"probability-prize-table": "/components/prize/probability-prize-table/probability-prize-table",
"list-table": "/components/list/list-table/list-table",
"rank-config": "/components/rank/rank-config/rank-config",
"rank-table": "/components/rank/rank-table/rank-table",
"task-config": "/components/task/task-config/task-config",
"tb-image-upload": "/components/form/tb-image-upload/tb-image-upload"
}
}
\ No newline at end of file
export const descriptor = {
title: {
required: true,
validator: (rule, value) => !!value && value.length <= 12,
message: "请输入正确的活动名称"
},
subtitle: {
required: true,
validator: (rule, value) => !!value && value.length <= 16,
message: "请输入正确的活动副标题"
},
timeRange: {
required: true
}
};
export const formatValidator = descriptor => {
const validators = {}
Object.keys(descriptor).forEach(key => {
validators[key] = {
status: 'success',
message: ''
}
});
return validators
}
\ No newline at end of file
......@@ -2,4 +2,4 @@
<text class="db-title">活动管理</text>
<button type="primary" onTap="tapname">创建活动</button>
</view>
<%- listTemp %>
<%- listTable %>
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