en-select.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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" @click="close"></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. close(){
  78. this.$emit('close')
  79. }
  80. }
  81. }
  82. </script>
  83. <style lang="scss">
  84. .select {
  85. height: 800rpx;
  86. border-radius: 20rpx 20rpx 0 0;
  87. }
  88. .icon {
  89. width: 40rpx;
  90. text-align: right;
  91. }
  92. .scroll-view-item {
  93. height: 90rpx;
  94. line-height: 90rpx;
  95. text-align: center;
  96. background: rgba(15, 177, 96, 0.1);
  97. border-radius: 10rpx;
  98. color: #0FB160;
  99. border: 1rpx solid #0FB160;
  100. margin: 16rpx 30rpx;
  101. }
  102. .active {
  103. border: none;
  104. color: #333333;
  105. background: #F7F9FE;
  106. }
  107. </style>