index.vue 9.6 KB

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