graceSelectMenu.nvue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.prevent="" v-if="show">
  9. <scroll-view class="grace-select-menus" scroll-y :style="{padding:padding, height:height+'rpx'}">
  10. <view @tap.stop="" class="grace-select-item" v-if="isInput"
  11. style="flex-direction:row; flex-wrap:nowrap; align-items:center;">
  12. <view class="grace-select-input-wrap">
  13. <input type="text" v-model="inputVal" class="grace-select-input" @confirm="addTag" :placeholder="placeholder" />
  14. </view>
  15. <text class="grace-select-input-btn" @tap.stop="addTag" @touchmove.stop.prevent="">{{addBtnName}}</text>
  16. </view>
  17. <view class="grace-select-item" v-for="(item, index) in items" :key="index" :data-index="index" @click.stop="select">
  18. <text class="grace-selected-icon grace-icons" :style="{color : index == currentIndex ? activeColor : color}" v-if="index == currentIndex">&#xe7f8;</text>
  19. <text class="grace-selected-text" :style="{color : index == currentIndex ? activeColor : color, fontSize:fontSize}">{{item}}</text>
  20. </view>
  21. </scroll-view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. props:{
  28. items : {
  29. type : Array,
  30. default : function () {
  31. return []
  32. }
  33. },
  34. show : {
  35. type : Boolean,
  36. default : false
  37. },
  38. height : {
  39. type : Number,
  40. default : 500
  41. },
  42. color : {
  43. type : String,
  44. default : "#333333"
  45. },
  46. activeColor : {
  47. type : String,
  48. default : "#3688FF"
  49. },
  50. selectIndex : {
  51. type : Number,
  52. default : 0
  53. },
  54. fontSize : {
  55. type : String,
  56. default : '26rpx'
  57. },
  58. padding:{
  59. type : String,
  60. default : "20rpx"
  61. },
  62. isInput:{type:Boolean, default:false},
  63. placeholder:{type:String, default:"自定义"},
  64. addBtnName:{type:String, default:"+ 添加"}
  65. },
  66. data() {
  67. return {
  68. currentIndex : 0,
  69. top : 0
  70. }
  71. },
  72. created : function () {
  73. this.currentIndex = this.selectIndex;
  74. },
  75. watch:{
  76. selectIndex : function () {
  77. this.currentIndex = this.selectIndex;
  78. }
  79. },
  80. methods:{
  81. showMenu:function () {
  82. this.$emit('showMenu');
  83. },
  84. close : function(){
  85. this.$emit('close');
  86. },
  87. select : function(e){
  88. var index = Number(e.currentTarget.dataset.index);
  89. this.currentIndex = index;
  90. this.$emit('select', index);
  91. this.close();
  92. },
  93. addTag : function () {
  94. if(this.inputVal == ''){return ;}
  95. this.$emit('submit', this.inputVal);
  96. this.inputVal = '';
  97. }
  98. }
  99. }
  100. </script>
  101. <style scoped>
  102. .grace-select-menu-wrap{}
  103. .grace-select-menu-title{flex-direction:row; justify-content:center; flex-wrap:nowrap; align-items:center;}
  104. .grace-select-menu-title-txt{font-size:28rpx; line-height:92rpx;}
  105. .grace-select-menu-title-icon{margin-left:10rpx; font-size:22rpx; line-height:92rpx;}
  106. .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;}
  107. .grace-select-menus{width:750rpx; position:absolute; left:0; bottom:0; background-color:#FFFFFF;}
  108. .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;}
  109. .grace-selected-icon{font-size:28rpx; line-height:80rpx; margin-right:20rpx;}
  110. .grace-selected-text{font-size:28rpx; line-height:80rpx;}
  111. .grace-select-input-wrap{width:200rpx; flex:1;}
  112. .grace-select-input{line-height:60rpx; height:60rpx; font-size:28rpx; margin-top:20rpx;margin-bottom:20rpx;}
  113. .grace-select-input-btn{width:120rpx; line-height:60rpx; height:60rpx; text-align:center; background-color:#F8F8F8; font-size:24rpx; border-radius:6rpx; color:#3688FF;}
  114. </style>