_key.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <template>
  2. <div class="mobile-center">
  3. <div class="com-mobile-header mobile-center-header">
  4. <a @click="goLastPage"><i class="iconfont icon-fanhui"></i></a>
  5. <p>器件收藏</p>
  6. <p class="en-name"><img :src="`/images/mobile/center/${user.data.enterprise.uu ? 'en' : 'self'}.png`" alt="">{{currentEnName}}</p>
  7. </div>
  8. <div class="mobile-fix-content mobile-centerfix-content" id="mobileFixContent">
  9. <div class="search-content search-content2" style="position: relative;padding-top: .25rem;">
  10. <input type="text" placeholder="请输入您要查找的型号" @input="onBrandChange" v-model="keyword" @keyup.13="searchComplist">
  11. <span @click.stop="searchComplist" >
  12. <i class="iconfont icon-sousuo"></i>
  13. </span>
  14. <ul class="similar brand-similar-list" v-show="showSimilarCodeList && keyword">
  15. <li v-for="sBrand in similarBrand" @click.stop="setBrand(sBrand.code)" v-text="sBrand.code"></li>
  16. </ul>
  17. </div>
  18. <template v-if="compList && compList.length">
  19. <div class="lock_count" v-if="keyword">
  20. <p>搜索“<span>{{keyword}}</span>”,为您找到{{compCollectList.data.total}}条信息</p>
  21. </div>
  22. <ul>
  23. <li class="clearfix" v-for="comp in compList" @click="goUrl('/mobile/brand/componentDetail/' + comp.componentinfo.uuid)">
  24. <div class="fl">
  25. <p>品牌:<span v-text="comp.brand.nameEn || '-'"></span></p>
  26. <p>物料名称:<span v-text="comp.kind.nameCn || '-'"></span></p>
  27. <p>型号:<span v-text="comp.code || '-'"></span></p>
  28. <p>规格:<span v-text="comp.spec || '-'"></span></p>
  29. <p>产品描述:<span v-text="comp.description || '-'"></span></p>
  30. </div>
  31. <div class="vir"></div>
  32. <div class="fr">
  33. <span class="focus" @click="cancelFocus(comp, $event)">
  34. <i class="iconfont icon-shoucang1" :class="comp.isFocus ? 'icon-shoucang1' : 'icon-shoucang2'"></i>
  35. {{comp.isFocus ? '已收藏' : '收藏'}}
  36. </span>
  37. <a class="sa-pub" @click="compInquiry(comp, $event)">立即询价</a>
  38. </div>
  39. </li>
  40. </ul>
  41. </template>
  42. <empty-status :type="'collect'" :showLink="true" :text="'抱歉,没有相关信息'" v-else></empty-status>
  43. </div>
  44. <remind-box :title="remindText" :timeoutCount="timeoutCount"></remind-box>
  45. <pull-up :fixId="'mobileFixContent'" :searchMore="fetching" :allPage="allPage" :page="page" @pullUpAction="onPullUpAction"></pull-up>
  46. <publish-supplier-seek :product="componentSeekObj" :showPublishBox="showPublishBox" @cancelAction="showPublishBox = false" @remindAction="onRemind"></publish-supplier-seek>
  47. </div>
  48. </template>
  49. <script>
  50. import { RemindBox, PullUp, EmptyStatus } from '~components/mobile/common'
  51. import { PublishSupplierSeek } from '~components/mobile/applyPurchase'
  52. export default {
  53. middleware: 'authenticated',
  54. layout: 'mobileNoHeader',
  55. data () {
  56. return {
  57. keyword: '',
  58. showSimilarCodeList: false,
  59. similarBrand: '',
  60. remindText: '',
  61. timeoutCount: 0,
  62. page: 1,
  63. count: 10,
  64. isChange: false,
  65. compList: [],
  66. componentSeekObj: {
  67. standard: 1,
  68. cmpCode: '',
  69. pbranden: '',
  70. spec: null,
  71. kind: ''
  72. },
  73. showPublishBox: false
  74. }
  75. },
  76. watch: {
  77. 'compCollectList.data': {
  78. handler: function (val) {
  79. if (val.components) {
  80. if (this.isChange) {
  81. this.compList = this.baseUtils.deepCopy(val.components)
  82. this.isChange = false
  83. } else {
  84. this.compList = [...this.compList, ...this.baseUtils.deepCopy(val.components)]
  85. }
  86. } else {
  87. this.compList = []
  88. }
  89. },
  90. immediate: true
  91. }
  92. },
  93. created () {
  94. this.compList = []
  95. this.keyword = this.$route.params.key
  96. this.$store.dispatch('searchData/searchForListInMobile', { page: 1, count: 10, w: this.$route.params.key })
  97. },
  98. computed: {
  99. compCollectList () {
  100. return this.$store.state.searchData.searchList.lists
  101. },
  102. fetching () {
  103. return this.compCollectList.fetching
  104. },
  105. allPage () {
  106. return Math.floor(this.compCollectList.data.total / this.compCollectList.data.size) + Math.floor(this.compCollectList.data.total % this.compCollectList.data.size > 0 ? 1 : 0)
  107. },
  108. colList () {
  109. return this.$store.state.product.common.collectList.data
  110. }
  111. },
  112. components: {
  113. RemindBox,
  114. PullUp,
  115. PublishSupplierSeek,
  116. EmptyStatus
  117. },
  118. methods: {
  119. onBrandChange: function () {
  120. this.keyword = this.keyword.trim()
  121. if ((/[^\x00-\xff]/g).test(this.keyword)) {
  122. let chineseIndex = -1
  123. for (let i = 0; i < this.keyword.length; i++) {
  124. if ((/[^\x00-\xff]/g).test(this.keyword.charAt(i)) && !(/[\u4e00-\u9fa5]/).test(this.keyword.charAt(i))) {
  125. chineseIndex = i
  126. break
  127. }
  128. }
  129. if (chineseIndex > -1) {
  130. this.keyword = this.keyword.substring(0, chineseIndex)
  131. }
  132. } else if (this.keyword && this.baseUtils.getRealLen(this.keyword) > 50) {
  133. this.keyword = this.baseUtils.cutOutString(this.keyword, 50)
  134. } else {
  135. this.getSimilarBrand()
  136. }
  137. },
  138. getSimilarBrand: function () {
  139. if (this.keyword) {
  140. this.$http.get('/search/similarKeywords', {params: {keyword: this.keyword, type: 'component'}})
  141. .then(response => {
  142. this.similarBrand = response.data.result
  143. this.showSimilarCodeList = response.data.result.length > 0
  144. })
  145. } else {
  146. this.showSimilarCodeList = false
  147. }
  148. },
  149. setBrand: function (brand) {
  150. this.keyword = brand
  151. this.showSimilarCodeList = false
  152. this.searchComplist()
  153. },
  154. searchComplist () {
  155. if (this.keyword !== '') {
  156. this.showSimilarCodeList = false
  157. this.showPublishBox = false
  158. this.page = 1
  159. this.isChange = true
  160. this.reloadList()
  161. } else {
  162. this.remindText = '请输入您要查找的型号'
  163. this.timeoutCount++
  164. }
  165. },
  166. onRemind: function (str) {
  167. this.remindText = str
  168. this.timeoutCount++
  169. },
  170. cancelFocus: function (item, event) {
  171. event.stopPropagation()
  172. if (!item.isFocus) {
  173. this.$http.post('/trade/collection/save', {componentid: item.id, kind: 2})
  174. .then(res => {
  175. if (res.data.code === 1) {
  176. this.onRemind('收藏成功')
  177. item.isFocus = true
  178. } else {
  179. this.onRemind(res.data.message || '收藏失败')
  180. }
  181. }, err => {
  182. this.onRemind(err.response.data || '收藏失败')
  183. console.log(err)
  184. })
  185. } else {
  186. this.$http.post('/trade/collection/delete/cmpId', [item.id]).then(response => {
  187. if (response.data === 'success') {
  188. this.onRemind('取消收藏成功')
  189. item.isFocus = false
  190. } else {
  191. this.onRemind('取消收藏失败')
  192. }
  193. }, err => {
  194. console.log(err)
  195. this.onRemind(err.response.data || '取消收藏失败')
  196. })
  197. }
  198. },
  199. reloadList: function () {
  200. this.$store.dispatch('searchData/searchForListInMobile', { page: this.page, count: this.count, w: this.keyword })
  201. },
  202. onPullUpAction: function () {
  203. this.page++
  204. this.reloadList()
  205. },
  206. compInquiry: function (item, e) {
  207. if (e) {
  208. e.stopPropagation()
  209. }
  210. this.componentSeekObj.cmpCode = item.code
  211. this.componentSeekObj.pbranden = item.brand.nameEn
  212. this.componentSeekObj.spec = item.spec
  213. this.componentSeekObj.kind = item.kind.nameCn
  214. this.componentSeekObj = JSON.parse(JSON.stringify(this.componentSeekObj))
  215. this.showPublishBox = true
  216. },
  217. goUrl: function (url) {
  218. this.$router.push(url)
  219. }
  220. }
  221. }
  222. </script>
  223. <style lang="scss" scoped>
  224. .mobile-fix-content {
  225. .similar {
  226. position: absolute;
  227. width: 6.5rem;
  228. max-height: 2.5rem;
  229. overflow-y: auto;
  230. z-index: 12;
  231. border: 1px solid #7e7e7e;
  232. border-radius: .05rem;
  233. top: 100%;
  234. background: #fff;
  235. left: 0.1rem;
  236. right: 0;
  237. margin: 0 auto;
  238. li {
  239. height: .5rem;
  240. line-height: .5rem;
  241. font-size: .26rem;
  242. color: #999;
  243. padding-left: .19rem;
  244. text-align: left;
  245. overflow: hidden;
  246. text-overflow: ellipsis;
  247. white-space: nowrap;
  248. &:focus, &:active, &:hover {
  249. background: #999;
  250. color: #fff;
  251. }
  252. }
  253. }
  254. .search-content {
  255. text-align: center;
  256. input {
  257. border: 1px solid #376ff3;
  258. }
  259. span{
  260. top:0;
  261. }
  262. }
  263. .lock_count{
  264. padding: .2rem;
  265. text-align: center;
  266. p{
  267. color:#666;
  268. span{
  269. color:#376ff3;
  270. }
  271. }
  272. }
  273. > ul {
  274. width: 7.1rem;
  275. margin: 0 auto;
  276. li {
  277. border-radius: .05rem;
  278. border: 1px solid #ccc;
  279. margin: .25rem 0 0 0;
  280. position: relative;
  281. background: #fff;
  282. .fl {
  283. width: 4.71rem;
  284. color: #666;
  285. padding: .25rem .1rem .25rem .23rem;
  286. p {
  287. font-size: .3rem;
  288. line-height: .42rem;
  289. overflow: hidden;
  290. text-overflow: ellipsis;
  291. white-space: nowrap;
  292. span {
  293. color: #333;
  294. }
  295. }
  296. }
  297. .vir {
  298. position: absolute;
  299. top: .28rem;
  300. bottom: .28rem;
  301. right: 2.36rem;
  302. border-right: .01rem dashed #9f9f9f;
  303. }
  304. .fr {
  305. width: 2.34rem;
  306. text-align: center;
  307. margin-top: .3rem;
  308. i {
  309. display: block;
  310. color: #008bf7;
  311. font-size: .5rem;
  312. width: .6rem;
  313. height: .5rem;
  314. line-height: .6rem;
  315. text-align: center;
  316. margin: .15rem auto .1rem
  317. }
  318. span.focus{
  319. font-size: .28rem;
  320. color: #008bf7;
  321. }
  322. .sa-pub {
  323. display: block;
  324. width: 1.7rem;
  325. height: .47rem;
  326. line-height: .47rem;
  327. text-align: center;
  328. font-size: .26rem;
  329. color: #fff;
  330. background: #008bf7;
  331. margin: 0 auto;
  332. margin-top: .1rem;
  333. border-radius: .05rem;
  334. }
  335. }
  336. }
  337. }
  338. }
  339. </style>