test.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <view>
  3. <view class="uni-title uni-common-pl">地区选择器</view>
  4. <view class="uni-list">
  5. <view class="uni-list-cell">
  6. <view class="uni-list-cell-left">
  7. 当前选择
  8. </view>
  9. <view class="uni-list-cell-db">
  10. <picker @change="bindPickerChange" :value="index" :range="array">
  11. <view class="uni-input">{{array[index]}}</view>
  12. </picker>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="uni-title uni-common-pl">时间选择器</view>
  17. <view class="uni-list">
  18. <view class="uni-list-cell">
  19. <view class="uni-list-cell-left">
  20. 当前选择
  21. </view>
  22. <view class="uni-list-cell-db">
  23. <picker mode="time" :value="time" start="09:01" end="21:01" @change="bindTimeChange">
  24. <view class="uni-input">{{time}}</view>
  25. </picker>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="uni-title uni-common-pl">日期选择器</view>
  30. <view class="uni-list">
  31. <view class="uni-list-cell">
  32. <view class="uni-list-cell-left">
  33. 当前选择
  34. </view>
  35. <view class="uni-list-cell-db">
  36. <picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
  37. <view class="uni-input">{{date}}</view>
  38. </picker>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import {
  46. mapState,
  47. mapGetters
  48. } from 'vuex'
  49. export default {
  50. data() {
  51. const currentDate = this.getDate({
  52. format: true
  53. })
  54. return {
  55. title: 'picker',
  56. array: ['中国', '美国', '巴西', '日本'],
  57. index: 0,
  58. date: currentDate,
  59. time: '12:01'
  60. }
  61. },
  62. computed: {
  63. startDate() {
  64. return this.getDate('start');
  65. },
  66. endDate() {
  67. return this.getDate('end');
  68. }
  69. },
  70. methods: {
  71. bindPickerChange: function(e) {
  72. console.log('picker发送选择改变,携带值为', e.target.value)
  73. this.index = e.target.value
  74. },
  75. bindDateChange: function(e) {
  76. this.date = e.target.value
  77. },
  78. bindTimeChange: function(e) {
  79. this.time = e.target.value
  80. },
  81. getDate(type) {
  82. const date = new Date();
  83. let year = date.getFullYear();
  84. let month = date.getMonth() + 1;
  85. let day = date.getDate();
  86. if (type === 'start') {
  87. year = year - 60;
  88. } else if (type === 'end') {
  89. year = year + 2;
  90. }
  91. month = month > 9 ? month : '0' + month;
  92. day = day > 9 ? day : '0' + day;
  93. return `${year}-${month}-${day}`;
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss">
  99. uni-popup {
  100. .pay-type {
  101. width: 750rpx;
  102. height: 750rpx;
  103. background-color: #4CD964;
  104. }
  105. }
  106. </style>