邹能昇 пре 3 месеци
родитељ
комит
e2820a0d2b

+ 103 - 0
nova-tourism/components/calendar/index.js

@@ -0,0 +1,103 @@
+// nova-tourism/components/calendar/index.js
+Component({
+    /**
+     * 组件的属性列表
+     */
+    properties: {
+        show:{
+            type:Boolean,
+            default: false
+        },
+        title: {
+            type: String,
+            value: '日期选择',
+        },
+        color: String,
+        formatter: null,
+        // defaultDate: {
+        //     type: null,
+        //     observer: function (val) {
+        //       this.setData({ currentDate: val });
+        //       this.scrollIntoView();
+        //     },
+        //   },
+    },
+    created: function () {
+        this.setData({
+          currentDate: this.getInitialDate(this.defaultDate),
+        });
+    },
+    /**
+     * 组件的初始数据
+     */
+    data: {
+        subtitle: '',
+        currentDate: null,
+        scrollIntoView: '',
+        startTime:'',
+        endTime: ''
+    },
+
+    /**
+     * 组件的方法列表
+     */
+    methods: {
+        getInitialDate: function(defaultDate){
+            let now = new Date()
+            let currentYear = now.getFullYear();
+            let currentMonth = now.getMonth()+1;
+            let currentDay = now.getDay();
+            // let months = 
+            if(!defaultDate){
+                
+            }
+        },
+        getInitialDate: function (defaultDate) {
+            var _this = this;
+            if (defaultDate === void 0) {// defaultDate 为undefined
+              defaultDate = null;
+            }
+            let {type,minDate,maxDate} = this.data;
+            var now = utils_1.getToday().getTime();
+            if (type === 'range') {
+              if (!Array.isArray(defaultDate)) {
+                defaultDate = [];
+              }
+              var _b = defaultDate || [],
+                startDay = _b[0],
+                endDay = _b[1];
+              var start = this.limitDateRange(
+                startDay || now,
+                minDate,
+                utils_1.getPrevDay(new Date(maxDate)).getTime()
+              );
+              var end = this.limitDateRange(
+                endDay || now,
+                utils_1.getNextDay(new Date(minDate)).getTime()
+              );
+              return [start, end];
+            }
+            if (type === 'multiple') {
+              if (Array.isArray(defaultDate)) {
+                return defaultDate.map(function (date) {
+                  return _this.limitDateRange(date);
+                });
+              }
+              return [this.limitDateRange(now)];
+            }
+            if (!defaultDate || Array.isArray(defaultDate)) {
+              defaultDate = now;
+            }
+            return this.limitDateRange(defaultDate);
+          },
+        emit: function (date) {
+            var getTime = function (date) {
+              return date instanceof Date ? date.getTime() : date;
+            };
+            this.setData({
+              currentDate: Array.isArray(date) ? date.map(getTime) : getTime(date),
+            });
+            this.$emit('select', utils_1.copyDates(date));
+          },
+    }
+})

+ 4 - 0
nova-tourism/components/calendar/index.json

@@ -0,0 +1,4 @@
+{
+    "component": true,
+    "usingComponents": {}
+}

+ 72 - 0
nova-tourism/components/calendar/index.wxml

@@ -0,0 +1,72 @@
+
+<block wx:if="{{show}}">
+    <view class="nova-calendar">
+        <header
+          title="{{ title }}"
+          showTitle="{{ showTitle }}"
+          subtitle="{{ subtitle }}"
+          showSubtitle="{{ showSubtitle }}"
+          firstDayOfWeek="{{ firstDayOfWeek }}"
+          bind:click-subtitle="onClickSubtitle"
+        >
+          <slot name="title" slot="title"></slot>
+        </header>
+        
+        <scroll-view
+          class="van-calendar__body"
+          scroll-y
+          scroll-into-view="{{ scrollIntoView }}"
+        >
+          <month
+            wx:for="{{ computed.getMonths(minDate, maxDate) }}"
+            wx:key="index"
+            id="month{{ index }}"
+            class="month"
+            data-date="{{ item }}"
+            date="{{ item }}"
+            type="{{ type }}"
+            color="{{ color }}"
+            minDate="{{ minDate }}"
+            maxDate="{{ maxDate }}"
+            showMark="{{ showMark }}"
+            formatter="{{ formatter }}"
+            rowHeight="{{ rowHeight }}"
+            currentDate="{{ currentDate }}"
+            showSubtitle="{{ showSubtitle }}"
+            allowSameDay="{{ allowSameDay }}"
+            showMonthTitle="{{ index !== 0 || !showSubtitle }}"
+            firstDayOfWeek="{{ firstDayOfWeek }}"
+            bind:click="onClickDay"
+          />
+        </scroll-view>
+      
+        <view
+          class="{{ utils.bem('calendar__footer', { safeAreaInsetBottom }) }}"
+        >
+          <slot name="footer"></slot>
+        </view>
+      
+        <view
+          class="{{ utils.bem('calendar__footer', { safeAreaInsetBottom }) }}"
+        >
+          <van-button
+            wx:if="{{ showConfirm }}"
+            round
+            block
+            type="danger"
+            color="{{ color }}"
+            custom-class="van-calendar__confirm"
+            disabled="{{ computed.getButtonDisabled(type, currentDate) }}"
+            nativeType="text"
+            bind:click="onConfirm"
+          >
+            {{
+              computed.getButtonDisabled(type, currentDate)
+                ? confirmDisabledText
+                : confirmText
+            }}
+          </van-button>
+        </view>
+    </view>
+      
+</block>

+ 1 - 0
nova-tourism/components/calendar/index.wxss

@@ -0,0 +1 @@
+.van-calendar{display:flex;flex-direction:column;height:100%;height:var(--calendar-height,100%);background-color:#fff;background-color:var(--calendar-background-color,#fff)}.van-calendar__close-icon{top:11px}.van-calendar__popup--bottom,.van-calendar__popup--top{height:80%;height:var(--calendar-popup-height,80%)}.van-calendar__popup--left,.van-calendar__popup--right{height:100%}.van-calendar__body{flex:1;overflow:auto;-webkit-overflow-scrolling:touch}.van-calendar__footer{flex-shrink:0;padding:0 16px;padding:0 var(--padding-md,16px)}.van-calendar__footer--safe-area-inset-bottom{padding-bottom:env(safe-area-inset-bottom)}.van-calendar__footer+.van-calendar__footer,.van-calendar__footer:empty{display:none}.van-calendar__footer:empty+.van-calendar__footer{display:block!important}.van-calendar__confirm{height:36px!important;height:var(--calendar-confirm-button-height,36px)!important;margin:7px 0!important;margin:var(--calendar-confirm-button-margin,7px 0)!important;line-height:34px!important;line-height:var(--calendar-confirm-button-line-height,34px)!important}