unlinked-selector-picker.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <view class="lb-selector-picker lb-picker-item"
  3. :style="{ height: height }">
  4. <picker-view :value="pickerValue"
  5. :indicator-style="indicatorStyle"
  6. :style="{ height: height }"
  7. @change="handleChange">
  8. <picker-view-column v-for="(column, index) in pickerColumns"
  9. :key="index">
  10. <view v-for="(item, i) in column || []"
  11. :class="[
  12. 'lb-picker-column',
  13. (item[props.value] || item) === selectValue[index]
  14. ? 'lb-picker-column-active'
  15. : ''
  16. ]"
  17. :key="i">
  18. <text class="lb-picker-column-label">
  19. {{ item[props.label] || item }}
  20. </text>
  21. </view>
  22. </picker-view-column>
  23. </picker-view>
  24. </view>
  25. </template>
  26. <script>
  27. import { isObject } from '../utils'
  28. import { commonMixin } from '../mixins'
  29. export default {
  30. props: {
  31. value: Array,
  32. list: Array,
  33. mode: String,
  34. props: Object,
  35. visible: Boolean,
  36. height: String
  37. },
  38. mixins: [commonMixin],
  39. data () {
  40. return {
  41. pickerValue: [],
  42. pickerColumns: [],
  43. selectValue: [],
  44. selectItem: []
  45. }
  46. },
  47. methods: {
  48. handleChange (item) {
  49. const pickerValue = item.detail.value
  50. const columnIndex = pickerValue.findIndex((item, i) => item !== this.pickerValue[i])
  51. if (columnIndex > -1) {
  52. const valueIndex = pickerValue[columnIndex]
  53. const columnItem = this.list[columnIndex][valueIndex]
  54. const valueItem = isObject(columnItem)
  55. ? columnItem[this.props.value]
  56. : columnItem
  57. this.pickerValue = pickerValue
  58. this.$set(this.selectValue, columnIndex, valueItem)
  59. this.$set(this.selectItem, columnIndex, columnItem)
  60. this.$emit('change', {
  61. value: this.selectValue,
  62. item: this.selectItem,
  63. index: this.pickerValue,
  64. change: 'scroll'
  65. })
  66. }
  67. }
  68. }
  69. }
  70. </script>
  71. <style lang="scss" scoped>
  72. @import "../style/picker-item.scss";
  73. </style>