zzlb-mutiselect.vue 3.0 KB

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