selectcompany.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <view>
  3. <luo-nav-bar @leftClick='navback' :searchText='searchText' @rightClick='cancel' @input='companyInput'
  4. :isSearch="true" :isPlaceText='true' placeText='输入企业名称' rightText='取消' leftIcon='back'></luo-nav-bar>
  5. <view v-if='searching' style='padding:10px;'>
  6. <view style='color:#999;margin-bottom:40px;font-size:14px;' v-if='more'>#输入更多关键字精准获取企业</view>
  7. <view @click='checkcompany(item)' class='company' v-for='item in companyList'>
  8. <rich-text :nodes="item.colorcompanyName"></rich-text>
  9. <view class='flex items-center align-center'>
  10. <view class='legal_person'>法人</view>
  11. <view>{{item.legalPersonName}}</view>
  12. </view>
  13. </view>
  14. </view>
  15. <view style='margin-left:20px;' v-if='!searching'>
  16. <view>最近搜索</view>
  17. <view @click='clicksearch(item)' class='historysearch' :style="{'margin-left':index==0 ? '0':'10px'}"
  18. v-for='(item,index) in history'>{{item.searchContent}}</view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import {
  24. mapState
  25. } from 'vuex';
  26. import luoNavBar from '@/components/luo-navBar/components/luo-navBar/luo-navBar.vue';
  27. export default {
  28. data() {
  29. return {
  30. more: false,
  31. companyList: [],
  32. lastTime: 0,
  33. history: [],
  34. searching: false,
  35. searchText: ''
  36. }
  37. },
  38. components: {
  39. luoNavBar
  40. },
  41. computed: {
  42. ...mapState(['hasLogin', 'userInfo']),
  43. },
  44. onLoad() {
  45. this.$request.baseRequest('get', '/searchRecordsInfo/selectSearchRecordsInfo', {
  46. functionType: 1,
  47. commonId: this.userInfo.id
  48. }).then(res => {
  49. this.history = res.data.records
  50. })
  51. .catch(res => {
  52. uni.showToast({
  53. title: res.message,
  54. icon: 'none',
  55. duration: 2000
  56. })
  57. });
  58. },
  59. methods: {
  60. navback() {
  61. uni.navigateBack({})
  62. },
  63. cancel() {
  64. this.searchText = ''
  65. this.searching = false
  66. this.companyList = []
  67. },
  68. join(str, key) {
  69. var reg = new RegExp((`(${key})`), "gm");
  70. var replace = '<span style="color:#2772FB;">$1</span>';
  71. return str.replace(reg, replace);
  72. },
  73. clicksearch(item) {
  74. this.searchText = item.searchContent
  75. this.companyInput('', this.searchText)
  76. // this.s
  77. },
  78. checkcompany(item) {
  79. uni.setStorageSync('currectcompany', item)
  80. this.goDetailPage('pages/mine/cargoowner/addEnerprise')
  81. },
  82. goDetailPage(src) {
  83. uni.$u.route(src);
  84. },
  85. currectsearch(value) {
  86. var _this = this
  87. var arr = [],
  88. filterArr = []
  89. this.$request.baseRequest('post', '/searchRecordsInfo/api/addInfo', {
  90. functionType: 1,
  91. commonId: this.userInfo.id,
  92. searchContent: value
  93. }).then(res => {})
  94. .catch(res => {
  95. uni.showToast({
  96. title: res.message,
  97. icon: 'none',
  98. duration: 2000
  99. })
  100. });
  101. this.$request.baseRequest('get', '/companyInfo/selectAllCompany', {
  102. searchKeyWord: value
  103. }).then(res => {
  104. uni.hideLoading()
  105. var len = 0
  106. console.log(res)
  107. if (res.data.records.length > 10) {
  108. _this.more = true
  109. len = 10
  110. } else {
  111. len = res.data.records.length
  112. _this.more = false
  113. }
  114. for (var i = 0; i < len; i++) {
  115. // console.log(res.data.records[i])
  116. res.data.records[i].colorcompanyName = res.data.records[i].companyName
  117. res.data.records[i].colorcompanyName = _this.join(res.data.records[i].colorcompanyName,
  118. value)
  119. arr.push(res.data.records[i])
  120. }
  121. _this.companyList = arr
  122. console.log(arr)
  123. })
  124. .catch(res => {
  125. uni.hideLoading()
  126. uni.showToast({
  127. title: res.message,
  128. icon: 'none',
  129. duration: 2000
  130. })
  131. });
  132. },
  133. companyInput(e, value) {
  134. var _this = this
  135. this.searching = true
  136. uni.showLoading({
  137. title: '加载中',
  138. mask: true
  139. })
  140. if (this.lastTime == 0) {
  141. this.lastTime = setTimeout(() => {
  142. _this.currectsearch(value)
  143. }, 2000)
  144. } else {
  145. clearTimeout(this.lastTime)
  146. this.lastTime = setTimeout(() => {
  147. _this.currectsearch(value)
  148. }, 2000)
  149. }
  150. }
  151. }
  152. }
  153. </script>
  154. <style lang='scss' scoped>
  155. /deep/.u-navbar__content {
  156. /deep/>.u-nav-solt {
  157. width: 90%;
  158. }
  159. }
  160. .legal_person {
  161. color: #2772FB;
  162. font-size: 20rpx;
  163. border: 1px solid #2772FB;
  164. padding: 4rpx 6rpx;
  165. border-radius: 10rpx;
  166. margin: 8rpx 10rpx 8rpx 0;
  167. }
  168. .company {
  169. padding-bottom: 80rpx;
  170. }
  171. .historysearch {
  172. background: #F5F6FA;
  173. display: inline-block;
  174. padding: 10rpx 20rpx;
  175. margin: 15rpx 20rpx;
  176. border-radius: 10rpx;
  177. }
  178. </style>