index.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <view class="single-drop-list" @click="show = true">
  3. <u--input
  4. v-model="name"
  5. disabled
  6. disabledColor="#ffffff"
  7. :placeholder="placeholder"
  8. border="none"
  9. ></u--input>
  10. <u-icon
  11. slot="right"
  12. name="arrow-right"
  13. ></u-icon>
  14. <u-action-sheet
  15. :show="show"
  16. :actions="src"
  17. :title="placeholder"
  18. @close="show = false"
  19. @select="onSelect"
  20. >
  21. </u-action-sheet>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. name: 'single-drop-list',
  27. props: {
  28. src: {
  29. type: Array,
  30. default: () => [],
  31. },
  32. defaultValue: {
  33. type: String,
  34. default: () => {},
  35. },
  36. placeholder: {
  37. type: String,
  38. default: '选择参会单位',
  39. }
  40. },
  41. data() {
  42. return {
  43. show: false,
  44. name: '',
  45. value: '',
  46. };
  47. },
  48. watch: {
  49. src: {
  50. handler(val) {
  51. if (val && val.length > 0 && this.defaultValue) {
  52. const defItem = val.find((item) => String(item.value) === this.defaultValue);
  53. if (defItem) {
  54. this.name = defItem.name;
  55. }
  56. }
  57. },
  58. immediate: true,
  59. },
  60. },
  61. created() {
  62. },
  63. mounted() {
  64. },
  65. methods: {
  66. onSelect(item) {
  67. this.name = item.name;
  68. this.$emit('onChange', item);
  69. },
  70. },
  71. };
  72. </script>
  73. <style lang="scss" src="./index.scss" />