温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何正确的使用vant时间控件

发布时间:2020-12-24 16:06:48 阅读:321 作者:Leah 栏目:开发技术
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

如何正确的使用vant时间控件?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

具体内容如下

<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""//活动详情
   showfalse//开始时间弹窗
   show1false//结束时间弹窗
   minHour10,
   maxHour20,
   minDatenew Date(),
   maxDatenew Date(20201131),
   currentDatenew Date(), //开始标准时间
   currentDate1new 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_namethis.name,
      activity_contentthis.message,
      start_timethis.starttime1,
      end_timethis.endtime1
     })
     .then(data => {
      this.$toast("添加活动成功");
      setTimeout(() => {
       this.$router.go(-1);
      }, 1000);
     });
   }
  }
 }
};
</script>

<style lang="less" scoped>
.shoukuan {
 padding-top44px;
 .van-button--large {
  width92%;
  margin-left4%;
  margin-top25%;
 }
}
</style>

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×