【微信小程序】日历插件,适用于酒店订房类小程序
本插件在原作者(传送门:http://blog.csdn.net/lengyue1084/article/details/71248778)基础上升级。
增加了点击选择具体日期和数据传输功能。
效果图:
1、WXML
<view class="page">
<view class="box">
<view class="box-flex">
<view class="flex-item">
<view class="item-content" bindtap="doDay" data-key='left'>
<view class="glyphicon glyphicon-triangle-left"></view>
</view>
</view>
<view class="flex-item item-content-current-day">
<view class="item-content">{{currentDate}}</view>
</view>
<view class="flex-item">
<view class="item-content" bindtap="doDay" data-key="right">
<view class="glyphicon glyphicon-triangle-right"></view>
</view>
</view>
</view>
<view class="box-flex">
<view class="flex-item">
<view class="item-content">一</view>
</view>
<view class="flex-item">
<view class="item-content">二</view>
</view>
<view class="flex-item">
<view class="item-content">三</view>
</view>
<view class="flex-item">
<view class="item-content">四</view>
</view>
<view class="flex-item">
<view class="item-content">五</view>
</view>
<view class="flex-item">
<view class="item-content">六</view>
</view>
<view class="flex-item">
<view class="item-content">日</view>
</view>
</view>
<view class="box-flex">
<view class="flex-item" wx:for="{{currentDayList}}" wx:for-index='key' wx:for-item="vo" wx:key="{{key}}">
<view data-day="{{vo}}" bindtap='selectDay' class="item-content {{!selectCSS}}" wx:if="{{currentDay != vo}}">{{vo}}</view>
<view data-day="{{vo}}" bindtap='selectDay' class="item-content {{selectCSS}}" wx:else>{{vo}}</view>
</view>
</view>
</view>
</view>
2、JS
var app = getApp();
Page({
data: {
currentDate: "2017年05月03日",
dayList: '',
currentDayList: '',
currentObj: '',
currentDay: '', //日期初始化选中样式
selectCSS: 'bk-color-day',
},
onLoad: function (options) {
var that = this;
console.log(options);
var currentObj = this.getCurrentDayString()
this.setData({
currentDate: currentObj.getFullYear() + '/' + (currentObj.getMonth() + 1) + '/' + currentObj.getDate(),
currentDay: currentObj.getDate(),
currentObj: currentObj,
/* 获取当前的年、月 */
currentYear: currentObj.getFullYear(),
currentMonth: (currentObj.getMonth() + 1),
})
this.setSchedule(currentObj);
},
doDay: function (e) {
var that = this;
console.log(e); var currentObj = that.data.currentObj
var Y = currentObj.getFullYear();
var m = currentObj.getMonth() + 1;
var d = currentObj.getDate();
var str = ''
if (e.currentTarget.dataset.key == 'left') {
m -= 1
if (m <= 0) {
str = (Y - 1) + '/' + 12 + '/' + d
} else {
str = Y + '/' + m + '/' + d
}
} else {
m += 1
if (m <= 12) {
str = Y + '/' + m + '/' + d
} else {
str = (Y + 1) + '/' + 1 + '/' + d
}
}
currentObj = new Date(str)
this.setData({
currentDate: currentObj.getFullYear() + '/' + (currentObj.getMonth() + 1) + '/' + currentObj.getDate(),
currentObj: currentObj,
/* 获取当前的年、月 */
currentYear: currentObj.getFullYear(),
currentMonth: (currentObj.getMonth() + 1),
})
console.log("选择当前年:" + that.data.currentYear);
console.log("选择当前月:" + that.data.currentMonth);
this.setSchedule(currentObj);
},
getCurrentDayString: function () {
var objDate = this.data.currentObj
if (objDate != '') {
return objDate
} else {
var c_obj = new Date()
var a = c_obj.getFullYear() + '/' + (c_obj.getMonth() + 1) + '/' + c_obj.getDate()
return new Date(a)
}
},
setSchedule: function (currentObj) {
console.log(currentObj);
var that = this
var m = currentObj.getMonth() + 1
var Y = currentObj.getFullYear()
var d = currentObj.getDate();
var dayString = Y + '/' + m + '/' + currentObj.getDate()
var currentDayNum = new Date(Y, m, 0).getDate()
var currentDayWeek = currentObj.getUTCDay() + 1
var result = currentDayWeek - (d % 7 - 1);
var firstKey = result <= 0 ? 7 + result : result;
var currentDayList = [];
var f = 0
for (var i = 0; i < 42; i++) {
let data =[]
if (i < firstKey - 1) {
currentDayList[i] = ''
} else {
if (f < currentDayNum) {
currentDayList[i] = f+1;
f = currentDayList[i]
} else if (f >= currentDayNum) {
currentDayList[i] = ''
}
}
}
that.setData({
currentDayList: currentDayList
})
}, //选择具体日期方法--xzz1211
selectDay:function(e){
var that = this;
console.log(e);
that.setData({
currentDay: e.target.dataset.day,//选择的数据,非真实当前日期
currentDa: e.target.dataset.day, //选择某月具体的一天
currentDate: that.data.currentYear + '/' + that.data.currentMonth + '/' + e.target.dataset.day,//真实选择数据
})
console.log("当前选择日期:" + that.data.currentDate);
}
})
3、CSS
/* pages/workspace/workspace/schedule/schedule.wxss */
@import '../../dist/css/icon.wxss';
page {
background-color: #2a8cef;
background:-webkit-gradient(linear, 0 0, 0 bottom, from(#2a8cef), to(#8A2BE2));
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
flex-wrap: nowrap;
justify-content: flex-start;
align-items: stretch;
font-size: 14px;
} .box {
display: block;
margin: 10px;
} .box-flex {
display: -webkit-box;
display: -webkit-flex;
display: flex;
flex-wrap: wrap;
} .flex-item {
flex-flow: nowrap;
flex-grow: 1;
flex-shrink: 1;
width: 14.2%;
} .item-content {
margin: 5px;
padding: 0 10px;
text-align: center;
background-color: #000;
height: 2rem;
line-height: 2rem;
color: #fff;
} .bk-color-day {
background-color: #8A2BE2;
} .item-content-current-day {
flex-grow: 2;
}
4、其中,@import '../../dist/css/icon.wxss'; 引入了bootstrap字体图标,自己去GIT上下载,连接:https://github.com/lengyue1084/wxapp-calendar
【微信小程序】日历插件,适用于酒店订房类小程序的更多相关文章
- 微信小程序日历插件
1/ wxml代码 <view class="timePick"> <picker mode="date" fields="mo ...
- 微信小程序个人/企业开放服务类目一览表
微信小程序个人/企业开放服务类目一览表 微信小程序个人开放服务类目表 服务类目 类目分类一 类目分类二 引导描述 出行与交通 代驾 / / 生活服务 家政.丽人.摄影/扩印.婚庆服务.环保回收/废 ...
- 微信小程序图表插件 - wx-charts
微信小程序图表插件(wx-charts)基于canvas绘制,体积小巧支持图表类型饼图.线图.柱状图 .区域图等图表图形绘制,目前wx-charts是微信小程序图表插件中比较强大好使的一个. wx-c ...
- 微信小程序日历签到
近日做了一个项目需要用到日历插件,在网上找了一部分感觉跟项目不对口,所以就查考了其他的日历插件做了一个. 需求: 如图: 代码如下: index.wxml: <!--pages/pictrues ...
- 微信小程序开发系列(一)小程序开发初体验
开发小程序所需的基本技能 关于小程序的介绍和使用场景这里不作介绍,这个系列的文章会一步一步地带领大家快速地学习和掌握小程序的开发. 关于还没有接触过小程序的开发者来说,最关心的问题无非就是,开发小 ...
- [转]微信小程序开发系列(一)小程序开发初体验
本文转自:http://www.cnblogs.com/rennix/p/6287432.html 开发小程序所需的基本技能 关于小程序的介绍和使用场景这里不作介绍,这个系列的文章会一步一步地带领 ...
- PHP实现支付宝小程序用户授权的工具类
背景 最近项目需要上线支付宝小程序,同时需要走用户的授权流程完成用户信息的存储,以前做过微信小程序的开发,本以为实现授权的过程是很简单的事情,但是再实现的过程中还是遇到了不少的坑,因此记录一下实现的过 ...
- 微信小程序开发系列(二)小程序的全局文件
其实你已经知道了小程序的文件结构 上一节讲到,小程序的页面由三部分组成: 视图(.wxml).逻辑(.js).样式(.wxss). 我们这次重新展开文件结构: 小程序用到的文件类型只有四种,正如你所看 ...
- 微信小程序-----安装,编写第一个小程序和运行到手机端
第一步: 微信公众平台注册账号,并选择小程序,网址:mp.weixin.qq.com 填写相关信息,如:主体类型(个人或者企业) AppID 在开发中都是用的到的,服务器域名在网络请求也是用的到的. ...
随机推荐
- 【主席树】Gym - 101237A - MEX-Query
主席树里每个值的位置存当前该值出现的最右位置. 如果root[r]的前缀主席树中,某值最右位置大于等于l,说明该值出现在了l,r中. 所以主席树维护区间最小值,如果左半值域的最小值<l,则说明左 ...
- 推荐系统中的SVD
本文主要参考:Factorization Meets the Neighborhood: a Multifaceted Collaborative Filtering Model 在用户对自己需求相对 ...
- (Mark)Myeclipse10.6 下怎么安装Jad插件
Jad是java的反编译工具,是命令行执行,反编译出来的源文件可读性较高.可惜用起来不太方便.还好找到eclipse下的插件,叫jadclipse,安装好之后,只要双击.class文件,就能直接看源文 ...
- YS动态口令系统接入流程
动态口令是保护用户账户的一种常见有效手段,即用户进行敏感操作(比如登录)时,需要用户提供此动态生成的口令做二次身份验证,假设用户的口令被盗,如果没有动态口令,也无法进行登录或进行敏感操作,保护了用户的 ...
- material design动画
这是一篇material design 文档动画部分的学习! Summary: Material Design动画交互 动画速度的3个原则 3种交互方式 如何设计有意义的动画 使人高兴的动画细节 1 ...
- oracle 察看用户是否被锁,解锁以及改密码
以管理员身份登陆 察看用户状态(是否被锁) select * from dba_users where username='user1' 解锁 ALTER USER user1 ACCOUNT UN ...
- php类库安装xml simplexml
问题 报错:Call to undefined function dom_import_simplexml() yum install php-dom service restart httpd 参考 ...
- Android 卡顿优化 3 布局优化 工具 Hierarchy Viewer
欲善其事, 先利其器. 分析布局, 就不得不用到Hierarchy Viewer了. 本文工具使用皆以GithubApp的详情界面RepoDetailActivity为例说明. 为了不影响阅读体验, ...
- Openshift template的使用
1.template的定义 官方对template的定义是 A template describes a set of objects that can be parameterized and pr ...
- 每天5分钟玩转Docker
总结的这个八爪鱼图,不懂的时候随时翻翻书.....