index.vue 2.4 KB

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