mx-datepicker.vue 24 KB

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