selector-picker.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view class="lb-selector-picker lb-picker-item"
  3. :style="{ height: height }">
  4. <picker-view :value="pickerValue"
  5. :style="{ height: height }"
  6. :indicator-style="indicatorStyle"
  7. @change="handleChange">
  8. <picker-view-column>
  9. <!-- #ifdef H5 -->
  10. <view v-for="(item, i) in list"
  11. :class="[
  12. 'lb-picker-column',
  13. (item[props.value] || item) === selectValue
  14. ? 'lb-picker-column-active'
  15. : ''
  16. ]"
  17. :key="i"
  18. :data-item="pressEnable ? JSON.stringify(item) : ''"
  19. @touchstart="touchstart"
  20. @touchmove="touchmove"
  21. @touchend="touchend">
  22. <!-- #endif -->
  23. <!-- #ifndef H5 -->
  24. <view v-for="(item, i) in list"
  25. :class="[
  26. 'lb-picker-column',
  27. (item[props.value] || item) === selectValue
  28. ? 'lb-picker-column-active'
  29. : ''
  30. ]"
  31. :key="i"
  32. :data-item="item"
  33. @touchstart="touchstart"
  34. @touchmove="touchmove"
  35. @touchend="touchend">
  36. <!-- #endif -->
  37. <!-- #ifdef APP-PLUS || H5 -->
  38. <text :class="[
  39. 'lb-picker-column-label',
  40. `lb-picker-column-label-${align}`
  41. ]"
  42. :style="[
  43. (item[props.value] || item) === selectValue
  44. ? activeColumnStyle
  45. : columnStyle
  46. ]">{{ getLabel(item.title, i, 0) }}</text>
  47. <!-- #endif -->
  48. <!-- #ifndef APP-PLUS || H5 -->
  49. <text :class="[
  50. 'lb-picker-column-label',
  51. `lb-picker-column-label-${align}`
  52. ]">{{ item[props.label] || item }}</text>
  53. <!-- #endif -->
  54. </view>
  55. </picker-view-column>
  56. </picker-view>
  57. </view>
  58. </template>
  59. <script>
  60. import { isObject } from '../utils'
  61. import { commonMixin } from '../mixins'
  62. export default {
  63. props: {
  64. value: [String, Number],
  65. list: Array,
  66. mode: String,
  67. props: Object,
  68. visible: Boolean,
  69. height: String,
  70. columnStyle: Object,
  71. activeColumnStyle: Object,
  72. align: String,
  73. pressEnable: Boolean,
  74. pressTime: Number,
  75. formatter: Function
  76. },
  77. mixins: [commonMixin],
  78. data () {
  79. return {
  80. pickerValue: [],
  81. selectValue: '',
  82. selectItem: null
  83. }
  84. },
  85. methods: {
  86. handleChange (item) {
  87. const index = item.detail.value[0] || 0
  88. this.selectItem = this.list[index]
  89. this.selectValue = isObject(this.selectItem)
  90. ? this.selectItem[this.props.value]
  91. : this.selectItem
  92. this.pickerValue = item.detail.value
  93. this.$emit('change', {
  94. value: this.selectValue,
  95. item: this.selectItem,
  96. index: index,
  97. change: 'scroll'
  98. })
  99. }
  100. }
  101. }
  102. </script>
  103. <style lang="scss" scoped>
  104. @import "../style/picker-item.scss";
  105. </style>