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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • unittest测试框架原理_学软件测试4个月没找到工作

    unittest测试框架原理_学软件测试4个月没找到工作unittest框架解析unittest是python的单元测试框架,unittest单元测试提供了创建测试用例,测试套件以及批量执行的方案,unittest在安装pyhton以后就直接自带了,直接importunittest就可以使用。作为单元测试的框架,unittest也是可以对程序最小模块的一种敏捷化的测试。在自动化测试中,必须需要知道所使用语言的单元测试框架。利用单元测试框架,创建一个类,该类继承unittest的TestCase,这样可以把每个case看成是一个最小的单元,

    2022年10月15日
    3
  • 2017年科技界十大新闻,你都知道吗?「建议收藏」

    2017年科技界十大新闻,你都知道吗?

    2022年3月12日
    43
  • Bootstrap 之Table样式[通俗易懂]

    Bootstrap 之Table样式[通俗易懂]将标签添加class=‘table’类后的样式Table样式编号姓名年龄001郭靖25002黄蓉23003杨过24我们可以看到,Tabl

    2026年2月1日
    4
  • 迁移学习简介及用途[通俗易懂]

    迁移学习简介及用途 https://mp.weixin.qq.com/s/5_EYEJUycTtpfbxM_uGwHw  ———————本文来自mishidemudong的CSDN博客  深度神经网络,相比于之前的传统机器学习方法,可以看成是一个全新的物种,这背后的原因,最明显的还是深度学习对机器算力的巨大需求,在深度学习入门最少需要知…

    2022年4月10日
    43
  • 键盘记录器,可截获到 QQ 的密码「建议收藏」

    键盘记录器,可截获到 QQ 的密码「建议收藏」虽然QQ 的密码框经过了特殊的处理,但是通过一些特殊手段仍然可以得到输入过程中键盘输入的内容。代码仅供娱乐使用!

    2022年7月20日
    19
  • html+css面试题集锦(一)

    html+css面试题集锦(一)1、对WEB标准以及W3C的理解与认识?web标准简单来说可以分为结构、表现和行为,其中结构主要是有HTML标签组成,或者通俗点来讲,在页面Body中我们写入的标签都是为了页面的结构,表现指css样式表,通过css可使页面的结构标签更具美感,行为是指页面和用户具有一定的交互,同时页面结构或者行为发生变化,主要是js组成。web标准一般是将该三部分独立分开,使其更具有模块化,但一般行为发生变…

    2022年5月6日
    63

发表回复

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

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