dmPickerView.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <dm-pop-view ref='popView' @confirm='handleConfirm' :title="title" :maskTapHide='maskTapHide'>
  3. <picker-view class="pop-pickerView" indicator-style='height:80rpx' :value="selectValue" @change="handleChange">
  4. <picker-view-column>
  5. <view class="column-item" v-for="(item,index) in options" :key="index">{{item.title}}</view>
  6. </picker-view-column>
  7. </picker-view>
  8. </dm-pop-view>
  9. </template>
  10. <script>
  11. import dmPopView from './dmPopView.vue'
  12. export default {
  13. props: {
  14. options: Array,
  15. value: [String, Number],
  16. title:{
  17. type:String,
  18. default:'请选择'
  19. },
  20. maskTapHide: {
  21. type: Boolean,
  22. default: true
  23. },
  24. },
  25. data() {
  26. return {
  27. selectValue: [0],
  28. selIdx: 0,
  29. }
  30. },
  31. methods: {
  32. show() {
  33. this.$refs.popView.show()
  34. this.options.forEach((item, i) => {
  35. if (item.value == this.value) {
  36. this.selIdx = i;
  37. this.selectValue = [this.selIdx];
  38. }
  39. })
  40. },
  41. handleConfirm() {
  42. var self = this
  43. var timeout = setTimeout(function() {
  44. self.$emit('confirm', {
  45. 'selItem': self.options[self.selIdx],
  46. 'selIdx': self.selIdx
  47. })
  48. clearTimeout(timeout)
  49. }, 100);
  50. },
  51. handleChange(e) {
  52. this.selectValue = e.detail.value
  53. this.selIdx = e.detail.value[0] || 0
  54. },
  55. },
  56. components: {
  57. dmPopView
  58. }
  59. }
  60. </script>
  61. <style scoped lang="scss">
  62. .pop-pickerView {
  63. margin: 40rpx 0;
  64. width: 750rpx;
  65. height: 300rpx;
  66. .column-item {
  67. height: 80rpx;
  68. display: flex;
  69. box-sizing: border-box;
  70. white-space: nowrap;
  71. overflow: hidden;
  72. flex-direction: row;
  73. align-items: center;
  74. justify-content: center;
  75. }
  76. }
  77. </style>