gui-select-menu.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="gui-select-menu-wrap">
  3. <!-- #ifndef APP-NVUE -->
  4. <view class="gui-masker"
  5. v-if="show"
  6. @tap.stop.prevent="close"
  7. @touchmove.stop.prevent="stopfun"
  8. :style="{zIndex:(zIndex-1)}" ></view>
  9. <!-- #endif -->
  10. <view class="gui-select-menu-title gui-flex gui-rows gui-nowrap gui-justify-content-center gui-align-items-center"
  11. @click.stop="showMenu"
  12. id="menuMain">
  13. <text class="gui-block-text gui-ellipsis"
  14. :style="{
  15. fontSize:fontSize,
  16. color:titleColor
  17. }">{{itemsIn[currentIndex]}}</text>
  18. <text :style="{fontSize:fontSize, color:iconColor}"
  19. class="gui-icons gui-select-menu-title-icon gui-block-text"
  20. v-if="!show">&#xe603;</text>
  21. <text :style="{fontSize:fontSize, color:iconColor}"
  22. class="gui-icons gui-select-menu-title-icon gui-block-text"
  23. v-if="show">&#xe654;</text>
  24. </view>
  25. <view class="gui-select-menu"
  26. v-if="show"
  27. :style="{top : top +'px', height:height, zIndex:zIndex}"
  28. @tap.stop="close"
  29. @touchmove.stop.prevent="stopfun">
  30. <scroll-view :scroll-y="true"
  31. :show-scrollbar="false"
  32. :style="{height:height, marginTop:'100rpx'}"
  33. class="gui-select-menus gui-border-box">
  34. <view @tap.stop="stopfun"
  35. class="gui-select-item gui-flex gui-rows gui-nowrap gui-align-items-center gui-bg-gray"
  36. v-if="isInput">
  37. <input type="text"
  38. v-model="inputVal"
  39. class="gui-select-input gui-flex1 gui-border-box"
  40. @confirm="addTag"
  41. :placeholder="placeholder" />
  42. <text class="gui-select-input-btn gui-block-text"
  43. :style="{color:activeColor}"
  44. @tap.stop="addTag">{{addBtnName}}</text>
  45. </view>
  46. <view class="gui-select-item gui-flex gui-rows gui-nowrap gui-align-items-center gui-bg-white"
  47. v-for="(item, index) in itemsIn" :key="index"
  48. :class="[index < getSize() ?'gui-border-b':'']"
  49. :data-index="index"
  50. @tap.stop="select">
  51. <text class="gui-selected-icon gui-icons"
  52. :style="{
  53. color : index == currentIndex ? activeColor : color,
  54. fontSize:fontSize
  55. }"
  56. v-if="index == currentIndex">&#xe7f8;</text>
  57. <text :style="{
  58. fontSize:fontSize,
  59. color : index == currentIndex ? activeColor : color
  60. }">{{item}}</text>
  61. </view>
  62. <view style="height:25rpx;" class="gui-bg-white"><text> </text></view>
  63. </scroll-view>
  64. </view>
  65. </view>
  66. </template>
  67. <script scoped>
  68. export default {
  69. name : "gui-select-menu",
  70. props : {
  71. items : { type : Array, default : function () { return [] } },
  72. titleColor : { type : String, default : "#2B2E3D" },
  73. color : { type : String, default : "#2B2E3D" },
  74. iconColor : { type : String, default : "rgba(69, 90, 100, 0.3)"},
  75. activeColor : { type : String, default : "#008AFF" },
  76. selectIndex : { type : Number, default : 0},
  77. isH5header : { type : Boolean, default : true },
  78. fontSize : { type : String, default : '28rpx' },
  79. zIndex : { type : Number, default : 9999 },
  80. isInput : { type : Boolean, default : false},
  81. placeholder : { type : String, default : "请输入自定义条件"},
  82. addBtnName : { type : String, default :"+ 添加"},
  83. height : { type : String, default : '600rpx'}
  84. },
  85. data() {
  86. return {
  87. currentIndex : 0,
  88. top : 0,
  89. showRes : [],
  90. inputVal : '',
  91. show : false,
  92. itemsIn : []
  93. }
  94. },
  95. watch:{
  96. selectIndex : function () {
  97. this.currentIndex = this.selectIndex;
  98. },
  99. items : function (val) {
  100. this.itemsIn = val;
  101. }
  102. },
  103. created : function () {
  104. this.currentIndex = this.selectIndex;
  105. this.itemsIn = this.items;
  106. },
  107. methods:{
  108. stopfun : function (e) {e.stopPropagation(); return ;},
  109. showMenu : function () {
  110. uni.createSelectorQuery().in(this).select('#menuMain').fields(
  111. {rect: true}, (res) => {
  112. this.top = res.top;
  113. // #ifdef H5
  114. if(this.isH5header){
  115. this.top += 44;
  116. }
  117. // #endif
  118. this.show = true;
  119. this.$emit('showMenu');
  120. }
  121. ).exec();
  122. },
  123. close : function(){
  124. setTimeout(()=>{this.show = false;}, 100);
  125. this.$emit('close');
  126. },
  127. select : function(e){
  128. var index = Number(e.currentTarget.dataset.index);
  129. this.currentIndex = index;
  130. this.$emit('select', index, this.items[index]);
  131. this.close();
  132. },
  133. addTag : function () {
  134. if(this.inputVal == ''){return ;}
  135. var newArr = JSON.stringify(this.itemsIn);
  136. newArr = JSON.parse(newArr);
  137. newArr.unshift(this.inputVal);
  138. this.itemsIn = [];
  139. this.itemsIn = newArr;
  140. //newArr;
  141. this.$emit('submit', this.inputVal);
  142. this.inputVal = '';
  143. this.close();
  144. },
  145. getSize : function(){
  146. return (this.itemsIn.length - 1);
  147. },
  148. setCurrentIndex : function (index) {
  149. this.currentIndex = index;
  150. }
  151. }
  152. }
  153. </script>
  154. <style scoped>
  155. /* #ifndef APP-NVUE */
  156. @import "@/GraceUI5/css/animate.css";
  157. .animate{animation-duration:200ms; animation-timing-function:linear;}
  158. /* #endif */
  159. .gui-masker{width:750rpx; position:fixed; left:0; top:250rpx; bottom:0; flex:1; background-color:rgba(0,0,0,0.3);}
  160. .gui-select-menu-title{height:100rpx;}
  161. .gui-select-menu-title-icon{margin-left:5px; margin-top:3px;}
  162. .gui-select-menu{position:fixed; width:750rpx; left:0; top:0;}
  163. .gui-select-menus{ height:300px;}
  164. .gui-select-item{padding:0 25rpx; height:88rpx;}
  165. .gui-selected-icon{margin-right:15rpx;}
  166. .gui-select-input{line-height:60rpx; height:100rpx; width:200rpx; padding:20rpx 0; font-size:26rpx; background-color:rgba(0,0,0,0);}
  167. .gui-select-input-btn{width:120rpx; line-height:60rpx; height:60rpx; text-align:center; font-size:24rpx; border-radius:6rpx;}
  168. </style>