mx-datepicker.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  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. console.log(defaultFormat)
  499. let fillTime = (date, timeArr) => {
  500. date.setHours(timeArr[0], timeArr[1]);
  501. if (this.showSeconds) date.setSeconds(timeArr[2]);
  502. };
  503. if (this.type == 'time') {
  504. let date = new Date();
  505. fillTime(date, this.beginTime);
  506. result.value = DateTools.format(date, this.format ? this.format : defaultFormat.time);
  507. result.date = date;
  508. console.log(result)
  509. } else {
  510. if (this.isMultiSelect) {
  511. let values = [],
  512. dates = [];
  513. if (this.checkeds.length < 2) return uni.showToast({
  514. icon: 'none',
  515. title: '请选择两个日期'
  516. });
  517. this.checkeds.forEach((date, index) => {
  518. let newDate = new Date(date);
  519. if (this.isContainTime) {
  520. let time = [this.beginTime, this.endTime];
  521. fillTime(newDate, time[index]);
  522. }
  523. values.push(DateTools.format(newDate, this.format ? this.format : defaultFormat[this.isContainTime ?
  524. 'datetime' : 'date']));
  525. dates.push(newDate);
  526. });
  527. result.value = values;
  528. result.date = dates;
  529. } else {
  530. let newDate = new Date(this.checkeds[0]);
  531. if (this.isContainTime) {
  532. newDate.setHours(this.beginTime[0], this.beginTime[1]);
  533. if (this.showSeconds) newDate.setSeconds(this.beginTime[2]);
  534. }
  535. result.value = DateTools.format(newDate, this.format ? this.format : defaultFormat[this.isContainTime ?
  536. 'datetime' : 'date']);
  537. result.date = newDate;
  538. }
  539. }
  540. this.$emit('confirm', result);
  541. }
  542. },
  543. computed: {
  544. BeginTitle() {
  545. let value = '未选择';
  546. if (this.checkeds.length) value = DateTools.format(this.checkeds[0], 'yy/mm/dd');
  547. return value;
  548. },
  549. EndTitle() {
  550. let value = '未选择';
  551. if (this.checkeds.length == 2) value = DateTools.format(this.checkeds[1], 'yy/mm/dd');
  552. return value;
  553. },
  554. PickerTimeTitle() {
  555. return DateTools.formatTimeArray(this.timeValue, this.showSeconds);
  556. },
  557. BeginTimeTitle() {
  558. return this.BeginTitle != '未选择' ? DateTools.formatTimeArray(this.beginTime, this.showSeconds) : '';
  559. },
  560. EndTimeTitle() {
  561. return this.EndTitle != '未选择' ? DateTools.formatTimeArray(this.endTime, this.showSeconds) : '';
  562. }
  563. },
  564. watch: {
  565. show(newValue, oldValue) {
  566. newValue && this.setValue(this.value);
  567. this.isShow = newValue;
  568. },
  569. value(newValue, oldValue) {
  570. setTimeout(()=>{
  571. this.setValue(newValue);
  572. }, 0);
  573. }
  574. }
  575. }
  576. </script>
  577. <style lang="scss" scoped>
  578. $z-index: 100;
  579. $cell-spacing: 20upx;
  580. $calendar-size: 630upx;
  581. $calendar-item-size: 90upx;
  582. .picker {
  583. position: fixed;
  584. z-index: $z-index;
  585. background: rgba(0, 0, 0, .2);
  586. left: 0;
  587. top: 0;
  588. width: 100%;
  589. height: 100%;
  590. font-size: 28upx;
  591. &-btn {
  592. padding: $cell-spacing*0.5 $cell-spacing;
  593. border-radius: 12upx;
  594. color: #666;
  595. &-active {
  596. background: rgba(0, 0, 0, .1);
  597. }
  598. }
  599. &-display {
  600. color: #666;
  601. &-text {
  602. color: #000;
  603. margin: 0 $cell-spacing*0.5;
  604. }
  605. &-link {
  606. display: inline-block;
  607. &-active {
  608. background: rgba(0, 0, 0, .1);
  609. }
  610. }
  611. }
  612. &-time {
  613. width: $calendar-size - 80upx !important;
  614. left: ((750upx - $calendar-size) / 2 + 40upx) !important;
  615. }
  616. &-modal {
  617. background: #fff;
  618. position: absolute;
  619. top: 50%;
  620. left: (750upx - $calendar-size) / 2;
  621. width: $calendar-size;
  622. transform: translateY(-50%);
  623. box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1);
  624. border-radius: 12upx;
  625. &-header {
  626. text-align: center;
  627. line-height: 80upx;
  628. font-size: 32upx;
  629. &-title {
  630. display: inline-block;
  631. width: 40%;
  632. }
  633. .picker-icon {
  634. display: inline-block;
  635. line-height: 50upx;
  636. width: 50upx;
  637. height: 50upx;
  638. border-radius: 50upx;
  639. text-align: center;
  640. margin: 10upx;
  641. background: #fff;
  642. font-size: 36upx;
  643. &-active {
  644. background: rgba(0, 0, 0, .1);
  645. }
  646. }
  647. }
  648. &-body {
  649. width: $calendar-size !important;
  650. height: $calendar-size !important;
  651. position: relative;
  652. }
  653. &-time {
  654. width: 100%;
  655. height: 180upx;
  656. text-align: center;
  657. line-height: 60upx;
  658. }
  659. &-footer {
  660. display: flex;
  661. justify-content: space-between;
  662. align-items: center;
  663. padding: $cell-spacing;
  664. &-info {
  665. flex-grow: 1;
  666. }
  667. &-btn {
  668. flex-shrink: 0;
  669. display: flex;
  670. }
  671. }
  672. }
  673. &-calendar {
  674. position: absolute;
  675. left: 0;
  676. top: 0;
  677. width: 100%;
  678. height: 100%;
  679. display: flex;
  680. align-items: center;
  681. flex-wrap: wrap;
  682. &-view {
  683. position: relative;
  684. width: $calendar-item-size;
  685. height: $calendar-item-size;
  686. text-align: center;
  687. &-bgbegin,
  688. &-bg,
  689. &-bgend,
  690. &-item,
  691. &-dot,
  692. &-tips {
  693. position: absolute;
  694. transition: .2s;
  695. }
  696. &-bgbegin,
  697. &-bg,
  698. &-bgend {
  699. opacity: .15;
  700. height: 80%;
  701. }
  702. &-bg {
  703. left: 0;
  704. top: 10%;
  705. width: 100%;
  706. }
  707. &-bgbegin {
  708. border-radius: $calendar-item-size 0 0 $calendar-item-size;
  709. top: 10%;
  710. left: 10%;
  711. width: 90%;
  712. }
  713. &-bgend {
  714. border-radius: 0 $calendar-item-size $calendar-item-size 0;
  715. top: 10%;
  716. left: 0%;
  717. width: 90%;
  718. }
  719. &-item {
  720. left: 5%;
  721. top: 5%;
  722. width: 90%;
  723. height: 90%;
  724. border-radius: $calendar-item-size;
  725. display: flex;
  726. align-items: center;
  727. justify-content: center;
  728. }
  729. &-dot {
  730. right: 10%;
  731. top: 10%;
  732. width: 12upx;
  733. height: 12upx;
  734. border-radius: 12upx;
  735. }
  736. &-tips {
  737. bottom: 100%;
  738. left: 50%;
  739. transform: translateX(-50%);
  740. background: #4E4B46;
  741. color: #fff;
  742. border-radius: 12upx;
  743. padding: 10upx 20upx;
  744. font-size: 24upx;
  745. width: max-content;
  746. margin-bottom: 5px;
  747. pointer-events: none;
  748. &:after {
  749. content: "";
  750. position: absolute;
  751. top: 100%;
  752. left: 50%;
  753. transform: translateX(-50%);
  754. width: 0;
  755. height: 0;
  756. border-style: solid;
  757. border-width: 5px 5px 0 5px;
  758. border-color: #4E4B46 transparent transparent transparent;
  759. }
  760. }
  761. }
  762. }
  763. }
  764. @font-face {
  765. font-family: "mxdatepickericon";
  766. 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');
  767. }
  768. .picker-icon {
  769. font-family: "mxdatepickericon" !important;
  770. }
  771. .picker-icon-you:before {
  772. content: "\e63e";
  773. }
  774. .picker-icon-zuo:before {
  775. content: "\e640";
  776. }
  777. .picker-icon-zuozuo:before {
  778. content: "\e641";
  779. }
  780. .picker-icon-youyou:before {
  781. content: "\e642";
  782. }
  783. </style>