tui-calendar.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926
  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.vue"
  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. if (this.openDisAbled(this.year, this.month, this.day)) {
  411. this.year = this.min.year;
  412. this.month = this.min.month;
  413. this.day = this.min.day;
  414. this.activeDate = `${this.min.year}-${this.min.month}-${this.min.day}`;
  415. this.max = this.initDate(this.maxDate || this.minDate);
  416. }
  417. this.startDate = '';
  418. this.startYear = 0;
  419. this.startMonth = 0;
  420. this.startDay = 0;
  421. if (this.initStartDate) {
  422. let start = new Date(this.initStartDate.replace(/\-/g, '/'));
  423. if (this.type == 1) {
  424. this.year = start.getFullYear();
  425. this.month = start.getMonth() + 1;
  426. this.day = start.getDate();
  427. this.activeDate = `${start.getFullYear()}-${start.getMonth() + 1}-${start.getDate()}`;
  428. } else {
  429. this.startDate = `${start.getFullYear()}-${start.getMonth() + 1}-${start.getDate()}`;
  430. this.startYear = start.getFullYear();
  431. this.startMonth = start.getMonth() + 1;
  432. this.startDay = start.getDate();
  433. this.activeDate = '';
  434. }
  435. }
  436. this.endYear = 0;
  437. this.endMonth = 0;
  438. this.endDay = 0;
  439. this.endDate = '';
  440. if (this.initEndDate && this.type == 2) {
  441. let end = new Date(this.initEndDate.replace(/\-/g, '/'));
  442. this.endDate = `${end.getFullYear()}-${end.getMonth() + 1}-${end.getDate()}`;
  443. this.endYear = end.getFullYear();
  444. this.endMonth = end.getMonth() + 1;
  445. this.endDay = end.getDate();
  446. this.activeDate = '';
  447. this.year = end.getFullYear();
  448. this.month = end.getMonth() + 1;
  449. this.day = end.getDate();
  450. }
  451. this.isStart = true;
  452. this.changeData();
  453. },
  454. //日期处理
  455. initDate(date) {
  456. let fdate = date.split('-');
  457. return {
  458. year: Number(fdate[0] || 1920),
  459. month: Number(fdate[1] || 1),
  460. day: Number(fdate[2] || 1)
  461. };
  462. },
  463. openDisAbled: function(year, month, day) {
  464. let bool = true;
  465. let date = `${year}/${month}/${day}`;
  466. // let today = this.today.replace(/\-/g, '/');
  467. let min = `${this.min.year}/${this.min.month}/${this.min.day}`;
  468. let max = `${this.max.year}/${this.max.month}/${this.max.day}`;
  469. let timestamp = new Date(date).getTime();
  470. if (timestamp >= new Date(min).getTime() && timestamp <= new Date(max).getTime()) {
  471. bool = false;
  472. }
  473. return bool;
  474. },
  475. generateArray: function(start, end) {
  476. return Array.from(new Array(end + 1).keys()).slice(start);
  477. },
  478. formatNum: function(num) {
  479. return num < 10 ? '0' + num : num + '';
  480. },
  481. stop() {
  482. return false;
  483. },
  484. //一个月有多少天
  485. getMonthDay(year, month) {
  486. let days = new Date(year, month, 0).getDate();
  487. return days;
  488. },
  489. getWeekday(year, month) {
  490. let date = new Date(`${year}/${month}/01 00:00:00`);
  491. return date.getDay();
  492. },
  493. checkRange(year) {
  494. let overstep = false;
  495. if (year < this.minYear || year > this.maxYear) {
  496. uni.showToast({
  497. title: '日期超出范围啦~',
  498. icon: 'none'
  499. });
  500. overstep = true;
  501. }
  502. return overstep;
  503. },
  504. changeMonth(isAdd) {
  505. if (isAdd) {
  506. let month = this.month + 1;
  507. let year = month > 12 ? this.year + 1 : this.year;
  508. if (!this.checkRange(year)) {
  509. this.month = month > 12 ? 1 : month;
  510. this.year = year;
  511. this.changeData();
  512. }
  513. } else {
  514. let month = this.month - 1;
  515. let year = month < 1 ? this.year - 1 : this.year;
  516. if (!this.checkRange(year)) {
  517. this.month = month < 1 ? 12 : month;
  518. this.year = year;
  519. this.changeData();
  520. }
  521. }
  522. },
  523. changeYear(isAdd) {
  524. let year = isAdd ? this.year + 1 : this.year - 1;
  525. if (!this.checkRange(year)) {
  526. this.year = year;
  527. this.changeData();
  528. }
  529. },
  530. changeData() {
  531. this.days = this.getMonthDay(this.year, this.month);
  532. this.daysArr = this.generateArray(1, this.days);
  533. this.weekday = this.getWeekday(this.year, this.month);
  534. this.weekdayArr = this.generateArray(1, this.weekday);
  535. this.showTitle = `${this.year}年${this.month}月`;
  536. if (this.isChange && this.type == 1) {
  537. this.btnFix(true);
  538. }
  539. },
  540. dateClick: function(day) {
  541. day += 1;
  542. if (!this.openDisAbled(this.year, this.month, day)) {
  543. this.day = day;
  544. let date = `${this.year}-${this.month}-${day}`;
  545. if (this.type == 1) {
  546. this.activeDate = date;
  547. } else {
  548. let compare = new Date(date.replace(/\-/g, '/')).getTime() < new Date(this.startDate.replace(
  549. /\-/g, '/')).getTime();
  550. if (this.isStart || compare) {
  551. this.startDate = date;
  552. this.startYear = this.year;
  553. this.startMonth = this.month;
  554. this.startDay = this.day;
  555. this.endYear = 0;
  556. this.endMonth = 0;
  557. this.endDay = 0;
  558. this.endDate = '';
  559. this.activeDate = '';
  560. this.isStart = false;
  561. } else {
  562. this.endDate = date;
  563. this.endYear = this.year;
  564. this.endMonth = this.month;
  565. this.endDay = this.day;
  566. this.isStart = true;
  567. }
  568. }
  569. if (!this.isFixed) {
  570. this.btnFix();
  571. }
  572. }
  573. },
  574. show() {
  575. this.isShow = true;
  576. },
  577. hide() {
  578. this.isShow = false;
  579. this.$emit('hide', {})
  580. },
  581. getWeekText(date) {
  582. date = new Date(`${date.replace(/\-/g, '/')} 00:00:00`);
  583. let week = date.getDay();
  584. return '星期' + ['日', '一', '二', '三', '四', '五', '六'][week];
  585. },
  586. btnFix(show) {
  587. if (!show) {
  588. this.hide();
  589. }
  590. if (this.type == 1) {
  591. let arr = this.activeDate.split('-');
  592. let year = this.isChange ? this.year : Number(arr[0]);
  593. let month = this.isChange ? this.month : Number(arr[1]);
  594. let day = this.isChange ? this.day : Number(arr[2]);
  595. //当前月有多少天
  596. let days = this.getMonthDay(year, month);
  597. let result = `${year}-${this.formatNum(month)}-${this.formatNum(day)}`;
  598. let weekText = this.getWeekText(result);
  599. let isToday = false;
  600. if (`${year}-${month}-${day}` == this.today) {
  601. //今天
  602. isToday = true;
  603. }
  604. let lunar = calendar.solar2lunar(year, month, day);
  605. this.$emit('change', {
  606. year: year,
  607. month: month,
  608. day: day,
  609. days: days,
  610. result: result,
  611. week: weekText,
  612. isToday: isToday,
  613. switch: show, //是否是切换年月操作
  614. lunar: lunar
  615. });
  616. } else {
  617. if (!this.startDate || !this.endDate) return;
  618. let startMonth = this.formatNum(this.startMonth);
  619. let startDay = this.formatNum(this.startDay);
  620. let startDate = `${this.startYear}-${startMonth}-${startDay}`;
  621. let startWeek = this.getWeekText(startDate);
  622. let startLunar = calendar.solar2lunar(this.startYear, startMonth, startDay);
  623. let endMonth = this.formatNum(this.endMonth);
  624. let endDay = this.formatNum(this.endDay);
  625. let endDate = `${this.endYear}-${endMonth}-${endDay}`;
  626. let endWeek = this.getWeekText(endDate);
  627. let endLunar = calendar.solar2lunar(this.endYear, endMonth, endDay);
  628. this.$emit('change', {
  629. startYear: this.startYear,
  630. startMonth: this.startMonth,
  631. startDay: this.startDay,
  632. startDate: startDate,
  633. startWeek: startWeek,
  634. startLunar: startLunar,
  635. endYear: this.endYear,
  636. endMonth: this.endMonth,
  637. endDay: this.endDay,
  638. endDate: endDate,
  639. endWeek: endWeek,
  640. endLunar: endLunar
  641. });
  642. }
  643. }
  644. }
  645. };
  646. </script>
  647. <style scoped>
  648. @font-face {
  649. font-family: 'tuiDateFont';
  650. 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');
  651. font-weight: normal;
  652. font-style: normal;
  653. }
  654. .tui-iconfont {
  655. font-family: 'tuiDateFont' !important;
  656. font-size: 36rpx;
  657. font-style: normal;
  658. -webkit-font-smoothing: antialiased;
  659. -moz-osx-font-smoothing: grayscale;
  660. }
  661. .tui-font-close:before {
  662. content: '\e608';
  663. }
  664. .tui-font-check:before {
  665. content: '\e6e1';
  666. }
  667. .tui-font-arrowright:before {
  668. content: '\e600';
  669. }
  670. .tui-font-arrowleft:before {
  671. content: '\e601';
  672. }
  673. .tui-date-box {
  674. width: 100%;
  675. display: flex;
  676. align-items: center;
  677. justify-content: center;
  678. padding: 20rpx 0 30rpx;
  679. background-color: #fff;
  680. }
  681. .tui-calendar-radius {
  682. border-top-left-radius: 20rpx;
  683. border-top-right-radius: 20rpx;
  684. overflow: hidden;
  685. }
  686. .tui-date_time {
  687. padding: 0 16rpx;
  688. color: #333;
  689. font-size: 32rpx;
  690. line-height: 32rpx;
  691. font-weight: bold;
  692. }
  693. .tui-font-arrowleft {
  694. margin-right: 32rpx;
  695. }
  696. .tui-font-arrowright {
  697. margin-left: 32rpx;
  698. }
  699. .tui-date-header {
  700. width: 100%;
  701. display: flex;
  702. align-items: center;
  703. background-color: #fff;
  704. font-size: 24rpx;
  705. line-height: 24rpx;
  706. color: #555;
  707. box-shadow: 0 15rpx 20rpx -15rpx #efefef;
  708. position: relative;
  709. z-index: 2;
  710. }
  711. .tui-date-content {
  712. width: 100%;
  713. display: flex;
  714. flex-wrap: wrap;
  715. padding: 12rpx 0;
  716. box-sizing: border-box;
  717. background-color: #fff;
  718. position: relative;
  719. }
  720. .tui-flex-start {
  721. align-content: flex-start;
  722. }
  723. .tui-bg-month {
  724. position: absolute;
  725. font-size: 260rpx;
  726. line-height: 260rpx;
  727. left: 50%;
  728. top: 50%;
  729. transform: translate(-50%, -50%);
  730. color: #f5f5f7;
  731. z-index: 1;
  732. }
  733. .tui-date {
  734. width: 14.2857%;
  735. display: flex;
  736. align-items: center;
  737. justify-content: center;
  738. padding: 12rpx 0;
  739. overflow: hidden;
  740. position: relative;
  741. z-index: 2;
  742. }
  743. .tui-date-pd_0 {
  744. padding: 0 !important;
  745. }
  746. .tui-start-date {
  747. border-top-left-radius: 8rpx;
  748. border-bottom-left-radius: 8rpx;
  749. }
  750. .tui-end-date {
  751. border-top-right-radius: 8rpx;
  752. border-bottom-right-radius: 8rpx;
  753. }
  754. .tui-date-text {
  755. width: 80rpx;
  756. height: 80rpx;
  757. display: flex;
  758. align-items: center;
  759. justify-content: center;
  760. flex-direction: column;
  761. font-size: 32rpx;
  762. line-height: 32rpx;
  763. position: relative;
  764. border-radius: 50%;
  765. }
  766. .tui-btn-calendar {
  767. padding: 16rpx;
  768. box-sizing: border-box;
  769. text-align: center;
  770. text-decoration: none;
  771. }
  772. .tui-opacity {
  773. opacity: 0.5;
  774. }
  775. .tui-bottom-popup {
  776. width: 100%;
  777. position: fixed;
  778. left: 0;
  779. right: 0;
  780. bottom: 0;
  781. z-index: 9999;
  782. visibility: hidden;
  783. transform: translate3d(0, 100%, 0);
  784. transform-origin: center;
  785. transition: all 0.3s ease-in-out;
  786. min-height: 20rpx;
  787. }
  788. .tui-popup-show {
  789. transform: translate3d(0, 0, 0);
  790. visibility: visible;
  791. }
  792. .tui-popup-mask {
  793. position: fixed;
  794. top: 0;
  795. left: 0;
  796. right: 0;
  797. bottom: 0;
  798. background: rgba(0, 0, 0, 0.6);
  799. z-index: 9996;
  800. transition: all 0.3s ease-in-out;
  801. opacity: 0;
  802. visibility: hidden;
  803. }
  804. .tui-mask-show {
  805. opacity: 1;
  806. visibility: visible;
  807. }
  808. .tui-calendar-header {
  809. width: 100%;
  810. height: 80rpx;
  811. padding: 0 40rpx;
  812. display: flex;
  813. justify-content: center;
  814. align-items: center;
  815. box-sizing: border-box;
  816. font-size: 30rpx;
  817. background-color: #fff;
  818. color: #555;
  819. position: relative;
  820. }
  821. .tui-font-close {
  822. position: absolute;
  823. right: 30rpx;
  824. top: 50%;
  825. transform: translateY(-50%);
  826. color: #999;
  827. }
  828. .tui-btn-calendar {
  829. padding: 16rpx;
  830. box-sizing: border-box;
  831. text-align: center;
  832. text-decoration: none;
  833. }
  834. .tui-font-check {
  835. color: #fff;
  836. font-size: 54rpx;
  837. line-height: 54rpx;
  838. }
  839. .tui-custom-desc {
  840. width: 100%;
  841. font-size: 24rpx;
  842. line-height: 24rpx;
  843. transform: scale(0.8);
  844. transform-origin: center center;
  845. text-align: center;
  846. }
  847. .tui-lunar-unshow {
  848. position: absolute;
  849. left: 0;
  850. bottom: 8rpx;
  851. z-index: 2;
  852. }
  853. .tui-date-desc {
  854. width: 100%;
  855. font-size: 24rpx;
  856. line-height: 24rpx;
  857. position: absolute;
  858. left: 0;
  859. transform: scale(0.8);
  860. transform-origin: center center;
  861. text-align: center;
  862. bottom: 8rpx;
  863. z-index: 2;
  864. }
  865. .tui-calendar-op {
  866. width: 100%;
  867. display: flex;
  868. align-items: center;
  869. justify-content: center;
  870. flex-direction: column;
  871. background-color: #fff;
  872. padding: 0 42rpx 30rpx;
  873. box-sizing: border-box;
  874. font-size: 24rpx;
  875. color: #666;
  876. }
  877. .tui-calendar-result {
  878. height: 48rpx;
  879. transform: scale(0.9);
  880. transform-origin: center 100%;
  881. }
  882. .tui-calendar-btn_box {
  883. width: 100%;
  884. }
  885. </style>