u-action-sheet-data.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <view class="u-action-sheet-data">
  3. <view class="u-action-sheet-data__trigger">
  4. <slot name="trigger"></slot>
  5. <up-input
  6. v-if="!$slots['trigger']"
  7. :modelValue="current"
  8. disabled
  9. disabledColor="#ffffff"
  10. :placeholder="title"
  11. border="none"
  12. ></up-input>
  13. <view @click="show = true"
  14. class="u-action-sheet-data__trigger__cover"></view>
  15. </view>
  16. <up-action-sheet
  17. :show="show"
  18. :actions="options"
  19. :title="title"
  20. safeAreaInsetBottom
  21. :description="description"
  22. @close="show = false"
  23. @select="select"
  24. >
  25. </up-action-sheet>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. props: {
  31. modelValue: {
  32. type: [String, Number],
  33. default: ''
  34. },
  35. title: {
  36. type: String,
  37. default: ''
  38. },
  39. description: {
  40. type: String,
  41. default: ''
  42. },
  43. options: {
  44. type: Array,
  45. default: () => {
  46. return []
  47. }
  48. },
  49. valueKey: {
  50. type: String,
  51. default: 'value'
  52. },
  53. labelKey: {
  54. type: String,
  55. default: 'name'
  56. }
  57. },
  58. data() {
  59. return {
  60. show: false,
  61. current: '',
  62. }
  63. },
  64. created() {
  65. if (this.modelValue) {
  66. this.options.forEach((ele) => {
  67. if (ele[this.valueKey] == this.modelValue) {
  68. this.current = ele[this.labelKey]
  69. }
  70. })
  71. }
  72. },
  73. emits: ['update:modelValue'],
  74. watch: {
  75. modelValue() {
  76. this.options.forEach((ele) => {
  77. if (ele[this.valueKey] == this.modelValue) {
  78. this.current = ele[this.labelKey]
  79. }
  80. })
  81. }
  82. },
  83. methods: {
  84. hideKeyboard() {
  85. uni.hideKeyboard()
  86. },
  87. select(e) {
  88. this.$emit('update:modelValue', e[this.valueKey])
  89. this.current = e[this.labelKey]
  90. },
  91. }
  92. }
  93. </script>
  94. <style lang="scss" scoped>
  95. .u-action-sheet-data {
  96. &__trigger {
  97. position: relative;
  98. &__cover {
  99. position: absolute;
  100. top: 0;
  101. left: 0;
  102. right: 0;
  103. bottom: 0;
  104. }
  105. }
  106. }
  107. </style>