mx-datepicker.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. <template>
  2. <view v-if="isShow" class="picker">
  3. <!-- 日期选择器 -->
  4. <view v-if="type!='time'" class="picker-modal">
  5. <view class="picker-modal-header">
  6. <view class="picker-icon picker-icon-zuozuo" :hover-stay-time="100" hover-class="picker-icon-active" @click="onSetYear('-1')"></view>
  7. <view class="picker-icon picker-icon-zuo" :hover-stay-time="100" hover-class="picker-icon-active" @click="onSetMonth('-1')"></view>
  8. <text class="picker-modal-header-title">{{title}}</text>
  9. <view class="picker-icon picker-icon-you" :hover-stay-time="100" hover-class="picker-icon-active" @click="onSetMonth('+1')"></view>
  10. <view class="picker-icon picker-icon-youyou" :hover-stay-time="100" hover-class="picker-icon-active" @click="onSetYear('+1')"></view>
  11. </view>
  12. <swiper class="picker-modal-body" :circular="true" :duration="200" :skip-hidden-item-layout="true" :current="calendarIndex" @change="onSwiperChange">
  13. <swiper-item class="picker-calendar" v-for="(calendar,calendarIndex2) in calendars" :key="calendarIndex2">
  14. <view class="picker-calendar-view" v-for="(week,index) in weeks" :key="index - 7">
  15. <view class="picker-calendar-view-item">{{week}}</view>
  16. </view>
  17. <view class="picker-calendar-view" v-for="(date,dateIndex) in calendar" :key="dateIndex" @click="onSelectDate(date)">
  18. <!-- 背景样式 -->
  19. <view v-show="date.bgStyle.type" :class="'picker-calendar-view-'+date.bgStyle.type" :style="{background: date.bgStyle.background}"></view>
  20. <!-- 正常和选中样式 -->
  21. <view class="picker-calendar-view-item" :style="{opacity: date.statusStyle.opacity, color: date.statusStyle.color, background: date.statusStyle.background}">
  22. <text>{{date.title}}</text>
  23. </view>
  24. <!-- 小圆点样式 -->
  25. <view class="picker-calendar-view-dot" :style="{opacity: date.dotStyle.opacity, background: date.dotStyle.background}"></view>
  26. <!-- 信息样式 -->
  27. <view v-show="date.tips" class="picker-calendar-view-tips">{{date.tips}}</view>
  28. </view>
  29. </swiper-item>
  30. </swiper>
  31. <view class="picker-modal-footer">
  32. <view class="picker-modal-footer-info">
  33. <block v-if="isMultiSelect">
  34. <view class="picker-display">
  35. <text>{{beginText}}日期</text>
  36. <text class="picker-display-text">{{BeginTitle}}</text>
  37. <view v-if="isContainTime" class="picker-display-link" :hover-stay-time="100" hover-class="picker-display-link-active"
  38. :style="{color}" @click="onShowTimePicker('begin')">{{BeginTimeTitle}}</view>
  39. </view>
  40. <view class="picker-display">
  41. <text>{{endText}}日期</text>
  42. <text class="picker-display-text">{{EndTitle}}</text>
  43. <view v-if="isContainTime" class="picker-display-link" :hover-stay-time="100" hover-class="picker-display-link-active"
  44. :style="{color}" @click="onShowTimePicker('end')">{{EndTimeTitle}}</view>
  45. </view>
  46. </block>
  47. <block v-else>
  48. <view class="picker-display">
  49. <text>当前选择</text>
  50. <text class="picker-display-text">{{BeginTitle}}</text>
  51. <view v-if="isContainTime" class="picker-display-link" :hover-stay-time="100" hover-class="picker-display-link-active"
  52. :style="{color}" @click="onShowTimePicker('begin')">{{BeginTimeTitle}}</view>
  53. </view>
  54. </block>
  55. </view>
  56. <view class="picker-modal-footer-btn">
  57. <view class="picker-btn" :hover-stay-time="100" hover-class="picker-btn-active" @click="onCancel">取消</view>
  58. <view class="picker-btn" :style="{color}" :hover-stay-time="100" hover-class="picker-btn-active" @click="onConfirm">确定</view>
  59. </view>
  60. </view>
  61. </view>
  62. <!-- 时间选择器 -->
  63. <view v-if="showTimePicker" class="picker">
  64. <view class="picker-modal picker-time">
  65. <view class="picker-modal-header">
  66. <text class="picker-modal-header-title">选择日期</text>
  67. </view>
  68. <picker-view class="picker-modal-time" indicator-class="picker-modal-time-item" :value="timeValue" @change="onTimeChange">
  69. <picker-view-column>
  70. <view v-for="(v,i) in 24" :key="i">{{i<10?'0'+i:i}}时</view>
  71. </picker-view-column>
  72. <picker-view-column>
  73. <view v-for="(v,i) in 60" :key="i">{{i<10?'0'+i:i}}分</view>
  74. </picker-view-column>
  75. <picker-view-column v-if="showSeconds">
  76. <view v-for="(v,i) in 60" :key="i">{{i<10?'0'+i:i}}秒</view>
  77. </picker-view-column>
  78. </picker-view>
  79. <view class="picker-modal-footer">
  80. <view class="picker-modal-footer-info">
  81. <view class="picker-display">
  82. <text>当前选择</text>
  83. <text class="picker-display-text">{{PickerTimeTitle}}</text>
  84. </view>
  85. </view>
  86. <view class="picker-modal-footer-btn">
  87. <view class="picker-btn" :hover-stay-time="100" hover-class="picker-btn-active" @click="onCancelTime">取消</view>
  88. <view class="picker-btn" :style="{color}" :hover-stay-time="100" hover-class="picker-btn-active" @click="onConfirmTime">确定</view>
  89. </view>
  90. </view>
  91. </view>
  92. </view>
  93. </view>
  94. </template>
  95. <script>
  96. /**
  97. * 工具函数库
  98. */
  99. const DateTools = {
  100. /**
  101. * 获取公历节日
  102. * @param date Date对象
  103. */
  104. getHoliday(date) {
  105. let holidays = {
  106. '0101': '元旦',
  107. '0214': '情人',
  108. '0308': '妇女',
  109. '0312': '植树',
  110. '0401': '愚人',
  111. '0501': '劳动',
  112. '0504': '青年',
  113. '0601': '儿童',
  114. '0701': '建党',
  115. '0801': '建军',
  116. '0903': '抗日',
  117. '0910': '教师',
  118. '1001': '国庆',
  119. '1031': '万圣',
  120. '1224': '平安',
  121. '1225': '圣诞'
  122. };
  123. let value = this.format(date, 'mmdd');
  124. if (holidays[value]) return holidays[value];
  125. return false;
  126. },
  127. /**
  128. * 解析标准日期格式
  129. * @param s 日期字符串
  130. * @return 返回Date对象
  131. */
  132. parse: s => new Date(s.replace(/(年|月|-)/g, '/').replace(/(日)/g, '')),
  133. /**
  134. * 比较日期是否为同一天
  135. * @param a Date对象
  136. * @param b Date对象
  137. * @return Boolean
  138. */
  139. isSameDay: (a, b) => a.getMonth() == b.getMonth() && a.getFullYear() == b.getFullYear() && a.getDate() == b.getDate(),
  140. /**
  141. * 格式化Date对象
  142. * @param d 日期对象
  143. * @param f 格式字符串
  144. * @return 返回格式化后的字符串
  145. */
  146. format(d, f) {
  147. var o = {
  148. "m+": d.getMonth() + 1,
  149. "d+": d.getDate(),
  150. "h+": d.getHours(),
  151. "i+": d.getMinutes(),
  152. "s+": d.getSeconds(),
  153. "q+": Math.floor((d.getMonth() + 3) / 3),
  154. };
  155. if (/(y+)/.test(f))
  156. f = f.replace(RegExp.$1, (d.getFullYear() + "").substr(4 - RegExp.$1.length));
  157. for (var k in o)
  158. if (new RegExp("(" + k + ")").test(f))
  159. f = f.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  160. return f;
  161. },
  162. /**
  163. * 用于format格式化后的反解析
  164. * @param s 日期字符串
  165. * @param f 格式字符串
  166. * @return 返回Date对象
  167. */
  168. inverse(s, f) {
  169. var o = {
  170. "y": '',
  171. "m": '',
  172. "d": '',
  173. "h": '',
  174. "i": '',
  175. "s": '',
  176. };
  177. let d = new Date();
  178. if (s.length != f.length) return d;
  179. for (let i in f)
  180. if (o[f[i]] != undefined) o[f[i]] += s[i];
  181. if (o.y) d.setFullYear(o.y.length < 4 ? (d.getFullYear() + '').substr(0, 4 - o.y.length) + o.y : o.y);
  182. o.m && d.setMonth(o.m - 1, 1);
  183. o.d && d.setDate(o.d - 0);
  184. o.h && d.setHours(o.h - 0);
  185. o.i && d.setMinutes(o.i - 0);
  186. o.s && d.setSeconds(o.s - 0);
  187. return d;
  188. },
  189. /**
  190. * 获取日历数组(42天)
  191. * @param date 日期对象或日期字符串
  192. * @param proc 处理日历(和forEach类似),传递一个数组中的item
  193. * @return Array
  194. */
  195. getCalendar(date, proc) {
  196. let it = new Date(date),
  197. calendars = [];
  198. it.setDate(1);
  199. it.setDate(it.getDate() - ((it.getDay() == 0 ? 7 : it.getDay()) - 1)); //偏移量
  200. for (let i = 0; i < 42; i++) {
  201. let tmp = {
  202. dateObj: new Date(it),
  203. title: it.getDate(),
  204. isOtherMonth: it.getMonth() < date.getMonth() || it.getMonth() > date.getMonth()
  205. };
  206. calendars.push(Object.assign(tmp, proc ? proc(tmp) : {}));
  207. it.setDate(it.getDate() + 1);
  208. }
  209. return calendars;
  210. },
  211. /**
  212. * 获取日期到指定的月份1号(不改变原来的date对象)
  213. * @param d Date对象
  214. * @param v 指定的月份
  215. * @return Date对象
  216. */
  217. getDateToMonth(d, v) {
  218. let n = new Date(d);
  219. n.setMonth(v, 1);
  220. return n;
  221. },
  222. /**
  223. * 把时间数组转为时间字符串
  224. * @param t Array[时,分,秒]
  225. * @param showSecinds 是否显示秒
  226. * @return 字符串 时:分[:秒]
  227. */
  228. formatTimeArray(t, s) {
  229. let r = [...t];
  230. if (!s) r.length = 2;
  231. r.forEach((v, k) => r[k] = ('0' + v).slice(-2));
  232. return r.join(':');
  233. }
  234. };
  235. export default {
  236. props: {
  237. //颜色
  238. color: {
  239. type: String,
  240. default: '#409eff'
  241. },
  242. //是否显示秒 针对type为datetime或time时生效
  243. showSeconds: {
  244. type: Boolean,
  245. default: false
  246. },
  247. //初始的值
  248. value: [String, Array],
  249. //类型date time datetime range rangetime
  250. type: {
  251. type: String,
  252. default: 'range'
  253. },
  254. //是否显示
  255. show: {
  256. type: Boolean,
  257. default: false
  258. },
  259. //初始格式
  260. format: {
  261. type: String,
  262. default: ''
  263. },
  264. //显示公历节日
  265. showHoliday: {
  266. type: Boolean,
  267. default: true
  268. },
  269. //显示提示
  270. showTips: {
  271. type: Boolean,
  272. default: false
  273. },
  274. //开始文案 针对type为范围选择时生效
  275. beginText: {
  276. type: String,
  277. default: '开始'
  278. },
  279. //结束文案 针对type为范围选择时生效
  280. endText: {
  281. type: String,
  282. default: '结束'
  283. }
  284. },
  285. data() {
  286. return {
  287. isShow: false, //是否显示
  288. isMultiSelect: false, //是否为多选
  289. isContainTime: false, //是否包含时间
  290. date: {}, //当前日期对象
  291. weeks: ["一", "二", "三", "四", "五", "六", "日"],
  292. title: '初始化', //标题
  293. calendars: [[],[],[]], //日历数组
  294. calendarIndex: 1, //当前日历索引
  295. checkeds: [], //选中的日期对象集合
  296. showTimePicker: false, //是否显示时间选择器
  297. timeValue: [0, 0, 0], //时间选择器的值
  298. timeType: 'begin', //当前时间选择的类型
  299. beginTime: [0, 0, 0], //当前所选的开始时间值
  300. endTime: [0, 0, 0], //当前所选的结束时间值
  301. };
  302. },
  303. methods: {
  304. //设置值
  305. setValue(value) {
  306. this.date = new Date();
  307. this.checkeds = [];
  308. this.isMultiSelect = this.type.indexOf('range') >= 0;
  309. this.isContainTime = this.type.indexOf('time') >= 0;
  310. //将字符串解析为Date对象
  311. let parseDateStr = (str) => (this.format ? DateTools.inverse(str, this.format) : DateTools.parse(str));
  312. if (value) {
  313. if (this.isMultiSelect) {
  314. Array.isArray(value) && value.forEach((dateStr, index) => {
  315. let date = parseDateStr(dateStr);
  316. let time = [date.getHours(), date.getMinutes(), date.getSeconds()];
  317. if (index == 0) this.beginTime = time;
  318. else this.endTime = time;
  319. this.checkeds.push(date);
  320. });
  321. } else {
  322. if (this.type == 'time') {
  323. let date = parseDateStr('2019/1/1 ' + value);
  324. this.beginTime = [date.getHours(), date.getMinutes(), date.getSeconds()];
  325. this.onShowTimePicker('begin');
  326. } else {
  327. this.checkeds.push(parseDateStr(value));
  328. if (this.isContainTime) this.beginTime = [
  329. this.checkeds[0].getHours(),
  330. this.checkeds[0].getMinutes(),
  331. this.checkeds[0].getSeconds()
  332. ];
  333. }
  334. }
  335. if (this.checkeds.length) this.date = new Date(this.checkeds[0]);
  336. } else {
  337. if (this.isContainTime) {
  338. this.beginTime = [this.date.getHours(), this.date.getMinutes(), this.date.getSeconds()];
  339. if (this.isMultiSelect) this.endTime = [...this.beginTime];
  340. }
  341. this.checkeds.push(new Date(this.date));
  342. }
  343. if (this.type != 'time') this.refreshCalendars(true);
  344. else this.onShowTimePicker('begin');
  345. },
  346. //改变年份
  347. onSetYear(value) {
  348. this.date.setFullYear(this.date.getFullYear() + parseInt(value));
  349. this.refreshCalendars(true);
  350. },
  351. //改变月份
  352. onSetMonth(value) {
  353. this.date.setMonth(this.date.getMonth() + parseInt(value));
  354. this.refreshCalendars(true);
  355. },
  356. //时间选择变更
  357. onTimeChange(e) {
  358. this.timeValue = e.detail.value;
  359. },
  360. //设置时间选择器的显示状态
  361. onShowTimePicker(type) {
  362. this.showTimePicker = true;
  363. this.timeType = type;
  364. this.timeValue = type == 'begin' ? [...this.beginTime] : [...this.endTime];
  365. },
  366. //处理日历
  367. procCalendar(item) {
  368. //定义初始样式
  369. item.statusStyle = {
  370. opacity: 1,
  371. color: item.isOtherMonth ? '#ddd' : '#000',
  372. background: 'transparent'
  373. };
  374. item.bgStyle = {
  375. type: '',
  376. background: 'transparent'
  377. };
  378. item.dotStyle = {
  379. opacity: 1,
  380. background: 'transparent'
  381. };
  382. item.tips = "";
  383. //标记今天的日期
  384. if (DateTools.isSameDay(new Date(), item.dateObj)) {
  385. item.statusStyle.color = this.color;
  386. if (item.isOtherMonth) item.statusStyle.opacity = 0.3;
  387. }
  388. //标记选中项
  389. this.checkeds.forEach(date => {
  390. if (DateTools.isSameDay(date, item.dateObj)) {
  391. item.statusStyle.background = this.color;
  392. item.statusStyle.color = '#fff';
  393. item.statusStyle.opacity = 1;
  394. if (this.isMultiSelect && this.showTips) item.tips = this.beginText;
  395. }
  396. });
  397. //节假日或今日的日期标点
  398. if (item.statusStyle.background != this.color) {
  399. let holiday = this.showHoliday ? DateTools.getHoliday(item.dateObj) : false;
  400. if (holiday || DateTools.isSameDay(new Date(), item.dateObj)) {
  401. item.title = holiday || item.title;
  402. item.dotStyle.background = this.color;
  403. if (item.isOtherMonth) item.dotStyle.opacity = 0.2;
  404. }
  405. } else {
  406. item.title = item.dateObj.getDate();
  407. }
  408. //有两个日期
  409. if (this.checkeds.length == 2) {
  410. if (DateTools.isSameDay(this.checkeds[0], item.dateObj)) { //开始日期
  411. item.bgStyle.type = 'bgbegin';
  412. }
  413. if (DateTools.isSameDay(this.checkeds[1], item.dateObj)) { //结束日期
  414. if (this.isMultiSelect && this.showTips) item.tips = item.bgStyle.type ? this.beginText + ' / ' + this.endText : this.endText;
  415. if (!item.bgStyle.type) { //开始日期不等于结束日期
  416. item.bgStyle.type = 'bgend';
  417. } else {
  418. item.bgStyle.type = '';
  419. }
  420. }
  421. if (!item.bgStyle.type && (+item.dateObj > +this.checkeds[0] && +item.dateObj < +this.checkeds[1])) { //中间的日期
  422. item.bgStyle.type = 'bg';
  423. item.statusStyle.color = this.color;
  424. }
  425. if (item.bgStyle.type) {
  426. item.bgStyle.background = this.color;
  427. item.dotStyle.opacity = 1;
  428. item.statusStyle.opacity = 1;
  429. }
  430. }
  431. },
  432. //刷新日历
  433. refreshCalendars(refresh = false) {
  434. let date = new Date(this.date);
  435. let before = DateTools.getDateToMonth(date, date.getMonth() - 1);
  436. let after = DateTools.getDateToMonth(date, date.getMonth() + 1);
  437. if (this.calendarIndex == 0) {
  438. if(refresh) this.calendars.splice(0, 1, DateTools.getCalendar(date, this.procCalendar));
  439. this.calendars.splice(1, 1, DateTools.getCalendar(after, this.procCalendar));
  440. this.calendars.splice(2, 1, DateTools.getCalendar(before, this.procCalendar));
  441. } else if (this.calendarIndex == 1) {
  442. this.calendars.splice(0, 1, DateTools.getCalendar(before, this.procCalendar));
  443. if(refresh) this.calendars.splice(1, 1, DateTools.getCalendar(date, this.procCalendar));
  444. this.calendars.splice(2, 1, DateTools.getCalendar(after, this.procCalendar));
  445. } else if (this.calendarIndex == 2) {
  446. this.calendars.splice(0, 1, DateTools.getCalendar(after, this.procCalendar));
  447. this.calendars.splice(1, 1, DateTools.getCalendar(before, this.procCalendar));
  448. if(refresh) this.calendars.splice(2, 1, DateTools.getCalendar(date, this.procCalendar));
  449. }
  450. this.title = DateTools.format(this.date, 'yyyy年mm月');
  451. },
  452. //滑块切换
  453. onSwiperChange(e) {
  454. this.calendarIndex = e.detail.current;
  455. let calendar = this.calendars[this.calendarIndex];
  456. this.date = new Date(calendar[22].dateObj); //取中间一天,保证是当前的月份
  457. this.refreshCalendars();
  458. },
  459. //选中日期
  460. onSelectDate(date) {
  461. if (~this.type.indexOf('range') && this.checkeds.length == 2) this.checkeds = [];
  462. else if (!(~this.type.indexOf('range')) && this.checkeds.length) this.checkeds = [];
  463. this.checkeds.push(new Date(date.dateObj));
  464. this.checkeds.sort((a, b) => a - b); //从小到大排序
  465. this.calendars.forEach(calendar => {
  466. calendar.forEach(this.procCalendar); //重新处理
  467. });
  468. },
  469. //时间选择取消
  470. onCancelTime() {
  471. this.showTimePicker = false;
  472. this.type == 'time' && this.onCancel();
  473. },
  474. //时间选择确定
  475. onConfirmTime() {
  476. if (this.timeType == 'begin') this.beginTime = this.timeValue;
  477. else this.endTime = this.timeValue;
  478. this.showTimePicker = false;
  479. this.type == 'time' && this.onConfirm();
  480. },
  481. //取消
  482. onCancel() {
  483. this.$emit('cancel', false);
  484. },
  485. //确定
  486. onConfirm() {
  487. let result = {
  488. value: null,
  489. date: null
  490. };
  491. //定义默认格式
  492. let defaultFormat = {
  493. 'date': 'yyyy/mm/dd',
  494. 'time': 'hh:ii' + (this.showSeconds ? ':ss' : ''),
  495. 'datetime': ''
  496. };
  497. defaultFormat['datetime'] = defaultFormat.date + ' ' + defaultFormat.time;
  498. let fillTime = (date, timeArr) => {
  499. date.setHours(timeArr[0], timeArr[1]);
  500. if (this.showSeconds) date.setSeconds(timeArr[2]);
  501. };
  502. if (this.type == 'time') {
  503. let date = new Date();
  504. fillTime(date, this.beginTime);
  505. result.value = DateTools.format(date, this.format ? this.format : defaultFormat.time);
  506. result.date = date;
  507. } else {
  508. if (this.isMultiSelect) {
  509. let values = [],
  510. dates = [];
  511. if (this.checkeds.length < 2) return uni.showToast({
  512. icon: 'none',
  513. title: '请选择两个日期'
  514. });
  515. this.checkeds.forEach((date, index) => {
  516. let newDate = new Date(date);
  517. if (this.isContainTime) {
  518. let time = [this.beginTime, this.endTime];
  519. fillTime(newDate, time[index]);
  520. }
  521. values.push(DateTools.format(newDate, this.format ? this.format : defaultFormat[this.isContainTime ?
  522. 'datetime' : 'date']));
  523. dates.push(newDate);
  524. });
  525. result.value = values;
  526. result.date = dates;
  527. } else {
  528. let newDate = new Date(this.checkeds[0]);
  529. if (this.isContainTime) {
  530. newDate.setHours(this.beginTime[0], this.beginTime[1]);
  531. if (this.showSeconds) newDate.setSeconds(this.beginTime[2]);
  532. }
  533. result.value = DateTools.format(newDate, this.format ? this.format : defaultFormat[this.isContainTime ?
  534. 'datetime' : 'date']);
  535. result.date = newDate;
  536. }
  537. }
  538. this.$emit('confirm', result);
  539. }
  540. },
  541. computed: {
  542. BeginTitle() {
  543. let value = '未选择';
  544. if (this.checkeds.length) value = DateTools.format(this.checkeds[0], 'yy/mm/dd');
  545. return value;
  546. },
  547. EndTitle() {
  548. let value = '未选择';
  549. if (this.checkeds.length == 2) value = DateTools.format(this.checkeds[1], 'yy/mm/dd');
  550. return value;
  551. },
  552. PickerTimeTitle() {
  553. return DateTools.formatTimeArray(this.timeValue, this.showSeconds);
  554. },
  555. BeginTimeTitle() {
  556. return this.BeginTitle != '未选择' ? DateTools.formatTimeArray(this.beginTime, this.showSeconds) : '';
  557. },
  558. EndTimeTitle() {
  559. return this.EndTitle != '未选择' ? DateTools.formatTimeArray(this.endTime, this.showSeconds) : '';
  560. }
  561. },
  562. watch: {
  563. show(newValue, oldValue) {
  564. newValue && this.setValue(this.value);
  565. this.isShow = newValue;
  566. },
  567. value(newValue, oldValue) {
  568. setTimeout(()=>{
  569. this.setValue(newValue);
  570. }, 0);
  571. }
  572. }
  573. }
  574. </script>
  575. <style lang="scss" scoped>
  576. $z-index: 100;
  577. $cell-spacing: 20upx;
  578. $calendar-size: 630upx;
  579. $calendar-item-size: 90upx;
  580. .picker {
  581. position: fixed;
  582. z-index: $z-index;
  583. background: rgba(255, 255, 255, 0);
  584. left: 0;
  585. top: 0;
  586. width: 100%;
  587. height: 100%;
  588. font-size: 28upx;
  589. &-btn {
  590. padding: $cell-spacing*0.5 $cell-spacing;
  591. border-radius: 12upx;
  592. color: #666;
  593. &-active {
  594. background: rgba(0, 0, 0, .1);
  595. }
  596. }
  597. &-display {
  598. color: #666;
  599. &-text {
  600. color: #000;
  601. margin: 0 $cell-spacing*0.5;
  602. }
  603. &-link {
  604. display: inline-block;
  605. &-active {
  606. background: rgba(0, 0, 0, .1);
  607. }
  608. }
  609. }
  610. &-time {
  611. width: $calendar-size - 80upx !important;
  612. left: ((750upx - $calendar-size) / 2 + 40upx) !important;
  613. }
  614. &-modal {
  615. background: #fff;
  616. position: absolute;
  617. top: 50%;
  618. left: (750upx - $calendar-size) / 2;
  619. width: $calendar-size;
  620. transform: translateY(-50%);
  621. box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1);
  622. border-radius: 12upx;
  623. &-header {
  624. text-align: center;
  625. line-height: 80upx;
  626. font-size: 32upx;
  627. &-title {
  628. display: inline-block;
  629. width: 40%;
  630. }
  631. .picker-icon {
  632. display: inline-block;
  633. line-height: 50upx;
  634. width: 50upx;
  635. height: 50upx;
  636. border-radius: 50upx;
  637. text-align: center;
  638. margin: 10upx;
  639. background: #fff;
  640. font-size: 36upx;
  641. &-active {
  642. background: rgba(0, 0, 0, .1);
  643. }
  644. }
  645. }
  646. &-body {
  647. width: $calendar-size !important;
  648. height: $calendar-size !important;
  649. position: relative;
  650. }
  651. &-time {
  652. width: 100%;
  653. height: 180upx;
  654. text-align: center;
  655. line-height: 60upx;
  656. }
  657. &-footer {
  658. display: flex;
  659. justify-content: space-between;
  660. align-items: center;
  661. padding: $cell-spacing;
  662. &-info {
  663. flex-grow: 1;
  664. }
  665. &-btn {
  666. flex-shrink: 0;
  667. display: flex;
  668. }
  669. }
  670. }
  671. &-calendar {
  672. position: absolute;
  673. left: 0;
  674. top: 0;
  675. width: 100%;
  676. height: 100%;
  677. display: flex;
  678. align-items: center;
  679. flex-wrap: wrap;
  680. &-view {
  681. position: relative;
  682. width: $calendar-item-size;
  683. height: $calendar-item-size;
  684. text-align: center;
  685. &-bgbegin,
  686. &-bg,
  687. &-bgend,
  688. &-item,
  689. &-dot,
  690. &-tips {
  691. position: absolute;
  692. transition: .2s;
  693. }
  694. &-bgbegin,
  695. &-bg,
  696. &-bgend {
  697. opacity: .15;
  698. height: 80%;
  699. }
  700. &-bg {
  701. left: 0;
  702. top: 10%;
  703. width: 100%;
  704. }
  705. &-bgbegin {
  706. border-radius: $calendar-item-size 0 0 $calendar-item-size;
  707. top: 10%;
  708. left: 10%;
  709. width: 90%;
  710. }
  711. &-bgend {
  712. border-radius: 0 $calendar-item-size $calendar-item-size 0;
  713. top: 10%;
  714. left: 0%;
  715. width: 90%;
  716. }
  717. &-item {
  718. left: 5%;
  719. top: 5%;
  720. width: 90%;
  721. height: 90%;
  722. border-radius: $calendar-item-size;
  723. display: flex;
  724. align-items: center;
  725. justify-content: center;
  726. }
  727. &-dot {
  728. right: 10%;
  729. top: 10%;
  730. width: 12upx;
  731. height: 12upx;
  732. border-radius: 12upx;
  733. }
  734. &-tips {
  735. bottom: 100%;
  736. left: 50%;
  737. transform: translateX(-50%);
  738. background: #4E4B46;
  739. color: #fff;
  740. border-radius: 12upx;
  741. padding: 10upx 20upx;
  742. font-size: 24upx;
  743. width: max-content;
  744. margin-bottom: 5px;
  745. pointer-events: none;
  746. &:after {
  747. content: "";
  748. position: absolute;
  749. top: 100%;
  750. left: 50%;
  751. transform: translateX(-50%);
  752. width: 0;
  753. height: 0;
  754. border-style: solid;
  755. border-width: 5px 5px 0 5px;
  756. border-color: #4E4B46 transparent transparent transparent;
  757. }
  758. }
  759. }
  760. }
  761. }
  762. @font-face {
  763. font-family: "mxdatepickericon";
  764. src: url('data:application/x-font-woff2;charset=utf-8;base64,d09GMgABAAAAAAMYAAsAAAAACBgAAALMAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHEIGVgCDIgqDRIJiATYCJAMUCwwABCAFhG0HSRvfBsg+QCa3noNAyAQ9w6GDvbwpNp2vloCyn8bD/x+y+/5qDhtj+T4eRVEcbsCoKMFASzCgLdDkmqYDwgxkWQ6YH5L/YnppOlLEjlnter43YRjU7M6vJ3iGADVAgJn5kqjv/wEii23T86UsAQT+04fV+o97VTMx4PPZt4DlorLXwIQiGMA5uhaVrBWqGHfQXcTEiE+PE+g2SUlxWlLVBHwUYFMgrgwSB3wstTKSGzqF1nOyiGeeOtNjV4An/vvxR58PSc3AzrMViyDvPo/7dVEUzn5GROfIWAcU4rLXfMFdhte56y4We9gGNEVIezkBOOaQXUrbTf/hJVkhGpDdCw7dSOEzByMEn3kIic98hMxnAfeFPKWCbjRcA148/HxhCEkaA94eGWFaGolsblpaWz8/Po2WVuNHh1fmBpZHIpqal9fOjizhTteY+RZ9rv02I/pq0W6QVH3pSncBz3m55r9ZIPycHfmenvxe4uyutIgfT5u4bgkDusl9gcF0rnfnz+b2NpSaQWBFeu8GIL1xQj5AH/6FAsEr/50F28e/gA9ny6KjLrxIp0TE+UucmQOl5AFNLXkzZufWamWHYEI39PEP2If97CMdm51N6DSmIekwAVmneXTBr0PVYx+aTgfQbU3p+R4jKHdRurBq0oEw6AKSfm+QDbpGF/w3VOP+oBnMHbqdx409FjP4RRHHkAj5IWgQiBUjHfMTuQ1Icpg5avI4sQVRu8EHdWptM1aKrIjuscfeL+kZwxBTYoElztOQ2UygjRIjEphaZsyWodHgvm9SC8QC/JygEA6DiCDeEMhAQFhhOpvxa/18A0TiYMahIy0L2hYIZWeYH9JR085Al4qts1re5St2/SR6DINBGEVYQCWOETHDMAHZ+pcZIQJGTV4RtMmg8UbhuWL1+VLLA2RFHYC71kiRo0SNpjwQh8pj2EFU3oTNmS1WqgIA') format('woff2');
  765. }
  766. .picker-icon {
  767. font-family: "mxdatepickericon" !important;
  768. }
  769. .picker-icon-you:before {
  770. content: "\e63e";
  771. }
  772. .picker-icon-zuo:before {
  773. content: "\e640";
  774. }
  775. .picker-icon-zuozuo:before {
  776. content: "\e641";
  777. }
  778. .picker-icon-youyou:before {
  779. content: "\e642";
  780. }
  781. </style>