selectcompany.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <view class="center">
  3. <!-- <view class="fixed1"></view> -->
  4. <luo-nav-bar @leftClick='navback' :searchText='searchText' @rightClick='cancel' @input='companyInput'
  5. :isSearch="true" :isPlaceText='true' placeText='输入企业名称' rightText='取消' leftIcon='back'></luo-nav-bar>
  6. <view v-if='searching' style='padding:10px;'>
  7. <view style='color:#999;margin-bottom:40px;font-size:14px;' v-if='more'>#输入更多关键字精准获取企业</view>
  8. <view @click='checkcompany(item)' class='company' v-for='item in companyList'>
  9. <rich-text :nodes="item.colorcompanyName"></rich-text>
  10. <view class='flex items-center align-center'>
  11. <view class='legal_person'>法人</view>
  12. <view>{{item.legalPersonName1}}</view>
  13. </view>
  14. </view>
  15. </view>
  16. <view style='margin-left:20px;' v-if='!searching'>
  17. <view>最近搜索</view>
  18. <view @click='clicksearch(item)' class='historysearch' :style="{'margin-left':index==0 ? '0':'10px'}"
  19. v-for='(item,index) in history'>{{item.searchContent}}</view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import {
  25. mapState
  26. } from 'vuex';
  27. import luoNavBar from '@/components/luo-navBar/components/luo-navBar/luo-navBar.vue';
  28. export default {
  29. data() {
  30. return {
  31. more: false,
  32. companyList: [],
  33. lastTime: 0,
  34. history: [],
  35. searching: false,
  36. searchText: ''
  37. }
  38. },
  39. components: {
  40. luoNavBar
  41. },
  42. computed: {
  43. ...mapState(['hasLogin', 'userInfo']),
  44. },
  45. onLoad() {
  46. this.$request.baseRequest('get', '/searchRecordsInfo/selectSearchRecordsInfo', {
  47. functionType: 1,
  48. commonId: this.userInfo.id
  49. }).then(res => {
  50. this.history = res.data.records
  51. })
  52. .catch(res => {
  53. uni.showToast({
  54. title: res.message,
  55. icon: 'none',
  56. duration: 2000
  57. })
  58. });
  59. },
  60. methods: {
  61. navback() {
  62. uni.navigateBack({})
  63. },
  64. cancel() {
  65. this.searchText = ''
  66. this.searching = false
  67. this.companyList = []
  68. },
  69. join(str, key) {
  70. var reg = new RegExp((`(${key})`), "gm");
  71. var replace = '<span style="color:#F5BA3C;">$1</span>';
  72. return str.replace(reg, replace);
  73. },
  74. clicksearch(item) {
  75. this.searchText = item.searchContent
  76. this.companyInput('', this.searchText)
  77. // this.s
  78. },
  79. checkcompany(item) {
  80. var that=this
  81. // console.log(item,this.userInfo)
  82. uni.showLoading({
  83. title: '加载中',
  84. mask: true
  85. })
  86. this.$request.baseRequest('get', '/cargoOwnerInfo/selectCargoOwner', {
  87. commonId: this.userInfo.id
  88. }).then(res => {
  89. uni.hideLoading()
  90. if (res.data) {
  91. // if(res.data.name==item.legalPersonName){
  92. // uni.showToast({
  93. // title: '您已经具备该公司货主身份',
  94. // icon: 'none',
  95. // duration: 2000
  96. // })
  97. // }else
  98. if(res.data.hyCargoOwnerCompInfoList){
  99. res.data.hyCargoOwnerCompInfoList.every(items=>{
  100. console.log(items.company,item.companyName)
  101. })
  102. if(res.data.hyCargoOwnerCompInfoList.every(items=>{
  103. return items.company!=item.companyName
  104. })){
  105. uni.setStorageSync('currectcompany', item)
  106. uni.navigateBack({
  107. delta: 1
  108. })
  109. // that.goDetailPage('pages/mine/cargoowner/addEnerprise')
  110. }else{
  111. for (var i = 0; i < res.data.hyCargoOwnerCompInfoList.length; i++) {
  112. if(res.data.hyCargoOwnerCompInfoList[i].company==item.companyName){
  113. uni.showToast({
  114. title: '该企业已认证过,删除后才可以再次选中该企业',
  115. icon: 'none',
  116. duration: 2000
  117. })
  118. }
  119. }
  120. }
  121. }else{
  122. uni.setStorageSync('currectcompany', item)
  123. that.goDetailPage('pages/mine/cargoowner/addEnerprise')
  124. }
  125. }
  126. })
  127. .catch(res => {
  128. uni.hideLoading()
  129. uni.showToast({
  130. title: res.message,
  131. icon: 'none',
  132. duration: 2000
  133. })
  134. });
  135. // if(){
  136. // }
  137. console.log(12331)
  138. },
  139. goDetailPage(src) {
  140. // uni.$u.route(src);
  141. uni.navigateBack({
  142. delta:1
  143. })
  144. },
  145. currectsearch(value) {
  146. var _this = this
  147. var arr = [],
  148. filterArr = []
  149. if(value){
  150. this.$request.baseRequest('post', '/searchRecordsInfo/api/addInfo', {
  151. functionType: 1,
  152. commonId: this.userInfo.id,
  153. searchContent: value
  154. }).then(res => {})
  155. .catch(res => {
  156. uni.showToast({
  157. title: res.message,
  158. icon: 'none',
  159. duration: 2000
  160. })
  161. });
  162. }
  163. if(value){
  164. this.$request.baseRequest('get', '/companyInfo/selectAllCompany', {
  165. searchKeyWord: value
  166. }).then(res => {
  167. // uni.hideLoading()
  168. var len = 0
  169. console.log(res)
  170. if (res.data.records.length > 10) {
  171. _this.more = true
  172. len = 10
  173. } else {
  174. len = res.data.records.length
  175. _this.more = false
  176. }
  177. for (var i = 0; i < len; i++) {
  178. var len2=res.data.records[i].legalPersonName.length
  179. var name=''
  180. for (var q = 0; q < len2; q++) {
  181. name+='*'
  182. }
  183. res.data.records[i].legalPersonName1=name.substr(0, name.length - 1) + res.data.records[i].legalPersonName[len2-1]
  184. // console.log(res.data.records[i])
  185. res.data.records[i].colorcompanyName = res.data.records[i].companyName
  186. res.data.records[i].colorcompanyName = _this.join(res.data.records[i].colorcompanyName,
  187. value)
  188. arr.push(res.data.records[i])
  189. }
  190. _this.companyList = arr
  191. console.log(arr)
  192. })
  193. .catch(res => {
  194. // uni.hideLoading()
  195. uni.showToast({
  196. title: res.message,
  197. icon: 'none',
  198. duration: 2000
  199. })
  200. });
  201. }else{
  202. this.companyList=[]
  203. }
  204. },
  205. companyInput(e, value) {
  206. var _this = this
  207. this.searching = true
  208. // uni.showLoading({
  209. // title: '加载中',
  210. // mask: true
  211. // })
  212. if (this.lastTime == 0) {
  213. this.lastTime = setTimeout(() => {
  214. if(e){
  215. _this.currectsearch(e.detail.value)
  216. }else{
  217. _this.currectsearch(value)
  218. }
  219. }, 2000)
  220. } else {
  221. clearTimeout(this.lastTime)
  222. this.lastTime = setTimeout(() => {
  223. if(e){
  224. _this.currectsearch(e.detail.value)
  225. }else{
  226. _this.currectsearch(value)
  227. }
  228. }, 2000)
  229. }
  230. }
  231. }
  232. }
  233. </script>
  234. <style lang='scss' scoped>
  235. /deep/.u-navbar__content {
  236. /deep/>.u-nav-solt {
  237. width: 90%;
  238. }
  239. }
  240. .center{
  241. margin-top:30px;
  242. }
  243. .legal_person {
  244. color: #F5BA3C;
  245. font-size: 20rpx;
  246. border: 1px solid #F5BA3C;
  247. padding: 4rpx 6rpx;
  248. border-radius: 10rpx;
  249. margin: 8rpx 10rpx 8rpx 0;
  250. }
  251. .company {
  252. padding-bottom: 80rpx;
  253. }
  254. .historysearch {
  255. background: #F5F6FA;
  256. display: inline-block;
  257. padding: 10rpx 20rpx;
  258. margin: 15rpx 20rpx;
  259. border-radius: 10rpx;
  260. }
  261. .fixed1 {
  262. top: 0;
  263. height: var(--status-bar-height);
  264. }
  265. </style>