当前位置:   article > 正文

element-ui日期控件el-canlender学习笔记_elcalendar如何给日期增加大的表格弹窗

elcalendar如何给日期增加大的表格弹窗

需求:点击日历控件中的某一天,弹出弹出框添加这一天的活动。
任务分析:
点击日历控件的某一天,获取当前日期信息

在这里插入图片描述
代码实现:

<el-calendar v-model="nowDate" >
      <template
        slot="dateCell"
        slot-scope="{date, data}"
        >
        <p :class="data.isSelected ? 'is-selected' : ''" style="width: 100%;height: 100%;" @click="clickDate(date)">
          {{ data.day.split('-').slice(1).join('月')+"日"}}
        </p>
      </template>
    </el-calendar>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
export default {
  name: "Month",
  components: {
  },
  data() {
    return {
      
      //新增活动日期
      addActiveDate:null,
       
      
    };
  },
   
  methods: {
     
    clickDate(date){
      //传入参数是点击的日期
      //点击某个日期后弹出弹出框
      this.reset();
      //弹出框开关
      this.open = true;
      //设置弹出框标题
      this.title = "添加月度活动";
      this.addActiveDate=date;
    }
  }
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

整个界面完整代码:

<template>
  <div class="app-container">
    <el-date-picker
      v-model="monthValue"
      type="month"
      style="width: 120px"
      value-format="yyyy-MM"
      format="yyyy-MM"
      placeholder="选择月"
      @change="changeMonth"
    >
    </el-date-picker>
    <el-calendar v-model="nowDate" >
      <template
        slot="dateCell"
        slot-scope="{date, data}"
        >
        <p :class="data.isSelected ? 'is-selected' : ''" style="width: 100%;height: 100%;" @click="clickDate(date)">
          {{ data.day.split('-').slice(1).join('月')+"日"}} {{ data.isSelected ? '✔️' : ''}}
        </p>
      </template>
    </el-calendar>

    <!-- 对话框(添加 / 修改) -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="活动类型" prop="type">
          <el-select v-model="form.type" placeholder="请选择活动类型">
            <el-option v-for="dict in this.getDictDatas(DICT_TYPE.ACTIVITY_MONTH_TYPE)"
                       :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" />
          </el-select>
        </el-form-item>
        <el-form-item label="活动时间" prop="time">
          <el-date-picker clearable v-model="form.time" type="date" value-format="timestamp" placeholder="选择活动时间" />
        </el-form-item>
        <el-form-item label="活动人数" prop="ptotal">
          <el-select v-model="form.ptotal" placeholder="请选择活动人数">
            <el-option v-for="dict in this.getDictDatas(DICT_TYPE.ACTIVITY_MONTH_PTOTAL)"
                       :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" />
          </el-select>
        </el-form-item>
        <el-form-item label="报名时间" prop="regTime">
          <el-date-picker clearable v-model="form.regTime" type="date" value-format="timestamp" placeholder="选择报名时间" />
        </el-form-item>
        <el-form-item label="活动题目" prop="title">
          <el-input v-model="form.title" placeholder="请输入活动题目" />
        </el-form-item>
        <el-form-item label="活动场景" prop="scene">
          <el-radio-group v-model="form.scene">
            <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.ACTIVITY_MONTH_SCENE)"
                      :key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="活动室名称" prop="roomnum">
          <el-select v-model="form.roomnum" placeholder="请选择活动室名称">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="活动预算" prop="badget">
          <el-input v-model="form.badget" placeholder="请输入活动预算" />
        </el-form-item>
        <el-form-item label="活动主管" prop="manager">
          <el-input v-model="form.manager" placeholder="请输入活动主管" />
        </el-form-item>
        <el-form-item label="协助人员" prop="assistant">
          <el-input v-model="form.assistant" placeholder="请输入协助人员" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>
<style rel="stylesheet/scss" lang="scss">
@import "~@/assets/styles/month.scss";
</style>

<script>
import { createMonth, updateMonth, deleteMonth, getMonth, getMonthPage, exportMonthExcel } from "@/api/activity/month";

export default {
  name: "Month",
  components: {
  },
  data() {
    return {
      monthValue:null,
      nowDate:new Date(),
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      
      
      // 月度活动列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
       
      //新增活动日期
      addActiveDate:null,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        id: null,
        type: null,
        ptotal: null,
        title: null,
        scene: null,
        roomnum: null,
        badget: null,
        manager: null,
        assistant: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        type: [{ required: true, message: "活动类型不能为空", trigger: "change" }],
        time: [{ required: true, message: "活动时间不能为空", trigger: "blur" }],
        ptotal: [{ required: true, message: "活动人数不能为空", trigger: "change" }],
        regTime: [{ required: true, message: "报名时间不能为空", trigger: "blur" }],
        title: [{ required: true, message: "活动题目不能为空", trigger: "blur" }],
        roomnum: [{ required: true, message: "活动室名称不能为空", trigger: "change" }],
        badget: [{ required: true, message: "活动预算不能为空", trigger: "blur" }],
        manager: [{ required: true, message: "活动主管不能为空", trigger: "blur" }],
      }
    };
  },
  created() {
    this.monthValue=this.nowDate;
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 处理查询参数
      let params = {...this.queryParams};
      this.addBeginAndEndTime(params, this.dateRangeTime, 'time');
      this.addBeginAndEndTime(params, this.dateRangeRegTime, 'regTime');
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
      // 执行查询
      getMonthPage(params).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (!valid) {
          return;
        }
        // 添加活动提交
        createMonth(this.form).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
      });
    },
     
    
    /** 上方月份选择后下方日历的联动 **/
    changeMonth() {
      //上方日期选择器选择了月份后,下方日历显示为选中月份
      this.nowDate = new Date(this.monthValue);
      console.log("this.nowDate",this.nowDate);
    },
    clickDate(date){
      //点击某个日期后弹出弹出框
      this.reset();
      this.open = true;
      this.title = "添加月度活动";
      this.addActiveDate=date;
    }
  }
};
</script>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/91308?site
推荐阅读