yukangzhe 3 年 前
コミット
8baab4b25e

+ 55 - 1
pages/Components/selectDate/selectDate.js

@@ -1,5 +1,17 @@
 // pages/Components/selectDate/selectDate.js
 Component({
+  lifetimes:{
+    attached:function(){
+      var date = new Date()
+      const year = date.getFullYear()
+      const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
+      const day = date.getDate() + 1 < 10 ? '0' + date.getDate() : data.getDate()
+      this.setData({
+        endDate: year + '-' + month + '-' + day,
+        lastDate: year + '-' + month + '-' + day
+      })
+    }
+  },
   /**
    * 组件的属性列表
    */
@@ -11,8 +23,10 @@ Component({
    * 组件的初始数据
    */
   data: {
-    beginDate: '2021-01-01',
+    beginDate: '2000-01-01',
     endDate: '2021-02-02',
+    initDate:'2000-01-01',
+    lastDate:'',
     yFlag: false,
     animationBox: {},
     animationBg: {},
@@ -22,6 +36,46 @@ Component({
    * 组件的方法列表
    */
   methods: {
+    bindBeginDateChange:function(e){
+      if(e.detail.value > this.data.endDate){
+        this.setData({
+          beginDate: this.data.endDate
+        })
+      } else {
+        this.setData({
+          beginDate: e.detail.value
+        })
+      }
+    },
+
+    bindEndDateChange:function(e){
+      if(e.detail.value > this.data.endDate){
+        this.setData({
+          endDate: this.data.lastDate
+        })
+      } else {
+        this.setData({
+          endDate: e.detail.value
+        })
+      }
+    },
+
+    resetDate:function(){
+      this.setData({
+        beginDate: this.data.initDate,
+        endDate: this.data.lastDate
+      })
+      const dateArr = [this.data.initDate,this.data.lastDate];
+      this.triggerEvent("getDates",dateArr);
+      this.showSelect()
+    },
+
+    submitDate:function(){
+      const dateArr = [this.data.beginDate,this.data.endDate];
+      this.triggerEvent("getDates",dateArr);
+      this.showSelect()
+    },
+
     showSelect:function(){
       var animation = wx.createAnimation({
         timingFunction: 'linear',

+ 4 - 4
pages/Components/selectDate/selectDate.wxml

@@ -4,13 +4,13 @@
       <view class="select-title">选择时间段:</view>
     <view class="select-date-view">
       <view class="section">
-        <picker mode="date" value="{{date}}" start="2015-09-01" end="2017-09-01" bindchange="bindDateChange">
+        <picker mode="date" value="{{beginDate}}" start="2000-01-01" end="{{endDate}}" bindchange="bindBeginDateChange">
           <view class="picker">
             {{beginDate}}
           </view>
         </picker>
         <view> 至 </view>
-        <picker mode="date" value="{{date}}" start="2015-09-01" end="2017-09-01" bindchange="bindDateChange">
+        <picker mode="date" value="{{beginDate}}" start="{{beginDate}}" end="{{endDate}}" bindchange="bindEndDateChange">
           <view class="picker">
             {{endDate}}
           </view>
@@ -19,8 +19,8 @@
     </view>
     </view>
     <view class="search-btn-view">
-      <view class="search-btn">确定</view>
-      <view class="reset-btn">重置</view>
+      <view class="search-btn" bindtap="submitDate">确定</view>
+      <view class="reset-btn" bindtap="resetDate">重置</view>
     </view>
   </view>
   <view class="select-box-bg" bindtap="showSelect" animation="{{animationBg}}" wx:if="{{yFlag == true}}"></view>

+ 9 - 0
pages/task/task.js

@@ -35,6 +35,15 @@ Page({
     })
   },
 
+  getDates:function(e){
+    this.setData({
+      beginDate: e.detail[0],
+      endDate: e.detail[1],
+      loading: '加载中'
+    })
+    this.queryList()
+  },
+
   /**
    * 生命周期函数--监听页面加载
    */

+ 1 - 1
pages/task/task.wxml

@@ -1,7 +1,7 @@
 <view class="container">
 
   <!-- 时间筛选 -->
-  <selectDate></selectDate>
+  <selectDate bind:getDates="getDates"></selectDate>
   <!-- end -->
   
   <!-- 顶部切换标题 -->

+ 3 - 2
project.config.json

@@ -62,8 +62,9 @@
     "miniprogram": {
       "list": [
         {
-          "name": "pages/login/login",
-          "pathName": "pages/Components/rating/rating",
+          "name": "pages/index/index",
+          "pathName": "pages/index/index",
+          "query": "",
           "scene": null
         }
       ]