en-select.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <view class="select sys-background-fff page-env-20">
  3. <view class="title p-30 row-justify-sb">
  4. <view class="icon"></view>
  5. <text class="size-30 sys-weight-600">{{title}}</text>
  6. <view class="icon">
  7. <uni-icons class="dropdown-icon" type="closeempty" size="20" color="#666"></uni-icons>
  8. </view>
  9. </view>
  10. <view class="select">
  11. <scroll-view scroll-y="true" class="scroll-Y select">
  12. <view id="demo1" class="scroll-view-item" :class="item[itemKey] === current?'':'active'"
  13. v-for="(item,index) in localData" @click="onSelect(index)">
  14. <text class="size-28">{{item[itemText]}}</text>
  15. </view>
  16. </scroll-view>
  17. </view>
  18. <EnButton v-if="showBut" :is_fixed="true" text="确认" @onSubmit="setAffirm(true)"></EnButton>
  19. </view>
  20. </template>
  21. <script>
  22. import EnButton from "@/components/en-utils/en-button/en-button.vue";
  23. export default {
  24. name: 'peak_chart',
  25. props: {
  26. showBut: {
  27. type: Boolean,
  28. default: true
  29. },
  30. title: {
  31. type: String,
  32. default: '选择'
  33. },
  34. localData: {
  35. default: []
  36. },
  37. itemKey: {
  38. type: String,
  39. default: 'id'
  40. },
  41. itemText: {
  42. type: String,
  43. default: 'name'
  44. },
  45. value: {
  46. default: ''
  47. }
  48. },
  49. components: {
  50. EnButton
  51. },
  52. data() {
  53. return {
  54. current: -1,
  55. newValue: 0
  56. };
  57. },
  58. watch: {
  59. 'value': function() {
  60. if (this.current !== this.value) {
  61. this.current = this.value
  62. }
  63. }
  64. },
  65. methods: {
  66. setAffirm(type) {
  67. this.$emit('input', this.newValue)
  68. this.$emit('setAffirm', type)
  69. },
  70. onSelect(index) {
  71. console.log(index)
  72. this.current = this.localData[index][this.itemKey]
  73. this.newValue = this.localData[index][this.itemKey]
  74. this.$emit('input', this.newValue)
  75. this.$emit('onChange', index)
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang="scss">
  81. .select {
  82. height: 800rpx;
  83. border-radius: 20rpx 20rpx 0 0;
  84. }
  85. .icon {
  86. width: 40rpx;
  87. text-align: right;
  88. }
  89. .scroll-view-item {
  90. height: 90rpx;
  91. line-height: 90rpx;
  92. text-align: center;
  93. background: rgba(15, 177, 96, 0.1);
  94. border-radius: 10rpx;
  95. color: #0FB160;
  96. border: 1rpx solid #0FB160;
  97. margin: 16rpx 30rpx;
  98. }
  99. .active {
  100. border: none;
  101. color: #333333;
  102. background: #F7F9FE;
  103. }
  104. </style>