tui-calendar.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. <template>
  2. <view @touchmove.stop.prevent="stop" v-if="isFixed">
  3. <view class="tui-bottom-popup" :class="{'tui-popup-show': isShow}">
  4. <view class="tui-calendar-header" :class="{ 'tui-calendar-radius': radius }">
  5. <view>{{title}}</view>
  6. <view class="tui-iconfont tui-font-close" hover-class="tui-opacity" :hover-stay-time="150" @tap="hide">
  7. </view>
  8. </view>
  9. <view class="tui-date-box">
  10. <view class="tui-iconfont tui-font-arrowleft" :style="{ color: yearArrowColor }"
  11. hover-class="tui-opacity" :hover-stay-time="150" v-if="arrowType == 1" @tap="changeYear(0)"></view>
  12. <view class="tui-iconfont tui-font-arrowleft" :style="{ color: monthArrowColor }"
  13. hover-class="tui-opacity" :hover-stay-time="150" @tap="changeMonth(0)"></view>
  14. <view class="tui-date_time">{{ showTitle }}</view>
  15. <view class="tui-iconfont tui-font-arrowright" :style="{ color: monthArrowColor }"
  16. hover-class="tui-opacity" :hover-stay-time="150" @tap="changeMonth(1)"></view>
  17. <view class="tui-iconfont tui-font-arrowright" :style="{ color: yearArrowColor }"
  18. hover-class="tui-opacity" :hover-stay-time="150" v-if="arrowType == 1" @tap="changeYear(1)"></view>
  19. </view>
  20. <view class="tui-date-header">
  21. <view class="tui-date">日</view>
  22. <view class="tui-date">一</view>
  23. <view class="tui-date">二</view>
  24. <view class="tui-date">三</view>
  25. <view class="tui-date">四</view>
  26. <view class="tui-date">五</view>
  27. <view class="tui-date">六</view>
  28. </view>
  29. <view class="tui-date-content" :class="{ 'tui-flex-start': isFixed && fixedHeight }"
  30. :style="{ height: isFixed && fixedHeight ? dateHeight * 6 + 'px' : 'auto' }">
  31. <block v-for="(item, index) in weekdayArr" :key="index">
  32. <view class="tui-date"></view>
  33. </block>
  34. <view class="tui-date" :class="{
  35. 'tui-date-pd_0': isFixed && fixedHeight,
  36. 'tui-opacity': openDisAbled(year, month, index + 1),
  37. 'tui-start-date': (type == 2 && startDate == `${year}-${month}-${index + 1}`) || type == 1,
  38. 'tui-end-date': (type == 2 && endDate == `${year}-${month}-${index + 1}`) || type == 1
  39. }" :style="{ backgroundColor: isFixed ? getColor(index, 1) : 'transparent', height: isFixed && fixedHeight ? dateHeight + 'px' : 'auto' }"
  40. v-for="(item, index) in daysArr" :key="index" @tap="dateClick(index)">
  41. <view class="tui-date-text"
  42. :style="{ color: isFixed ? getColor(index, 2) : getStatusData(3, index), backgroundColor: getStatusData(2, index) }">
  43. <view v-if="isFixed || !getStatusData(4, index)">{{ index + 1 }}</view>
  44. <view v-if="!getStatusData(4, index)" class="tui-custom-desc"
  45. :class="{ 'tui-lunar-unshow': !lunar && isFixed }">
  46. {{ getDescText(index, startDate, endDate) }}
  47. </view>
  48. <text class="tui-iconfont tui-font-check" v-if="getStatusData(4, index)"></text>
  49. </view>
  50. <view class="tui-date-desc" :style="{ color: activeColor }"
  51. v-if="!lunar && type == 2 && startDate == `${year}-${month}-${index + 1}` && startDate != endDate">
  52. {{ startText }}
  53. </view>
  54. <view class="tui-date-desc" :style="{ color: activeColor }"
  55. v-if="!lunar && type == 2 && endDate == `${year}-${month}-${index + 1}`">{{ endText }}</view>
  56. </view>
  57. <view class="tui-bg-month">{{ month }}</view>
  58. </view>
  59. <view class="tui-calendar-op">
  60. <view class="tui-calendar-result">
  61. <text>{{ type == 1 ? activeDate : startDate }}</text>
  62. <text v-if="endDate">至{{ endDate }}</text>
  63. </view>
  64. <view class="tui-calendar-btn_box">
  65. <tui-button :type="btnType" height="72rpx" shape="circle" :size="28" :disabled="disabled"
  66. @click="btnFix(false)">确定
  67. </tui-button>
  68. </view>
  69. </view>
  70. </view>
  71. <view class="tui-popup-mask" :class="[isShow ? 'tui-mask-show' : '']" @tap="hide"></view>
  72. </view>
  73. <view v-else>
  74. <view class="tui-date-box">
  75. <view class="tui-iconfont tui-font-arrowleft" :style="{ color: yearArrowColor }" hover-class="tui-opacity"
  76. :hover-stay-time="150" v-if="arrowType == 1" @tap="changeYear(0)"></view>
  77. <view class="tui-iconfont tui-font-arrowleft" :style="{ color: monthArrowColor }" hover-class="tui-opacity"
  78. :hover-stay-time="150" @tap="changeMonth(0)"></view>
  79. <view class="tui-date_time">{{ showTitle }}</view>
  80. <view class="tui-iconfont tui-font-arrowright" :style="{ color: monthArrowColor }" hover-class="tui-opacity"
  81. :hover-stay-time="150" @tap="changeMonth(1)"></view>
  82. <view class="tui-iconfont tui-font-arrowright" :style="{ color: yearArrowColor }" hover-class="tui-opacity"
  83. :hover-stay-time="150" v-if="arrowType == 1" @tap="changeYear(1)"></view>
  84. </view>
  85. <view class="tui-date-header">
  86. <view class="tui-date">日</view>
  87. <view class="tui-date">一</view>
  88. <view class="tui-date">二</view>
  89. <view class="tui-date">三</view>
  90. <view class="tui-date">四</view>
  91. <view class="tui-date">五</view>
  92. <view class="tui-date">六</view>
  93. </view>
  94. <view class="tui-date-content" :style="{ height: isFixed && fixedHeight ? dateHeight * 6 + 'px' : 'auto' }">
  95. <block v-for="(item, index) in weekdayArr" :key="index">
  96. <view class="tui-date"></view>
  97. </block>
  98. <view class="tui-date" :class="{
  99. 'tui-date-pd_0': isFixed && fixedHeight,
  100. 'tui-opacity': openDisAbled(year, month, index + 1),
  101. 'tui-start-date': (type == 2 && startDate == `${year}-${month}-${index + 1}`) || type == 1,
  102. 'tui-end-date': (type == 2 && endDate == `${year}-${month}-${index + 1}`) || type == 1
  103. }" :style="{ backgroundColor: isFixed ? getColor(index, 1) : 'transparent', height: isFixed && fixedHeight ? dateHeight + 'px' : 'auto' }"
  104. v-for="(item, index) in daysArr" :key="index" @tap="dateClick(index)">
  105. <view class="tui-date-text"
  106. :style="{ color: isFixed ? getColor(index, 2) : getStatusData(3, index), backgroundColor: getStatusData(2, index) }">
  107. <view v-if="isFixed || !getStatusData(4, index)">{{ index + 1 }}</view>
  108. <view v-if="!getStatusData(4, index)" class="tui-custom-desc"
  109. :class="{ 'tui-lunar-unshow': !lunar && isFixed }">
  110. {{ getDescText(index, startDate, endDate) }}
  111. </view>
  112. <text class="tui-iconfont tui-font-check" v-if="getStatusData(4, index)"></text>
  113. </view>
  114. <view class="tui-date-desc" :style="{ color: activeColor }"
  115. v-if="!lunar && type == 2 && startDate == `${year}-${month}-${index + 1}` && startDate != endDate">
  116. {{ startText }}
  117. </view>
  118. <view class="tui-date-desc" :style="{ color: activeColor }"
  119. v-if="!lunar && type == 2 && endDate == `${year}-${month}-${index + 1}`">{{ endText }}</view>
  120. </view>
  121. <view class="tui-bg-month">{{ month }}</view>
  122. </view>
  123. </view>
  124. </template>
  125. <script>
  126. //easycom组件模式 无需手动引入
  127. // import tuiButton from "../tui-button/tui-button"
  128. import calendar from './tui-calendar.js';
  129. export default {
  130. name: 'tuiCalendar',
  131. emits: ['hide', 'change'],
  132. // components:{
  133. // tuiButton
  134. // },
  135. props: {
  136. //1-切换月份和年份 2-切换月份
  137. arrowType: {
  138. type: [Number, String],
  139. default: 1
  140. },
  141. //1-单个日期选择 2-开始日期+结束日期选择 3-多个日期
  142. type: {
  143. type: Number,
  144. default: 1
  145. },
  146. //可切换最大年份
  147. maxYear: {
  148. type: Number,
  149. default: 2030
  150. },
  151. //可切换最小年份
  152. minYear: {
  153. type: Number,
  154. default: 1920
  155. },
  156. //最小可选日期(不在范围内日期禁用不可选)
  157. minDate: {
  158. type: String,
  159. default: '1920-01-01'
  160. },
  161. /**
  162. * 最大可选日期
  163. * 默认最大值为今天,之后的日期不可选
  164. * 2030-12-31
  165. * */
  166. maxDate: {
  167. type: String,
  168. default: ''
  169. },
  170. title:{
  171. type:String,
  172. default:'日期选择'
  173. },
  174. //显示圆角
  175. radius: {
  176. type: Boolean,
  177. default: true
  178. },
  179. //状态 数据顺序与当月天数一致,index=>day
  180. /**
  181. * [{
  182. * text:"", 描述:2字以内
  183. * value:"",状态值
  184. * bgColor:"",背景色
  185. * color:"" 文字颜色,
  186. * check:false //是否显示对勾
  187. *
  188. }]
  189. *
  190. * **/
  191. status: {
  192. type: Array,
  193. default () {
  194. return [];
  195. }
  196. },
  197. //月份切换箭头颜色
  198. monthArrowColor: {
  199. type: String,
  200. default: '#999'
  201. },
  202. //年份切换箭头颜色
  203. yearArrowColor: {
  204. type: String,
  205. default: '#bcbcbc'
  206. },
  207. //默认日期字体颜色
  208. color: {
  209. type: String,
  210. default: '#333'
  211. },
  212. //选中|起始结束日期背景色
  213. activeBgColor: {
  214. type: String,
  215. default: '#5677fc'
  216. },
  217. //选中|起始结束日期字体颜色
  218. activeColor: {
  219. type: String,
  220. default: '#fff'
  221. },
  222. //范围内日期背景色
  223. rangeBgColor: {
  224. type: String,
  225. default: 'rgba(86,119,252,0.1)'
  226. },
  227. //范围内日期字体颜色
  228. rangeColor: {
  229. type: String,
  230. default: '#5677fc'
  231. },
  232. //type=2时生效,起始日期自定义文案
  233. startText: {
  234. type: String,
  235. default: '开始'
  236. },
  237. //type=2时生效,结束日期自定义文案
  238. endText: {
  239. type: String,
  240. default: '结束'
  241. },
  242. //按钮样式类型
  243. btnType: {
  244. type: String,
  245. default: 'primary'
  246. },
  247. //固定在底部
  248. isFixed: {
  249. type: Boolean,
  250. default: false
  251. },
  252. //固定日历容器高度,isFixed=true时生效
  253. fixedHeight: {
  254. type: Boolean,
  255. default: true
  256. },
  257. //当前选中日期带选中效果
  258. isActiveCurrent: {
  259. type: Boolean,
  260. default: true
  261. },
  262. //切换年月是否触发事件 type=1时生效
  263. isChange: {
  264. type: Boolean,
  265. default: false
  266. },
  267. //是否显示农历
  268. lunar: {
  269. type: Boolean,
  270. default: false
  271. },
  272. //初始化起始选中日期 格式: 2020-06-06 或 2020/06/06 【type=1 or 2】
  273. initStartDate: {
  274. type: [String,Array],
  275. default: ''
  276. },
  277. //初始化结束日期 格式: 2020-06-06 或 2020/06/06【type=2】
  278. initEndDate: {
  279. type: String,
  280. default: ''
  281. }
  282. },
  283. data() {
  284. return {
  285. isShow: false,
  286. weekday: 1, // 星期几,值为1-7
  287. weekdayArr: [],
  288. days: 0, //当前月有多少天
  289. daysArr: [],
  290. showTitle: '',
  291. year: 2020,
  292. month: 0,
  293. day: 0,
  294. startYear: 0,
  295. startMonth: 0,
  296. startDay: 0,
  297. endYear: 0,
  298. endMonth: 0,
  299. endDay: 0,
  300. today: '',
  301. activeDate: '',
  302. startDate: '',
  303. endDate: '',
  304. isStart: true,
  305. min: null,
  306. max: null,
  307. dateHeight: 20
  308. };
  309. },
  310. computed: {
  311. dataChange() {
  312. return `${this.type}-${this.minDate}-${this.maxDate}-${this.initStartDate}-${this.initEndDate}`;
  313. },
  314. disabled() {
  315. return this.type == 2 && (!this.startDate || !this.endDate)
  316. }
  317. },
  318. watch: {
  319. dataChange(val) {
  320. this.init();
  321. },
  322. fixedHeight(val) {
  323. if (val) {
  324. this.initDateHeight();
  325. }
  326. }
  327. },
  328. created() {
  329. this.init();
  330. },
  331. methods: {
  332. getColor(index, type) {
  333. let color = type == 1 ? '' : this.color;
  334. let day = index + 1;
  335. let date = `${this.year}-${this.month}-${day}`;
  336. let timestamp = new Date(date.replace(/\-/g, '/')).getTime();
  337. let start = this.startDate.replace(/\-/g, '/');
  338. let end = this.endDate.replace(/\-/g, '/');
  339. if ((this.isActiveCurrent && this.activeDate == date) || this.startDate == date || this.endDate == date) {
  340. color = type == 1 ? this.activeBgColor : this.activeColor;
  341. } else if (this.endDate && timestamp > new Date(start).getTime() && timestamp < new Date(end).getTime()) {
  342. color = type == 1 ? this.rangeBgColor : this.rangeColor;
  343. }
  344. return color;
  345. },
  346. //获取状态数据
  347. getStatusData(type, index) {
  348. //1-描述text,2-bgColor背景色,3-color文字颜色 4-check 是否显示对勾
  349. let val = ['', 'transparent', '#333', ''][type - 1];
  350. if (!this.isFixed && this.status && this.status.length > 0) {
  351. let item = this.status[index];
  352. if (item) {
  353. switch (type) {
  354. case 1:
  355. val = item.text;
  356. break;
  357. case 2:
  358. val = item.bgColor;
  359. break;
  360. case 3:
  361. val = item.color;
  362. break;
  363. case 4:
  364. val = item.check;
  365. break;
  366. default:
  367. break;
  368. }
  369. }
  370. }
  371. return val;
  372. },
  373. getDescText(index, startDate, endDate) {
  374. let text = this.lunar ? this.getLunar(this.year, this.month, index + 1) : '';
  375. if (this.isFixed && this.type == 2) {
  376. //此判断不能与上面条件一起判断
  377. if (this.lunar) {
  378. let date = `${this.year}-${this.month}-${index + 1}`;
  379. if (startDate == date && startDate != endDate) {
  380. text = this.startText;
  381. } else if (endDate == date) {
  382. text = this.endText;
  383. }
  384. }
  385. } else {
  386. let status = this.getStatusData(1, index);
  387. if (status) text = status;
  388. }
  389. return text;
  390. },
  391. getLunar(year, month, day) {
  392. let obj = calendar.solar2lunar(year, month, day);
  393. return obj.IDayCn;
  394. },
  395. initDateHeight() {
  396. if (this.fixedHeight && this.isFixed) {
  397. this.dateHeight = uni.getSystemInfoSync().windowWidth / 7;
  398. }
  399. },
  400. init() {
  401. this.initDateHeight();
  402. let now = new Date();
  403. this.year = now.getFullYear();
  404. this.month = now.getMonth() + 1;
  405. this.day = now.getDate();
  406. this.today = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`;
  407. this.activeDate = this.today;
  408. this.min = this.initDate(this.minDate);
  409. this.max = this.initDate(this.maxDate || this.today);
  410. this.startDate = '';
  411. this.startYear = 0;
  412. this.startMonth = 0;
  413. this.startDay = 0;
  414. if (this.initStartDate) {
  415. let start = new Date(this.initStartDate.replace(/\-/g, '/'));
  416. if (this.type == 1) {
  417. this.year = start.getFullYear();
  418. this.month = start.getMonth() + 1;
  419. this.day = start.getDate();
  420. this.activeDate = `${start.getFullYear()}-${start.getMonth() + 1}-${start.getDate()}`;
  421. } else {
  422. this.startDate = `${start.getFullYear()}-${start.getMonth() + 1}-${start.getDate()}`;
  423. this.startYear = start.getFullYear();
  424. this.startMonth = start.getMonth() + 1;
  425. this.startDay = start.getDate();
  426. this.activeDate = '';
  427. }
  428. }
  429. this.endYear = 0;
  430. this.endMonth = 0;
  431. this.endDay = 0;
  432. this.endDate = '';
  433. if (this.initEndDate && this.type == 2) {
  434. let end = new Date(this.initEndDate.replace(/\-/g, '/'));
  435. this.endDate = `${end.getFullYear()}-${end.getMonth() + 1}-${end.getDate()}`;
  436. this.endYear = end.getFullYear();
  437. this.endMonth = end.getMonth() + 1;
  438. this.endDay = end.getDate();
  439. this.activeDate = '';
  440. this.year = end.getFullYear();
  441. this.month = end.getMonth() + 1;
  442. this.day = end.getDate();
  443. }
  444. this.isStart = true;
  445. this.changeData();
  446. },
  447. //日期处理
  448. initDate(date) {
  449. let fdate = date.split('-');
  450. return {
  451. year: Number(fdate[0] || 1920),
  452. month: Number(fdate[1] || 1),
  453. day: Number(fdate[2] || 1)
  454. };
  455. },
  456. openDisAbled: function(year, month, day) {
  457. let bool = true;
  458. let date = `${year}/${month}/${day}`;
  459. // let today = this.today.replace(/\-/g, '/');
  460. let min = `${this.min.year}/${this.min.month}/${this.min.day}`;
  461. let max = `${this.max.year}/${this.max.month}/${this.max.day}`;
  462. let timestamp = new Date(date).getTime();
  463. if (timestamp >= new Date(min).getTime() && timestamp <= new Date(max).getTime()) {
  464. bool = false;
  465. }
  466. return bool;
  467. },
  468. generateArray: function(start, end) {
  469. return Array.from(new Array(end + 1).keys()).slice(start);
  470. },
  471. formatNum: function(num) {
  472. return num < 10 ? '0' + num : num + '';
  473. },
  474. stop() {
  475. return false;
  476. },
  477. //一个月有多少天
  478. getMonthDay(year, month) {
  479. let days = new Date(year, month, 0).getDate();
  480. return days;
  481. },
  482. getWeekday(year, month) {
  483. let date = new Date(`${year}/${month}/01 00:00:00`);
  484. return date.getDay();
  485. },
  486. checkRange(year) {
  487. let overstep = false;
  488. if (year < this.minYear || year > this.maxYear) {
  489. uni.showToast({
  490. title: '日期超出范围啦~',
  491. icon: 'none'
  492. });
  493. overstep = true;
  494. }
  495. return overstep;
  496. },
  497. changeMonth(isAdd) {
  498. if (isAdd) {
  499. let month = this.month + 1;
  500. let year = month > 12 ? this.year + 1 : this.year;
  501. if (!this.checkRange(year)) {
  502. this.month = month > 12 ? 1 : month;
  503. this.year = year;
  504. this.changeData();
  505. }
  506. } else {
  507. let month = this.month - 1;
  508. let year = month < 1 ? this.year - 1 : this.year;
  509. if (!this.checkRange(year)) {
  510. this.month = month < 1 ? 12 : month;
  511. this.year = year;
  512. this.changeData();
  513. }
  514. }
  515. },
  516. changeYear(isAdd) {
  517. let year = isAdd ? this.year + 1 : this.year - 1;
  518. if (!this.checkRange(year)) {
  519. this.year = year;
  520. this.changeData();
  521. }
  522. },
  523. changeData() {
  524. this.days = this.getMonthDay(this.year, this.month);
  525. this.daysArr = this.generateArray(1, this.days);
  526. this.weekday = this.getWeekday(this.year, this.month);
  527. this.weekdayArr = this.generateArray(1, this.weekday);
  528. this.showTitle = `${this.year}年${this.month}月`;
  529. if (this.isChange && this.type == 1) {
  530. this.btnFix(true);
  531. }
  532. },
  533. dateClick: function(day) {
  534. day += 1;
  535. if (!this.openDisAbled(this.year, this.month, day)) {
  536. this.day = day;
  537. let date = `${this.year}-${this.month}-${day}`;
  538. if (this.type == 1) {
  539. this.activeDate = date;
  540. } else {
  541. let compare = new Date(date.replace(/\-/g, '/')).getTime() < new Date(this.startDate.replace(
  542. /\-/g, '/')).getTime();
  543. if (this.isStart || compare) {
  544. this.startDate = date;
  545. this.startYear = this.year;
  546. this.startMonth = this.month;
  547. this.startDay = this.day;
  548. this.endYear = 0;
  549. this.endMonth = 0;
  550. this.endDay = 0;
  551. this.endDate = '';
  552. this.activeDate = '';
  553. this.isStart = false;
  554. } else {
  555. this.endDate = date;
  556. this.endYear = this.year;
  557. this.endMonth = this.month;
  558. this.endDay = this.day;
  559. this.isStart = true;
  560. }
  561. }
  562. if (!this.isFixed) {
  563. this.btnFix();
  564. }
  565. }
  566. },
  567. show() {
  568. this.isShow = true;
  569. },
  570. hide() {
  571. this.isShow = false;
  572. this.$emit('hide', {})
  573. },
  574. getWeekText(date) {
  575. date = new Date(`${date.replace(/\-/g, '/')} 00:00:00`);
  576. let week = date.getDay();
  577. return '星期' + ['日', '一', '二', '三', '四', '五', '六'][week];
  578. },
  579. btnFix(show) {
  580. if (!show) {
  581. this.hide();
  582. }
  583. if (this.type == 1) {
  584. let arr = this.activeDate.split('-');
  585. let year = this.isChange ? this.year : Number(arr[0]);
  586. let month = this.isChange ? this.month : Number(arr[1]);
  587. let day = this.isChange ? this.day : Number(arr[2]);
  588. //当前月有多少天
  589. let days = this.getMonthDay(year, month);
  590. let result = `${year}-${this.formatNum(month)}-${this.formatNum(day)}`;
  591. let weekText = this.getWeekText(result);
  592. let isToday = false;
  593. if (`${year}-${month}-${day}` == this.today) {
  594. //今天
  595. isToday = true;
  596. }
  597. let lunar = calendar.solar2lunar(year, month, day);
  598. this.$emit('change', {
  599. year: year,
  600. month: month,
  601. day: day,
  602. days: days,
  603. result: result,
  604. week: weekText,
  605. isToday: isToday,
  606. switch: show, //是否是切换年月操作
  607. lunar: lunar
  608. });
  609. } else {
  610. if (!this.startDate || !this.endDate) return;
  611. let startMonth = this.formatNum(this.startMonth);
  612. let startDay = this.formatNum(this.startDay);
  613. let startDate = `${this.startYear}-${startMonth}-${startDay}`;
  614. let startWeek = this.getWeekText(startDate);
  615. let startLunar = calendar.solar2lunar(this.startYear, startMonth, startDay);
  616. let endMonth = this.formatNum(this.endMonth);
  617. let endDay = this.formatNum(this.endDay);
  618. let endDate = `${this.endYear}-${endMonth}-${endDay}`;
  619. let endWeek = this.getWeekText(endDate);
  620. let endLunar = calendar.solar2lunar(this.endYear, endMonth, endDay);
  621. this.$emit('change', {
  622. startYear: this.startYear,
  623. startMonth: this.startMonth,
  624. startDay: this.startDay,
  625. startDate: startDate,
  626. startWeek: startWeek,
  627. startLunar: startLunar,
  628. endYear: this.endYear,
  629. endMonth: this.endMonth,
  630. endDay: this.endDay,
  631. endDate: endDate,
  632. endWeek: endWeek,
  633. endLunar: endLunar
  634. });
  635. }
  636. }
  637. }
  638. };
  639. </script>
  640. <style scoped>
  641. @font-face {
  642. font-family: 'tuiDateFont';
  643. src: url(data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAAAVgAA0AAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAAFRAAAABoAAAAci0/w50dERUYAAAUkAAAAHgAAAB4AKQANT1MvMgAAAaAAAABDAAAAVjxuSNNjbWFwAAAB+AAAAEoAAAFS5iPQt2dhc3AAAAUcAAAACAAAAAj//wADZ2x5ZgAAAlQAAAFHAAABvPf29TBoZWFkAAABMAAAADAAAAA2GMsN3WhoZWEAAAFgAAAAHQAAACQHjAOFaG10eAAAAeQAAAATAAAAFgzQAPJsb2NhAAACRAAAABAAAAAQAOoBSG1heHAAAAGAAAAAHgAAACABEwA3bmFtZQAAA5wAAAFJAAACiCnmEVVwb3N0AAAE6AAAADQAAABLUwjqHHjaY2BkYGAAYp5Gj5/x/DZfGbhZGEDg1tUn7+F00P/LzOuY9YFcDgYmkCgAa0gNlHjaY2BkYGBu+N/AEMPCAALM6xgYGVABCwBT4AMaAAAAeNpjYGRgYGBn0GZgYgABEMkFhAwM/8F8BgANaAFLAAB42mNgZGFgnMDAysDA1Ml0hoGBoR9CM75mMGLkAIoysDIzYAUBaa4pDA7PGJ49ZG7438AQw9zA0AAUZgTJAQDrcAy8AHjaY2GAABYIDgLCBQx1AAcEAc8AeNpjYGBgZoBgGQZGBhDwAfIYwXwWBgMgzQGETAwMzxifcTx7+P8/kMUAYUkxS/6VVIXqAgNGNgY4lxGoB6QPBTAyDHsAADDkDYkAAAAAAAAAAAAAADQAagC2AN542m2QsU7DMBCG/Tt1bNPUiUnkSgiVtqKpxJAgVLVbeAa6MaK+B4JXgJWBjY21UtW5gpkdMTFX7dzApaJLhXU6n8+n//ttxtn458N79XJWZ8eMxS00C4wy9A1EP8PQncAlIQzS4WgsVtPpSmwzV3OFRqLetH5TSQMK939X61ptPZ2p2EAttNMLBRMrtschQblDeS34aY50cIkCzg/B2Y5C+VpyQxhFkRgu515O8jvU5mmPM2O0wJ5Z27vhX+yMsV437WvCdTM+GI40MgwKfuGammC0uURqeqFMfe9cxaJclkt5GMaB1hIR1VobOgpEiKq+sLZcIrJWhO3/Jw7qWlYj1Jf21FaCtmd5bevrlk28O/7A4spXTl4KTh9MTlqQ8PESBRstReic+sRj0Dni9fIqmNS/pXNWCvWOeYBmx5S9Bsn9Ah+5WtAAeNp9kD1OAzEQhZ/zByQSQiCoXVEA2vyUKRMp9Ailo0g23pBo1155nUg5AS0VB6DlGByAGyDRcgpelkmTImvt6PObmeexAZzjGwr/3yXuhBWO8ShcwREy4Sr1F+Ea+V24jhY+hRvUf4SbuFUD4RYu1BsdVO2Eu5vSbcsKZxgIV3CKJ+Eq9ZVwjfwqXMcVPoQb1L+EmxjjV7iFa2WpDOFhMEFgnEFjig3jAjEcLJIyBtahOfRmEsxMTzd6ETubOBso71dilwMeaDnngCntPbdmvkon/mDLgdSYbh4FS7YpjS4idCgbXyyc1d2oc7D9nu22tNi/a4E1x+xRDWzU/D3bM9JIbAyvkJI18jK3pBJTj2hrrPG7ZynW814IiU68y/SIx5o0dTr3bmniwOLn8owcfbS5kj33qBw+Y1kIeb/dTsQgil2GP5PYcRkAAAB42mNgYoAALjDJyIAO2MGiTIxMjMyMLIys7GmJeRmlmWZQ2pQ5OSORLaU0Mz2/FACDfwlbAAAAAf//AAIAAQAAAAwAAAAWAAAAAgABAAMABgABAAQAAAACAAAAAHjaY2BgYGQAgqtL1DlA9K2rT97DaABNlwiuAAA=) format('woff');
  644. font-weight: normal;
  645. font-style: normal;
  646. }
  647. .tui-iconfont {
  648. font-family: 'tuiDateFont' !important;
  649. font-size: 36rpx;
  650. font-style: normal;
  651. -webkit-font-smoothing: antialiased;
  652. -moz-osx-font-smoothing: grayscale;
  653. }
  654. .tui-font-close:before {
  655. content: '\e608';
  656. }
  657. .tui-font-check:before {
  658. content: '\e6e1';
  659. }
  660. .tui-font-arrowright:before {
  661. content: '\e600';
  662. }
  663. .tui-font-arrowleft:before {
  664. content: '\e601';
  665. }
  666. .tui-date-box {
  667. width: 100%;
  668. display: flex;
  669. align-items: center;
  670. justify-content: center;
  671. padding: 20rpx 0 30rpx;
  672. background-color: #fff;
  673. }
  674. .tui-calendar-radius {
  675. border-top-left-radius: 20rpx;
  676. border-top-right-radius: 20rpx;
  677. overflow: hidden;
  678. }
  679. .tui-date_time {
  680. padding: 0 16rpx;
  681. color: #333;
  682. font-size: 32rpx;
  683. line-height: 32rpx;
  684. font-weight: bold;
  685. }
  686. .tui-font-arrowleft {
  687. margin-right: 32rpx;
  688. }
  689. .tui-font-arrowright {
  690. margin-left: 32rpx;
  691. }
  692. .tui-date-header {
  693. width: 100%;
  694. display: flex;
  695. align-items: center;
  696. background-color: #fff;
  697. font-size: 24rpx;
  698. line-height: 24rpx;
  699. color: #555;
  700. box-shadow: 0 15rpx 20rpx -15rpx #efefef;
  701. position: relative;
  702. z-index: 2;
  703. }
  704. .tui-date-content {
  705. width: 100%;
  706. display: flex;
  707. flex-wrap: wrap;
  708. padding: 12rpx 0;
  709. box-sizing: border-box;
  710. background-color: #fff;
  711. position: relative;
  712. }
  713. .tui-flex-start {
  714. align-content: flex-start;
  715. }
  716. .tui-bg-month {
  717. position: absolute;
  718. font-size: 260rpx;
  719. line-height: 260rpx;
  720. left: 50%;
  721. top: 50%;
  722. transform: translate(-50%, -50%);
  723. color: #f5f5f7;
  724. z-index: 1;
  725. }
  726. .tui-date {
  727. width: 14.2857%;
  728. display: flex;
  729. align-items: center;
  730. justify-content: center;
  731. padding: 12rpx 0;
  732. overflow: hidden;
  733. position: relative;
  734. z-index: 2;
  735. }
  736. .tui-date-pd_0 {
  737. padding: 0 !important;
  738. }
  739. .tui-start-date {
  740. border-top-left-radius: 8rpx;
  741. border-bottom-left-radius: 8rpx;
  742. }
  743. .tui-end-date {
  744. border-top-right-radius: 8rpx;
  745. border-bottom-right-radius: 8rpx;
  746. }
  747. .tui-date-text {
  748. width: 80rpx;
  749. height: 80rpx;
  750. display: flex;
  751. align-items: center;
  752. justify-content: center;
  753. flex-direction: column;
  754. font-size: 32rpx;
  755. line-height: 32rpx;
  756. position: relative;
  757. border-radius: 50%;
  758. }
  759. .tui-btn-calendar {
  760. padding: 16rpx;
  761. box-sizing: border-box;
  762. text-align: center;
  763. text-decoration: none;
  764. }
  765. .tui-opacity {
  766. opacity: 0.5;
  767. }
  768. .tui-bottom-popup {
  769. width: 100%;
  770. position: fixed;
  771. left: 0;
  772. right: 0;
  773. bottom: 0;
  774. z-index: 9999;
  775. visibility: hidden;
  776. transform: translate3d(0, 100%, 0);
  777. transform-origin: center;
  778. transition: all 0.3s ease-in-out;
  779. min-height: 20rpx;
  780. }
  781. .tui-popup-show {
  782. transform: translate3d(0, 0, 0);
  783. visibility: visible;
  784. }
  785. .tui-popup-mask {
  786. position: fixed;
  787. top: 0;
  788. left: 0;
  789. right: 0;
  790. bottom: 0;
  791. background: rgba(0, 0, 0, 0.6);
  792. z-index: 9996;
  793. transition: all 0.3s ease-in-out;
  794. opacity: 0;
  795. visibility: hidden;
  796. }
  797. .tui-mask-show {
  798. opacity: 1;
  799. visibility: visible;
  800. }
  801. .tui-calendar-header {
  802. width: 100%;
  803. height: 80rpx;
  804. padding: 0 40rpx;
  805. display: flex;
  806. justify-content: center;
  807. align-items: center;
  808. box-sizing: border-box;
  809. font-size: 30rpx;
  810. background-color: #fff;
  811. color: #555;
  812. position: relative;
  813. }
  814. .tui-font-close {
  815. position: absolute;
  816. right: 30rpx;
  817. top: 50%;
  818. transform: translateY(-50%);
  819. color: #999;
  820. }
  821. .tui-btn-calendar {
  822. padding: 16rpx;
  823. box-sizing: border-box;
  824. text-align: center;
  825. text-decoration: none;
  826. }
  827. .tui-font-check {
  828. color: #fff;
  829. font-size: 54rpx;
  830. line-height: 54rpx;
  831. }
  832. .tui-custom-desc {
  833. width: 100%;
  834. font-size: 24rpx;
  835. line-height: 24rpx;
  836. transform: scale(0.8);
  837. transform-origin: center center;
  838. text-align: center;
  839. }
  840. .tui-lunar-unshow {
  841. position: absolute;
  842. left: 0;
  843. bottom: 8rpx;
  844. z-index: 2;
  845. }
  846. .tui-date-desc {
  847. width: 100%;
  848. font-size: 24rpx;
  849. line-height: 24rpx;
  850. position: absolute;
  851. left: 0;
  852. transform: scale(0.8);
  853. transform-origin: center center;
  854. text-align: center;
  855. bottom: 8rpx;
  856. z-index: 2;
  857. }
  858. .tui-calendar-op {
  859. width: 100%;
  860. display: flex;
  861. align-items: center;
  862. justify-content: center;
  863. flex-direction: column;
  864. background-color: #fff;
  865. padding: 0 42rpx 30rpx;
  866. box-sizing: border-box;
  867. font-size: 24rpx;
  868. color: #666;
  869. }
  870. .tui-calendar-result {
  871. height: 48rpx;
  872. transform: scale(0.9);
  873. transform-origin: center 100%;
  874. }
  875. .tui-calendar-btn_box {
  876. width: 100%;
  877. }
  878. </style>