vant时间控件的使用「建议收藏」

vant时间控件的使用「建议收藏」<template><divclass=”shoukuan”><!–头部公共搜索框–><tabbartitle=”添加团队活动”></tabbar><divclass=”con”><van-cell-group><van-fi…

大家好,又见面了,我是你们的朋友全栈君。

在这里插入图片描述

<template>
  <div class="shoukuan">
    <!-- 头部公共搜索框 -->
    <tabbar title="添加团队活动"></tabbar>
    <div class="con">
      <van-cell-group>
        <van-field v-model="name" clearable label="活动名称" placeholder="请选择活动名称" />
        <van-field v-model="starttime" clearable label="开始时间" placeholder="请输入开始时间" @focus="start" />
        <van-field v-model="endtime" clearable label="结束时间" placeholder="请输入结束时间" @focus="end" />
      </van-cell-group>
      <van-cell-group>
        <van-field
          v-model="message"
          rows="2"
          autosize
          label="活动详情"
          type="textarea"
          maxlength="50"
          placeholder="请输入"
          show-word-limit
        />
      </van-cell-group>
    </div>
    <van-button type="primary" size="large" @click="add">确认添加</van-button>
    <!-- 开始时间控件 -->
    <van-popup v-model="show" position="bottom">
      <van-datetime-picker
        v-model="currentDate"
        type="datetime"
        :min-date="minDate"
        :max-date="maxDate"
        @confirm="confirm"
        @cancel="cancel"
        :formatter="formatter"
      />
    </van-popup>
    <!-- 结束时间控件 -->
    <van-popup v-model="show1" position="bottom">
      <van-datetime-picker
        v-model="currentDate1"
        type="datetime"
        :min-date="minDate"
        :max-date="maxDate"
        @confirm="confirm1"
        @cancel="cancel1"
        :formatter="formatter"
      />
    </van-popup>
  </div>
</template>
<script>
import tabbar from "../../components/navbar";
export default {
  data() {
    return {
      name: "", //活动名称
      message: "", //活动详情
      show: false, //开始时间弹窗
      show1: false, //结束时间弹窗
      minHour: 10,
      maxHour: 20,
      minDate: new Date(),
      maxDate: new Date(2020, 11, 31),
      currentDate: new Date(), //开始标准时间
      currentDate1: new Date(), //结束标准时间
      starttime: "", //开始时间
      starttime1: "", //开始时间时间戳
      endtime: "", //结束时间
      endtime1: "" //结束时间时间戳
    };
  },
  components: {
    tabbar
  },
  mounted() {},
  methods: {
    // 选择开始时间
    start() {
      this.show = true;
    },
    // 选择结束时间
    end() {
      this.show1 = true;
    },
    // 点击确定
    confirm() {
      this.show = false;
      this.starttime =
        this.currentDate.getFullYear() +
        "年" +
        (Number(this.currentDate.getMonth()) + 1) +
        "月" +
        this.currentDate.getDate() +
        "日 " +
        this.currentDate.getHours() +
        ":" +
        this.currentDate.getMinutes();
      this.starttime1 = new Date(this.currentDate).getTime() / 1000;
    },
    // 点击取消
    cancel() {
      this.show = false;
    },
    confirm1() {
      this.show1 = false;
      this.endtime =
        this.currentDate1.getFullYear() +
        "年" +
        (Number(this.currentDate1.getMonth()) + 1) +
        "月" +
        this.currentDate1.getDate() +
        "日 " +
        this.currentDate1.getHours() +
        ":" +
        this.currentDate1.getMinutes();
      this.endtime1 = new Date(this.currentDate1).getTime() / 1000;
    },
    cancel1() {
      this.show1 = false;
    },
    // 处理控件显示的时间格式
    formatter(type, value) {
      // 格式化选择器日期
      if (type === "year") {
        return `${value}年`;
      } else if (type === "month") {
        return `${value}月`;
      } else if (type === "day") {
        return `${value}日`;
      } else if (type === "hour") {
        return `${value}时`;
      } else if (type === "minute") {
        return `${value}分`;
      }
      return value;
    },
    // 点击添加按钮
    add() {
      if (
        !this.name.trim() ||
        !this.starttime.trim() ||
        !this.starttime.trim() ||
        !this.message.trim()
      ) {
        this.$toast("请输入完整的活动信息");
      } else {
        this.axios
          .post("/api/agent_team/addTeamActivity", {
            activity_name: this.name,
            activity_content: this.message,
            start_time: this.starttime1,
            end_time: this.endtime1
          })
          .then(data => {
            this.$toast("添加活动成功");
            setTimeout(() => {
              this.$router.go(-1);
            }, 1000);
          });
      }
    }
  }
};
</script>

<style lang="less" scoped>
.shoukuan {
  padding-top: 44px;
  .van-button--large {
    width: 92%;
    margin-left: 4%;
    margin-top: 25%;
  }
}
</style>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/142577.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 微信二维码登录原理是什么_请使用微信扫描二维码登录

    微信二维码登录原理是什么_请使用微信扫描二维码登录网页登陆是微信4.2以后版本提供的一种全新的登陆方式。用户只需要用手机扫一扫微信网页中的二维码,就能马上实现微信网页登陆。这种登陆方式虽然炫酷,但是多少有些违背直觉:网页端是怎么知道是哪个微信账号

    2022年8月4日
    3
  • IIS7.5配置防盗链

    IIS7.5配置防盗链首先,要下载、安装一个IIS重写模块。是到微软站点下载的,可以放心了。(靠,之前以为IIS7是内置了的,想不到还是要另外安装东西)64位:http://www.microsoft.com/downloads/zh-cn/details.aspx?familyid=1b8c7bd8-8824-4408-b8fc-49dc7f951a0032位:http://www.microsoft.com/…

    2022年7月23日
    8
  • 2022考研数学一考试大纲最新_数学一考研大纲2021官方

    2022考研数学一考试大纲最新_数学一考研大纲2021官方2022年考研数学1考试大纲(2022年)

    2022年8月11日
    7
  • 数据结构七大排序算法图解[通俗易懂]

    数据结构七大排序算法图解[通俗易懂]万字手撕七大排序(代码+动图演示)…

    2022年8月30日
    0
  • SpringApplication初始化阶段[通俗易懂]

    SpringApplication初始化阶段[通俗易懂]在SpringFramework时代,Spring应用上下文通常由容器启动,如ContextLoaderListener或WebApplicationInitializer的实现类由Servlet容器装载并驱动。到了SpringBoot时代,Spring应用上下文的启动则通过调用SpringApplication.run(Object,String…)或SpringApplicationBuilder.run(String…)方法并配合@SpringBootApplication或@EnableAu

    2022年9月9日
    0
  • VC编程入门浅谈「建议收藏」

    VC编程入门浅谈「建议收藏」
    学VC并不是传说的那么难,可不下些功夫是学不成的。学编程急不得,没有编程的基础知识上来就学VC肯定碰一头灰,说VC难就难在这点上了。如果硬上,意志坚强的话还能挺过来,但最后还得回头来补习基础知识。意志不坚强的话,很有可能就此放弃,并留下一个VC难得不得了的印象。

      其实,只要踏踏实实一步一步来,学VC很简单。对于没有编程基础的人首先要学习编程的基础知识,如变量,语句,基本的算法等,然后写一些小的程序,实现些常用算法对自己的思维是很好的锻炼,对以后的学习大有好处。起码要能排

    2022年6月17日
    28

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号