Authored by huangyi

Merge branch 'feature/wheel-surf' of http://git.yoho.cn/fe/yoho-activity-platfor…

…m into feature/wheel-surf
@@ -49,6 +49,10 @@ module.exports = function(Sequelize, DataTypes) { @@ -49,6 +49,10 @@ module.exports = function(Sequelize, DataTypes) {
49 type: DataTypes.INTEGER(8), 49 type: DataTypes.INTEGER(8),
50 allowNull: true 50 allowNull: true
51 }, 51 },
  52 + times_type: {
  53 + type: DataTypes.INTEGER(8),
  54 + allowNull: true
  55 + },
52 act_total_times: { 56 act_total_times: {
53 type: DataTypes.INTEGER(8), 57 type: DataTypes.INTEGER(8),
54 allowNull: true 58 allowNull: true
@@ -3,30 +3,30 @@ @@ -3,30 +3,30 @@
3 <div class="add-area-split"> 3 <div class="add-area-split">
4 <Split v-model="split"> 4 <Split v-model="split">
5 <div slot="left" class="split-pane"> 5 <div slot="left" class="split-pane">
6 - <Form ref="formValidate" :label-width="120">  
7 - <FormItem label="奖品位置" prop="prize_idx" required> 6 + <Form ref="prizeForm" :model="prize" :rules="prizeRules" :label-width="120">
  7 + <FormItem label="奖品位置" prop="prize_idx">
8 <Input v-model="prize.prize_idx" placeholder="奖品位置序号(竖直方向顺时针从1开始)"></Input> 8 <Input v-model="prize.prize_idx" placeholder="奖品位置序号(竖直方向顺时针从1开始)"></Input>
9 </FormItem> 9 </FormItem>
10 - <FormItem label="奖品名称" prop="name" required> 10 + <FormItem label="奖品名称" prop="name">
11 <Input v-model="prize.name" placeholder="奖品名称"></Input> 11 <Input v-model="prize.name" placeholder="奖品名称"></Input>
12 </FormItem> 12 </FormItem>
13 - <FormItem label="奖品类型" prop="type" required> 13 + <FormItem label="奖品类型" prop="type">
14 <Select v-model="prize.type"> 14 <Select v-model="prize.type">
15 <Option :value="1">谢谢惠顾</Option> 15 <Option :value="1">谢谢惠顾</Option>
16 <Option :value="2">红包</Option> 16 <Option :value="2">红包</Option>
17 <Option :value="3">优惠券</Option> 17 <Option :value="3">优惠券</Option>
18 </Select> 18 </Select>
19 </FormItem> 19 </FormItem>
20 - <FormItem label="奖品值" prop="value" required> 20 + <FormItem label="奖品值" prop="value">
21 <Input v-model="prize.value" placeholder="口令或面值等"></Input> 21 <Input v-model="prize.value" placeholder="口令或面值等"></Input>
22 </FormItem> 22 </FormItem>
23 - <FormItem label="奖品总数" prop="total" required> 23 + <FormItem label="奖品总数" prop="total">
24 <Input v-model="prize.total" placeholder="奖品总数"></Input> 24 <Input v-model="prize.total" placeholder="奖品总数"></Input>
25 </FormItem> 25 </FormItem>
26 - <FormItem label="中奖概率" prop="chance" required> 26 + <FormItem label="中奖概率" prop="chance">
27 <Input v-model="prize.chance" placeholder="中奖概率"></Input> 27 <Input v-model="prize.chance" placeholder="中奖概率"></Input>
28 </FormItem> 28 </FormItem>
29 - <FormItem label="中奖背景图" prop="prize_bg" required> 29 + <FormItem label="中奖背景图" prop="prize_bg">
30 <img class="win-prize-bg" v-show="prize.prize_bg" :src="prize.prize_bg"> 30 <img class="win-prize-bg" v-show="prize.prize_bg" :src="prize.prize_bg">
31 <Button v-show="!prize.prize_bg"> 31 <Button v-show="!prize.prize_bg">
32 <span ref="winPrizeBg">添加中奖背景图</span> 32 <span ref="winPrizeBg">添加中奖背景图</span>
@@ -127,11 +127,34 @@ @@ -127,11 +127,34 @@
127 prize_bg: '', 127 prize_bg: '',
128 prize_idx: '' 128 prize_idx: ''
129 }, 129 },
  130 + prizeRules: {
  131 + prize_idx: [
  132 + { required: true, message: '奖品位置序号不能为空', trigger: 'blur' }
  133 + ],
  134 + name: [
  135 + { required: true, message: '奖品名称不能为空', trigger: 'blur' }
  136 + ],
  137 + type: [
  138 + { required: true}
  139 + ],
  140 + value: [
  141 + { required: true, message: '奖品值不能为空', trigger: 'blur' }
  142 + ],
  143 + total: [
  144 + { required: true, message: '奖品总数不能为空', trigger: 'blur' }
  145 + ],
  146 + chance: [
  147 + { required: true, message: '中奖概率不能为空', trigger: 'blur' }
  148 + ]
  149 + },
130 prizes: [] 150 prizes: []
131 } 151 }
132 }, 152 },
133 methods: { 153 methods: {
134 addPrize() { 154 addPrize() {
  155 + const form = 'prizeForm';
  156 +
  157 + this.validateForm(form).then(() => {
135 $.ajax({ 158 $.ajax({
136 method: 'post', 159 method: 'post',
137 url: '/admin/wheelSurf/api/prize/create', 160 url: '/admin/wheelSurf/api/prize/create',
@@ -140,11 +163,13 @@ @@ -140,11 +163,13 @@
140 }).then(res => { 163 }).then(res => {
141 if (res.code === 200) { 164 if (res.code === 200) {
142 this.$Message.success('奖品新增成功'); 165 this.$Message.success('奖品新增成功');
  166 + this.formReset(form);
143 this.prizeList(); 167 this.prizeList();
144 } else { 168 } else {
145 this.$Message.error(res.msg); 169 this.$Message.error(res.msg);
146 } 170 }
147 }); 171 });
  172 + }).catch(() => {});
148 }, 173 },
149 deletePrize(id) { 174 deletePrize(id) {
150 this.$Modal.warning({ 175 this.$Modal.warning({
@@ -177,8 +202,22 @@ @@ -177,8 +202,22 @@
177 window.qn_dynamic_el_upload(this.$refs.winPrizeBg, url => { 202 window.qn_dynamic_el_upload(this.$refs.winPrizeBg, url => {
178 this.prize.prize_bg = url; 203 this.prize.prize_bg = url;
179 }); 204 });
  205 + },
  206 + validateForm (name) {
  207 + return new Promise((resolve, reject) => {
  208 + console.log(this)
  209 + this.$refs[name].validate(valid => {
  210 + if (valid) {
  211 + resolve();
  212 + } else {
  213 + reject();
  214 + }
  215 + })
  216 + });
  217 + },
  218 + formReset (name) {
  219 + this.$refs[name].resetFields();
180 } 220 }
181 -  
182 }, 221 },
183 mounted() { 222 mounted() {
184 this.actId = this.$route.query.actId; 223 this.actId = this.$route.query.actId;
@@ -3,36 +3,43 @@ @@ -3,36 +3,43 @@
3 <TabPane label="基础配置"> 3 <TabPane label="基础配置">
4 <div class="base-conf"> 4 <div class="base-conf">
5 <div class="base-left"> 5 <div class="base-left">
6 - <Form :label-width="120">  
7 - <FormItem label="活动规则" required> 6 + <Form ref="confForm" :models="conf" :rules="confRules" :label-width="120">
  7 + <FormItem label="活动规则" prop="rule">
8 <Input type="textarea" v-model="conf.rule" 8 <Input type="textarea" v-model="conf.rule"
9 placeholder="请输入活动规则" :maxlength="2000"></Input> 9 placeholder="请输入活动规则" :maxlength="2000"></Input>
10 </FormItem> 10 </FormItem>
11 - <FormItem label="分享链接" required> 11 + <FormItem label="分享链接" prop="rule">
12 <Input type="text" v-model="conf.share_url" 12 <Input type="text" v-model="conf.share_url"
13 placeholder="活动分享链接"></Input> 13 placeholder="活动分享链接"></Input>
14 </FormItem> 14 </FormItem>
15 - <FormItem label="提示文案(上)" required> 15 + <FormItem label="提示文案(上)" prop="btm_tip_one">
16 <Input type="text" v-model="conf.btm_tip_one" 16 <Input type="text" v-model="conf.btm_tip_one"
17 placeholder="提示文案(上)"></Input> 17 placeholder="提示文案(上)"></Input>
18 </FormItem> 18 </FormItem>
19 - <FormItem label="提示文案(下)" required> 19 + <FormItem label="提示文案(下)" prop="btm_tip_two">
20 <Input type="text" v-model="conf.btm_tip_two" 20 <Input type="text" v-model="conf.btm_tip_two"
21 placeholder="提示文案(下)"></Input> 21 placeholder="提示文案(下)"></Input>
22 </FormItem> 22 </FormItem>
23 - <FormItem label="跳转链接(左)" required> 23 + <FormItem label="跳转链接(左)" prop="jump_url_left">
24 <Input type="text" v-model="conf.jump_url_left" 24 <Input type="text" v-model="conf.jump_url_left"
25 placeholder="活动底部链接(左)"></Input> 25 placeholder="活动底部链接(左)"></Input>
26 </FormItem> 26 </FormItem>
27 - <FormItem label="跳转链接(右)" required> 27 + <FormItem label="跳转链接(右)" prop="jump_url_right">
28 <Input type="text" v-model="conf.jump_url_right" 28 <Input type="text" v-model="conf.jump_url_right"
29 placeholder="活动底部链接(右)"></Input> 29 placeholder="活动底部链接(右)"></Input>
30 </FormItem> 30 </FormItem>
31 - <FormItem label="活动最大参与次数" required> 31 + <FormItem label="活动次数限制" prop="times_type">
  32 + <Select v-model="conf.times_type">
  33 + <Option :value="0">只限制每天最大参与次数</Option>
  34 + <Option :value="1">只限制每人参与活动最大次数</Option>
  35 + <Option :value="2">同时限制以上两种</Option>
  36 + </Select>
  37 + </FormItem>
  38 + <FormItem label="活动最大参与次数" prop="act_total_times">
32 <Input type="text" v-model="conf.act_total_times" 39 <Input type="text" v-model="conf.act_total_times"
33 placeholder="活动最大参与次数"></Input> 40 placeholder="活动最大参与次数"></Input>
34 </FormItem> 41 </FormItem>
35 - <FormItem label="每天最大抽奖次数" required> 42 + <FormItem label="每天最大抽奖次数" prop="day_limit_times">
36 <Input type="text" v-model="conf.day_limit_times" 43 <Input type="text" v-model="conf.day_limit_times"
37 placeholder="每天最大抽奖次数"></Input> 44 placeholder="每天最大抽奖次数"></Input>
38 </FormItem> 45 </FormItem>
@@ -40,62 +47,62 @@ @@ -40,62 +47,62 @@
40 </div> 47 </div>
41 <div class="base-middle"> 48 <div class="base-middle">
42 <Form :label-width="120"> 49 <Form :label-width="120">
43 - <FormItem label="主背景图" prop="prize_bg" required> 50 + <FormItem label="主背景图" prop="main_bg">
44 <img class="preview-img" v-show="conf.main_bg" :src="conf.main_bg"> 51 <img class="preview-img" v-show="conf.main_bg" :src="conf.main_bg">
45 <Button v-show="!conf.main_bg"> 52 <Button v-show="!conf.main_bg">
46 - <span ref="mainBg" img-key="main_bg">添加</span> 53 + <span ref="upload_img_mainBg" img-key="main_bg">添加</span>
47 </Button> 54 </Button>
48 </FormItem> 55 </FormItem>
49 - <FormItem label="转盘背景图" prop="prize_bg" required> 56 + <FormItem label="转盘背景图" prop="wheel_bg">
50 <img class="preview-img" v-show="conf.wheel_bg" :src="conf.wheel_bg"> 57 <img class="preview-img" v-show="conf.wheel_bg" :src="conf.wheel_bg">
51 <Button v-show="!conf.wheel_bg"> 58 <Button v-show="!conf.wheel_bg">
52 - <span ref="wheelBg" img-key="wheel_bg">添加</span> 59 + <span ref="upload_img_wheelBg" img-key="wheel_bg">添加</span>
53 </Button> 60 </Button>
54 </FormItem> 61 </FormItem>
55 - <FormItem label="活动规则按钮" prop="prize_bg" required> 62 + <FormItem label="活动规则按钮" prop="rule_btn_bg">
56 <img class="preview-img" v-show="conf.rule_btn_bg" :src="conf.rule_btn_bg"> 63 <img class="preview-img" v-show="conf.rule_btn_bg" :src="conf.rule_btn_bg">
57 <Button v-show="!conf.rule_btn_bg"> 64 <Button v-show="!conf.rule_btn_bg">
58 - <span ref="ruleBg" img-key="rule_btn_bg">添加</span> 65 + <span ref="upload_img_ruleBg" img-key="rule_btn_bg">添加</span>
59 </Button> 66 </Button>
60 </FormItem> 67 </FormItem>
61 - <FormItem label="分享按钮" prop="prize_bg" required> 68 + <FormItem label="分享按钮" prop="share_btn_bg">
62 <img class="preview-img" v-show="conf.share_btn_bg" :src="conf.share_btn_bg"> 69 <img class="preview-img" v-show="conf.share_btn_bg" :src="conf.share_btn_bg">
63 <Button v-show="!conf.share_btn_bg"> 70 <Button v-show="!conf.share_btn_bg">
64 - <span ref="shareBg" img-key="share_btn_bg">添加</span> 71 + <span ref="upload_img_shareBg" img-key="share_btn_bg">添加</span>
65 </Button> 72 </Button>
66 </FormItem> 73 </FormItem>
67 - <FormItem label="抽奖按钮" prop="prize_bg" required> 74 + <FormItem label="抽奖按钮" prop="prize_btn_bg">
68 <img class="preview-img" v-show="conf.prize_btn_bg" :src="conf.prize_btn_bg"> 75 <img class="preview-img" v-show="conf.prize_btn_bg" :src="conf.prize_btn_bg">
69 <Button v-show="!conf.prize_btn_bg"> 76 <Button v-show="!conf.prize_btn_bg">
70 - <span ref="tryBg" img-key="prize_btn_bg">添加</span> 77 + <span ref="upload_img_tryBg" img-key="prize_btn_bg">添加</span>
71 </Button> 78 </Button>
72 </FormItem> 79 </FormItem>
73 </Form> 80 </Form>
74 </div> 81 </div>
75 <div class="base-right"> 82 <div class="base-right">
76 <Form :label-width="120"> 83 <Form :label-width="120">
77 - <FormItem label="次数上限背景图" prop="prize_bg" required> 84 + <FormItem label="次数上限背景图" prop="day_over_limit_bg">
78 <img class="preview-img" v-show="conf.day_over_limit_bg" :src="conf.day_over_limit_bg"> 85 <img class="preview-img" v-show="conf.day_over_limit_bg" :src="conf.day_over_limit_bg">
79 <Button v-show="!conf.day_over_limit_bg"> 86 <Button v-show="!conf.day_over_limit_bg">
80 - <span ref="overBg" img-key="day_over_limit_bg">添加</span> 87 + <span ref="upload_img_overBg" img-key="day_over_limit_bg">添加</span>
81 </Button> 88 </Button>
82 </FormItem> 89 </FormItem>
83 - <FormItem label="我的奖品" prop="prize_bg" required> 90 + <FormItem label="我的奖品" prop="my_prize_btn_bg">
84 <img class="preview-img" v-show="conf.my_prize_btn_bg" :src="conf.my_prize_btn_bg"> 91 <img class="preview-img" v-show="conf.my_prize_btn_bg" :src="conf.my_prize_btn_bg">
85 <Button v-show="!conf.my_prize_btn_bg"> 92 <Button v-show="!conf.my_prize_btn_bg">
86 - <span ref="myPrizeBg" img-key="my_prize_btn_bg">添加</span> 93 + <span ref="upload_img_myPrizeBg" img-key="my_prize_btn_bg">添加</span>
87 </Button> 94 </Button>
88 </FormItem> 95 </FormItem>
89 - <FormItem label="提示中奖背景图" prop="prize_bg" required> 96 + <FormItem label="提示中奖背景图" prop="win_prize_bg">
90 <img class="preview-img" v-show="conf.win_prize_bg" :src="conf.win_prize_bg"> 97 <img class="preview-img" v-show="conf.win_prize_bg" :src="conf.win_prize_bg">
91 <Button v-show="!conf.win_prize_bg"> 98 <Button v-show="!conf.win_prize_bg">
92 - <span ref="winPrizeBg" img-key="win_prize_bg">添加</span> 99 + <span ref="upload_img_winPrizeBg" img-key="win_prize_bg">添加</span>
93 </Button> 100 </Button>
94 </FormItem> 101 </FormItem>
95 - <FormItem label="再来一次按钮" prop="prize_bg" required> 102 + <FormItem label="再来一次按钮" prop="try_again_bg">
96 <img class="preview-img" v-show="conf.try_again_bg" :src="conf.try_again_bg"> 103 <img class="preview-img" v-show="conf.try_again_bg" :src="conf.try_again_bg">
97 <Button v-show="!conf.try_again_bg"> 104 <Button v-show="!conf.try_again_bg">
98 - <span ref="tryAgainBg" img-key="try_again_bg">添加</span> 105 + <span ref="upload_img_tryAgainBg" img-key="try_again_bg">添加</span>
99 </Button> 106 </Button>
100 </FormItem> 107 </FormItem>
101 </Form> 108 </Form>
@@ -135,9 +142,30 @@ @@ -135,9 +142,30 @@
135 prize_btn_bg: '', 142 prize_btn_bg: '',
136 rule_btn_bg: '', 143 rule_btn_bg: '',
137 share_btn_bg: '', 144 share_btn_bg: '',
  145 + times_type: 0,
138 day_over_limit_bg: '', 146 day_over_limit_bg: '',
139 my_prize_btn_bg: '', 147 my_prize_btn_bg: '',
140 win_prize_bg: '' 148 win_prize_bg: ''
  149 + },
  150 + confRules: {
  151 + rule: [
  152 + { required: true, message: '活动规则不能为空', trigger: 'blur' }
  153 + ],
  154 + name: [
  155 + { required: true, message: '奖品名称不能为空', trigger: 'blur' }
  156 + ],
  157 + type: [
  158 + { required: true}
  159 + ],
  160 + value: [
  161 + { required: true, message: '奖品值不能为空', trigger: 'blur' }
  162 + ],
  163 + total: [
  164 + { required: true, message: '奖品总数不能为空', trigger: 'blur' }
  165 + ],
  166 + chance: [
  167 + { required: true, message: '中奖概率不能为空', trigger: 'blur' }
  168 + ]
141 } 169 }
142 } 170 }
143 }, 171 },
@@ -150,7 +178,7 @@ @@ -150,7 +178,7 @@
150 data: JSON.stringify(Object.assign(this.conf, {act_id: this.actId})) 178 data: JSON.stringify(Object.assign(this.conf, {act_id: this.actId}))
151 }).then(res => { 179 }).then(res => {
152 if (res.code === 200) { 180 if (res.code === 200) {
153 - this.$Message.success('奖品新增成功'); 181 + this.$Message.success('基础配置更新成功');
154 this.prizeList(); 182 this.prizeList();
155 } else { 183 } else {
156 this.$Message.error(res.msg); 184 this.$Message.error(res.msg);
@@ -170,7 +198,9 @@ @@ -170,7 +198,9 @@
170 }); 198 });
171 }, 199 },
172 bindUpload() { 200 bindUpload() {
173 - Object.keys(this.$refs).map(key => { 201 + Object.keys(this.$refs)
  202 + .filter(key => /^upload_img_/ig.test(key))
  203 + .map(key => {
174 let $el = this.$refs[key]; 204 let $el = this.$refs[key];
175 let imgKey = $el.getAttribute('img-key'); 205 let imgKey = $el.getAttribute('img-key');
176 206