Commit 6444ac45 authored by qinhaitao's avatar qinhaitao

refactor: 💡 统一字段

parent 43e53752
...@@ -28,11 +28,11 @@ Component({ ...@@ -28,11 +28,11 @@ Component({
<%- !taskKeys.includes(configList[i].key) && configList[i].key !== 'label' ? `${configList[i].key}: ${configList[i].defaultValue || "''"},` : '' %><% } %> <%- !taskKeys.includes(configList[i].key) && configList[i].key !== 'label' ? `${configList[i].key}: ${configList[i].defaultValue || "''"},` : '' %><% } %>
tasks: { tasks: {
// 关注店铺 // 关注店铺
attentionStore: { follow: {
value: '', value: '',
}, },
// 成为会员 // 成为会员
beMembership: { member: {
value: '', value: '',
}, },
// 签到 // 签到
...@@ -45,7 +45,7 @@ Component({ ...@@ -45,7 +45,7 @@ Component({
times: '', times: '',
}, },
// 邀请好友 // 邀请好友
inviteFriends: { invites: {
title: '', // 任务标题 title: '', // 任务标题
taskRateType: 1, // 任务频率类型 taskRateType: 1, // 任务频率类型
times: 3, // 任务为每日限次次数值 times: 3, // 任务为每日限次次数值
......
...@@ -81,17 +81,17 @@ ...@@ -81,17 +81,17 @@
<form-item <form-item
class="edit-content-form-item" class="edit-content-form-item"
label="成为会员" label="成为会员"
validateState="{{formState['taskMap.beMembership'].status}}" validateState="{{formState['taskMap.member'].status}}"
help="{{formState['taskMap.beMembership'].message}}" help="{{formState['taskMap.member'].message}}"
asterisk="{{false}}"> asterisk="{{false}}">
<view class="form-flex"> <view class="form-flex">
<checkbox class="form-check" checked="{{taskMap.beMembership.checked}}" data-name="taskMap.beMembership.checked" onChange="onCheckChange"></checkbox> <checkbox class="form-check" checked="{{taskMap.member.checked}}" data-name="taskMap.member.checked" onChange="onCheckChange"></checkbox>
<tb-config-input <tb-config-input
textBefore="获得" textBefore="获得"
textAfter="体力值" textAfter="体力值"
validateRange="{{[1, 99]}}" validateRange="{{[1, 99]}}"
value="{{taskMap.beMembership.value}}" value="{{taskMap.member.value}}"
dataName="taskMap.beMembership.value" dataName="taskMap.member.value"
onChange="onTaskInputChange", onChange="onTaskInputChange",
placeholder="1-99" placeholder="1-99"
/> />
...@@ -101,16 +101,16 @@ ...@@ -101,16 +101,16 @@
<form-item <form-item
class="edit-content-form-item" class="edit-content-form-item"
label="邀请好友" label="邀请好友"
validateState="{{formState['taskMap.inviteFriends'].status}}" validateState="{{formState['taskMap.invites'].status}}"
help="{{formState['taskMap.inviteFriends'].message}}" help="{{formState['taskMap.invites'].message}}"
asterisk="{{false}}"> asterisk="{{false}}">
<view class="form-flex"> <view class="form-flex">
<checkbox class="form-check" checked="{{taskMap.inviteFriends.checked}}" data-name="taskMap.inviteFriends.checked" onChange="onCheckChange"></checkbox> <checkbox class="form-check" checked="{{taskMap.invites.checked}}" data-name="taskMap.invites.checked" onChange="onCheckChange"></checkbox>
<task-config <task-config
unit="体力值" unit="体力值"
type="inviteFriends" type="invites"
taskData="{{taskMap.inviteFriends}}" taskData="{{taskMap.invites}}"
dataName="taskMap.inviteFriends" dataName="taskMap.invites"
onUpdate="onTaskChange" onUpdate="onTaskChange"
/> />
</view> </view>
......
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, saveActivityInfo, generateRule } from "/api";
getActivityDetail, import { addFloat } from "/utils/helper";
saveActivityInfo,
generateRule
} from '/api'
import {
addFloat
} from '/utils/helper'
const THANKS_TYPE = 5; const THANKS_TYPE = 5;
const STOCK_LIMIT = 1; const STOCK_LIMIT = 1;
const STOCK_NO_LIMIT = 2; const STOCK_NO_LIMIT = 2;
var validator = new schema(descriptor); var validator = new schema(descriptor);
Component({ Component({
data: { data: {
labelCol: { fixedSpan: 5 }, labelCol: { fixedSpan: 5 },
id: '', id: "",
title: '', title: "",
subtitle: '', subtitle: "",
startTime: '', startTime: "",
endTime: '', endTime: "",
timeRange: [], timeRange: [],
rule: '', rule: "",
prizeInfoList: [ prizeInfoList: [
{ {
ename: "", ename: "",
...@@ -37,7 +30,7 @@ Component({ ...@@ -37,7 +30,7 @@ Component({
name: "", name: "",
switchStock: STOCK_NO_LIMIT, switchStock: STOCK_NO_LIMIT,
useStock: 0, useStock: 0,
rank: "1" rank: "1",
}, },
{ {
ename: "", ename: "",
...@@ -49,7 +42,7 @@ Component({ ...@@ -49,7 +42,7 @@ Component({
name: "", name: "",
switchStock: STOCK_NO_LIMIT, switchStock: STOCK_NO_LIMIT,
useStock: 0, useStock: 0,
rank: "2" rank: "2",
}, },
{ {
ename: "", ename: "",
...@@ -61,20 +54,20 @@ Component({ ...@@ -61,20 +54,20 @@ Component({
name: "", name: "",
switchStock: STOCK_NO_LIMIT, switchStock: STOCK_NO_LIMIT,
useStock: 0, useStock: 0,
rank: "3" rank: "3",
} },
], ],
commandTitle: '', commandTitle: "",
commandImg: '', commandImg: "",
logoImg: '', logoImg: "",
beenInvitedText: '', beenInvitedText: "",
taskList: [ taskList: [
// { // {
// type: "beMembership",//会员 // type: "member",//会员
// value: 20,//完成任务获得值 // value: 20,//完成任务获得值
// }, // },
// { // {
// type: "attentionStore", // type: "follow",
// value: 20, // value: 20,
// }, // },
// { // {
...@@ -87,7 +80,7 @@ Component({ ...@@ -87,7 +80,7 @@ Component({
// times: 1, // times: 1,
// }, // },
// { // {
// type: "inviteFriends", // type: "invites",
// title: "标题",//任务标题 // title: "标题",//任务标题
// taskRateType: 1,//任务频率类型 // taskRateType: 1,//任务频率类型
// times: 3,//任务为每日限次次数值 // times: 3,//任务为每日限次次数值
...@@ -128,12 +121,12 @@ Component({ ...@@ -128,12 +121,12 @@ Component({
], ],
taskMap: { taskMap: {
// attentionStore: { // follow: {
// value: '', // value: '',
// }, // },
beMembership: { member: {
value: '', value: "",
checked: false checked: false,
}, },
// sign: { // sign: {
// value: '' // value: ''
...@@ -142,21 +135,21 @@ Component({ ...@@ -142,21 +135,21 @@ Component({
// value: '', // value: '',
// times: '', // times: '',
// }, // },
inviteFriends: { invites: {
title: '', // 任务标题 title: "", // 任务标题
taskRateType: 1, // 任务频率类型 taskRateType: 1, // 任务频率类型
times: 3, // 任务为每日限次次数值 times: 3, // 任务为每日限次次数值
value: '', // 任务奖励 value: "", // 任务奖励
checked: false checked: false,
}, },
browseGoods: { browseGoods: {
title: "寻宝屋商品", title: "寻宝屋商品",
taskRateType: 1, taskRateType: 1,
times: 3, times: 3,
value: '', value: "",
link: '', link: "",
itemIds: '', itemIds: "",
checked: true checked: true,
}, },
// collectGoods: { // collectGoods: {
// title: "", // title: "",
...@@ -168,32 +161,34 @@ Component({ ...@@ -168,32 +161,34 @@ Component({
jumpLink: { jumpLink: {
title: "", title: "",
taskRateType: 3, taskRateType: 3,
link: "",//跳转链接 link: "", //跳转链接
times: 3, times: 3,
value: '', value: "",
checked: false checked: false,
}, },
}, },
image: '', image: "",
isEnd: false, isEnd: false,
isStart: false, isStart: false,
originalStartTime: '', originalStartTime: "",
prizeDialogData: {}, prizeDialogData: {},
formState: formatValidator(descriptor), formState: formatValidator(descriptor),
isPostParams: true isPostParams: true,
}, },
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);
} }
}, },
methods: { methods: {
// 获取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;
...@@ -207,49 +202,51 @@ Component({ ...@@ -207,49 +202,51 @@ Component({
originalStartTime: +rest.startTime, originalStartTime: +rest.startTime,
isStart: +rest.startTime < Date.now(), isStart: +rest.startTime < Date.now(),
isEnd: +rest.endTime < Date.now(), isEnd: +rest.endTime < Date.now(),
prizeInfoList: prizeInfoList && prizeInfoList.length > 0 ? prizeInfoList : this.data.prizeInfoList, prizeInfoList:
prizeInfoList && prizeInfoList.length > 0
? prizeInfoList
: this.data.prizeInfoList,
taskList: rest.taskList, taskList: rest.taskList,
taskMap: this.formatTaskListToMap(rest.taskList) taskMap: this.formatTaskListToMap(rest.taskList),
}) });
} catch (error) { } catch (error) {
console.log(error, 'err') console.log(error, "err");
} }
}, },
onChange(e) { onChange(e) {
const { value } = e.detail; const { value } = e.detail;
const { name } = e.target.dataset; const { name } = e.target.dataset;
this.setData({ this.setData({
[name]: value [name]: value,
}) });
}, },
onRuleChange(rule) { onRuleChange(rule) {
this.setData({ this.setData({
rule rule,
}) });
}, },
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);
this.setData({ this.setData({
[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);
this.setData({ this.setData({
[keys[0]]: newVal [keys[0]]: newVal,
}) });
} }
}, },
onTaskInputChange(e) { onTaskInputChange(e) {
...@@ -263,14 +260,14 @@ Component({ ...@@ -263,14 +260,14 @@ Component({
this.setDataByKey(name, value); this.setDataByKey(name, value);
}, },
onTaskChange(data, key) { onTaskChange(data, key) {
console.log(data, key) console.log(data, key);
this.setDataByKey(key, data); this.setDataByKey(key, data);
}, },
onImageChange(image) { onImageChange(image) {
console.log('image', image) console.log("image", image);
this.setData({ this.setData({
image image,
}) });
}, },
onTimeChange(timeRange, error) { onTimeChange(timeRange, error) {
const { formState } = this.data; const { formState } = this.data;
...@@ -282,27 +279,26 @@ Component({ ...@@ -282,27 +279,26 @@ Component({
formState: { formState: {
...formState, ...formState,
timeRange: { timeRange: {
status: error ? 'error' : 'success', status: error ? "error" : "success",
message: error || '' message: error || "",
} },
} },
}) });
}, },
onPrizeListChange(prizeInfoList) { onPrizeListChange(prizeInfoList) {
console.log('prizeInfoList', prizeInfoList); console.log("prizeInfoList", prizeInfoList);
this.setData({ this.setData({
prizeInfoList prizeInfoList,
}) });
}, },
validateForm(data, target) { validateForm(data, target) {
const _this = this; const _this = this;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
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 {
...@@ -311,52 +307,53 @@ Component({ ...@@ -311,52 +307,53 @@ Component({
// validation passed // validation passed
}); });
}) });
}, },
setFormTips(formState, errors, target) { setFormTips(formState, errors, target) {
errors = errors || [] errors = errors || [];
let newValidator = {}; let newValidator = {};
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];
newValidator[key] = { newValidator[key] = {
status: error ? 'error' : 'success', status: error ? "error" : "success",
message: error ? error.message : '' message: error ? error.message : "",
} };
}) });
console.log('newValidator', newValidator) console.log("newValidator", newValidator);
this.setData({ this.setData({
formState: newValidator formState: newValidator,
}) });
}, },
// 提交信息 // 提交信息
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("成功");
const params = this.formatActivityParams(this.data) const params = this.formatActivityParams(this.data);
console.log(params) console.log(params);
if (this.data.isPostParams) { if (this.data.isPostParams) {
this.setData({ this.setData({
isPostParams: false isPostParams: false,
}) });
const { success, message } = await saveActivityInfo(params); const { success, message } = await saveActivityInfo(params);
if (success) { if (success) {
this.backList(); this.backList();
this.setData({ this.setData({
isPostParams: true isPostParams: true,
}) });
} else { } else {
this.showFailToast(message); this.showFailToast(message);
} }
...@@ -364,15 +361,15 @@ Component({ ...@@ -364,15 +361,15 @@ Component({
}, },
showFailToast(text) { showFailToast(text) {
my.showToast({ my.showToast({
type: 'fail', type: "fail",
content: text content: text,
}) });
}, },
// 格式化参数 // 格式化参数
formatActivityParams(params) { formatActivityParams(params) {
const { const {
id = '', id = "",
activityId = '', activityId = "",
startTime, startTime,
endTime, endTime,
rule, rule,
...@@ -387,7 +384,6 @@ Component({ ...@@ -387,7 +384,6 @@ Component({
beenInvitedText, beenInvitedText,
} = params; } = params;
return { return {
id, id,
activityId, activityId,
...@@ -401,131 +397,127 @@ Component({ ...@@ -401,131 +397,127 @@ Component({
taskList: this.formatTaskMapToList(taskMap), taskList: this.formatTaskMapToList(taskMap),
commandTitle, commandTitle,
commandImg, commandImg,
beenInvitedText 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,
} };
list.push(task) list.push(task);
}); });
return list; return list;
}, },
// taskList转化taskMap // taskList转化taskMap
formatTaskListToMap(taskList = []) { formatTaskListToMap(taskList = []) {
let taskMap = {}; let taskMap = {};
taskList.forEach(task => { taskList.forEach((task) => {
taskMap[task['type']] = task; taskMap[task["type"]] = task;
}); });
return taskMap return taskMap;
}, },
// 补足谢谢参与类型 // 补足谢谢参与类型
formatPobalityPrizeList(prizeInfoList = []) { formatPobalityPrizeList(prizeInfoList = []) {
let totalPercent = prizeInfoList.reduce((total, next) => { let totalPercent = prizeInfoList.reduce((total, next) => {
return total = addFloat(total, +next.probability) return (total = addFloat(total, +next.probability));
}, 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 = {
type: THANKS_TYPE, type: THANKS_TYPE,
name: '谢谢参与', name: "谢谢参与",
probability: 100 - totalPercent probability: 100 - totalPercent,
} };
prizeInfoListCopy.push(thanksType) prizeInfoListCopy.push(thanksType);
} }
return prizeInfoListCopy return prizeInfoListCopy;
}, },
cancelEdit() { cancelEdit() {
this.backList() this.backList();
}, },
onInputChange(e) { onInputChange(e) {
let { detail: { value }, let {
currentTarget: { dataset } detail: { value },
} = e currentTarget: { dataset },
let { name } = dataset } = e;
this.setData({ [name]: value }) let { name } = dataset;
this.setData({ [name]: value });
}, },
onChangeByDataName(val, dataName) { onChangeByDataName(val, dataName) {
this.setDataByKey(dataName, val) this.setDataByKey(dataName, val);
}, },
// 选择奖品弹窗 // 选择奖品弹窗
handlerShowPrize(evt) { handlerShowPrize(evt) {
const { const { prizeInfoList } = this.data;
prizeInfoList let { name } = evt.target.dataset;
} = this.data if (name === "edit") {
let {
name
} = evt.target.dataset
if (name === 'edit') {
this.setData({ this.setData({
showPrize: true, showPrize: true,
prizeDialogData: evt.target.dataset.x, prizeDialogData: evt.target.dataset.x,
prizeDialogEdit: true, prizeDialogEdit: true,
hasEditPrize: true hasEditPrize: true,
}) });
} else { } else {
if (prizeInfoList.length >= 20) { if (prizeInfoList.length >= 20) {
this.showFailToast('最多创建20个奖励配置') this.showFailToast("最多创建20个奖励配置");
return false return false;
} }
this.setData({ this.setData({
showPrize: true, showPrize: true,
prizeDialogData: {}, prizeDialogData: {},
prizeDialogEdit: false, prizeDialogEdit: false,
hasEditPrize: false hasEditPrize: false,
}) });
} }
}, },
//生成规则 //生成规则
generateRule() { generateRule() {
const { const { title, startTime, endTime, prizeInfoList } = this.data;
title,
startTime,
endTime,
prizeInfoList
} = this.data;
if (title && startTime && endTime && prizeInfoList.length) { if (title && startTime && endTime && prizeInfoList.length) {
let bool = true; let bool = true;
prizeInfoList.forEach(i => { prizeInfoList.forEach((i) => {
if (!i.image || !i.name) { if (!i.image || !i.name) {
bool = false bool = false;
} }
}) });
if (!bool) { if (!bool) {
this.showFailToast('请检查奖品配置是否正确') this.showFailToast("请检查奖品配置是否正确");
return return;
} }
console.log({ console.log(
title, {
startTime: startTime, title,
endTime: endTime, startTime: startTime,
prizeInfoList endTime: endTime,
}, 'time'); prizeInfoList,
},
"time"
);
generateRule({ generateRule({
title, title,
startTime: new Date(startTime).getTime(), startTime: new Date(startTime).getTime(),
endTime: new Date(endTime).getTime(), endTime: new Date(endTime).getTime(),
prizeInfoList prizeInfoList,
}).then(res => { }).then((res) => {
if (res.success) { if (res.success) {
this.setData({ this.setData({
rule: res.data, rule: res.data,
hasEditChangePrize: false hasEditChangePrize: false,
}) });
} }
}) });
} else { } else {
this.showFailToast('请填写完整信息') this.showFailToast("请填写完整信息");
} }
}, },
...@@ -533,29 +525,29 @@ Component({ ...@@ -533,29 +525,29 @@ Component({
switch (data) { switch (data) {
case "group": case "group":
this.setData({ this.setData({
showGroup: false showGroup: false,
}) });
return return;
case "prize": case "prize":
this.setData({ this.setData({
showPrize: false, showPrize: false,
prizeDialogData: {} prizeDialogData: {},
}) });
return return;
case "baby": case "baby":
this.setData({ this.setData({
showBaby: false showBaby: false,
}) });
return return;
case "link": case "link":
this.setData({ this.setData({
showLink: false showLink: false,
}) });
return return;
} }
}, },
backList() { backList() {
this.$page.$router.push("/activity/list"); this.$page.$router.push("/activity/list");
} },
}, },
}) });
\ No newline at end of file
import { TASK_RATE_TYPE } from '../const' import { TASK_RATE_TYPE } from "../const";
import flatten from 'lodash/flatten' import flatten from "lodash/flatten";
import { rankTableValidator } from "../../../utils/validate"; import { rankTableValidator } from "../../../utils/validate";
// 使用 async-validator 校验 // 使用 async-validator 校验
...@@ -9,22 +9,22 @@ export const descriptor = { ...@@ -9,22 +9,22 @@ export const descriptor = {
required: true, required: true,
validator: (rule, value) => { validator: (rule, value) => {
value = value.trim(); value = value.trim();
return !!value && value.length <= 12 return !!value && value.length <= 12;
}, },
message: "请输入正确的活动名称" message: "请输入正确的活动名称",
}, },
subtitle: { subtitle: {
required: true, required: true,
validator: (rule, value) => { validator: (rule, value) => {
value = value.trim(); value = value.trim();
return !!value && value.length <= 16 return !!value && value.length <= 16;
}, },
message: "请输入正确的活动副标题" message: "请输入正确的活动副标题",
}, },
prizeInfoList: { prizeInfoList: {
required: true, required: true,
validator: rankTableValidator validator: rankTableValidator,
}, },
//活动的开始时间和结束时间校验判断 //活动的开始时间和结束时间校验判断
timeRange: { timeRange: {
...@@ -45,7 +45,7 @@ export const descriptor = { ...@@ -45,7 +45,7 @@ export const descriptor = {
}, },
logoImg: { logoImg: {
required: true, required: true,
message: '请配置图片' message: "请配置图片",
}, },
commandTitle: { commandTitle: {
required: true, required: true,
...@@ -53,7 +53,7 @@ export const descriptor = { ...@@ -53,7 +53,7 @@ export const descriptor = {
value = value.trim(); value = value.trim();
return !!value; return !!value;
}, },
message: '请输入淘口令名称' message: "请输入淘口令名称",
}, },
beenInvitedText: { beenInvitedText: {
required: true, required: true,
...@@ -61,11 +61,11 @@ export const descriptor = { ...@@ -61,11 +61,11 @@ export const descriptor = {
value = value.trim(); value = value.trim();
return !!value; return !!value;
}, },
message: '请输入被邀请者文案' message: "请输入被邀请者文案",
}, },
commandImg: { commandImg: {
required: true, required: true,
message: '请输入淘口令图片' message: "请输入淘口令图片",
}, },
rule: { rule: {
required: true, required: true,
...@@ -73,62 +73,59 @@ export const descriptor = { ...@@ -73,62 +73,59 @@ export const descriptor = {
value = value.trim(); value = value.trim();
return !!value; return !!value;
}, },
message: '请输入活动规则' message: "请输入活动规则",
}, },
taskMap: { taskMap: {
type: 'object', type: "object",
required: true, required: true,
fields: { fields: {
beMembership: { member: {
validator: (rule, val, cb, source) => { validator: (rule, val, cb, source) => {
if(!source.beMembership.checked) return true; if (!source.member.checked) return true;
return !!val.value return !!val.value;
}, },
message: '请输入成为会员任务的奖励' message: "请输入成为会员任务的奖励",
}, },
inviteFriends: { invites: {
validator: (rule, val, cb, source) => { validator: (rule, val, cb, source) => {
if(!source.inviteFriends.checked) return true; if (!source.invites.checked) return true;
return !!(val.title && val.value) return !!(val.title && val.value);
}, },
message: '请输入邀请任务' message: "请输入邀请任务",
}, },
jumpLink: { jumpLink: {
validator: (rule, val, cb, source) => { validator: (rule, val, cb, source) => {
if(!source.jumpLink.checked) return true; if (!source.jumpLink.checked) return true;
return !!(val.title && val.value && val.link); return !!(val.title && val.value && val.link);
}, },
message: '请输入浏览指定页面任务' message: "请输入浏览指定页面任务",
}, },
browseGoods: { browseGoods: {
validator: (rule, val) => { validator: (rule, val) => {
return !!(val.itemIds); return !!val.itemIds;
}, },
message: '请输入寻宝屋商品任务' message: "请输入寻宝屋商品任务",
} },
} },
} },
}; };
export const formatValidator = (descriptor, validators) => { export const formatValidator = (descriptor, validators) => {
validators = validators || {} validators = validators || {};
Object.keys(descriptor).forEach(key => { Object.keys(descriptor).forEach((key) => {
if(descriptor[key].fields) { if (descriptor[key].fields) {
Object.keys(descriptor[key].fields).forEach(fieldKey => { Object.keys(descriptor[key].fields).forEach((fieldKey) => {
validators[`${key}.${fieldKey}`] = { validators[`${key}.${fieldKey}`] = {
status: 'success', status: "success",
message: '' message: "",
} };
}) });
} else { } else {
validators[key] = { validators[key] = {
status: 'success', status: "success",
message: '' message: "",
} };
} }
}); });
return validators return validators;
} };
\ No newline at end of file
...@@ -29,9 +29,8 @@ const DRAW_STATUS = { ...@@ -29,9 +29,8 @@ const DRAW_STATUS = {
//库存类型 //库存类型
const STOCK_TYPE = { const STOCK_TYPE = {
LIMIT_STOCK: 1, LIMIT_STOCK: 1,
NO_LIMIT_STOCK: 2 NO_LIMIT_STOCK: 2,
} };
// 日志类型: error,info // 日志类型: error,info
const LOGGER_TYPE = { const LOGGER_TYPE = {
...@@ -42,8 +41,8 @@ const LOGGER_TYPE = { ...@@ -42,8 +41,8 @@ const LOGGER_TYPE = {
const SHIP_STATUS = { const SHIP_STATUS = {
NO_ADDRESS: 1, NO_ADDRESS: 1,
NO_SHIP: 2, NO_SHIP: 2,
HAS_SHIP: 3 HAS_SHIP: 3,
} };
const PRIZE_TYPE = { const PRIZE_TYPE = {
EQUITY: 1, EQUITY: 1,
...@@ -55,8 +54,8 @@ const PRIZE_TYPE = { ...@@ -55,8 +54,8 @@ const PRIZE_TYPE = {
const PRIZE_DATA_TYPR = { const PRIZE_DATA_TYPR = {
RANK_PRIZE: 1, RANK_PRIZE: 1,
PRO_PRIZE: 2, PRO_PRIZE: 2,
BUILD_PRIZE: 3 BUILD_PRIZE: 3,
} };
// code类型 // code类型
const CODE_TYPES = { const CODE_TYPES = {
PARAMS_ERROR: { PARAMS_ERROR: {
...@@ -95,11 +94,11 @@ const TEMPLATE_INFO = { ...@@ -95,11 +94,11 @@ const TEMPLATE_INFO = {
}; };
const TASK_TYPE_CHINA = { const TASK_TYPE_CHINA = {
beMembership: "成为会员", member: "成为会员",
attentionStore: "关注店铺", follow: "关注店铺",
sign: "签到", sign: "签到",
exchangeCredits: "兑换积分", exchangeCredits: "兑换积分",
inviteFriends: "邀请好友", invites: "邀请好友",
orderGoods: "下单商品", orderGoods: "下单商品",
browseGoods: "浏览商品", browseGoods: "浏览商品",
jumpLink: "跳转链接", jumpLink: "跳转链接",
...@@ -108,11 +107,11 @@ const TASK_TYPE_CHINA = { ...@@ -108,11 +107,11 @@ const TASK_TYPE_CHINA = {
const TASK_CHECK_TYPE = { const TASK_CHECK_TYPE = {
value: { value: {
list: [ list: [
"beMembership", "member",
"attentionStore", "follow",
"sign", "sign",
"exchangeCredits", "exchangeCredits",
"inviteFriends", "invites",
"orderGoods", "orderGoods",
"jumpLink", "jumpLink",
"collectGoods", "collectGoods",
...@@ -123,7 +122,7 @@ const TASK_CHECK_TYPE = { ...@@ -123,7 +122,7 @@ const TASK_CHECK_TYPE = {
times: { times: {
list: [ list: [
"exchangeCredits", "exchangeCredits",
"inviteFriends", "invites",
"orderGoods", "orderGoods",
"browseGoods", "browseGoods",
"jumpLink", "jumpLink",
...@@ -131,19 +130,13 @@ const TASK_CHECK_TYPE = { ...@@ -131,19 +130,13 @@ const TASK_CHECK_TYPE = {
], ],
}, },
title: { title: {
list: [ list: ["invites", "orderGoods", "browseGoods", "jumpLink", "collectGoods"],
"inviteFriends",
"orderGoods",
"browseGoods",
"jumpLink",
"collectGoods",
],
}, },
itemIds: { itemIds: {
list: ["orderGoods", "browseGoods", "collectGoods"], list: ["orderGoods", "browseGoods", "collectGoods"],
}, },
taskRateType: { taskRateType: {
list: ["inviteFriends", "orderGoods", "browseGoods", "collectGoods"], list: ["invites", "orderGoods", "browseGoods", "collectGoods"],
}, },
link: { list: ["jumpLink"] }, link: { list: ["jumpLink"] },
}; };
...@@ -171,5 +164,5 @@ module.exports = { ...@@ -171,5 +164,5 @@ module.exports = {
PRIZE_TYPE, PRIZE_TYPE,
SHIP_STATUS, SHIP_STATUS,
STOCK_TYPE, STOCK_TYPE,
PRIZE_DATA_TYPR PRIZE_DATA_TYPR,
}; };
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