SearchForm.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <view class="search-popup-v">
  3. <u-popup v-model="showPopup" width="100%" height="100vh" mode="right" :mask="false" @close="close">
  4. <view class="search-popup-b">
  5. <view class="search-popup-h">
  6. <view class="search-popup-h-txt">
  7. <u-icon name="close" @click="showPopup=false" class="search-popup-h-icon" />
  8. </view>
  9. <u-input type="text" v-model="value" placeholder="请输入" @input="onInput" :clearable="clearable" />
  10. </view>
  11. </view>
  12. <view class="search-popup-item" v-if="showList.length>0">
  13. <view v-for="(item, index) in showList" :key="index" @tap="selectThisItem(item)"
  14. class="u-p-l-20 u-p-r-20">{{item[relationField]}}</view>
  15. </view>
  16. <JnpfEmpty v-if="showList.length<1"></JnpfEmpty>
  17. </u-popup>
  18. </view>
  19. </template>
  20. <script>
  21. import {
  22. getPopSelect
  23. } from '@/api/common.js'
  24. export default {
  25. props: {
  26. interfaceId: {
  27. type: String,
  28. default: ''
  29. },
  30. clearable: {
  31. type: Boolean,
  32. default: true
  33. },
  34. relationField: {
  35. type: String,
  36. default: 'fullName'
  37. },
  38. total: {
  39. type: [String, Number],
  40. default: 50
  41. },
  42. formData: {
  43. type: Object
  44. },
  45. templateJson: {
  46. type: Array,
  47. default: () => []
  48. },
  49. rowIndex: {
  50. default: null
  51. },
  52. },
  53. data() {
  54. return {
  55. istQuery: {
  56. keyword: '',
  57. pageSize: 1000
  58. },
  59. showPopup: false,
  60. value: '',
  61. showList: [],
  62. timer: ''
  63. }
  64. },
  65. methods: {
  66. init(val) {
  67. this.showPopup = true
  68. this.value = val
  69. this.getDataInterfaceList()
  70. },
  71. getDataInterfaceList() {
  72. this.showList = []
  73. const paramList = this.getParamList()
  74. let query = {
  75. interfaceId: this.interfaceId,
  76. relationField: this.relationField,
  77. pageSize: 10000,
  78. paramList
  79. }
  80. getPopSelect(this.interfaceId, query).then(res => {
  81. let list = JSON.parse(JSON.stringify(res.data.list)) || []
  82. if (list.length) list = this.unique(list, this.relationField)
  83. this.showList = list.splice(0, this.total)
  84. })
  85. },
  86. unique(arr, attrName) {
  87. const res = new Map();
  88. // 根据对象的某个属性值去重
  89. return arr.filter(o => !res.has(o[attrName]) && res.set(o[attrName], 1));
  90. },
  91. getParamList() {
  92. let templateJson = this.templateJson
  93. for (let i = 0; i < templateJson.length; i++) {
  94. if (templateJson[i].relationField && this.formData && templateJson[i].sourceType == 1) {
  95. if (templateJson[i].relationField.includes('-')) {
  96. let tableVModel = templateJson[i].relationField.split('-')[0]
  97. let childVModel = templateJson[i].relationField.split('-')[1]
  98. templateJson[i].defaultValue = this.formData[tableVModel] && this.formData[tableVModel][this
  99. .rowIndex
  100. ] && this.formData[tableVModel][this.rowIndex][childVModel] || ''
  101. } else {
  102. templateJson[i].defaultValue = this.formData[templateJson[i].relationField] || ''
  103. }
  104. }
  105. if (templateJson[i].relationField == '@keyword') templateJson[i].defaultValue = this.value
  106. }
  107. return templateJson
  108. },
  109. onInput(e) {
  110. this.value = e
  111. this.$emit('confirm', this.value);
  112. this.timer && clearTimeout(this.timer);
  113. this.timer = setTimeout(() => {
  114. this.list = [];
  115. this.getDataInterfaceList()
  116. }, 300);
  117. },
  118. close() {
  119. this.showPopup = false
  120. },
  121. selectThisItem(item) {
  122. this.value = item[this.relationField];
  123. this.$emit('confirm', this.value);
  124. this.close()
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="scss">
  130. .search-popup-v {
  131. .search-popup-b {
  132. height: 158rpx;
  133. .search-popup-h {
  134. padding: 0 20rpx;
  135. border-bottom: 1rpx solid #cbcbcb;
  136. position: fixed;
  137. width: 100%;
  138. background-color: #fff;
  139. z-index: 9;
  140. text-align: center;
  141. .search-popup-h-txt {
  142. height: 86rpx;
  143. width: 100%;
  144. padding: 15rpx 0;
  145. text-align: center;
  146. line-height: 54rpx;
  147. box-sizing: border-box;
  148. font-size: 32rpx;
  149. font-weight: 700;
  150. letter-spacing: 2rpx;
  151. .search-popup-h-icon {
  152. float: right;
  153. margin-top: 12rpx;
  154. }
  155. }
  156. }
  157. }
  158. .search-popup-item {
  159. width: 100%;
  160. height: 100%;
  161. z-index: 9997;
  162. }
  163. .search-notData {
  164. width: 100%;
  165. height: calc(100% - 160rpx);
  166. background-color: #fff;
  167. .notData-box {
  168. width: 100%;
  169. height: 100%;
  170. justify-content: center;
  171. align-items: center;
  172. .notData-inner {
  173. width: 280rpx;
  174. height: 340rpx;
  175. align-items: center;
  176. .iconImg {
  177. width: 100%;
  178. height: 100%;
  179. }
  180. .notData-inner-text {
  181. padding: 30rpx 0;
  182. color: #909399;
  183. }
  184. }
  185. }
  186. }
  187. }
  188. </style>