app-datetime-picker.vue 5.1 KB

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