en-select.vue 2.2 KB

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