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

update

parent 7eabebef
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
style="width:400px;margin: 10px 0 0 0" style="width:400px;margin: 10px 0 0 0"
value="{{value}}" value="{{value}}"
onChange="onChange" onChange="onChange"
data-name="{{dataName}}"
maxLength="2000" maxLength="2000"
hasLimitHint="{{true}}" hasLimitHint="{{true}}"
> >
......
...@@ -5,13 +5,14 @@ Component({ ...@@ -5,13 +5,14 @@ Component({
props: { props: {
onChange: () => {}, onChange: () => {},
value: '', value: '',
dataName: '',
generateRuleInfo: {} generateRuleInfo: {}
}, },
didMount() {}, didMount() {},
didUpdate() {}, didUpdate() {},
methods: { methods: {
onChange(e) { 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() { async handleTapGeneralRule() {
console.log(this.props.generateRuleInfo, 'this.props.generateRuleInfo') console.log(this.props.generateRuleInfo, 'this.props.generateRuleInfo')
......
import moment from 'moment' import moment from 'moment'
import schema from 'async-validator'; import schema from 'async-validator';
import { methods } from './mixins'
import { import {
descriptor, descriptor,
formatValidator formatValidator
...@@ -16,19 +17,7 @@ import { ...@@ -16,19 +17,7 @@ import {
const THANKS_TYPE = 5 const THANKS_TYPE = 5
var validator = new schema(descriptor); 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",//会员 // type: "beMembership",//会员
// value: 20,//完成任务获得值 // value: 20,//完成任务获得值
// }, // },
...@@ -84,8 +73,16 @@ Component({ ...@@ -84,8 +73,16 @@ Component({
// value: 90, // value: 90,
// itemIds: "111,222,333", // 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: { taskMap: {
attentionStore: { attentionStore: {
value: '', value: '',
...@@ -142,136 +139,34 @@ Component({ ...@@ -142,136 +139,34 @@ Component({
originalStartTime: '', originalStartTime: '',
formState: formatValidator(descriptor) formState: formatValidator(descriptor)
}, },
props: {},
didMount() { didMount() {
const { const { id } = this.$page.$router.params
id id && this.getActivityInfo(id)
} = this.$page.$router.params
if (id) {
this.getActivityInfo(id)
}
}, },
methods: { methods: {
// 获取id活动信息 // 获取activityId活动信息
async getActivityInfo(activityId) { async getActivityInfo(activityId) {
try { try {
const { const { success, data, message } = await getActivityDetail({ activityId})
success,
data,
message
} = await getActivityDetail({
activityId
})
if (!success) { if (!success) {
this.showFailToast(message); this.showFailToast(message);
return; return;
} }
let {
prizeInfoList,
...rest
} = data;
this.setData({ this.setData({
...rest, ...data,
timeRange: [+rest.startTime, +rest.endTime], timeRange: [+data.startTime, +data.endTime],
originalStartTime: +rest.startTime, originalStartTime: +data.startTime,
isStart: +rest.startTime < Date.now(), isStart: +data.startTime < Date.now(),
isEnd: +rest.endTime < Date.now(), isEnd: +data.endTime < Date.now(),
taskList: rest.taskList, taskList: data.taskList,
taskMap: this.formatTaskListToMap(rest.taskList) taskMap: this.formatTaskListToMap(data.taskList)
}) })
} catch (error) { } catch (error) {
console.log(error, 'err') 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) { validateForm(data, target) {
const _this = this; const _this = this;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
...@@ -316,11 +211,10 @@ Component({ ...@@ -316,11 +211,10 @@ Component({
// 提交信息 // 提交信息
async onSubmit() { async onSubmit() {
console.log(this.data) console.log(this.data, 'this.data')
const isValidForm = await this.validateForm(this.data); const isValidForm = await this.validateForm(this.data);
// console.log(this.formatActivityParams(this.data))
if (!isValidForm) return; if (!isValidForm) return;
...@@ -329,19 +223,16 @@ Component({ ...@@ -329,19 +223,16 @@ Component({
const params = this.formatActivityParams(this.data) const params = this.formatActivityParams(this.data)
console.log(params) console.log(params, 'params')
saveActivityInfo(params) const { success, message } = await saveActivityInfo(params)
.then(res => {
if (res.success) { if(success) {
this.backList() this.backList()
} else { } else {
this.showFailToast(res.message) this.showFailToast(res.message)
} }
}).catch(err => {
console.log(err)
})
}, },
showFailToast(text) { showFailToast(text) {
my.showToast({ my.showToast({
...@@ -416,28 +307,6 @@ Component({ ...@@ -416,28 +307,6 @@ Component({
} }
return prizeInfoListCopy 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() { backList() {
this.$page.$router.push("/activity/list"); 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