ui-picker.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <!-- 全局下拉框组件 -->
  3. <view>
  4. <picker class="picker" @change="bindPickerChange" :range="list" range-key="text">
  5. <view class="picker-wrapper">
  6. <view class="">{{text}}</view>
  7. <uni-icons type="bottom" :size="12" color="#DDDDDD"></uni-icons>
  8. </view>
  9. </picker>
  10. </view>
  11. </template>
  12. <script>
  13. /**
  14. * 全局单列下拉框组件
  15. * @description 全局下拉组件选择样式行为统一封装
  16. */
  17. export default {
  18. name: "ui-picker",
  19. data() {
  20. return {
  21. text: '',
  22. };
  23. },
  24. props: {
  25. // 文件地址
  26. value: {
  27. type: String,
  28. default: ''
  29. },
  30. list: {
  31. type: Array,
  32. default: () => {
  33. return []
  34. }
  35. },
  36. },
  37. watch: {
  38. value(val) {
  39. let res = this.list.find(item => item.value == val);
  40. this.text = res?.text ?? ''
  41. }
  42. },
  43. mounted() {
  44. let res = this.list.find(item => item.value == this.value);
  45. this.text = res?.text ?? ''
  46. },
  47. methods: {
  48. // 选择项目
  49. bindPickerChange(e) {
  50. let index = e.detail.value;
  51. this.text = this.list[index].text;
  52. this.$emit('onChagne', this.list[index])
  53. }
  54. }
  55. }
  56. </script>
  57. <style lang="scss">
  58. .picker {
  59. width: 240rpx;
  60. height: 60rpx;
  61. margin-left: 18rpx;
  62. font-size: 24rpx;
  63. border: #DDDDDD 1rpx solid;
  64. border-radius: 8rpx;
  65. }
  66. .picker-wrapper {
  67. display: flex;
  68. align-items: center;
  69. justify-content: space-between;
  70. height: 60rpx;
  71. padding: 0 24rpx;
  72. color: #999999;
  73. line-height: 1;
  74. }
  75. </style>