demo.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <view>
  3. <view class="set">
  4. <button type="primary" @click="name">选择日期</button>
  5. <view class="zhi">{{inputValue}}</view>
  6. </view>
  7. <!-- 放入页面调用 -->
  8. <sen-set-picker ref="setpicker" :shixian="shixian" @quxiaoButton="quxiaobutton" @quedingButton="quedingbutton"></sen-set-picker>
  9. </view>
  10. </template>
  11. <script>
  12. // 引入组件
  13. import senSetPicker from '../../components/sen-pickerview/sen-pickerview.vue'
  14. export default {
  15. components: {
  16. senSetPicker
  17. },
  18. data() {
  19. const currentDate = this.getDate({
  20. format: true
  21. });
  22. return {
  23. inputValue : currentDate,
  24. shixian : false
  25. }
  26. },
  27. methods: {
  28. name : function () {
  29. this.$refs.setpicker.confirm(this.inputValue);
  30. this.shixian = true;
  31. },
  32. quxiaobutton : function () {
  33. this.shixian = false;
  34. },
  35. quedingbutton : function(bangdingyear,bangdingmonth,bangdingday){
  36. this.shixian = false;
  37. this.inputValue = bangdingyear + "-" + bangdingmonth + "-" + bangdingday;
  38. },
  39. getDate(type) {
  40. const date = new Date();
  41. let year = date.getFullYear();
  42. let month = date.getMonth() + 1;
  43. let day = date.getDate();
  44. if (type === 'start') {
  45. year = year - 60;
  46. } else if (type === 'end') {
  47. year = year + 2;
  48. }else if(type === 'now') {
  49. year = year;
  50. }
  51. month = month > 9 ? month : '0' + month;;
  52. day = day > 9 ? day : '0' + day;
  53. return `${year}-${month}-${day}`;
  54. }
  55. }
  56. }
  57. </script>
  58. <style>
  59. .set{
  60. width: 100%;
  61. }
  62. .set button{
  63. width: 50%;
  64. float: right;
  65. line-height:60upx;
  66. }
  67. .zhi{
  68. width: 50%;
  69. float: left;
  70. line-height: 60upx;
  71. }
  72. </style>