You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

575 lines
29 KiB

6 months ago
  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,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAhFBMVEUAAACNjY2KioqOjo6JiYmJiYmJiYmKioqKioqKioqJiYmKioqJiYmJiYmKioqJiYmKioqKioqQkJCKioqKioqJiYmKioqKioqKioqLi4uKioqJiYmKioqKioqKioqJiYmJiYmKioqKioqJiYmKioqJiYmKioqKioqJiYmKioqJiYmKioqm4nF9AAAAK3RSTlMACL0Ow9XbyR7g7KQWEs/yuFAE+KyNM5eAGkBiszkk51krbnlpSOSThpx0BMPRAQAAChhJREFUeNrUm9l2okAURQ8iMoqCDALGOSax/v//+qm7bigUsLhI78dkLZY7d6wKgolTdE9zfzezLdcTwnMte5b4eXqPTvhPcMprunbFExbr9FoWmDL7a+KJjhz8ysEUCSr/IHri/hyXmBSfXwvxIlZaYhoYke8JLQ75Z4x385GvxAB46R5vxDxbYjDsysB7cL5WYlC8bYDxyZL2Dxbu8u0/8l3YXkv52Bl2eqaxsv3LsdyjgX1ZXfxwIx7zU2A8HP9xpqeRg1b2UWqLR3wtMQ5mKpoJvz/Qg/LbehDRO8agas70dRWgN8V11ryOleDmNG9MqPPL6VBcGuPiB+DESDcNmaDbajK/6aln8BHdhIJ7NqFNsD0IhTADD2YiFGYRhiE+hkLhOwYD5UFN5BMGpNypQWGYj2rPTU4YmA+1h10xLIWttNsTGChDJeo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08WsKFH9JW9n/5u59WzkgDAP4i+QUU1HaDqWDqOf+7+9b3z+bUJuMMb8raK28Zqzhed6H/ex7bgYdkpCHXwV9cvTrOwXp1Ib4pPWuM2DS1cVGqGT0mWLhlzF/JemLH3tIVNIGlYKk0ismt+JA0jEpULkMDD71JYqSzgbXXpx9/LpLk/mb1n+VRr3Essetp9STI10A/uo+YEAqinSVBPqXbSomk+omrBj4NlE5Qs2VRhJf21G5oOZCc2kXqaQ00EOWKhVlgZqMBlMhRZnKmLKh6k4x/9NJo/6JQ46OsaIZpKMLudpJjPczCRejTuVUvsc2JFiBOkPhFsRbkkhu+2uBysisvLVLwqR3gONOyfVQd4pIjO2hUbXJvfy0UEgA0wD3i3qb4IUV0dS2VzZJA3Uots2e0iXfguDKRWSb/crBKzvlvsBW9IimsX0yvDJWUw4f4Jg0gc0SDSFxVqDp8UOc5QYaWEbc5TaaiiNxtDHQtDBpAu4aLUlEfCi3JZr8K00ks9HixTSeuWNoWZxpMlqBNrscOSx5gjY7pkntPXRQY42+dCwtdHi4NLUbQxcnPtJg6dVDFy8lAdwQ3U7BzaTeonKBbvaNBDkneEff5X3egLsFDG/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+KyNM5eAGkBiszkk51krbnlpSOSThpx0BMPRAQAAChhJREFUeNrUm9l2okAURQ8iMoqCDALGOSax/v//+qm7bigUsLhI78dkLZY7d6wKgolTdE9zfzezLdcTwnMte5b4eXqPTvhPcMprunbFExbr9FoWmDL7a+KJjhz8ysEUCSr/IHri/hyXmBSfXwvxIlZaYhoYke8JLQ75Z4x385GvxAB46R5vxDxbYjDsysB7cL5WYlC8bYDxyZL2Dxbu8u0/8l3YXkv52Bl2eqaxsv3LsdyjgX1ZXfxwIx7zU2A8HP9xpqeRg1b2UWqLR3wtMQ5mKpoJvz/Qg/LbehDRO8agas70dRWgN8V11ryOleDmNG9MqPPL6VBcGuPiB+DESDcNmaDbajK/6aln8BHdhIJ7NqFNsD0IhTADD2YiFGYRhiE+hkLhOwYD5UFN5BMGpNypQWGYj2rPTU4YmA+1h10xLIWttNsTGChDJeoYkg+vXuIRmLh69fQqBny4qLEFH8u8vnuWXOUxc8BKVsuvTYQhiGtd9xaBnXPtpHOHPuasV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ex7bgYdkpCHXwV9cvTrOwXp1Ib4pPWuM2DS1cVGqGT0mWLhlzF/JemLH3tIVNIGlYKk0ismt+JA0jEpULkMDD71JYqSzgbXXpx9/LpLk/mb1n+VRr3Essetp9STI10A/uo+YEAqinSVBPqXbSomk+omrBj4NlE5Qs2VRhJf21G5oOZCc2kXqaQ00EOWKhVlgZqMBlMhRZnKmLKh6k4x/9NJo/6JQ46OsaIZpKMLudpJjPczCRejTuVUvsc2JFiBOkPhFsRbkkhu+2uBysisvLVLwqR3gONOyfVQd4pIjO2hUbXJvfy0UEgA0wD3i3qb4IUV0dS2VzZJA3Uots2e0iXfguDKRWSb/crBKzvlvsBW9IimsX0yvDJWUw4f4Jg0gc0SDSFxVqDp8UOc5QYaWEbc5TaaiiNxtDHQtDBpAu4aLUlEfCi3JZr8K00ks9HixTSeuWNoWZxpMlqBNrscOSx5gjY7pkntPXRQY42+dCwtdHi4NLUbQxcnPtJg6dVDFy8lAdwQ3U7BzaTeonKBbvaNBDkneEff5X3egLsFDG/4pUbi7FW8Zy/CZ5aa1Kad8/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. //历史日期不允许选择
  268. let month=objTime.month+1<10?'0'+(objTime.month+1):objTime.month+1;
  269. let day=objTime.day<10?'0'+objTime.day:objTime.day;
  270. let rq=objTime.year+'-'+(month)+'-'+day;
  271. let date=new Date(rq);
  272. let date2=new Date(this.calendarData.Disablerq);
  273. if(date.getTime()<date2.getTime()){
  274. return;
  275. }
  276. //历史日期不允许选择
  277. //遍历选中时间是否与当前时间一致,一致flag = true or flag = false;
  278. this.totalDaysArr.map((item) => {
  279. item.day === objTime.day && item.month === objTime.month ? item.flag = true : item.flag = false;
  280. });
  281. //为了不影响objTime这个数据源,定义一个临时obj
  282. let tempObj = {};
  283. //处理选中的时间
  284. for (let i in objTime) {
  285. if (i === 'day') {
  286. tempObj.day = objTime[i];
  287. tempObj.day = tempObj.day < 10 ? `0${tempObj.day}` : tempObj.day;
  288. }
  289. if (i === 'month') {
  290. //选中时间跨入上一年12月份
  291. tempObj.month = objTime[i];
  292. if (objTime[i] < 0) {
  293. tempObj.month = 12;
  294. } else {
  295. tempObj.month = tempObj.month + 1 < 10 ? `0${tempObj.month + 1}` : tempObj.month + 1;
  296. }
  297. }
  298. if(i === 'year'){
  299. tempObj.year = objTime[i];
  300. }
  301. }
  302. this.choseCurTime = tempObj;
  303. //判断选择时间跨入了下一年换算当前月份
  304. if (this.choseCurTime.month > 12) {
  305. this.choseCurTime.month = this.choseCurTime.month - 12 < 10 ? `0${this.choseCurTime.month - 12}` : this.choseCurTime.month - 12;
  306. }
  307. this.calendarData.isShow = false;
  308. //用于computed计算标识不然函数会再次执行
  309. this.actFlag = false;
  310. this.calendarData.choseTime = `${this.choseCurTime.year}-${this.choseCurTime.month}-${this.choseCurTime.day}`;
  311. this.selectTime = this.calendarData.choseTime;
  312. //传值给父组件
  313. // this.$emit('returnDate',{time:`${this.choseCurTime.year}-${this.choseCurTime.month}-${this.choseCurTime.day}`,timeType:this.calendarData.type,isShow:false});
  314. },
  315. //显示与隐藏日历
  316. clickShowCalendar(){
  317. this.showMonthFlag = false;
  318. this.showYearFlag = false;
  319. this.actFlag = false;
  320. this.$emit('closeCalendar',{
  321. time: this.selectTime,
  322. isShow: false
  323. });
  324. },
  325. //显示
  326. show(curYear,curMonth,curDate) {
  327. this.returnType = this.calendarData.type;
  328. this.totalDaysArr = [];
  329. const objDate = new Date();
  330. //当前年份
  331. this.curYear = curYear||objDate.getFullYear();
  332. //当前月份
  333. if(curMonth === 0 || curMonth){
  334. this.curMonth = curMonth;
  335. }else{
  336. this.curMonth = objDate.getMonth();
  337. }
  338. //当前几号
  339. this.curDate = curDate||objDate.getDate();
  340. //生成对应年份区间列表数据
  341. this.crateYearRange();
  342. //生成日历数据
  343. this.createCalendarData(this.curYear, this.curMonth, this.curDate);
  344. },
  345. //方法调用
  346. lotusCalendar() {
  347. this.show();
  348. },
  349. //是否为闰年
  350. isLeapYear(year) {
  351. return ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0);
  352. },
  353. //获取当前月份天数
  354. getCurMonthDays(year, month) {
  355. //console.log(year, month);
  356. if (this.isLeapYear(year)) {
  357. //判断当前月份是2月
  358. if (this.curMonth === 1&&this.curMonth === month) {
  359. return this.aMonth[1] = 29;
  360. }else {
  361. return this.aMonth[month];
  362. }
  363. } else {
  364. //不是闰年重置2月天数为28
  365. this.aMonth[1] = 28;
  366. return this.aMonth[month];
  367. }
  368. },
  369. //自动补0
  370. autoPatchZero(val) {
  371. return val < 10 ? `0${val}` : val;
  372. },
  373. //生成日历数据 curYear年份 curMonth月份 curDate号数
  374. createCalendarData(curYear, curMonth, curDate) {
  375. //换算当前月份自动补全 val < 10 ? `0${val}` : val;
  376. this.showCurMonth = curMonth;
  377. this.showCurMonth = this.autoPatchZero(this.showCurMonth + 1);
  378. let preYear = '';
  379. //当前月份1号星期几
  380. let iWeek = new Date(curYear, curMonth, 1).getDay();
  381. if (iWeek === 0) {
  382. iWeek = 7;
  383. }
  384. if (curMonth === 0) {
  385. const t = 12;
  386. preYear = curYear;
  387. preYear -= 1;
  388. this.prevYear = preYear;
  389. //上一个月份共多少天
  390. this.preMonthDays = this.getCurMonthDays(preYear, t - 1);
  391. } else {
  392. //上一个月份共多少天
  393. this.preMonthDays = this.getCurMonthDays(curYear, curMonth - 1);
  394. }
  395. //当前月份共多少天
  396. this.curMonthDays = this.getCurMonthDays(curYear, curMonth);
  397. //下一个月份共多少天
  398. this.nextMonthDays = this.getCurMonthDays(curYear, curMonth + 1);
  399. //上一个月剩下几天
  400. for (let i = iWeek - 2; i >= 0; i--) {
  401. const obj = {
  402. day: this.preMonthDays - i,
  403. className: 'gray',
  404. type: 0,
  405. flag: false,
  406. month: curMonth - 1,
  407. year: preYear ? preYear : curYear
  408. };
  409. this.totalDaysArr.push(obj);
  410. }
  411. //当前月份天数
  412. for (let i = 1; i <= this.curMonthDays; i++) {
  413. const obj = {
  414. day: i,
  415. type: 1,
  416. flag: false,
  417. className: '',
  418. month: curMonth,
  419. year: curYear
  420. };
  421. if (i === curDate && curMonth === this.savePreMonth&& curYear === this.savePreYear) {
  422. obj.flag = true;
  423. obj.className = 'act';
  424. obj.type = 2;
  425. }
  426. //历史日期不允许选择
  427. let month=curMonth+1<10?'0'+(curMonth+1):curMonth+1;
  428. let day=i<10?'0'+i:i;
  429. let rq=curYear+'-'+(month)+'-'+day;
  430. let date=new Date(rq);
  431. let date2=new Date(this.calendarData.Disablerq);
  432. if(date.getTime()<date2.getTime()){
  433. obj.flag = false;
  434. obj.className = 'gray';
  435. obj.type = 0;
  436. }
  437. //历史日期不允许选择
  438. this.totalDaysArr.push(obj);
  439. }
  440. //下一个月开始的几天
  441. const leaveLength = 42 - this.totalDaysArr.length;
  442. for (let i = 1; i <= leaveLength; i++) {
  443. const obj = {
  444. day: i,
  445. className: '',
  446. type: 1,
  447. flag: false,
  448. month: curMonth + 1,
  449. year: curYear
  450. };
  451. //点击月份进入了下一年
  452. if(obj.month >= 12){
  453. obj.year += 1
  454. }
  455. //历史日期不允许选择
  456. let month=curMonth+2<10?'0'+(curMonth+2):curMonth+2;
  457. let day=obj.day<10?'0'+obj.day:obj.day;
  458. let rq=obj.year+'-'+(month)+'-'+day;
  459. let date=new Date(rq);
  460. let date2=new Date(this.calendarData.Disablerq);
  461. if(date.getTime()<date2.getTime()){
  462. obj.flag = false;
  463. obj.className = 'gray';
  464. obj.type = 0;
  465. }
  466. //历史日期不允许选择
  467. this.totalDaysArr.push(obj);
  468. }
  469. },
  470. //月份/年份设置高亮
  471. setAct(obj,type){
  472. if(type === "month"){
  473. this.monthArray.map((item,index)=>{
  474. item.flag = false;
  475. });
  476. this.curMonth = obj.showCurMonth*1-1;
  477. this.setStauts('showMonthFlag',false);
  478. }else{
  479. this.yearArray.map((item,index)=>{
  480. item.flag = false;
  481. });
  482. this.setStauts('showYearFlag',false);
  483. this.curYear = obj.y;
  484. }
  485. obj.flag = true;
  486. this.totalDaysArr = [];
  487. this.createCalendarData(this.curYear,this.curMonth,this.curDate);
  488. this.selectTime = `${this.curYear}-${this.curMonth+1<10?'0'+(this.curMonth+1):(this.curMonth+1)}-${this.curDate<10?'0'+this.curDate:this.curDate}`
  489. this.actFlag = true;
  490. this.fullFlag = true;
  491. },
  492. //更改状态
  493. setStauts(type,obj){
  494. //月份选中
  495. if(type === "showMonthFlag" && obj){
  496. this.monthArray.map((item,index)=>{
  497. item.flag = false;
  498. if(item.showCurMonth*1-1 === this.curMonth){
  499. item.flag = true;
  500. }
  501. });
  502. }else{
  503. //年份选中
  504. this.yearArray.map((item,index)=>{
  505. item.flag = false;
  506. if(item.y === this.curYear){
  507. item.flag = true;
  508. }
  509. });
  510. }
  511. this[type] = obj;
  512. this.fullFlag = false;
  513. },
  514. //年份区间数据创建
  515. crateYearRange(year){
  516. this.yearArray = [];
  517. this.startYear = this.curYear-15;
  518. this.endYear = this.curYear+5;
  519. this.actFlag = true;
  520. for(let i = this.startYear+1;i<this.startYear+15;i++){
  521. let sObj = {
  522. y:i,
  523. flag:false
  524. }
  525. //判断切换年份是否与之前年份一致&高亮
  526. if(i === this.savePreYear){
  527. sObj.flag = true;
  528. }
  529. this.yearArray.push(sObj);
  530. }
  531. for(let j = this.curYear;j<=this.curYear+5;j++){
  532. let eObj = {
  533. y:j,
  534. flag:false
  535. }
  536. //判断切换年份是否与之前年份一致&高亮
  537. if(j === this.savePreYear){
  538. eObj.flag = true;
  539. }
  540. this.yearArray.push(eObj);
  541. }
  542. },
  543. //年份区间变化
  544. yearRangeChanage(type){
  545. this.curYear += type;
  546. this.crateYearRange();
  547. },
  548. // 点击确定按钮
  549. confirmFn(){
  550. this.showMonthFlag = false;
  551. this.showYearFlag = false;
  552. this.actFlag = false;
  553. let option = {
  554. isShow: false
  555. }
  556. if(this.choseCurTime){
  557. option.time = `${this.choseCurTime.year}-${this.choseCurTime.month}-${this.choseCurTime.day}`;
  558. option.timeType = this.calendarData.type?this.calendarData.type:'';
  559. }
  560. if(this.selectTime){
  561. option.time = this.selectTime;
  562. }
  563. this.$emit('returnDate',{
  564. ...option,
  565. });
  566. }
  567. }
  568. }
  569. </script>