Commit 19d8f20e authored by 秦海涛's avatar 秦海涛

update

parent 7eabebef
......@@ -7,6 +7,7 @@
style="width:400px;margin: 10px 0 0 0"
value="{{value}}"
onChange="onChange"
data-name="{{dataName}}"
maxLength="2000"
hasLimitHint="{{true}}"
>
......
......@@ -5,13 +5,14 @@ Component({
props: {
onChange: () => {},
value: '',
dataName: '',
generateRuleInfo: {}
},
didMount() {},
didUpdate() {},
methods: {
onChange(e) {
this.props.onChange && this.props.onChange(e.detail.value);
this.props.onChange && this.props.onChange(e.detail.value, e.target.dataset.name);
},
async handleTapGeneralRule() {
console.log(this.props.generateRuleInfo, 'this.props.generateRuleInfo')
......
import moment from 'moment'
import schema from 'async-validator';
import { methods } from './mixins'
import {
descriptor,
formatValidator
......@@ -16,18 +17,6 @@ import {
const THANKS_TYPE = 5
var validator = new schema(descriptor);
Component({
data: {
labelCol: {
fixedSpan: 5
},
id: '',
startTime: '',
endTime: '',
<% for(var i = 0; i < configList.length; ++i) {%>
<%- !taskKeys.includes(configList[i].key) && configList[i].key !== 'label' ? `${configList[i].key}: ${configList[i].defaultValue || "''"},` : '' %><% } %>
taskList: [
// {
// type: "beMembership",//会员
// value: 20,//完成任务获得值
......@@ -84,8 +73,16 @@ Component({
// value: 90,
// itemIds: "111,222,333",
// }
],
Component({
mixins: [ methods ],
data: {
labelCol: { fixedSpan: 5 },
id: '',
startTime: '',
endTime: '',
<% for(var i = 0; i < configList.length; ++i) {%>
<%- !taskKeys.includes(configList[i].key) && configList[i].key !== 'label' ? `${configList[i].key}: ${configList[i].defaultValue || "''"},` : '' %><% } %>
taskList: [],
taskMap: {
attentionStore: {
value: '',
......@@ -142,136 +139,34 @@ Component({
originalStartTime: '',
formState: formatValidator(descriptor)
},
props: {},
didMount() {
const {
id
} = this.$page.$router.params
if (id) {
this.getActivityInfo(id)
}
const { id } = this.$page.$router.params
id && this.getActivityInfo(id)
},
methods: {
// 获取id活动信息
// 获取activityId活动信息
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;
this.setData({
...rest,
timeRange: [+rest.startTime, +rest.endTime],
originalStartTime: +rest.startTime,
isStart: +rest.startTime < Date.now(),
isEnd: +rest.endTime < Date.now(),
taskList: rest.taskList,
taskMap: this.formatTaskListToMap(rest.taskList)
...data,
timeRange: [+data.startTime, +data.endTime],
originalStartTime: +data.startTime,
isStart: +data.startTime < Date.now(),
isEnd: +data.endTime < Date.now(),
taskList: data.taskList,
taskMap: this.formatTaskListToMap(data.taskList)
})
} catch (error) {
console.log(error, 'err')
}
},
onChange(e) {
const {
value
} = e.detail;
const {
name
} = e.target.dataset;
this.setData({
[name]: value
})
},
onRuleChange(rule) {
this.setData({
rule
})
},
setDataByKey(val, name) {
const keys = name.split('.');
if (keys.length === 1) {
this.setData({
[keys[0]]: val
})
}
if (keys.length === 2) {
let targetKey = this.data[keys[0]];
targetKey[keys[1]] = val;
let newVal = Object.assign({}, targetKey)
this.setData({
[keys[0]]: newVal
})
}
if (keys.length === 3) {
let targetKey = this.data[keys[0]];
targetKey[keys[1]][keys[2]] = val;
let newVal = Object.assign({}, targetKey)
this.setData({
[keys[0]]: newVal
})
}
},
onConfigInputChange(e) {
const {
name
} = e.target.dataset;
const {
value
} = e.detail;
this.setDataByKey(value, name);
},
onCheckChange(e) {
const {
name
} = e.target.dataset;
const {
value
} = e.detail;
this.setDataByKey(value, name);
},
onTaskChange(data, key) {
console.log(data, key)
this.setDataByKey(data, key);
},
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 || ''
}
}
})
},
onPrizeListChange(list, target) {
this.setData({
[target]: list
})
},
validateForm(data, target) {
const _this = this;
return new Promise((resolve, reject) => {
......@@ -316,11 +211,10 @@ Component({
// 提交信息
async onSubmit() {
console.log(this.data)
console.log(this.data, 'this.data')
const isValidForm = await this.validateForm(this.data);
// console.log(this.formatActivityParams(this.data))
if (!isValidForm) return;
......@@ -329,19 +223,16 @@ Component({
const params = this.formatActivityParams(this.data)
console.log(params)
console.log(params, 'params')
saveActivityInfo(params)
.then(res => {
if (res.success) {
const { success, message } = await saveActivityInfo(params)
if(success) {
this.backList()
} else {
this.showFailToast(res.message)
}
}).catch(err => {
console.log(err)
})
},
showFailToast(text) {
my.showToast({
......@@ -416,28 +307,6 @@ Component({
}
return prizeInfoListCopy
},
cancelEdit() {
this.backList()
},
onInputChange(e) {
let {
detail: {
value
},
currentTarget: {
dataset
}
} = e
let {
name
} = dataset
this.setData({
[name]: value
})
},
onChangeByDataName(val, dataName) {
this.setDataByKey(val, dataName)
},
backList() {
this.$page.$router.push("/activity/list");
}
......
export const methods = {
// 根据dataName 改变值
onInputChangeByDataName(e) {
const { name } = e.target.dataset;
const { value } = e.detail;
this.setDataByKey(value, name);
},
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 || ''
}
}
})
},
onChangeByDataName(val, key) {
this.setDataByKey(val, key)
},
/**
*根据key值改变数据, 支持key a/a.b/a.b.c的形式
*
* @param {*} val
* @param {string} key
*/
setDataByKey(val, key) {
const keys = key.split('.');
if (keys.length === 1) {
this.setData({
[keys[0]]: val
})
}
if (keys.length === 2) {
let targetKey = this.data[keys[0]];
targetKey[keys[1]] = val;
let newVal = Object.assign({}, targetKey)
this.setData({
[keys[0]]: newVal
})
}
if (keys.length === 3) {
let targetKey = this.data[keys[0]];
targetKey[keys[1]][keys[2]] = val;
let newVal = Object.assign({}, targetKey)
this.setData({
[keys[0]]: newVal
})
}
},
}
\ No newline at end of file
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