multipleSelect.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <uni-popup ref="popup" :showClose="true" background-color="#fff" @change="change">
  3. <scroll-view class="scroll-content" scroll-y style="height: 80vh;">
  4. <view class="popup-title">
  5. <text>选择</text>
  6. </view>
  7. <!-- 选择列表 -->
  8. <uni-data-checkbox multiple wrap v-model="value" :localdata="range" @change="change"></uni-data-checkbox>
  9. <view class="footerButton">
  10. <u-button type="default" @click="handleClose" text="关闭"></u-button>
  11. <u-button type="primary" @click="handleConfirm" text="确认"></u-button>
  12. </view>
  13. </scroll-view>
  14. </uni-popup>
  15. </template>
  16. <script>
  17. export default {
  18. props: {
  19. range: {
  20. type: Array,
  21. default: () => []
  22. }
  23. },
  24. data() {
  25. return {
  26. // range: [{"value": 0,"text": "篮球" },{"value": 1,"text": "足球"},{"value": 2,"text": "游泳"}],
  27. value: [],
  28. key: ''
  29. }
  30. },
  31. computed: {
  32. },
  33. methods: {
  34. open(current, index, key) {
  35. this.current = current;
  36. this.currentIndex = index;
  37. this.key = key
  38. this.$refs.popup.open('bottom');
  39. if(current[key]) {
  40. if(typeof current[key] == 'string') {
  41. this.value = current[key].split(',')
  42. } else {
  43. this.value = current[key]
  44. }
  45. } else {
  46. this.value = []
  47. }
  48. },
  49. change(e) {
  50. console.log('当前模式:' + e.type + ',状态:' + e.show);
  51. },
  52. handleConfirm() {
  53. this.$emit('confirm', this.value.join(','), this.key );
  54. this.handleClose()
  55. },
  56. handleClose() {
  57. this.$refs.popup.close()
  58. },
  59. }
  60. }
  61. </script>
  62. <style scoped lang="scss">
  63. .footerButton {
  64. width: 100%;
  65. height: 84rpx;
  66. display: flex;
  67. position: fixed;
  68. bottom: 0;
  69. z-index: 10;
  70. background-color: #fff;
  71. /deep/.u-button {
  72. height: 100%;
  73. }
  74. >view {
  75. flex: 1;
  76. }
  77. }
  78. .scroll-content {
  79. padding: 20rpx;
  80. }
  81. .popup-title {
  82. display: flex;
  83. align-items: center;
  84. padding: 20rpx;
  85. }
  86. .popup-title-btn {
  87. width: 100rpx;
  88. margin-right: 20rpx;
  89. }
  90. </style>