unlinked-selector-picker.vue 3.3 KB

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