wing-time-selector.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  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. this.$forceUpdate()
  721. },
  722. getDate() {
  723. var date = new Date();
  724. this.year = date.getFullYear();
  725. if (parseInt(this.beginYear) > parseInt(this.year)) {
  726. this.year = this.beginYear;
  727. this.month = this.beginMonth;
  728. this.day = this.beginDay;
  729. } else if (parseInt(this.endYear) < parseInt(this.year)) {
  730. this.year = this.endYear;
  731. this.month = this.endMonth;
  732. this.day = this.endDay;
  733. } else {
  734. this.month = date.getMonth() + 1;
  735. this.day = date.getDate();
  736. }
  737. this.hour = date.getHours();
  738. this.minute = date.getMinutes();
  739. this.second = date.getSeconds();
  740. },
  741. getData() {
  742. this.dates = [];
  743. let yearIndex = 0;
  744. let monthIndex = 0;
  745. let dayIndex = 0;
  746. let hourIndex = 0;
  747. let minuteIndex = 0;
  748. let secondIndex = 0;
  749. switch (this.showMode) {
  750. case 'year':
  751. {
  752. this.dates.push(this.years);
  753. this.years.map((item, index) => {
  754. if (this.year == item.substring(0, 4)) {
  755. yearIndex = index;
  756. }
  757. });
  758. this.value = [yearIndex];
  759. }
  760. break;
  761. case 'month':
  762. {
  763. this.dates.push(this.months);
  764. this.months.map((item, index) => {
  765. if (this.month == item.substring(0, item.length - 1)) {
  766. monthIndex = index;
  767. }
  768. });
  769. this.value = [monthIndex];
  770. }
  771. break;
  772. case 'day':
  773. {
  774. this.dates.push(this.days);
  775. this.days.map((item, index) => {
  776. if (this.day == item.substring(0, item.length - 1)) {
  777. dayIndex = index;
  778. }
  779. });
  780. this.value = [dayIndex];
  781. }
  782. break;
  783. case 'hour':
  784. {
  785. this.dates.push(this.hours);
  786. this.hours.map((item, index) => {
  787. if (this.hour == item.substring(0, item.length - 1)) {
  788. hourIndex = index;
  789. }
  790. });
  791. this.value = [hourIndex];
  792. }
  793. break;
  794. case 'minute':
  795. {
  796. this.dates.push(this.minutes);
  797. this.minutes.map((item, index) => {
  798. if (this.minute == item.substring(0, item.length - 1)) {
  799. minuteIndex = index;
  800. }
  801. });
  802. this.value = [minuteIndex];
  803. }
  804. break;
  805. case 'second':
  806. {
  807. this.dates.push(this.seconds);
  808. this.seconds.map((item, index) => {
  809. if (this.second == item.substring(0, item.length - 1)) {
  810. secondIndex = index;
  811. }
  812. });
  813. this.value = [secondIndex];
  814. }
  815. break;
  816. case 'yearToMonth':
  817. {
  818. this.dates.push(this.years);
  819. this.dates.push(this.months);
  820. this.years.map((item, index) => {
  821. if (this.year == item.substring(0, 4)) {
  822. yearIndex = index;
  823. }
  824. });
  825. this.months.map((item, index) => {
  826. if (this.month == item.substring(0, item.length - 1)) {
  827. monthIndex = index;
  828. }
  829. });
  830. this.value = [yearIndex, monthIndex];
  831. }
  832. break;
  833. case 'monthToDay':
  834. {
  835. this.dates.push(this.months);
  836. this.dates.push(this.days);
  837. this.months.map((item, index) => {
  838. if (this.month == item.substring(0, item.length - 1)) {
  839. monthIndex = index;
  840. }
  841. });
  842. this.days.map((item, index) => {
  843. if (this.day == item.substring(0, item.length - 1)) {
  844. dayIndex = index;
  845. }
  846. });
  847. this.value = [monthIndex, dayIndex];
  848. }
  849. break;
  850. case 'hourToMinute':
  851. {
  852. this.dates.push(this.hours);
  853. this.dates.push(this.minutes);
  854. this.hours.map((item, index) => {
  855. if (this.hour == item.substring(0, item.length - 1)) {
  856. hourIndex = index;
  857. }
  858. });
  859. this.minutes.map((item, index) => {
  860. if (this.minute == item.substring(0, item.length - 1)) {
  861. minuteIndex = index;
  862. }
  863. });
  864. this.value = [hourIndex, minuteIndex];
  865. }
  866. break;
  867. case 'minuteToSecond':
  868. {
  869. this.dates.push(this.minutes);
  870. this.dates.push(this.seconds);
  871. this.minutes.map((item, index) => {
  872. if (this.minute == item.substring(0, item.length - 1)) {
  873. minuteIndex = index;
  874. }
  875. });
  876. this.seconds.map((item, index) => {
  877. if (this.second == item.substring(0, item.length - 1)) {
  878. secondIndex = index;
  879. }
  880. });
  881. this.value = [minuteIndex, secondIndex];
  882. }
  883. break;
  884. case 'date':
  885. {
  886. this.dates.push(this.years);
  887. this.dates.push(this.months);
  888. this.dates.push(this.days);
  889. this.years.map((item, index) => {
  890. if (this.year == item.substring(0, 4)) {
  891. yearIndex = index;
  892. }
  893. });
  894. this.months.map((item, index) => {
  895. if (this.month == item.substring(0, item.length - 1)) {
  896. monthIndex = index;
  897. }
  898. });
  899. this.days.map((item, index) => {
  900. if (this.day == item.substring(0, item.length - 1)) {
  901. dayIndex = index;
  902. }
  903. });
  904. this.value = [yearIndex, monthIndex, dayIndex];
  905. }
  906. break;
  907. case 'time':
  908. {
  909. this.dates.push(this.hours);
  910. this.dates.push(this.minutes);
  911. this.dates.push(this.seconds);
  912. this.hours.map((item, index) => {
  913. if (this.hour == item.substring(0, item.length - 1)) {
  914. hourIndex = index;
  915. }
  916. });
  917. this.minutes.map((item, index) => {
  918. if (this.minute == item.substring(0, item.length - 1)) {
  919. minuteIndex = index;
  920. }
  921. });
  922. this.seconds.map((item, index) => {
  923. if (this.second == item.substring(0, item.length - 1)) {
  924. secondIndex = index;
  925. }
  926. });
  927. this.value = [hourIndex, minuteIndex, secondIndex];
  928. }
  929. break;
  930. case 'yearToMinute':
  931. {
  932. this.dates.push(this.years);
  933. this.dates.push(this.months);
  934. this.dates.push(this.days);
  935. this.dates.push(this.hours);
  936. this.dates.push(this.minutes);
  937. this.years.map((item, index) => {
  938. if (this.year == item.substring(0, 4)) {
  939. yearIndex = index;
  940. }
  941. });
  942. this.months.map((item, index) => {
  943. if (this.month == item.substring(0, item.length - 1)) {
  944. monthIndex = index;
  945. }
  946. });
  947. this.days.map((item, index) => {
  948. if (this.day == item.substring(0, item.length - 1)) {
  949. dayIndex = index;
  950. }
  951. });
  952. this.hours.map((item, index) => {
  953. if (this.hour == item.substring(0, item.length - 1)) {
  954. hourIndex = index;
  955. }
  956. });
  957. this.minutes.map((item, index) => {
  958. if (this.minute == item.substring(0, item.length - 1)) {
  959. minuteIndex = index;
  960. }
  961. });
  962. this.value = [yearIndex, monthIndex, dayIndex, hourIndex, minuteIndex];
  963. }
  964. break;
  965. default:
  966. {
  967. this.dates.push(this.years);
  968. this.dates.push(this.months);
  969. this.dates.push(this.days);
  970. this.dates.push(this.hours);
  971. this.dates.push(this.minutes);
  972. this.dates.push(this.seconds);
  973. this.years.map((item, index) => {
  974. if (this.year == item.substring(0, 4)) {
  975. yearIndex = index;
  976. }
  977. });
  978. this.months.map((item, index) => {
  979. if (this.month == item.substring(0, item.length - 1)) {
  980. monthIndex = index;
  981. }
  982. });
  983. this.days.map((item, index) => {
  984. if (this.day == item.substring(0, item.length - 1)) {
  985. dayIndex = index;
  986. }
  987. });
  988. this.hours.map((item, index) => {
  989. if (this.hour == item.substring(0, item.length - 1)) {
  990. hourIndex = index;
  991. }
  992. });
  993. this.minutes.map((item, index) => {
  994. if (this.minute == item.substring(0, item.length - 1)) {
  995. minuteIndex = index;
  996. }
  997. });
  998. this.seconds.map((item, index) => {
  999. if (this.second == item.substring(0, item.length - 1)) {
  1000. secondIndex = index;
  1001. }
  1002. });
  1003. this.value = [yearIndex, monthIndex, dayIndex, hourIndex, minuteIndex, secondIndex];
  1004. }
  1005. break;
  1006. }
  1007. },
  1008. // 日期转为时间戳
  1009. getMillisecond(date) {
  1010. return new Date(date).getTime();
  1011. }
  1012. }
  1013. };
  1014. </script>
  1015. <style></style>