index.vue 9.4 KB

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