uni-drawer-all.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <view v-if="visibleSync" :class="{ 'uni-drawer--visible': showDrawer }" class="uni-drawer">
  3. <view class="uni-drawer__mask" :class="{ 'uni-drawer__mask--visible': showDrawer && mask }" @tap="close" />
  4. <view class="uni-drawer__content" :class="{ 'uni-drawer--right': rightMode, 'uni-drawer--left': !rightMode, 'uni-drawer__content--visible': showDrawer }">
  5. <view class="content">
  6. <view class="item" v-for="ls in relist">
  7. <view class="content_box" :class="{ active: ls.id == checkid }" @click="change(ls)">{{ls.name}}</view>
  8. <view v-if="ls.id == checkid" class="content_img"><image src="/static/xpy/023.png"></image></view>
  9. <view v-else></view>
  10. </view>
  11. </view>
  12. <view class="submit" @click="submit()">确定</view>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. name: 'UniDrawer',
  20. props: {
  21. /**
  22. * 显示状态
  23. */
  24. visible: {
  25. type: Boolean,
  26. default: false
  27. },
  28. /**
  29. * 显示模式(左、右),只在初始化生效
  30. */
  31. mode: {
  32. type: String,
  33. default: 'right'
  34. },
  35. /**
  36. * 蒙层显示状态
  37. */
  38. mask: {
  39. type: Boolean,
  40. default: true
  41. }
  42. },
  43. data() {
  44. return {
  45. visibleSync: false,
  46. showDrawer: false,
  47. rightMode: false,
  48. watchTimer: null,
  49. show:false,
  50. checkid:1,
  51. value:'',
  52. relist:[
  53. {
  54. id:1,
  55. name:'产品成本收益'
  56. },{
  57. id:2,
  58. name:'产品利润收益'
  59. },{
  60. id:3,
  61. name:'推荐加盟商'
  62. },{
  63. id:4,
  64. name:'总部发放'
  65. },{
  66. id:5,
  67. name:'退款'
  68. },{
  69. id:'',
  70. name:'全部'
  71. }]
  72. };
  73. },
  74. watch: {
  75. visible(val) {
  76. if (val) {
  77. this.open();
  78. } else {
  79. this.close();
  80. }
  81. }
  82. },
  83. created() {
  84. this.visibleSync = this.visible;
  85. setTimeout(() => {
  86. this.showDrawer = this.visible;
  87. }, 100);
  88. this.rightMode = this.mode === 'right';
  89. },
  90. methods: {
  91. change(ls){
  92. this.checkid = ls.id;
  93. this.value = ls.name;
  94. console.log(this.checkid,this.value,77)
  95. },
  96. submit(){
  97. this.close();
  98. // console.log(this.value,this.checkid,66)
  99. this.$emit('getMessage', this.value,this.checkid)
  100. },
  101. close() {
  102. this._change('showDrawer', 'visibleSync', false);
  103. },
  104. open() {
  105. this._change('visibleSync', 'showDrawer', true);
  106. },
  107. _change(param1, param2, status) {
  108. this[param1] = status;
  109. if (this.watchTimer) {
  110. clearTimeout(this.watchTimer);
  111. }
  112. this.watchTimer = setTimeout(
  113. () => {
  114. this[param2] = status;
  115. this.$emit(status ? 'open' : 'close');
  116. },
  117. status ? 50 : 300
  118. );
  119. }
  120. }
  121. };
  122. </script>
  123. <style lang="scss" scoped>
  124. // 抽屉宽度
  125. $drawer-width: 220px;
  126. .uni-drawer {
  127. /* #ifndef APP-NVUE */
  128. display: block;
  129. /* #endif */
  130. position: fixed;
  131. top: 0;
  132. left: 0;
  133. right: 0;
  134. bottom: 0;
  135. overflow: hidden;
  136. z-index: 999;
  137. }
  138. .uni-drawer__content {
  139. /* #ifndef APP-NVUE */
  140. display: block;
  141. /* #endif */
  142. position: absolute;
  143. top: 0;
  144. width: $drawer-width;
  145. bottom: 0;
  146. background-color: $uni-bg-color;
  147. transition: transform 0.3s ease;
  148. padding: 100rpx 0rpx;
  149. }
  150. .content {
  151. font-size: 30rpx;
  152. color: #333333;
  153. }
  154. .item{
  155. display: inline-block;
  156. }
  157. .content_box{
  158. border: 2rpx solid #CCCCCC;
  159. padding: 15rpx 0rpx;
  160. margin-bottom: 30rpx;
  161. width: 190rpx;
  162. border-radius: 10rpx;
  163. display: inline-block;
  164. margin-right: 10rpx;
  165. margin-left: 15rpx;
  166. }
  167. .content_img{
  168. position: absolute;
  169. margin-top: -65rpx;
  170. margin-left: 155rpx;
  171. }
  172. .content_img image{
  173. width: 50rpx;
  174. height: 35rpx;
  175. }
  176. .submit{
  177. font-size: 30rpx;
  178. color: #FFFFFF;
  179. background:linear-gradient(90deg,rgba(253,59,51,1) 0%,rgba(254,75,52,1) 100%);
  180. box-shadow:0px 0px 10px 1px rgba(235,37,27,0.3);
  181. border-radius:10px;
  182. width: 83%;
  183. margin: 50rpx auto;
  184. padding: 20rpx 0rpx;
  185. }
  186. .uni-drawer--left {
  187. left: 0;
  188. transform: translateX(-$drawer-width);
  189. }
  190. .uni-drawer--right {
  191. right: 0;
  192. transform: translateX($drawer-width);
  193. }
  194. .uni-drawer__content--visible {
  195. transform: translateX(0px);
  196. }
  197. .uni-drawer__mask {
  198. /* #ifndef APP-NVUE */
  199. display: block;
  200. /* #endif */
  201. opacity: 0;
  202. position: absolute;
  203. top: 0;
  204. left: 0;
  205. bottom: 0;
  206. right: 0;
  207. background-color: $uni-bg-color-mask;
  208. transition: opacity 0.3s;
  209. }
  210. .uni-drawer__mask--visible {
  211. /* #ifndef APP-NVUE */
  212. display: block;
  213. /* #endif */
  214. opacity: 1;
  215. }
  216. .active{
  217. background-color: #FDF2F0;
  218. color:#FC2A3F ;
  219. border: 2rpx solid #FC2A3F;
  220. }
  221. </style>