uni-drawer.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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:'',
  64. name:'全部 '
  65. }]
  66. };
  67. },
  68. watch: {
  69. visible(val) {
  70. if (val) {
  71. this.open();
  72. } else {
  73. this.close();
  74. }
  75. }
  76. },
  77. created() {
  78. this.visibleSync = this.visible;
  79. setTimeout(() => {
  80. this.showDrawer = this.visible;
  81. }, 100);
  82. this.rightMode = this.mode === 'right';
  83. },
  84. methods: {
  85. change(ls){
  86. this.checkid = ls.id;
  87. this.value = ls.name;
  88. console.log(this.checkid,this.value,77)
  89. },
  90. submit(){
  91. this.close();
  92. // console.log(this.value,this.checkid,66)
  93. this.$emit('getMessage', this.value,this.checkid)
  94. },
  95. close() {
  96. this._change('showDrawer', 'visibleSync', false);
  97. },
  98. open() {
  99. this._change('visibleSync', 'showDrawer', true);
  100. },
  101. _change(param1, param2, status) {
  102. this[param1] = status;
  103. if (this.watchTimer) {
  104. clearTimeout(this.watchTimer);
  105. }
  106. this.watchTimer = setTimeout(
  107. () => {
  108. this[param2] = status;
  109. this.$emit(status ? 'open' : 'close');
  110. },
  111. status ? 50 : 300
  112. );
  113. }
  114. }
  115. };
  116. </script>
  117. <style lang="scss" scoped>
  118. // 抽屉宽度
  119. $drawer-width: 220px;
  120. .uni-drawer {
  121. /* #ifndef APP-NVUE */
  122. display: block;
  123. /* #endif */
  124. position: fixed;
  125. top: 0;
  126. left: 0;
  127. right: 0;
  128. bottom: 0;
  129. overflow: hidden;
  130. z-index: 999;
  131. }
  132. .uni-drawer__content {
  133. /* #ifndef APP-NVUE */
  134. display: block;
  135. /* #endif */
  136. position: absolute;
  137. top: 0;
  138. width: $drawer-width;
  139. bottom: 0;
  140. background-color: $uni-bg-color;
  141. transition: transform 0.3s ease;
  142. padding: 100rpx 0rpx;
  143. }
  144. .content {
  145. font-size: 30rpx;
  146. color: #333333;
  147. }
  148. .item{
  149. display: inline-block;
  150. }
  151. .content_box{
  152. border: 2rpx solid #CCCCCC;
  153. padding: 15rpx 0rpx;
  154. margin-bottom: 30rpx;
  155. width: 190rpx;
  156. border-radius: 10rpx;
  157. display: inline-block;
  158. margin-right: 10rpx;
  159. margin-left: 15rpx;
  160. }
  161. .content_img{
  162. position: absolute;
  163. margin-top: -65rpx;
  164. margin-left: 155rpx;
  165. }
  166. .content_img image{
  167. width: 50rpx;
  168. height: 35rpx;
  169. }
  170. .submit{
  171. font-size: 30rpx;
  172. color: #FFFFFF;
  173. background:linear-gradient(90deg,rgba(253,59,51,1) 0%,rgba(254,75,52,1) 100%);
  174. box-shadow:0px 0px 10px 1px rgba(235,37,27,0.3);
  175. border-radius:10px;
  176. width: 83%;
  177. margin: 50rpx auto;
  178. padding: 20rpx 0rpx;
  179. }
  180. .uni-drawer--left {
  181. left: 0;
  182. transform: translateX(-$drawer-width);
  183. }
  184. .uni-drawer--right {
  185. right: 0;
  186. transform: translateX($drawer-width);
  187. }
  188. .uni-drawer__content--visible {
  189. transform: translateX(0px);
  190. }
  191. .uni-drawer__mask {
  192. /* #ifndef APP-NVUE */
  193. display: block;
  194. /* #endif */
  195. opacity: 0;
  196. position: absolute;
  197. top: 0;
  198. left: 0;
  199. bottom: 0;
  200. right: 0;
  201. background-color: $uni-bg-color-mask;
  202. transition: opacity 0.3s;
  203. }
  204. .uni-drawer__mask--visible {
  205. /* #ifndef APP-NVUE */
  206. display: block;
  207. /* #endif */
  208. opacity: 1;
  209. }
  210. .active{
  211. background-color: #FDF2F0;
  212. color:#FC2A3F ;
  213. border: 2rpx solid #FC2A3F;
  214. }
  215. </style>