en-select.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 :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. title: {
  28. type: String,
  29. default: '选择'
  30. },
  31. localData: {
  32. default: []
  33. },
  34. itemKey: {
  35. type: String,
  36. default: 'id'
  37. },
  38. itemText: {
  39. type: String,
  40. default: 'name'
  41. },
  42. value: {
  43. default: ''
  44. }
  45. },
  46. components: {
  47. EnButton
  48. },
  49. data() {
  50. return {
  51. current: -1,
  52. newValue: 0
  53. };
  54. },
  55. watch: {
  56. 'value': function() {
  57. if (this.current !== this.value) {
  58. this.current = this.value
  59. }
  60. }
  61. },
  62. methods: {
  63. setAffirm(type) {
  64. this.$emit('input', this.newValue)
  65. this.$emit('setAffirm', type)
  66. },
  67. onSelect(index) {
  68. console.log(index)
  69. this.current = this.localData[index][this.itemKey]
  70. this.newValue = this.localData[index][this.itemKey]
  71. this.$emit('input', this.newValue)
  72. }
  73. }
  74. }
  75. </script>
  76. <style lang="scss">
  77. .select {
  78. height: 800rpx;
  79. border-radius: 20rpx 20rpx 0 0;
  80. }
  81. .icon {
  82. width: 40rpx;
  83. text-align: right;
  84. }
  85. .scroll-view-item {
  86. height: 90rpx;
  87. line-height: 90rpx;
  88. text-align: center;
  89. background: rgba(15, 177, 96, 0.1);
  90. border-radius: 10rpx;
  91. color: #0FB160;
  92. border: 1rpx solid #0FB160;
  93. margin: 16rpx 30rpx;
  94. }
  95. .active {
  96. border: none;
  97. color: #333333;
  98. background: #F7F9FE;
  99. }
  100. </style>