app-datetime-picker.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <view class="app-datetime-picker" @click="handleClick">
  3. <picker :mode="mode"
  4. :value="value"
  5. :start="start"
  6. :end="end"
  7. :fields="fields"
  8. @change="handleChange"
  9. @cancel="handleCancel">
  10. <view class="dir-left-nowrap cross-center" :style="{
  11. 'background': `${background}`,
  12. 'border': showBorder? `1rpx solid ${borderColor}` : 'none',
  13. 'height': `${height}rpx`,
  14. 'border-radius': `${radius}rpx`,
  15. 'text-color': `${textColor}`,
  16. }">
  17. <view class="box-grow-1" :class="[`text-align-${textPosition}`]">
  18. <!-- #ifdef MP-TOUTIAO -->
  19. <slot></slot>
  20. <!-- #endif -->
  21. <!-- #ifndef MP-TOUTIAO -->
  22. {{text}}
  23. <!-- #endif -->
  24. </view>
  25. <view class="box-grow-0" v-if="showArrow" style="padding: 0 24rpx">
  26. <image class="arrow" src="/static/image/icon/arrow-right.png"
  27. style="width: 12rpx;height: 22rpx;"></image>
  28. </view>
  29. </view>
  30. </picker>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. name: 'app-datetime-picker',
  36. props: {
  37. value: {
  38. type: String,
  39. default: '0',
  40. },
  41. text: null,
  42. mode: {
  43. type: String,
  44. default: 'date',
  45. },
  46. start: {
  47. type: String,
  48. default: '',
  49. },
  50. end: {
  51. type: String,
  52. default: '',
  53. },
  54. fields: {
  55. type: String,
  56. default: 'day',
  57. },
  58. disabled: false,
  59. showArrow: {
  60. type: Boolean,
  61. default: true,
  62. },
  63. sign: {
  64. default: null,
  65. },
  66. background: {
  67. default: 'transparent',
  68. },
  69. showBorder: {
  70. default: false,
  71. },
  72. borderColor: {
  73. default: 'transparent',
  74. },
  75. height: {
  76. default: 80,
  77. },
  78. radius: {
  79. default: 0,
  80. },
  81. textColor: {
  82. default: '#666666',
  83. },
  84. textPosition: {
  85. default: 'right',
  86. },
  87. },
  88. methods: {
  89. handleChange(e) {
  90. this.$emit('input', e.detail.value, this.sign);
  91. this.$emit('change', e, this.sign);
  92. },
  93. handleCancel(e) {
  94. this.$emit('cancel', e.detail.value, this.sign);
  95. },
  96. handleClick(e) {
  97. // #ifdef MP-ALIPAY
  98. my.datePicker({
  99. format: this.mode === 'date' ? 'yyyy-MM-dd' : 'HH:mm',
  100. success: (e) => {
  101. this.handleChange({
  102. detail: {
  103. value: e.date,
  104. },
  105. });
  106. },
  107. fail: this.handleCancel,
  108. });
  109. // #endif
  110. },
  111. },
  112. }
  113. </script>
  114. <style lang="scss" scoped>
  115. .text-align-left {
  116. text-align: left;
  117. }
  118. .text-align-right {
  119. text-align: right;
  120. }
  121. </style>