graceNvueSelectMenu.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <view class="grace-select-menu-wrap">
  3. <view class="grace-select-menu-title" @click.stop="showMenu" id="menumain">
  4. <text class="grace-select-menu-title-txt" :style="{fontSize:fontSize}">{{items[currentIndex]}}</text>
  5. <text class="grace-select-menu-title-icon grace-icons" v-if="!show">&#xe603;</text>
  6. <text class="grace-select-menu-title-icon grace-icons" v-if="show">&#xe654;</text>
  7. </view>
  8. <view class="grace-select-menu" @click.stop="close" @touchmove.stop="" v-if="show">
  9. <scroll-view class="grace-select-menus" scroll-y :style="{padding:padding, height:height+'rpx'}">
  10. <view class="grace-select-item" v-for="(item, index) in items" :key="index" :data-index="index" @click.stop="select">
  11. <text class="grace-selected-icon grace-icons" :style="{color : index == currentIndex ? activeColor : color}" v-if="index == currentIndex">&#xe7f8;</text>
  12. <text class="grace-selected-text" :style="{color : index == currentIndex ? activeColor : color, fontSize:fontSize}">{{item}}</text>
  13. </view>
  14. </scroll-view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. props:{
  21. items : {
  22. type : Array,
  23. default : function () {
  24. return []
  25. }
  26. },
  27. show : {
  28. type : Boolean,
  29. default : false
  30. },
  31. height : {
  32. type : Number,
  33. default : 300
  34. },
  35. color : {
  36. type : String,
  37. default : "#333333"
  38. },
  39. activeColor : {
  40. type : String,
  41. default : "#3688FF"
  42. },
  43. selectIndex : {
  44. type : Number,
  45. default : 0
  46. },
  47. fontSize : {
  48. type : String,
  49. default : '26rpx'
  50. },
  51. padding:{
  52. type : String,
  53. default : "20rpx"
  54. }
  55. },
  56. data() {
  57. return {
  58. currentIndex : 0,
  59. top : 0
  60. }
  61. },
  62. created : function () {
  63. this.currentIndex = this.selectIndex;
  64. },
  65. watch:{
  66. selectIndex : function () {
  67. this.currentIndex = this.selectIndex;
  68. }
  69. },
  70. methods:{
  71. showMenu:function () {
  72. this.$emit('showMenu');
  73. },
  74. close : function(){
  75. this.$emit('close');
  76. },
  77. select : function(e){
  78. var index = Number(e.currentTarget.dataset.index);
  79. this.currentIndex = index;
  80. this.$emit('select', index);
  81. this.close();
  82. }
  83. }
  84. }
  85. </script>
  86. <style scoped>
  87. .grace-select-menu-wrap{}
  88. .grace-select-menu-title{flex-direction:row; justify-content:center; flex-wrap:nowrap; align-items:center;}
  89. .grace-select-menu-title-txt{font-size:28rpx; line-height:92rpx;}
  90. .grace-select-menu-title-icon{margin-left:10rpx; font-size:22rpx; line-height:92rpx;}
  91. .grace-select-menu{position:fixed; width:750rpx; left:0; top:0; bottom:0; background-color:rgba(0,0,0,0.2); flex-direction:column; align-items:flex-end;}
  92. .grace-select-menus{width:750rpx; position:absolute; left:0; bottom:0; background-color:#FFFFFF;}
  93. .grace-select-item{padding:10rpx; background-color:#FFFFFF; font-size:28rpx; color:#333333; border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#F8F8F8; flex-direction:row; flex-wrap:nowrap; align-items:center;}
  94. .grace-selected-icon{font-size:28rpx; line-height:80rpx; margin-right:20rpx;}
  95. .grace-selected-text{font-size:28rpx; line-height:80rpx;}
  96. </style>