wing-time-selector.vue 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019
  1. <template>
  2. <view>
  3. <picker mode="multiSelector" :range="dates" :value="value" @change="confirm" @columnchange="scroll" @cancel="cancel" :disabled="disabled"><slot></slot></picker>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. dates: [],
  11. years: [],
  12. year: 2020,
  13. beginYear: 1900,
  14. endYear: 2050,
  15. months: [],
  16. month: 1,
  17. beginMonth: 1,
  18. endMonth: 12,
  19. days: [],
  20. day: 1,
  21. beginDay: 1,
  22. endDay: 31,
  23. hours: [],
  24. hour: 0,
  25. beginHour: 0,
  26. endHour: 23,
  27. minutes: [],
  28. minute: 0,
  29. beginMinute: 0,
  30. endMinute: 59,
  31. seconds: [],
  32. second: 0,
  33. beginSecond: 0,
  34. endSecond: 59,
  35. value: [],
  36. showMode: this.showType,
  37. disabled: this.isClick
  38. };
  39. },
  40. props: {
  41. showType: {
  42. type: String,
  43. default: 'dateToTime'
  44. },
  45. beginDate: {
  46. type: String,
  47. default: '1900-01-01'
  48. },
  49. beginTime: {
  50. type: String,
  51. default: '00:00:00'
  52. },
  53. endDate: {
  54. type: String,
  55. default: '2050-12-31'
  56. },
  57. endTime: {
  58. type: String,
  59. default: '23:59:59'
  60. },
  61. isClick: {
  62. type: Boolean,
  63. default: false
  64. }
  65. },
  66. watch: {
  67. showType(oldValue, newValue) {
  68. // console.log('showType传入数值变化:', oldValue + '->' + newValue);
  69. this.showMode = newValue;
  70. },
  71. isClick(oldValue, newValue) {
  72. // console.log('isClick传入数值变化:', oldValue + '->' + newValue);
  73. this.disabled = newValue;
  74. }
  75. },
  76. created() {
  77. // console.log('========传参数==========',this.beginDate)
  78. if (this.getMillisecond(this.beginDate) > this.getMillisecond(this.endDate)) {
  79. let date = this.beginDate;
  80. this.beginDate = this.endDate;
  81. this.endDate = date;
  82. }
  83. if (this.getMillisecond('2020-01-01 ' + this.beginTime) > this.getMillisecond('2020-01-01 ' + this.endTime)) {
  84. let time = this.beginTime;
  85. this.beginTime = this.endTime;
  86. this.endTime = time;
  87. }
  88. // 日期
  89. let beginDateList = this.beginDate.split('-');
  90. this.beginYear = beginDateList[0];
  91. this.beginMonth = beginDateList[1].charAt(0) == '0' ? beginDateList[1].charAt(1) : beginDateList[1];
  92. this.beginDay = beginDateList[2].charAt(0) == '0' ? beginDateList[2].charAt(1) : beginDateList[2];
  93. let endDateList = this.endDate.split('-');
  94. this.endYear = endDateList[0];
  95. this.endMonth = endDateList[1].charAt(0) == '0' ? endDateList[1].charAt(1) : endDateList[1];
  96. this.endDay = endDateList[2].charAt(0) == '0' ? endDateList[2].charAt(1) : endDateList[2];
  97. // 时间
  98. let beginTimeList = this.beginTime.split(':');
  99. this.beginHour = beginTimeList[0].charAt(0) == '0' ? beginTimeList[0].charAt(1) : beginTimeList[0];
  100. this.beginMinute = beginTimeList[1].charAt(0) == '0' ? beginTimeList[1].charAt(1) : beginTimeList[1];
  101. this.beginSecond = beginTimeList[2].charAt(0) == '0' ? beginTimeList[2].charAt(1) : beginTimeList[2];
  102. let endTimeList = this.endTime.split(':');
  103. this.endHour = endTimeList[0].charAt(0) == '0' ? endTimeList[0].charAt(1) : endTimeList[0];
  104. this.endMinute = endTimeList[1].charAt(0) == '0' ? endTimeList[1].charAt(1) : endTimeList[1];
  105. this.endSecond = endTimeList[2].charAt(0) == '0' ? endTimeList[2].charAt(1) : endTimeList[2];
  106. this.getDate();
  107. for (var i = parseInt(this.beginYear); i <= parseInt(this.endYear); i++) {
  108. this.years.push(i + '年');
  109. }
  110. this.getMonths();
  111. this.getDays();
  112. for (var i = parseInt(this.beginHour); i <= parseInt(this.endHour); i++) {
  113. this.hours.push(i + '时');
  114. }
  115. if (this.beginHour == this.endHour) {
  116. if (parseInt(this.beginMinute) > parseInt(this.endMinute)) {
  117. for (var i = parseInt(this.endMinute); i <= parseInt(this.beginMinute); i++) {
  118. this.minutes.push(i + '分');
  119. }
  120. } else {
  121. for (var i = parseInt(this.beginMinute); i <= parseInt(this.endMinute); i++) {
  122. this.minutes.push(i + '分');
  123. }
  124. }
  125. } else {
  126. for (var i = parseInt(this.beginMinute); i <= 59; i++) {
  127. this.minutes.push(i + '分');
  128. }
  129. }
  130. if (this.beginMinute == this.endMinute) {
  131. if (parseInt(this.beginSecond) > parseInt(this.endSecond)) {
  132. for (var i = parseInt(this.endSecond); i <= parseInt(this.beginSecond); i++) {
  133. this.seconds.push(i + '秒');
  134. }
  135. } else {
  136. for (var i = parseInt(this.beginSecond); i <= parseInt(this.endSecond); i++) {
  137. this.seconds.push(i + '秒');
  138. }
  139. }
  140. } else {
  141. for (var i = parseInt(this.beginSecond); i <= 59; i++) {
  142. this.seconds.push(i + '秒');
  143. }
  144. }
  145. this.getData();
  146. },
  147. methods: {
  148. scroll(e) {
  149. // console.log('每一列滑动监听:', e);
  150. let column = e.detail.column;
  151. let value = e.detail.value;
  152. switch (this.showMode) {
  153. case 'time':
  154. {
  155. if (column == 0) {
  156. this.minutes = [];
  157. if (this.hours.length == 1) {
  158. if (parseInt(this.beginMinute) > parseInt(this.endMinute)) {
  159. for (var i = parseInt(this.endMinute); i <= parseInt(this.beginMinute); i++) {
  160. this.minutes.push(i + '分');
  161. }
  162. } else {
  163. for (var i = parseInt(this.beginMinute); i <= parseInt(this.endMinute); i++) {
  164. this.minutes.push(i + '分');
  165. }
  166. }
  167. } else {
  168. if (value == 0) {
  169. for (var i = parseInt(this.beginMinute); i <= 59; i++) {
  170. this.minutes.push(i + '分');
  171. }
  172. } else if (value == this.hours.length - 1) {
  173. for (var i = 0; i <= parseInt(this.endMinute); i++) {
  174. this.minutes.push(i + '分');
  175. }
  176. } else {
  177. for (var i = 0; i <= 59; i++) {
  178. this.minutes.push(i + '分');
  179. }
  180. }
  181. }
  182. this.dates[1] = this.minutes;
  183. } else if (column == 1) {
  184. this.seconds = [];
  185. if (this.minutes.length == 1) {
  186. if (parseInt(this.beginSecond) > parseInt(this.endSecond)) {
  187. for (var i = parseInt(this.endSecond); i <= parseInt(this.beginSecond); i++) {
  188. this.seconds.push(i + '秒');
  189. }
  190. } else {
  191. for (var i = parseInt(this.beginSecond); i <= parseInt(this.endSecond); i++) {
  192. this.seconds.push(i + '秒');
  193. }
  194. }
  195. } else {
  196. if (value == 0) {
  197. for (var i = parseInt(this.beginSecond); i <= 59; i++) {
  198. this.seconds.push(i + '秒');
  199. }
  200. } else if (value == this.minutes.length - 1) {
  201. for (var i = 0; i <= parseInt(this.endSecond); i++) {
  202. this.seconds.push(i + '秒');
  203. }
  204. } else {
  205. for (var i = 0; i <= 59; i++) {
  206. this.seconds.push(i + '秒');
  207. }
  208. }
  209. this.dates[2] = this.seconds;
  210. }
  211. }
  212. }
  213. break;
  214. case 'monthToDay':
  215. {
  216. this.getMonths();
  217. if (column == 0) {
  218. this.month = this.months[value].substring(0, this.months[value].length - 1);
  219. this.getDays();
  220. }
  221. this.dates[0] = this.months;
  222. this.dates[1] = this.days;
  223. }
  224. break;
  225. case 'yearToMonth':
  226. {
  227. if (column == 0) {
  228. this.year = this.years[value].substring(0, 4);
  229. if (value == 0) {
  230. this.month = this.beginMonth;
  231. }
  232. }
  233. this.getMonths();
  234. if (column == 1) {
  235. this.month = this.months[value].substring(0, this.months[value].length - 1);
  236. }
  237. this.dates[1] = this.months;
  238. }
  239. break;
  240. case 'dateToTime': {
  241. if (column == 4) {
  242. this.seconds = [];
  243. if (this.minutes.length == 1) {
  244. if (parseInt(this.beginSecond) > parseInt(this.endSecond)) {
  245. for (var i = parseInt(this.endSecond); i <= parseInt(this.beginSecond); i++) {
  246. this.seconds.push(i + '秒');
  247. }
  248. } else {
  249. for (var i = parseInt(this.beginSecond); i <= parseInt(this.endSecond); i++) {
  250. this.seconds.push(i + '秒');
  251. }
  252. }
  253. } else {
  254. if (value == 0) {
  255. for (var i = parseInt(this.beginSecond); i <= 59; i++) {
  256. this.seconds.push(i + '秒');
  257. }
  258. } else if (value == this.minutes.length - 1) {
  259. for (var i = 0; i <= parseInt(this.endSecond); i++) {
  260. this.seconds.push(i + '秒');
  261. }
  262. } else {
  263. for (var i = 0; i <= 59; i++) {
  264. this.seconds.push(i + '秒');
  265. }
  266. }
  267. }
  268. }
  269. this.dates[5] = this.seconds;
  270. }
  271. case 'yearToMinute': {
  272. if (column == 3) {
  273. this.minutes = [];
  274. if (this.hours.length == 1) {
  275. if (parseInt(this.beginMinute) > parseInt(this.endMinute)) {
  276. for (var i = parseInt(this.endMinute); i <= parseInt(this.beginMinute); i++) {
  277. this.minutes.push(i + '分');
  278. }
  279. } else {
  280. for (var i = parseInt(this.beginMinute); i <= parseInt(this.endMinute); i++) {
  281. this.minutes.push(i + '分');
  282. }
  283. }
  284. } else {
  285. if (value == 0) {
  286. for (var i = parseInt(this.beginMinute); i <= 59; i++) {
  287. this.minutes.push(i + '分');
  288. }
  289. } else if (value == this.hours.length - 1) {
  290. for (var i = 0; i <= parseInt(this.endMinute); i++) {
  291. this.minutes.push(i + '分');
  292. }
  293. } else {
  294. for (var i = 0; i <= 59; i++) {
  295. this.minutes.push(i + '分');
  296. }
  297. }
  298. }
  299. }
  300. this.dates[4] = this.minutes;
  301. }
  302. case 'date':
  303. {
  304. if (column == 0) {
  305. this.year = this.years[value].substring(0, 4);
  306. if (value == 0) {
  307. this.month = this.beginMonth;
  308. }
  309. if (value == this.years.length - 1) {
  310. this.month = this.endMonth;
  311. }
  312. }
  313. this.getMonths();
  314. if (column == 1) {
  315. this.month = this.months[value].length == 3 ? this.months[value].substring(0, 2) : this.months[value].substring(0, 1);
  316. }
  317. this.getDays();
  318. this.dates[1] = this.months;
  319. this.dates[2] = this.days;
  320. }
  321. break;
  322. }
  323. },
  324. confirm(e) {
  325. // console.log('确定:', e);
  326. let value = e.detail.value;
  327. let date = '';
  328. switch (this.showMode) {
  329. case 'year':
  330. {
  331. date = {
  332. key: this.years[value[0]].substring(0, 4),
  333. value: this.years[value[0]]
  334. };
  335. }
  336. break;
  337. case 'month':
  338. {
  339. date = {
  340. key: this.months[value[0]].substring(0, this.months[value[0]].length - 1),
  341. value: this.months[value[0]]
  342. };
  343. }
  344. break;
  345. case 'day':
  346. {
  347. date = {
  348. key: this.days[value[0]].substring(0, this.days[value[0]].length - 1),
  349. value: this.days[value[0]]
  350. };
  351. }
  352. break;
  353. case 'hour':
  354. {
  355. date = {
  356. key: this.hours[value[0]].substring(0, this.hours[value[0]].length - 1),
  357. value: this.hours[value[0]]
  358. };
  359. }
  360. break;
  361. case 'minute':
  362. {
  363. date = {
  364. key: this.minutes[value[0]].substring(0, this.minutes[value[0]].length - 1),
  365. value: this.minutes[value[0]]
  366. };
  367. }
  368. break;
  369. case 'second':
  370. {
  371. date = {
  372. key: this.seconds[value[0]].substring(0, this.seconds[value[0]].length - 1),
  373. value: this.seconds[value[0]]
  374. };
  375. }
  376. break;
  377. case 'yearToMonth':
  378. {
  379. let month = this.months[value[1]].substring(0, this.months[value[1]].length - 1);
  380. date = {
  381. year: this.years[value[0]].substring(0, 4),
  382. month,
  383. key: this.years[value[0]].substring(0, 4) + '-' + (month.length == 1 ? '0' + month : month),
  384. value: this.years[value[0]] + this.months[value[1]]
  385. };
  386. }
  387. break;
  388. case 'monthToDay':
  389. {
  390. let month = this.months[value[0]].substring(0, this.months[value[0]].length - 1);
  391. let day = this.days[value[1]].substring(0, this.days[value[1]].length - 1);
  392. date = {
  393. month,
  394. day,
  395. key: (month.length == 1 ? '0' + month : month) + '-' + (day.length == 1 ? '0' + day : day),
  396. value: this.months[value[0]] + this.days[value[1]]
  397. };
  398. }
  399. break;
  400. case 'hourToMinute':
  401. {
  402. let hour = this.hours[value[0]].substring(0, this.hours[value[0]].length - 1);
  403. let minute = this.minutes[value[1]].substring(0, this.minutes[value[1]].length - 1);
  404. date = {
  405. hour,
  406. minute,
  407. key: (hour.length == 1 ? '0' + hour : hour) + ':' + (minute.length == 1 ? '0' + minute : minute),
  408. value: this.hours[value[0]] + this.minutes[value[1]]
  409. };
  410. }
  411. break;
  412. case 'minuteToSecond':
  413. {
  414. let minute = this.minutes[value[0]].substring(0, this.minutes[value[0]].length - 1);
  415. let second = this.seconds[value[1]].substring(0, this.seconds[value[1]].length - 1);
  416. date = {
  417. key: (minute.length == 1 ? '0' + minute : minute) + ':' + (second.length == 1 ? '0' + second : second),
  418. value: this.minutes[value[0]] + this.seconds[value[1]]
  419. };
  420. }
  421. break;
  422. case 'date':
  423. {
  424. let month = this.months[value[1]].substring(0, this.months[value[1]].length - 1);
  425. let day = this.days[value[2]].substring(0, this.days[value[2]].length - 1);
  426. date = {
  427. year: this.years[value[0]].substring(0, 4),
  428. month,
  429. day,
  430. key: this.years[value[0]].substring(0, 4) + '-' + (month.length == 1 ? '0' + month : month) + '-' + (day.length == 1 ? '0' + day : day),
  431. value: this.years[value[0]] + this.months[value[1]] + this.days[value[2]]
  432. };
  433. }
  434. break;
  435. case 'time':
  436. {
  437. let hour = this.hours[value[0]].substring(0, this.hours[value[0]].length - 1);
  438. let minute = this.minutes[value[1]].substring(0, this.minutes[value[1]].length - 1);
  439. let second = this.seconds[value[2]].substring(0, this.seconds[value[2]].length - 1);
  440. date = {
  441. hour,
  442. minute,
  443. second,
  444. key: (hour.length == 1 ? '0' + hour : hour) + ':' + (minute.length == 1 ? '0' + minute : minute) + ':' + (second.length == 1 ? '0' + second : second),
  445. value: this.hours[value[0]] + this.minutes[value[1]] + this.seconds[value[2]]
  446. };
  447. }
  448. break;
  449. case 'yearToMinute':
  450. {
  451. let month = this.months[value[1]].substring(0, this.months[value[1]].length - 1);
  452. let day = this.days[value[2]].substring(0, this.days[value[2]].length - 1);
  453. let hour = this.hours[value[3]].substring(0, this.hours[value[3]].length - 1);
  454. let minute = this.minutes[value[4]].substring(0, this.minutes[value[4]].length - 1);
  455. date = {
  456. year: this.years[value[0]].substring(0, 4),
  457. month,
  458. day,
  459. hour,
  460. minute,
  461. key:
  462. this.years[value[0]].substring(0, 4) +
  463. '-' +
  464. (month.length == 1 ? '0' + month : month) +
  465. '+' +
  466. (day.length == 1 ? '0' + day : day) +
  467. ' ' +
  468. (hour.length == 1 ? '0' + hour : hour) +
  469. ':' +
  470. (minute.length == 1 ? '0' + minute : minute),
  471. value: this.years[value[0]] + this.months[value[1]] + this.days[value[2]] + this.hours[value[3]] + this.minutes[value[4]]
  472. };
  473. }
  474. break;
  475. default:
  476. {
  477. let month = this.months[value[1]].substring(0, this.months[value[1]].length - 1);
  478. let day = this.days[value[2]].substring(0, this.days[value[2]].length - 1);
  479. let hour = this.hours[value[3]].substring(0, this.hours[value[3]].length - 1);
  480. let minute = this.minutes[value[4]].substring(0, this.minutes[value[4]].length - 1);
  481. let second = this.seconds[value[5]].substring(0, this.seconds[value[5]].length - 1);
  482. date = {
  483. year: this.years[value[0]].substring(0, 4),
  484. month,
  485. day,
  486. hour,
  487. minute,
  488. second,
  489. key:
  490. this.years[value[0]].substring(0, 4) +
  491. '-' +
  492. (month.length == 1 ? '0' + month : month) +
  493. '-' +
  494. (day.length == 1 ? '0' + day : day) +
  495. ' ' +
  496. (hour.length == 1 ? '0' + hour : hour) +
  497. ':' +
  498. (minute.length == 1 ? '0' + minute : minute) +
  499. ':' +
  500. (second.length == 1 ? '0' + second : second),
  501. value: this.years[value[0]] + this.months[value[1]] + this.days[value[2]] + this.hours[value[3]] + this.minutes[value[4]] + this.seconds[value[5]]
  502. };
  503. }
  504. break;
  505. }
  506. this.$emit('btnConfirm', date);
  507. },
  508. cancel(e) {
  509. // console.log('取消:', e);
  510. this.$emit('btnCancel');
  511. },
  512. getMonths() {
  513. this.months = [];
  514. if (parseInt(this.beginYear) == parseInt(this.year) && parseInt(this.endYear) == parseInt(this.year)) {
  515. for (var i = parseInt(this.beginMonth); i <= parseInt(this.endMonth); i++) {
  516. this.months.push(i + '月');
  517. }
  518. } else if (parseInt(this.beginYear) >= parseInt(this.year)) {
  519. for (var i = parseInt(this.beginMonth); i <= 12; i++) {
  520. this.months.push(i + '月');
  521. }
  522. } else if (parseInt(this.endYear) <= parseInt(this.year)) {
  523. for (var i = 1; i <= parseInt(this.endMonth); i++) {
  524. this.months.push(i + '月');
  525. }
  526. } else {
  527. for (var i = 1; i <= 12; i++) {
  528. this.months.push(i + '月');
  529. }
  530. }
  531. },
  532. getDays() {
  533. this.days = [];
  534. switch (this.month) {
  535. case 1:
  536. case 3:
  537. case 5:
  538. case 7:
  539. case 8:
  540. case 10:
  541. case 12:
  542. case '1':
  543. case '3':
  544. case '5':
  545. case '7':
  546. case '8':
  547. case '10':
  548. case '12':
  549. {
  550. if (parseInt(this.beginDay) < 0 || parseInt(this.beginDay) > 31) {
  551. this.beginDay = 1;
  552. }
  553. if (parseInt(this.endDay) < 0 || parseInt(this.endDay) > 31) {
  554. this.endDay = 31;
  555. }
  556. if (
  557. parseInt(this.beginYear) == parseInt(this.year) &&
  558. parseInt(this.endYear) == parseInt(this.year) &&
  559. parseInt(this.beginMonth) == parseInt(this.month) &&
  560. parseInt(this.endMonth) == parseInt(this.month)
  561. ) {
  562. for (var i = parseInt(this.beginDay); i <= parseInt(this.endDay); i++) {
  563. this.days.push(i + '日');
  564. }
  565. } else if (
  566. (parseInt(this.beginYear) == parseInt(this.year) &&
  567. parseInt(this.endYear) == parseInt(this.year) &&
  568. parseInt(this.beginMonth) == parseInt(this.month)) ||
  569. (parseInt(this.beginYear) >= parseInt(this.year) && parseInt(this.beginMonth) == parseInt(this.month))
  570. ) {
  571. for (var i = parseInt(this.beginDay); i <= 31; i++) {
  572. this.days.push(i + '日');
  573. }
  574. } else if (
  575. (parseInt(this.beginYear) == parseInt(this.year) && parseInt(this.endYear) == parseInt(this.year) && parseInt(this.endMonth) == parseInt(this.month)) ||
  576. (parseInt(this.endYear) <= parseInt(this.year) && parseInt(this.endMonth) == parseInt(this.month))
  577. ) {
  578. for (var i = 1; i <= parseInt(this.endDay); i++) {
  579. this.days.push(i + '日');
  580. }
  581. } else {
  582. for (var i = 1; i <= 31; i++) {
  583. this.days.push(i + '日');
  584. }
  585. }
  586. }
  587. break;
  588. case 4:
  589. case 6:
  590. case 9:
  591. case 11:
  592. case '4':
  593. case '6':
  594. case '9':
  595. case '11':
  596. {
  597. if (parseInt(this.beginDay) < 0 || parseInt(this.beginDay) > 30) {
  598. this.beginDay = 1;
  599. }
  600. if (parseInt(this.endDay) < 0 || parseInt(this.endDay) > 30) {
  601. this.endDay = 30;
  602. }
  603. if (
  604. parseInt(this.beginYear) == parseInt(this.year) &&
  605. parseInt(this.endYear) == parseInt(this.year) &&
  606. parseInt(this.beginMonth) == parseInt(this.month) &&
  607. parseInt(this.endMonth) == parseInt(this.month)
  608. ) {
  609. for (var i = parseInt(this.beginDay); i <= parseInt(this.endDay); i++) {
  610. this.days.push(i + '日');
  611. }
  612. } else if (
  613. (parseInt(this.beginYear) == parseInt(this.year) &&
  614. parseInt(this.endYear) == parseInt(this.year) &&
  615. parseInt(this.beginMonth) == parseInt(this.month)) ||
  616. (parseInt(this.beginYear) >= parseInt(this.year) && parseInt(this.beginMonth) == parseInt(this.month))
  617. ) {
  618. for (var i = parseInt(this.beginDay); i <= 30; i++) {
  619. this.days.push(i + '日');
  620. }
  621. } else if (
  622. (parseInt(this.beginYear) == parseInt(this.year) && parseInt(this.endYear) == parseInt(this.year) && parseInt(this.endMonth) == parseInt(this.month)) ||
  623. (parseInt(this.endYear) <= parseInt(this.year) && parseInt(this.endMonth) == parseInt(this.month))
  624. ) {
  625. for (var i = 1; i <= parseInt(this.endDay); i++) {
  626. this.days.push(i + '日');
  627. }
  628. } else {
  629. for (var i = 1; i <= 30; i++) {
  630. this.days.push(i + '日');
  631. }
  632. }
  633. }
  634. break;
  635. case 2:
  636. case '2':
  637. {
  638. if ((parseInt(this.year) % 4 == 0 && parseInt(this.year) % 100 != 0) || parseInt(this.year) % 400 == 0) {
  639. if (parseInt(this.beginDay) < 0 || parseInt(this.beginDay) > 29) {
  640. this.beginDay = 1;
  641. }
  642. if (parseInt(this.endDay) < 0 || parseInt(this.endDay) > 29) {
  643. this.endDay = 29;
  644. }
  645. if (
  646. parseInt(this.beginYear) == parseInt(this.year) &&
  647. parseInt(this.endYear) == parseInt(this.year) &&
  648. parseInt(this.beginMonth) == parseInt(this.month) &&
  649. parseInt(this.endMonth) == parseInt(this.month)
  650. ) {
  651. for (var i = parseInt(this.beginDay); i <= parseInt(this.endDay); i++) {
  652. this.days.push(i + '日');
  653. }
  654. } else if (
  655. (parseInt(this.beginYear) == parseInt(this.year) &&
  656. parseInt(this.endYear) == parseInt(this.year) &&
  657. parseInt(this.beginMonth) == parseInt(this.month)) ||
  658. (parseInt(this.beginYear) >= parseInt(this.year) && parseInt(this.beginMonth) == parseInt(this.month))
  659. ) {
  660. for (var i = parseInt(this.beginDay); i <= 29; i++) {
  661. this.days.push(i + '日');
  662. }
  663. } else if (
  664. (parseInt(this.beginYea) == parseInt(this.year) &&
  665. parseInt(this.endYear) == parseInt(this.year) &&
  666. parseInt(this.endMonth) == parseInt(this.month)) ||
  667. (parseInt(this.endYear) <= parseInt(this.year) && parseInt(this.endMonth) == parseInt(this.month))
  668. ) {
  669. for (var i = 1; i <= parseInt(this.endDay); i++) {
  670. this.days.push(i + '日');
  671. }
  672. } else {
  673. for (var i = 1; i <= 29; i++) {
  674. this.days.push(i + '日');
  675. }
  676. }
  677. } else {
  678. if (parseInt(this.beginDay) < 0 || parseInt(this.beginDay) > 28) {
  679. this.beginDay = 1;
  680. }
  681. if (parseInt(this.endDay) < 0 || parseInt(this.endDay) > 28) {
  682. this.endDay = 28;
  683. }
  684. if (
  685. parseInt(this.beginYear) == parseInt(this.year) &&
  686. parseInt(this.endYear) == parseInt(this.year) &&
  687. parseInt(this.beginMonth) == parseInt(this.month) &&
  688. parseInt(this.endMonth) == parseInt(this.month)
  689. ) {
  690. for (var i = parseInt(this.beginDay); i <= parseInt(this.endDay); i++) {
  691. this.days.push(i + '日');
  692. }
  693. } else if (
  694. (parseInt(this.beginYear) == parseInt(this.year) &&
  695. parseInt(this.endYear) == parseInt(this.year) &&
  696. parseInt(this.beginMonth) == parseInt(this.month)) ||
  697. (parseInt(this.beginYear) >= parseInt(this.year) && parseInt(this.beginMonth) == parseInt(this.month))
  698. ) {
  699. for (var i = parseInt(this.beginDay); i <= 28; i++) {
  700. this.days.push(i + '日');
  701. }
  702. } else if (
  703. (parseInt(this.beginYear) == parseInt(this.year) &&
  704. parseInt(this.endYear) == parseInt(this.year) &&
  705. parseInt(this.endMonth) == parseInt(this.month)) ||
  706. (parseInt(this.endYear) <= parseInt(this.year) && parseInt(this.endMonth) == parseInt(this.month))
  707. ) {
  708. for (var i = 1; i <= parseInt(this.endDay); i++) {
  709. this.days.push(i + '日');
  710. }
  711. } else {
  712. for (var i = 1; i <= 28; i++) {
  713. this.days.push(i + '日');
  714. }
  715. }
  716. }
  717. }
  718. break;
  719. }
  720. },
  721. getDate() {
  722. var date = new Date();
  723. this.year = date.getFullYear();
  724. if (parseInt(this.beginYear) > parseInt(this.year)) {
  725. this.year = this.beginYear;
  726. this.month = this.beginMonth;
  727. this.day = this.beginDay;
  728. } else if (parseInt(this.endYear) < parseInt(this.year)) {
  729. this.year = this.endYear;
  730. this.month = this.endMonth;
  731. this.day = this.endDay;
  732. } else {
  733. this.month = date.getMonth() + 1;
  734. this.day = date.getDate();
  735. }
  736. this.hour = date.getHours();
  737. this.minute = date.getMinutes();
  738. this.second = date.getSeconds();
  739. },
  740. getData() {
  741. this.dates = [];
  742. let yearIndex = 0;
  743. let monthIndex = 0;
  744. let dayIndex = 0;
  745. let hourIndex = 0;
  746. let minuteIndex = 0;
  747. let secondIndex = 0;
  748. switch (this.showMode) {
  749. case 'year':
  750. {
  751. this.dates.push(this.years);
  752. this.years.map((item, index) => {
  753. if (this.year == item.substring(0, 4)) {
  754. yearIndex = index;
  755. }
  756. });
  757. this.value = [yearIndex];
  758. }
  759. break;
  760. case 'month':
  761. {
  762. this.dates.push(this.months);
  763. this.months.map((item, index) => {
  764. if (this.month == item.substring(0, item.length - 1)) {
  765. monthIndex = index;
  766. }
  767. });
  768. this.value = [monthIndex];
  769. }
  770. break;
  771. case 'day':
  772. {
  773. this.dates.push(this.days);
  774. this.days.map((item, index) => {
  775. if (this.day == item.substring(0, item.length - 1)) {
  776. dayIndex = index;
  777. }
  778. });
  779. this.value = [dayIndex];
  780. }
  781. break;
  782. case 'hour':
  783. {
  784. this.dates.push(this.hours);
  785. this.hours.map((item, index) => {
  786. if (this.hour == item.substring(0, item.length - 1)) {
  787. hourIndex = index;
  788. }
  789. });
  790. this.value = [hourIndex];
  791. }
  792. break;
  793. case 'minute':
  794. {
  795. this.dates.push(this.minutes);
  796. this.minutes.map((item, index) => {
  797. if (this.minute == item.substring(0, item.length - 1)) {
  798. minuteIndex = index;
  799. }
  800. });
  801. this.value = [minuteIndex];
  802. }
  803. break;
  804. case 'second':
  805. {
  806. this.dates.push(this.seconds);
  807. this.seconds.map((item, index) => {
  808. if (this.second == item.substring(0, item.length - 1)) {
  809. secondIndex = index;
  810. }
  811. });
  812. this.value = [secondIndex];
  813. }
  814. break;
  815. case 'yearToMonth':
  816. {
  817. this.dates.push(this.years);
  818. this.dates.push(this.months);
  819. this.years.map((item, index) => {
  820. if (this.year == item.substring(0, 4)) {
  821. yearIndex = index;
  822. }
  823. });
  824. this.months.map((item, index) => {
  825. if (this.month == item.substring(0, item.length - 1)) {
  826. monthIndex = index;
  827. }
  828. });
  829. this.value = [yearIndex, monthIndex];
  830. }
  831. break;
  832. case 'monthToDay':
  833. {
  834. this.dates.push(this.months);
  835. this.dates.push(this.days);
  836. this.months.map((item, index) => {
  837. if (this.month == item.substring(0, item.length - 1)) {
  838. monthIndex = index;
  839. }
  840. });
  841. this.days.map((item, index) => {
  842. if (this.day == item.substring(0, item.length - 1)) {
  843. dayIndex = index;
  844. }
  845. });
  846. this.value = [monthIndex, dayIndex];
  847. }
  848. break;
  849. case 'hourToMinute':
  850. {
  851. this.dates.push(this.hours);
  852. this.dates.push(this.minutes);
  853. this.hours.map((item, index) => {
  854. if (this.hour == item.substring(0, item.length - 1)) {
  855. hourIndex = index;
  856. }
  857. });
  858. this.minutes.map((item, index) => {
  859. if (this.minute == item.substring(0, item.length - 1)) {
  860. minuteIndex = index;
  861. }
  862. });
  863. this.value = [hourIndex, minuteIndex];
  864. }
  865. break;
  866. case 'minuteToSecond':
  867. {
  868. this.dates.push(this.minutes);
  869. this.dates.push(this.seconds);
  870. this.minutes.map((item, index) => {
  871. if (this.minute == item.substring(0, item.length - 1)) {
  872. minuteIndex = index;
  873. }
  874. });
  875. this.seconds.map((item, index) => {
  876. if (this.second == item.substring(0, item.length - 1)) {
  877. secondIndex = index;
  878. }
  879. });
  880. this.value = [minuteIndex, secondIndex];
  881. }
  882. break;
  883. case 'date':
  884. {
  885. this.dates.push(this.years);
  886. this.dates.push(this.months);
  887. this.dates.push(this.days);
  888. this.years.map((item, index) => {
  889. if (this.year == item.substring(0, 4)) {
  890. yearIndex = index;
  891. }
  892. });
  893. this.months.map((item, index) => {
  894. if (this.month == item.substring(0, item.length - 1)) {
  895. monthIndex = index;
  896. }
  897. });
  898. this.days.map((item, index) => {
  899. if (this.day == item.substring(0, item.length - 1)) {
  900. dayIndex = index;
  901. }
  902. });
  903. this.value = [yearIndex, monthIndex, dayIndex];
  904. }
  905. break;
  906. case 'time':
  907. {
  908. this.dates.push(this.hours);
  909. this.dates.push(this.minutes);
  910. this.dates.push(this.seconds);
  911. this.hours.map((item, index) => {
  912. if (this.hour == item.substring(0, item.length - 1)) {
  913. hourIndex = index;
  914. }
  915. });
  916. this.minutes.map((item, index) => {
  917. if (this.minute == item.substring(0, item.length - 1)) {
  918. minuteIndex = index;
  919. }
  920. });
  921. this.seconds.map((item, index) => {
  922. if (this.second == item.substring(0, item.length - 1)) {
  923. secondIndex = index;
  924. }
  925. });
  926. this.value = [hourIndex, minuteIndex, secondIndex];
  927. }
  928. break;
  929. case 'yearToMinute':
  930. {
  931. this.dates.push(this.years);
  932. this.dates.push(this.months);
  933. this.dates.push(this.days);
  934. this.dates.push(this.hours);
  935. this.dates.push(this.minutes);
  936. this.years.map((item, index) => {
  937. if (this.year == item.substring(0, 4)) {
  938. yearIndex = index;
  939. }
  940. });
  941. this.months.map((item, index) => {
  942. if (this.month == item.substring(0, item.length - 1)) {
  943. monthIndex = index;
  944. }
  945. });
  946. this.days.map((item, index) => {
  947. if (this.day == item.substring(0, item.length - 1)) {
  948. dayIndex = index;
  949. }
  950. });
  951. this.hours.map((item, index) => {
  952. if (this.hour == item.substring(0, item.length - 1)) {
  953. hourIndex = index;
  954. }
  955. });
  956. this.minutes.map((item, index) => {
  957. if (this.minute == item.substring(0, item.length - 1)) {
  958. minuteIndex = index;
  959. }
  960. });
  961. this.value = [yearIndex, monthIndex, dayIndex, hourIndex, minuteIndex];
  962. }
  963. break;
  964. default:
  965. {
  966. this.dates.push(this.years);
  967. this.dates.push(this.months);
  968. this.dates.push(this.days);
  969. this.dates.push(this.hours);
  970. this.dates.push(this.minutes);
  971. this.dates.push(this.seconds);
  972. this.years.map((item, index) => {
  973. if (this.year == item.substring(0, 4)) {
  974. yearIndex = index;
  975. }
  976. });
  977. this.months.map((item, index) => {
  978. if (this.month == item.substring(0, item.length - 1)) {
  979. monthIndex = index;
  980. }
  981. });
  982. this.days.map((item, index) => {
  983. if (this.day == item.substring(0, item.length - 1)) {
  984. dayIndex = index;
  985. }
  986. });
  987. this.hours.map((item, index) => {
  988. if (this.hour == item.substring(0, item.length - 1)) {
  989. hourIndex = index;
  990. }
  991. });
  992. this.minutes.map((item, index) => {
  993. if (this.minute == item.substring(0, item.length - 1)) {
  994. minuteIndex = index;
  995. }
  996. });
  997. this.seconds.map((item, index) => {
  998. if (this.second == item.substring(0, item.length - 1)) {
  999. secondIndex = index;
  1000. }
  1001. });
  1002. this.value = [yearIndex, monthIndex, dayIndex, hourIndex, minuteIndex, secondIndex];
  1003. }
  1004. break;
  1005. }
  1006. },
  1007. // 日期转为时间戳
  1008. getMillisecond(date) {
  1009. return new Date(date).getTime();
  1010. }
  1011. }
  1012. };
  1013. </script>
  1014. <style></style>