Winglau14-lotusCalendar.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. <!--
  2. *calendarData.isShow:日历组件显示隐藏
  3. *calendarData.yearStyle:设置年样式
  4. *calendarData.monthStyle:设置月样式
  5. *calendarData.dayStyle:设置日样式
  6. *returnDate:已选日期回调方法,返回结果{time:'已选日期',timeType:'对应选择模块',isShow:'为了处理组件显示隐藏回调uniapp的坑'}
  7. :status="checkStatus"
  8. -->
  9. <template>
  10. <view :status="checkStatus" v-if="calendarData.isShow" class="lotus-calendar-wrap">
  11. <view :class="calendarData.isShow?'lotus-calendar':'lotus-calendar lotus-calendar-out'">
  12. <view class="lotus-calendar-title">选择日期</view>
  13. <view class="lotus-calendar-cur-bg-month">{{curMonth+1}}</view>
  14. <view class="lotus-calendar-cur-date">
  15. <view class="lotus-calendar-center">
  16. <view class="lotus-calendar-month">
  17. <view class="lotus-calendar-prev" @tap="clickPrevMonth">←</view>
  18. <view :style="calendarData.monthStyle" @tap="setStauts('showMonthFlag',true);" class="lotus-calendar-cur-text">{{showCurMonth}}月</view>
  19. <view class="lotus-calendar-next" @tap="clickNextMonth">→</view>
  20. </view>
  21. <view class="lotus-calendar-year">
  22. <view class="lotus-calendar-prev" @tap="clickPrevYear">←</view>
  23. <view :style="calendarData.yearStyle" @tap="setStauts('showYearFlag',true);" class="lotus-calendar-cur-text">{{curYear}}</view>
  24. <view class="lotus-calendar-next" @tap="clickNextYear">→</view>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="lotus-calendar-week">
  29. <view class="lotus-calendar-week-text lotus-calendar-week-range" v-for="(item,index) in weekText" :key="index">
  30. {{item}}
  31. </view>
  32. </view>
  33. <view class="lotus-calendar-days">
  34. <view class="lotus-calendar-days-text" v-for="(item,index) in totalDaysArr" :key="index" @tap="clickTargetTime(item,index)">
  35. <view :class="item.flag?'lotus-calendar-days-act':'lotus-calendar-days-gray'" v-if="item.type == 0">{{item.day}}</view>
  36. <view :class="item.flag?'lotus-calendar-days-act':''" v-if="item.type == 1">{{item.day}}</view>
  37. <view :style="calendarData.dayStyle" :class="item.flag?'lotus-calendar-days-act':''" v-if="item.type == 2">{{item.day}}</view>
  38. </view>
  39. </view>
  40. <view class="lotus-calendar-result">
  41. <view class="lotus-calendar-result-time" v-text="selectTime"></view>
  42. <view class="lotus-calendar-result-btn" @tap="confirmFn">确定</view>
  43. </view>
  44. </view>
  45. <!--月份选择-->
  46. <view v-if="showMonthFlag" class="lotus-calendar-months">
  47. <!-- <view class="lotus-calendar-months-cancel">
  48. <image @tap="setStauts('showMonthFlag',false);" class="lotus-calendar-months-cancel-icon" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAhFBMVEUAAACNjY2KioqOjo6JiYmJiYmJiYmKioqKioqKioqJiYmKioqJiYmJiYmKioqJiYmKioqKioqQkJCKioqKioqJiYmKioqKioqKioqLi4uKioqJiYmKioqKioqKioqJiYmJiYmKioqKioqJiYmKioqJiYmKioqKioqJiYmKioqJiYmKioqm4nF9AAAAK3RSTlMACL0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Fy8lAdwQ3U7BzaTeonKBbvaNBDkneEff5X3egLsFDG/4pUbi7FW8Zy/CZ5aa1Kad8/gQ6Phg55JYUYK/sJNuqIFTHMrQSVTPsvEXtvsh8Y4PH1xZT43msbpa4Gad0ZwixwcH1mH+Q30tCxhGWe5SkoOyedzxJeMgWYXk+RbYGEgvcknOWhv2z4Shp2WYSXP03emYX0L1hA/0oIxTOf+JNmWfXXf/l0FDv9uAbemL9f+l8ZKbNI1/bg1FP4fVoaEAAAAASUVORK5CYII=" mode="aspectFit"></image>
  49. </view> -->
  50. <view class="lotus-calendar-months-box">
  51. <view v-for="(item,index) in monthArray" :key="index" :style="item.flag&&calendarData.monthStyle" class="lotus-calendar-months-text">
  52. <text @tap="setAct(item,'month');" v-text="item.monthText"></text>
  53. </view>
  54. </view>
  55. </view>
  56. <!--年份份选择-->
  57. <view v-if="showYearFlag" class="lotus-calendar-months">
  58. <view class="lotus-calendar-year lotus-calendar-year2">
  59. <view class="lotus-calendar-prev" @tap="yearRangeChanage(-10);">←</view>
  60. <view :style="calendarData.yearStyle" @tap="setStauts('showYearFlag',true);" class="lotus-calendar-cur-text">{{curYear-10}}-{{curYear}}</view>
  61. <view class="lotus-calendar-next" @tap="yearRangeChanage(+10);">→</view>
  62. <!-- <view class="lotus-calendar-months-cancel lotus-calendar-months-cancel2">
  63. <image @tap="setStauts('showYearFlag',false);" class="lotus-calendar-months-cancel-icon" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAhFBMVEUAAACNjY2KioqOjo6JiYmJiYmJiYmKioqKioqKioqJiYmKioqJiYmJiYmKioqJiYmKioqKioqQkJCKioqKioqJiYmKioqKioqKioqLi4uKioqJiYmKioqKioqKioqJiYmJiYmKioqKioqJiYmKioqJiYmKioqKioqJiYmKioqJiYmKioqm4nF9AAAAK3RSTlMACL0Ow9XbyR7g7KQWEs/yuFAE+KyNM5eAGkBiszkk51krbnlpSOSThpx0BMPRAQAAChhJREFUeNr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gQ6Phg55JYUYK/sJNuqIFTHMrQSVTPsvEXtvsh8Y4PH1xZT43msbpa4Gad0ZwixwcH1mH+Q30tCxhGWe5SkoOyedzxJeMgWYXk+RbYGEgvcknOWhv2z4Shp2WYSXP03emYX0L1hA/0oIxTOf+JNmWfXXf/l0FDv9uAbemL9f+l8ZKbNI1/bg1FP4fVoaEAAAAASUVORK5CYII=" mode="aspectFit"></image>
  64. </view> -->
  65. </view>
  66. <view style="padding-top:20rpx;" class="lotus-calendar-months-box">
  67. <view v-for="(item,index) in yearArray" :key="index" :style="item.flag&&calendarData.monthStyle" class="lotus-calendar-months-text lotus-calendar-months-text2">
  68. <text @tap="setAct(item,'year');" v-text="item.y"></text>
  69. </view>
  70. </view>
  71. </view>
  72. <view v-if="calendarData.isShow" @tap="clickShowCalendar" class="lotus-calendar-mask"></view>
  73. </view>
  74. </template>
  75. <style lang="less">
  76. @import './Winglau14-lotusCalendar.css';
  77. </style>
  78. <script>
  79. export default {
  80. name: 'lotus-calendar',
  81. props: ['calendarData'],
  82. data () {
  83. return {
  84. isShow: true,
  85. weekText: ['一', '二', '三', '四', '五', '六', '日'],
  86. aMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
  87. showMonthFlag:false,
  88. fullFlag:false,
  89. monthArray:[{
  90. monthText:'01月',
  91. showCurMonth:'1',
  92. flag:false
  93. },{
  94. monthText:'02月',
  95. showCurMonth:'2',
  96. flag:false
  97. },{
  98. monthText:'03月',
  99. showCurMonth:'3',
  100. flag:false
  101. },{
  102. monthText:'04月',
  103. showCurMonth:'4',
  104. flag:false
  105. },{
  106. monthText:'05月',
  107. showCurMonth:'5',
  108. flag:false
  109. },{
  110. monthText:'06月',
  111. showCurMonth:'6',
  112. flag:false
  113. },{
  114. monthText:'07月',
  115. showCurMonth:'7',
  116. flag:false
  117. },{
  118. monthText:'08月',
  119. showCurMonth:'8',
  120. flag:false
  121. },{
  122. monthText:'09月',
  123. showCurMonth:'9',
  124. flag:true
  125. },{
  126. monthText:'10月',
  127. showCurMonth:'10',
  128. flag:false
  129. },{
  130. monthText:'11月',
  131. showCurMonth:'11',
  132. flag:false
  133. },{
  134. monthText:'12月',
  135. showCurMonth:'12',
  136. flag:false
  137. }],
  138. yearArray:[],
  139. showYearFlag:false,
  140. curMonthDays: 0,//当前月天数
  141. preMonthDays: 0,//上一个月天数
  142. nextMonthDays: 0,//下一个月天数
  143. totalDaysArr: [],//日历总天数
  144. curYear: 0,//当前年份
  145. curMonth: 0,//当前月份
  146. curDate: 0,//当前日份
  147. showCurMonth: 0,//显示日历中月份
  148. choseIndex: 0,
  149. choseCurTime: null,//每个日期obj有day/month/year
  150. prevYear: '',//上一年
  151. time:null,
  152. returnType:'',
  153. sTime:'',
  154. eTime:'',
  155. systemMonth:(new Date().getMonth()),//系统当前月份
  156. parentDate:'',
  157. actFlag:false,
  158. savePreMonth:0,
  159. savePreYear:0,
  160. startYear:0,
  161. endYear:0,
  162. selectTime: ''
  163. }
  164. },
  165. components: {},
  166. computed:{
  167. checkStatus(){
  168. const _this = this;
  169. const t = _this.calendarData.isShow;
  170. _this.fullFlag = true;
  171. if(t&&!_this.actFlag){
  172. //获取父组件已选的时间值
  173. _this.parentDate = _this.calendarData.choseTime.split('-');
  174. _this.selectTime = _this.calendarData.choseTime;
  175. _this.totalDaysArr = [];
  176. //记录父组件的年份与月份的值,用于年月日比对上当前日期高亮
  177. _this.savePreMonth = _this.parentDate[1]*1-1;
  178. _this.savePreYear = _this.parentDate[0]*1;
  179. //显示日历组件并生成对应数据
  180. _this.show(_this.parentDate[0]*1,_this.parentDate[1]*1-1,_this.parentDate[2]*1);
  181. }
  182. return t;
  183. }
  184. },
  185. methods: {
  186. //点击上一月
  187. clickPrevMonth(){
  188. //console.log('prev'+this.curMonth);
  189. this.totalDaysArr = [];
  190. this.actFlag = true;
  191. //缓存当前切换月份,用于当前日期高亮判断
  192. const tMonth = this.curMonth;
  193. this.savePreMonth = tMonth;
  194. //判断点击到一月进入一年设置月份为12月
  195. if (this.curMonth <= 0) {
  196. this.curMonth = 11;
  197. this.curYear--;
  198. } else {
  199. this.curMonth--;
  200. }
  201. //判断当前切换的月份是否与父组件传的月份一致,用于当前日期高亮
  202. const pMonth = this.calendarData.choseTime.split('-')[1]*1-1;
  203. if(this.curMonth === pMonth){
  204. this.savePreMonth = pMonth;
  205. }
  206. //生成日历数据
  207. this.createCalendarData(this.curYear, this.curMonth, this.curDate);
  208. },
  209. //点击下一月
  210. clickNextMonth(){
  211. this.totalDaysArr = [];
  212. //缓存当前切换月份,用于当前日期高亮判断
  213. const tMonth = this.curMonth;
  214. this.savePreMonth = tMonth;
  215. this.curMonth++;
  216. this.actFlag = true;
  217. //超过12月进入下一年判断设置月份为1月
  218. if (this.curMonth >= 12) {
  219. this.curMonth = 0;
  220. this.curYear++;
  221. }
  222. //判断当前切换的月份是否与父组件传的月份一致,用于当前日期高亮
  223. const pMonth = this.calendarData.choseTime.split('-')[1]*1-1;
  224. if(this.curMonth === pMonth){
  225. this.savePreMonth = pMonth;
  226. }
  227. //生成日历数据
  228. this.createCalendarData(this.curYear, this.curMonth, this.curDate);
  229. },
  230. //点击上一年
  231. clickPrevYear(){
  232. this.prevYear = '';
  233. this.totalDaysArr = [];
  234. this.actFlag = true;
  235. //缓存当前切换年份,用于当前日期高亮判断
  236. const tYear = this.curYear;
  237. this.savePreYear = tYear;
  238. this.curYear--;
  239. //判断当前切换的年份是否与父组件传的年份一致,用于当前日期高亮
  240. const pYear = this.calendarData.choseTime.split('-')[0]*1;
  241. if(this.curYear === pYear){
  242. this.savePreYear = pYear;
  243. }
  244. //生成日历数据
  245. this.createCalendarData(this.curYear, this.curMonth, this.curDate);
  246. },
  247. //点击下一年
  248. clickNextYear(){
  249. this.prevYear = '';
  250. this.totalDaysArr = [];
  251. //缓存当前切换年份,用于当前日期高亮判断
  252. const tYear = this.curYear;
  253. this.savePreYear = tYear;
  254. this.curYear++;
  255. this.actFlag = true;
  256. //判断当前切换的年份是否与父组件传的年份一致,用于当前日期高亮
  257. const pYear = this.calendarData.choseTime.split('-')[0]*1;
  258. if(this.curYear === pYear){
  259. this.savePreYear = pYear;
  260. }
  261. //生成日历数据
  262. this.createCalendarData(this.curYear, this.curMonth, this.curDate);
  263. },
  264. //选中日期
  265. clickTargetTime(curTime){
  266. let objTime = curTime;
  267. //遍历选中时间是否与当前时间一致,一致flag = true or flag = false;
  268. //console.log(this.totalDaysArr);
  269. this.totalDaysArr.map((item) => {
  270. item.day === objTime.day && item.month === objTime.month ? item.flag = true : item.flag = false;
  271. });
  272. //为了不影响objTime这个数据源,定义一个临时obj
  273. let tempObj = {};
  274. //处理选中的时间
  275. for (let i in objTime) {
  276. if (i === 'day') {
  277. tempObj.day = objTime[i];
  278. tempObj.day = tempObj.day < 10 ? `0${tempObj.day}` : tempObj.day;
  279. }
  280. if (i === 'month') {
  281. //选中时间跨入上一年12月份
  282. tempObj.month = objTime[i];
  283. if (objTime[i] < 0) {
  284. tempObj.month = 12;
  285. } else {
  286. tempObj.month = tempObj.month + 1 < 10 ? `0${tempObj.month + 1}` : tempObj.month + 1;
  287. }
  288. }
  289. if(i === 'year'){
  290. tempObj.year = objTime[i];
  291. }
  292. }
  293. this.choseCurTime = tempObj;
  294. //判断选择时间跨入了下一年换算当前月份
  295. if (this.choseCurTime.month > 12) {
  296. this.choseCurTime.month = this.choseCurTime.month - 12 < 10 ? `0${this.choseCurTime.month - 12}` : this.choseCurTime.month - 12;
  297. }
  298. this.calendarData.isShow = false;
  299. //用于computed计算标识不然函数会再次执行
  300. this.actFlag = false;
  301. this.calendarData.choseTime = `${this.choseCurTime.year}-${this.choseCurTime.month}-${this.choseCurTime.day}`;
  302. this.selectTime = this.calendarData.choseTime;
  303. //传值给父组件
  304. // this.$emit('returnDate',{time:`${this.choseCurTime.year}-${this.choseCurTime.month}-${this.choseCurTime.day}`,timeType:this.calendarData.type,isShow:false});
  305. },
  306. //显示与隐藏日历
  307. clickShowCalendar(){
  308. this.showMonthFlag = false;
  309. this.showYearFlag = false;
  310. this.actFlag = false;
  311. this.$emit('closeCalendar',{
  312. time: this.selectTime,
  313. isShow: false
  314. });
  315. },
  316. //显示
  317. show(curYear,curMonth,curDate) {
  318. this.returnType = this.calendarData.type;
  319. this.totalDaysArr = [];
  320. const objDate = new Date();
  321. //当前年份
  322. this.curYear = curYear||objDate.getFullYear();
  323. //当前月份
  324. if(curMonth === 0 || curMonth){
  325. this.curMonth = curMonth;
  326. }else{
  327. this.curMonth = objDate.getMonth();
  328. }
  329. //当前几号
  330. this.curDate = curDate||objDate.getDate();
  331. //生成对应年份区间列表数据
  332. this.crateYearRange();
  333. //生成日历数据
  334. this.createCalendarData(this.curYear, this.curMonth, this.curDate);
  335. },
  336. //方法调用
  337. lotusCalendar() {
  338. this.show();
  339. },
  340. //是否为闰年
  341. isLeapYear(year) {
  342. return ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0);
  343. },
  344. //获取当前月份天数
  345. getCurMonthDays(year, month) {
  346. //console.log(year, month);
  347. if (this.isLeapYear(year)) {
  348. //判断当前月份是2月
  349. if (this.curMonth === 1&&this.curMonth === month) {
  350. return this.aMonth[1] = 29;
  351. }else {
  352. return this.aMonth[month];
  353. }
  354. } else {
  355. //不是闰年重置2月天数为28
  356. this.aMonth[1] = 28;
  357. return this.aMonth[month];
  358. }
  359. },
  360. //自动补0
  361. autoPatchZero(val) {
  362. return val < 10 ? `0${val}` : val;
  363. },
  364. //生成日历数据 curYear年份 curMonth月份 curDate号数
  365. createCalendarData(curYear, curMonth, curDate) {
  366. //换算当前月份自动补全 val < 10 ? `0${val}` : val;
  367. this.showCurMonth = curMonth;
  368. this.showCurMonth = this.autoPatchZero(this.showCurMonth + 1);
  369. let preYear = '';
  370. //当前月份1号星期几
  371. let iWeek = new Date(curYear, curMonth, 1).getDay();
  372. if (iWeek === 0) {
  373. iWeek = 7;
  374. }
  375. if (curMonth === 0) {
  376. const t = 12;
  377. preYear = curYear;
  378. preYear -= 1;
  379. this.prevYear = preYear;
  380. //上一个月份共多少天
  381. this.preMonthDays = this.getCurMonthDays(preYear, t - 1);
  382. } else {
  383. //上一个月份共多少天
  384. this.preMonthDays = this.getCurMonthDays(curYear, curMonth - 1);
  385. }
  386. //当前月份共多少天
  387. this.curMonthDays = this.getCurMonthDays(curYear, curMonth);
  388. //下一个月份共多少天
  389. this.nextMonthDays = this.getCurMonthDays(curYear, curMonth + 1);
  390. //上一个月剩下几天
  391. for (let i = iWeek - 2; i >= 0; i--) {
  392. const obj = {
  393. day: this.preMonthDays - i,
  394. className: 'gray',
  395. type: 0,
  396. flag: false,
  397. month: curMonth - 1,
  398. year: preYear ? preYear : curYear
  399. };
  400. this.totalDaysArr.push(obj);
  401. }
  402. //当前月份天数
  403. for (let i = 1; i <= this.curMonthDays; i++) {
  404. const obj = {
  405. day: i,
  406. type: 1,
  407. flag: false,
  408. className: '',
  409. month: curMonth,
  410. year: curYear
  411. };
  412. if (i === curDate && curMonth === this.savePreMonth&& curYear === this.savePreYear) {
  413. obj.flag = true;
  414. obj.className = 'act';
  415. obj.type = 2;
  416. }
  417. this.totalDaysArr.push(obj);
  418. }
  419. //下一个月开始的几天
  420. const leaveLength = 42 - this.totalDaysArr.length;
  421. for (let i = 1; i <= leaveLength; i++) {
  422. const obj = {
  423. day: i,
  424. className: 'gray',
  425. type: 0,
  426. flag: false,
  427. month: curMonth + 1,
  428. year: curYear
  429. };
  430. //点击月份进入了下一年
  431. if(obj.month >= 12){
  432. obj.year += 1
  433. }
  434. this.totalDaysArr.push(obj);
  435. }
  436. },
  437. //月份/年份设置高亮
  438. setAct(obj,type){
  439. if(type === "month"){
  440. this.monthArray.map((item,index)=>{
  441. item.flag = false;
  442. });
  443. this.curMonth = obj.showCurMonth*1-1;
  444. this.setStauts('showMonthFlag',false);
  445. }else{
  446. this.yearArray.map((item,index)=>{
  447. item.flag = false;
  448. });
  449. this.setStauts('showYearFlag',false);
  450. this.curYear = obj.y;
  451. }
  452. obj.flag = true;
  453. this.totalDaysArr = [];
  454. this.createCalendarData(this.curYear,this.curMonth,this.curDate);
  455. this.selectTime = `${this.curYear}-${this.curMonth+1<10?'0'+(this.curMonth+1):(this.curMonth+1)}-${this.curDate<10?'0'+this.curDate:this.curDate}`
  456. this.actFlag = true;
  457. this.fullFlag = true;
  458. },
  459. //更改状态
  460. setStauts(type,obj){
  461. //月份选中
  462. if(type === "showMonthFlag" && obj){
  463. this.monthArray.map((item,index)=>{
  464. item.flag = false;
  465. if(item.showCurMonth*1-1 === this.curMonth){
  466. item.flag = true;
  467. }
  468. });
  469. }else{
  470. //年份选中
  471. this.yearArray.map((item,index)=>{
  472. item.flag = false;
  473. if(item.y === this.curYear){
  474. item.flag = true;
  475. }
  476. });
  477. }
  478. this[type] = obj;
  479. this.fullFlag = false;
  480. },
  481. //年份区间数据创建
  482. crateYearRange(year){
  483. this.yearArray = [];
  484. this.startYear = this.curYear-15;
  485. this.endYear = this.curYear+5;
  486. this.actFlag = true;
  487. for(let i = this.startYear+1;i<this.startYear+15;i++){
  488. let sObj = {
  489. y:i,
  490. flag:false
  491. }
  492. //判断切换年份是否与之前年份一致&高亮
  493. if(i === this.savePreYear){
  494. sObj.flag = true;
  495. }
  496. this.yearArray.push(sObj);
  497. }
  498. for(let j = this.curYear;j<=this.curYear+5;j++){
  499. let eObj = {
  500. y:j,
  501. flag:false
  502. }
  503. //判断切换年份是否与之前年份一致&高亮
  504. if(j === this.savePreYear){
  505. eObj.flag = true;
  506. }
  507. this.yearArray.push(eObj);
  508. }
  509. },
  510. //年份区间变化
  511. yearRangeChanage(type){
  512. this.curYear += type;
  513. this.crateYearRange();
  514. },
  515. // 点击确定按钮
  516. confirmFn(){
  517. this.showMonthFlag = false;
  518. this.showYearFlag = false;
  519. this.actFlag = false;
  520. let option = {
  521. isShow: false
  522. }
  523. if(this.choseCurTime){
  524. option.time = `${this.choseCurTime.year}-${this.choseCurTime.month}-${this.choseCurTime.day}`;
  525. option.timeType = this.calendarData.type?this.calendarData.type:'';
  526. }
  527. if(this.selectTime){
  528. option.time = this.selectTime;
  529. }
  530. this.$emit('returnDate',{
  531. ...option,
  532. });
  533. }
  534. }
  535. }
  536. </script>