popup-picker-view.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <view class="popup-wrap" :class="{ show: visible }">
  3. <view class="popup-mask" v-if="visible"></view>
  4. <u-popup
  5. mode="bottom"
  6. closeable
  7. :zIndex="99"
  8. :overlay="false"
  9. :show="visible"
  10. safe-area-inset-bottom
  11. :closeable="false"
  12. @close="popupClose"
  13. @open="popupOpen">
  14. <view class="container">
  15. <view class="top-tools">
  16. <view class="cancel" @click="visible = false">取消</view>
  17. <view class="confirm" :style="{ color: isConfirm ? '#000' : '#ececec' }" @click="handConfirm">确定</view>
  18. </view>
  19. <picker-view :value="checkValue" @pickstart="isConfirm = false" @pickend="isConfirm = true" @change="bindChange" class="picker-view">
  20. <picker-view-column v-for="(item, index) in list" :key="index">
  21. <view class="item" v-for="i in item" :key="i[itemKey]">{{ i[itemName] }}</view>
  22. </picker-view-column>
  23. </picker-view>
  24. </view>
  25. </u-popup>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. name: 'popup-picker-view',
  31. props: {
  32. itemKey: {
  33. type: String,
  34. default: 'goodsTypeId'
  35. },
  36. itemName: {
  37. type: String,
  38. default: 'goodsTypeName'
  39. },
  40. list: {
  41. type: Array,
  42. default() {
  43. return []
  44. }
  45. }
  46. },
  47. data () {
  48. return {
  49. visible: false,
  50. isConfirm: true,
  51. checkValue: 0,
  52. tempPickerIndex: null,
  53. pickerIndex: null
  54. }
  55. },
  56. methods: {
  57. show () {
  58. this.visible = true
  59. },
  60. popupClose () {
  61. this.visible = false
  62. },
  63. popupOpen () {
  64. },
  65. // bindChange ({ target: { value } }) {
  66. // this.isConfirm = true
  67. // this.checkValue = value
  68. // },
  69. bindChange(e) {
  70. this.tempPickerIndex = e.detail.value
  71. },
  72. handConfirm () {
  73. if (!this.isConfirm) {
  74. // uni.showToast({
  75. // title: '您的操作过快,请慢一点儿!',
  76. // icon: 'none'
  77. // })
  78. return
  79. }
  80. if (this.tempPickerIndex === null) {
  81. this.pickerIndex = 0
  82. } else {
  83. this.pickerIndex = this.tempPickerIndex;
  84. }
  85. let item = this.list[0][this.pickerIndex]
  86. this.$emit('callback', item)
  87. this.visible = false
  88. }
  89. }
  90. }
  91. </script>
  92. <style scoped lang="scss">
  93. .popup-wrap {
  94. width: 100vw;
  95. height: 100vh;
  96. overflow: hidden;
  97. z-index: -1;
  98. position: fixed;
  99. top: 0;
  100. left: 0;
  101. }
  102. .popup-wrap.show {
  103. z-index: 999;
  104. }
  105. .container {
  106. width: 100%;
  107. height: 35vh;
  108. position: relative;
  109. z-index: 999;
  110. }
  111. .top-tools {
  112. height: 80rpx;
  113. padding: 0 40rpx;
  114. box-sizing: border-box;
  115. @include between;
  116. border-bottom: 2rpx solid #ececec;
  117. }
  118. .popup-mask {
  119. position: fixed;
  120. width: 100vw;
  121. height: 100vh;
  122. z-index: 1;
  123. background-color: rgba(0,0,0,.5);
  124. }
  125. // 设置头部的取消和确定按钮
  126. picker-view .btns {
  127. width: 100%;
  128. height: 100rpx;
  129. color: #baa076;
  130. display: flex;
  131. align-items: center;
  132. justify-content: space-between;
  133. position: absolute;
  134. top: 0;
  135. left: 0;
  136. z-index: 5;
  137. }
  138. picker-view .btns view {
  139. width: 20%;
  140. text-align: center;
  141. font-size: 32rpx;
  142. }
  143. picker-view {
  144. background-color: #FFF;
  145. text-align: center;
  146. box-sizing: border-box;
  147. width: 100%;
  148. border-radius: 30rpx 30rpx 0 0;
  149. z-index: 999;
  150. height: calc(35vh - 80rpx);
  151. }
  152. // 添加弹出的过渡动画
  153. picker-view.show {
  154. height: 36%;
  155. transition: all 0.4s;
  156. }
  157. // 设置单列数据的样式
  158. picker-view-column {
  159. border-radius: 30rpx 30rpx 0 0;
  160. color: #000;
  161. font-size: 32rpx;
  162. }
  163. .item {
  164. line-height: 68rpx !important;
  165. }
  166. </style>