//app.json中加入這一段
"plugins": {
"myPlugin": {
"version": "2.1.1",
"provider": "wx6b6cb15df2836ebe"
}
},
//index.js
// pages/wyxz/wyxz.js
Page({
/**
* 頁面的初始數據
*/
data: {
isShow: false, // 默認不顯示插件
themeColor: '#ffd00a',
calendarType: 'yydates'
},
/**
* 生命週期函數--監聽頁面加載
*/
onLoad: function (options) {
},
// 點擊顯示插件
btnClick: function () {
this.setData({
isShow: true,
})
},
_yybindchange: function (e) {
var data = e.detail;
var start_date = new Date(data.startTime.replace(/-/g, "/"));
var end_date = new Date(data.endTime.replace(/-/g, "/"));
var days = end_date.getTime() - start_date.getTime();
var day = parseInt(days / (1000 * 60 * 60 * 24));
console.log("天數", day);
if (day > 0) {
this.setData({
day: day,
startdate: data.startTime + "至" + data.endTime,
sdate: data.startTime,
edate: data.endTime
})
} else {
wx.showToast({
title: '請認真選擇餵養時間哦!',
icon: "none",
duration: 3000
})
}
console.log('結束時間', e.detail.value, "天數", day)
},
_yybindhide: function () {
console.log('隱藏')
},
/**
* 生命週期函數--監聽頁面顯示
*/
onShow: function () {
},
/**
* 生命週期函數--監聽頁面隱藏
*/
onHide: function () {
},
/**
* 生命週期函數--監聽頁面卸載
*/
onUnload: function () {
},
/**
* 頁面相關事件處理函數--監聽用戶下拉動作
*/
onPullDownRefresh: function () {
},
/**
* 頁面上拉觸底事件的處理函數
*/
onReachBottom: function () {
},
/**
* 用戶點擊右上角分享
*/
onShareAppMessage: function () {
}
})
//index.wxml
<view class="cont">
<view class="title-views">
<label class="title-num" bindtap="btnClick">
<span wx:if="{{startdate=='請選擇餵養時間'}}" style="color:red;">{{startdate}}</span>
<span wx:else>{{startdate}}</span>
</label>
<label class="title-name">餵養時間</label>
</view>
</view>
<yycalendar
show='{{isShow}}'
themeColor="{{themeColor}}"
calendarType="{{calendarType}}"
bind:yybindchange="_yybindchange"
title="選擇寄養時間段"
dateTitle="開始時間"
endDateTitle="結束時間"
confirmClick="true"
/>