selector-picker.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. <view v-for="(item, i) in list"
  10. :class="[
  11. 'lb-picker-column',
  12. (item[props.value] || item) === selectValue
  13. ? 'lb-picker-column-active'
  14. : ''
  15. ]"
  16. :key="i">
  17. <text class="lb-picker-column-label">
  18. {{ item[props.label] || item }}
  19. </text>
  20. </view>
  21. </picker-view-column>
  22. </picker-view>
  23. </view>
  24. </template>
  25. <script>
  26. import { isObject } from '../utils'
  27. import { commonMixin } from '../mixins'
  28. export default {
  29. props: {
  30. value: [String, Number],
  31. list: Array,
  32. mode: String,
  33. props: Object,
  34. visible: Boolean,
  35. height: String
  36. },
  37. mixins: [commonMixin],
  38. data () {
  39. return {
  40. pickerValue: [],
  41. selectValue: '',
  42. selectItem: null
  43. }
  44. },
  45. methods: {
  46. handleChange (item) {
  47. const index = item.detail.value[0] || 0
  48. this.selectItem = this.list[index]
  49. this.selectValue = isObject(this.selectItem)
  50. ? this.selectItem[this.props.value]
  51. : this.selectItem
  52. this.pickerValue = item.detail.value
  53. this.$emit('change', {
  54. value: this.selectValue,
  55. item: this.selectItem,
  56. index: index,
  57. change: 'scroll'
  58. })
  59. }
  60. }
  61. }
  62. </script>
  63. <style lang="scss" scoped>
  64. @import "../style/picker-item.scss";
  65. </style>