seiminPicker.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <view class="seiminPicker">
  3. <view class="picker-modal" v-if="showPicker" @click="_close"></view>
  4. <view class="picker-content" :style="{transform: showPicker ? 'translateY(0)' : 'translateY(100%)'}">
  5. <view class="picker-header" v-if="title">
  6. <view class="packer-title" :style="{color:titleColor, fontSize:titleFontSize}" v-html="title"></view>
  7. </view>
  8. <picker-view indicator-style="height: 90rpx;" class="picker-view" :value="pickerValue" @change="changePicker">
  9. <picker-view-column>
  10. <view class="picker-item" :style="{fontSize:itemFontSize}" v-for="(item, index) in pickerList" :key="index">
  11. {{(deptDisplay == 2&&item.labelAlias)?item.labelAlias:item.label}}
  12. </view>
  13. </picker-view-column>
  14. </picker-view>
  15. <view class="picker-confirm"
  16. :style="{color: confirmColor, fontSize: confirmFontSize, fontWeight:confirmFontWeight}"
  17. @click="__confirmPicker">确定</view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import {
  23. mapState
  24. } from "vuex";
  25. export default {
  26. name: 'seiminPicker',
  27. computed: {
  28. ...mapState('other', ["deptDisplay"]),
  29. },
  30. props: {
  31. title: { //标题文字
  32. type: String,
  33. default: ""
  34. },
  35. titleColor: { //标题文字颜色
  36. type: String,
  37. default: ""
  38. },
  39. titleFontSize: { //标题文字大小
  40. type: String,
  41. default: '26rpx'
  42. },
  43. confirmColor: { // 确定按钮颜色
  44. type: String,
  45. default: ''
  46. },
  47. confirmFontSize: { //确定文字大小
  48. type: String,
  49. default: '28rpx'
  50. },
  51. confirmFontWeight: { //确定按钮的字体粗细
  52. type: String,
  53. default: ''
  54. },
  55. itemFontSize: { //选项文字大小
  56. type: String,
  57. default: '28rpx'
  58. },
  59. pickerList: { //数据
  60. type: Array
  61. },
  62. },
  63. data() {
  64. return {
  65. showPicker: false,
  66. pickerValue: [0],
  67. }
  68. },
  69. methods: {
  70. _close() {
  71. this.showPicker = false
  72. },
  73. _open() {
  74. this.showPicker = true
  75. },
  76. //确定
  77. __confirmPicker() {
  78. this.showPicker = false
  79. let checkedObj = this.pickerList[this.pickerValue]
  80. this.$emit('onConfirm', checkedObj)
  81. },
  82. // 选择初始选项
  83. _changeValue(index) {
  84. this.pickerValue = [index];
  85. },
  86. //滑动picker
  87. changePicker(e) {
  88. this.pickerValue = e.detail.value
  89. },
  90. }
  91. }
  92. </script>
  93. <style lang="scss" scoped>
  94. .picker-modal {
  95. position: fixed;
  96. top: 0;
  97. left: 0;
  98. right: 0;
  99. bottom: 0;
  100. background-color: rgba(0, 0, 0, 0.5);
  101. z-index: 99;
  102. }
  103. .picker-content {
  104. position: fixed;
  105. bottom: 0;
  106. left: 0;
  107. right: 0;
  108. z-index: 99;
  109. background-color: #F9FAFB;
  110. transition: all .3s;
  111. }
  112. .picker-header {
  113. padding: 20rpx;
  114. background-color: #fff;
  115. @include flex(center, center);
  116. @include border(bottom);
  117. }
  118. .picker-confirm {
  119. margin-top: 10rpx;
  120. background-color: #fff;
  121. height: 90rpx;
  122. @include border(top);
  123. @include flex(center, center);
  124. }
  125. .packer-title {
  126. text-align: center;
  127. }
  128. .picker-view {
  129. position: relative;
  130. bottom: 0;
  131. left: 0;
  132. right: 0;
  133. height: 490rpx;
  134. background-color: rgba(255, 255, 255, 1);
  135. }
  136. .uni-picker-view-mask {
  137. @include border(bottom);
  138. }
  139. .picker-item {
  140. text-align: center;
  141. line-height: 90rpx;
  142. text-overflow: ellipsis;
  143. }
  144. </style>