create.vue 5.69 KB
<template>
    <div>
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>签到活动创建</h2>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                        <Form>
                            <FormItem label="活动名称">
                              <Input v-model="title" placeholder="活动名称" style="width: 400px"></Input>
                            </FormItem>
                            <FormItem label="活动时间">
                                <DatePicker type="daterange" placeholder="开始时间-结束时间"
                                            style="width: 400px" @on-change="dateTimeChange"></DatePicker>
                            </FormItem>
                            <FormItem label="每日领取大转盘ID">
                              <Input v-model="normalWheelId" placeholder="平时每日领取对应的大转盘id" style="width: 400px;"></Input>
                            </FormItem>
                            <FormItem label="第一次累计天数">
                              <Input v-model="days1.count" placeholder="第一次累计天数" style="width: 100px;"></Input>
                              转盘ID
                              <Input v-model="days1.wheelId" placeholder="对应的大转盘id" style="width: 200px;"></Input>
                            </FormItem>
                            <FormItem label="第二次累计天数">
                              <Input v-model="days2.count" placeholder="第二次累计天数" style="width: 100px;"></Input>
                              转盘ID
                              <Input v-model="days2.wheelId" placeholder="对应的大转盘id" style="width: 200px;"></Input>
                            </FormItem>
                            <FormItem label="第三次累计天数">
                              <Input v-model="days3.count" placeholder="第二次累计天数" style="width: 100px;"></Input>
                              转盘ID
                              <Input v-model="days3.wheelId" placeholder="对应的大转盘id" style="width: 200px;"></Input>
                            </FormItem>
                            <FormItem>
                                <Button type="primary" @click="save">保存</Button>
                                <Button style="margin-left: 8px" @click="cancel">取消</Button>
                            </FormItem>
                        </Form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
    import moment from 'moment';
    export default {
        data() {
            return {
                title: '',
                startTime: '',
                endTime: '',
                normalWheelId: '',
                days1: {
                  count: 0,
                  wheelId: ''
                },
                days2: {
                  count: 0,
                  wheelId: ''
                },
                days3: {
                  count: 0,
                  wheelId: ''
                }
            };
        },
        mounted() {

        },
        methods: {
            dateTimeChange(range) {
              this.startTime = range[0];
              this.endTime = range[1];
            },
            save() {
                let prizeDayArr = [];


                if (parseInt(this.days1.count, 10) && this.days1.wheelId) { // 第一次累计
                  prizeDayArr.push(this.days1);
                  if (parseInt(this.days2.count, 10) && this.days2.wheelId) { // 第二次累计
                    if (parseInt(this.days2.count, 10) <= parseInt(this.days1.count, 10)) {
                      return alert('第二次的天数必须大于第一次的天数');
                    } else {
                      prizeDayArr.push(this.days2);
                      if (parseInt(this.days3.count, 10) && this.days3.wheelId) { // 第三次累计
                        if (parseInt(this.days3.count, 10) <= parseInt(this.days2.count, 10)) {
                          return alert('第三次的天数必须大于第二次的天数');
                        } else {
                          prizeDayArr.push(this.days3);
                        }
                      }
                    }
                  }
                }

                if (!this.title) {
                  return alert('清填写标题');
                }

                if (!this.startTime || !this.endTime) {
                  return alert('请选择开始结束时间');
                }

                if (!this.normalWheelId) {
                  return alert('请填写每日领取的大转盘ID');
                }


                $.ajax({
                    method: 'post',
                    url: '/admin/dailyCheckIn/api/create',
                    data: {
                        title: this.title,
                        startTime: moment(this.startTime).format('X'),
                        endTime: moment(this.endTime).format('X'),
                        normalWheelId: this.normalWheelId,
                        prizeDayArr: JSON.stringify(prizeDayArr)
                    }
                }).then(res => {
                  if (res.code === 200) {
                    this.$router.push({name: 'list'});
                  } else {
                    alert('创建失败');
                  }
                });

            },
            cancel() {
              this.$router.push({name: 'list'});
            }
        },
        components: {
        }
    };
</script>
<style>

</style>