unlinked-selector-picker.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. isConfirmChange: Boolean
  38. },
  39. mixins: [commonMixin],
  40. data () {
  41. return {
  42. pickerValue: [],
  43. pickerColumns: [],
  44. selectValue: [],
  45. selectItem: []
  46. }
  47. },
  48. methods: {
  49. handleChange (item) {
  50. const pickerValue = item.detail.value
  51. const columnIndex = pickerValue.findIndex((item, i) => item !== this.pickerValue[i])
  52. if (columnIndex > -1) {
  53. const valueIndex = pickerValue[columnIndex]
  54. const columnItem = this.list[columnIndex][valueIndex]
  55. const valueItem = isObject(columnItem)
  56. ? columnItem[this.props.value]
  57. : columnItem
  58. this.pickerValue = pickerValue
  59. this.$set(this.selectValue, columnIndex, valueItem)
  60. this.$set(this.selectItem, columnIndex, columnItem)
  61. this.$emit('change', {
  62. value: this.selectValue,
  63. item: this.selectItem,
  64. index: this.pickerValue,
  65. change: 'scroll'
  66. })
  67. }
  68. }
  69. }
  70. }
  71. </script>
  72. <style lang="scss" scoped>
  73. @import "../style/picker-item.scss";
  74. </style>