index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <view class="jnpf-auto-complete">
  3. <selectBox v-model="innerValue" :disabled='disabled' :placeholder="placeholder" @openSelect="showSearch"
  4. >
  5. </selectBox>
  6. <SearchForm ref="searchForm" :interfaceId="interfaceId" :relationField="relationField"
  7. :templateJson="templateJson" @confirm="confirm" :total="total || 50" :formData="formData"
  8. :clearable="clearable" :rowIndex="rowIndex" />
  9. </view>
  10. </template>
  11. <script>
  12. import SearchForm from './SearchForm';
  13. import selectBox from '@/components/selectBox'
  14. export default {
  15. name: 'jnpf-auto-complete',
  16. components: {
  17. SearchForm,
  18. selectBox
  19. },
  20. props: {
  21. modelValue: {
  22. default: ''
  23. },
  24. formData: {
  25. type: Object
  26. },
  27. options: {
  28. type: Array,
  29. default: () => []
  30. },
  31. placeholder: {
  32. type: String,
  33. default: '请输入'
  34. },
  35. clearable: {
  36. type: Boolean,
  37. default: false
  38. },
  39. disabled: {
  40. type: Boolean,
  41. default: false
  42. },
  43. templateJson: {
  44. type: Array,
  45. default: () => []
  46. },
  47. interfaceId: {
  48. type: String,
  49. default: ''
  50. },
  51. relationField: {
  52. type: String,
  53. default: 'fullName'
  54. },
  55. total: {
  56. type: Number,
  57. default: 50
  58. },
  59. rowIndex: {
  60. default: null
  61. }
  62. },
  63. data() {
  64. return {
  65. innerValue: ''
  66. }
  67. },
  68. watch: {
  69. modelValue: {
  70. handler(val) {
  71. this.innerValue = val || ''
  72. },
  73. immediate: true
  74. }
  75. },
  76. methods: {
  77. showSearch() {
  78. if (this.disabled) return
  79. this.$nextTick(() => {
  80. this.$refs.searchForm.init(this.innerValue)
  81. })
  82. },
  83. confirm(e) {
  84. this.innerValue = e
  85. this.$emit('update:modelValue', e);
  86. this.$emit('change', e);
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="scss">
  92. .jnpf-auto-complete {
  93. width: 100%;
  94. .str-auto-complete-container {
  95. width: 549rpx;
  96. height: 360px;
  97. border-radius: 8rpx;
  98. box-shadow: 0rpx 0rpx 12rpx #dfe3e9;
  99. position: absolute;
  100. z-index: 9997;
  101. background: #fff;
  102. top: 94rpx;
  103. left: 0;
  104. right: 0;
  105. overflow-y: scroll;
  106. .str-auto-complete-mask {
  107. width: 100%;
  108. height: calc(100% - 90rpx);
  109. position: fixed;
  110. left: 0;
  111. top: 0;
  112. bottom: 0;
  113. right: 0;
  114. z-index: 9999;
  115. }
  116. .str-auto-complete-item {
  117. position: relative;
  118. padding: 10rpx;
  119. z-index: 9999
  120. }
  121. }
  122. .auto-complete-b {
  123. width: 549rpx;
  124. height: 360px;
  125. z-index: 999;
  126. position: absolute;
  127. background-color: #fff;
  128. border: 1px solid red;
  129. top: 94rpx;
  130. left: 0;
  131. right: 0;
  132. }
  133. }
  134. </style>