zzlb-mutiselect.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <view class="" style="width: 100%;">
  3. <view class=" flex flex-wrap">
  4. <view v-for="(item, index) in items" class="cu-tag bg-cyan radius">
  5. <slot name="default" v-bind:item="item">{{ item }}</slot>
  6. <text class="margin-left line-blue cuIcon-close round bg-red" @click="onremove(index)"></text>
  7. </view>
  8. <view class="flex ">
  9. <input style1="width: 60px;" placeholder="输入..." type="text" v-model="query" @input="onshuru" @click="onquery" @keyup="onquery" />
  10. <text
  11. v-if="query"
  12. class=" cuIcon-close "
  13. @click="
  14. query = '';
  15. onquery();
  16. "
  17. ></text>
  18. <text v-if="visible" class="cu-btn sm" @click="onqueren">确认</text>
  19. </view>
  20. </view>
  21. <view v-if="visible" class="fixed bg-white">
  22. <!-- <view class="flex justify-between ">
  23. <button class="cu-btn " @click="visible = 0">取消</button>
  24. <button class="cu-btn " @click="onqueren">确认</button>
  25. </view> -->
  26. <picker-view
  27. class="picker-view"
  28. @change="e => (pvvalue = mlist[e.detail.value[0]])"
  29. indicator-style1="height:40px"
  30. :style1="{ height: (mlist.length > 6 ? 6 : mlist.length / 2) * 34 + 'px' }"
  31. >
  32. <picker-view-column>
  33. <view class="item" v-for="(item, index) in mlist" :key="index">
  34. <slot name="option" v-bind:item="item">{{ item }}</slot>
  35. </view>
  36. </picker-view-column>
  37. </picker-view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. props: {
  44. url: { type: String, default: '' },
  45. list: {
  46. type: Array,
  47. default: function() {
  48. return [];
  49. }
  50. },
  51. value: {
  52. type: Array,
  53. default: function() {
  54. return [];
  55. }
  56. }
  57. },
  58. data() {
  59. return {
  60. visible: 0,
  61. items: [],
  62. query: '',
  63. mlist: [],
  64. pvvalue: []
  65. };
  66. },
  67. computed: {},
  68. watch: {
  69. value() {
  70. this.items = this.value || [];
  71. }
  72. },
  73. methods: {
  74. onquery() {
  75. console.log(this.query);
  76. this.visible = 1;
  77. this.pvvalue = this.mlist[0];
  78. if (this.list && this.list.length > 0) {
  79. const l = this.list.filter(f => f.indexOf(this.query) > -1);
  80. if (l.indexOf(this.pvvalue) === -1) {
  81. this.pvvalue = l[0];
  82. }
  83. this.mlist = l;
  84. return;
  85. }
  86. this.$http.get(this.url, { params: { title: this.query } }).then(r => {
  87. r.data.list;
  88. this.mlist = r.data.list;
  89. this.pvvalue = this.mlist[0];
  90. });
  91. },
  92. onremove(index) {
  93. this.items.splice(index, 1);
  94. this.$emit('input', this.items);
  95. },
  96. onshuru() {
  97. this.visible = 1;
  98. },
  99. onqueren() {
  100. this.visible = 0;
  101. if (this.pvvalue) this.items.push(this.pvvalue);
  102. this.$emit('input', this.items);
  103. }
  104. }
  105. };
  106. </script>
  107. <style>
  108. .picker-view {
  109. width: 100%;
  110. height: 100px;
  111. /* margin-top: 20rpx; */
  112. }
  113. .item {
  114. /* height: 50px; */
  115. align-items: center;
  116. justify-content: center;
  117. text-align: center;
  118. }
  119. </style>