ComponentDetail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. <template>
  2. <div class="component-detail mobile-content">
  3. <div class="base-detail">
  4. <div class="base-detail-item" v-if="component.kind.nameCn">
  5. <span>类&nbsp;&nbsp;&nbsp;&nbsp;目:</span>
  6. <span>{{component.kind.nameCn}}</span>
  7. </div>
  8. <div class="base-detail-item" v-if="component.brand.nameCn">
  9. <span>品&nbsp;&nbsp;&nbsp;&nbsp;牌:</span>
  10. <span>{{component.brand.nameCn}}</span>
  11. </div>
  12. <div class="base-detail-item attach" @click="goAttach(component.attach)">
  13. <span v-if="component.attach">规格书:<img src="/images/mobile/@2x/productDetail/pdf.png" alt=""><span>查看</span></span>
  14. <span v-else>规格书:-</span>
  15. </div>
  16. <div class="base-detail-item product-description" v-if="component.description">
  17. <span class="description">产品描述:{{component.description}}</span>
  18. </div>
  19. <i class="iconfont icon-shoucang" :style="isCollect?'color:#ff7800':'color: #ddd'" @click="collectComponent"></i>
  20. </div>
  21. <div class="product-switch-item">
  22. <span :class="activeType=='store'?'mobile-switch-btn active':'mobile-switch-btn'" @click="activeType='store'">商家</span>
  23. <span :class="activeType=='param'?'mobile-switch-btn active':'mobile-switch-btn'" @click="activeType='param'">参数</span>
  24. </div>
  25. <div class="product-params" v-if="activeType == 'param'">
  26. <div class="param-item" v-if="prop.value && prop.value!=''" v-for="prop in component.properties">
  27. <span class="prop-name">{{prop.property.labelCn}}</span>
  28. <span class="prop-value">{{prop.value}}</span>
  29. </div>
  30. </div>
  31. <div class="product-store" v-if="activeType == 'store'">
  32. <table v-if="searchLists&&searchLists.length > 0">
  33. <thead id="product-head">
  34. <tr>
  35. <th style="width: 1.55rem;">商家</th>
  36. <th style="width: 1.59rem;">生产日期</th>
  37. <th style="width: 2.58rem;">价格梯度</th>
  38. <th style="width: 1.77rem;">交期(天)</th>
  39. </tr>
  40. </thead>
  41. <thead class="active" v-show="isScrollOverTab">
  42. <tr>
  43. <th style="width: 1.55rem;">商家</th>
  44. <th style="width: 1.59rem;">生产日期</th>
  45. <th style="width: 2.58rem;">价格梯度</th>
  46. <th style="width: 1.77rem;">交期(天)</th>
  47. </tr>
  48. </thead>
  49. <tbody id="product-body">
  50. <tr v-for="store in searchLists">
  51. <td class="store-name">
  52. <nuxt-link :to="'/mobile/shop/' + store.storeid">
  53. {{store.storeName || '-' | storeNameFilter}}
  54. </nuxt-link>
  55. </td>
  56. <td>
  57. <div v-if="!store.packaging && !store.breakUp && !store.produceDate">-</div>
  58. <div>{{store.produceDate}}</div>
  59. <div>{{store.packaging}}</div>
  60. <div>{{store.breakUp?'可拆卖':'不可拆卖'}}</div>
  61. </td>
  62. <td class="price-level-wrap">
  63. <div v-if="!store.prices || store.prices.length == 0">-</div>
  64. <div class="price-number fl">
  65. <div v-for="price in store.prices">{{price.start}}+</div>
  66. </div>
  67. <div class="price-number fr">
  68. <div v-for="price in store.prices" class="price-level">
  69. <span v-if="store.currencyName.indexOf('RMB')!==-1">¥{{price.rMBPrice | currency}}</span>
  70. <span v-if="store.currencyName.indexOf('USD')!==-1">${{price.uSDPrice | currency}}</span>
  71. </div>
  72. </div>
  73. </td>
  74. <td class="push-date">
  75. <div v-if="store.b2cMinDelivery">
  76. <span>{{store.b2cMinDelivery}}</span>
  77. <span v-if="store.b2cMaxDelivery && store.b2cMaxDelivery !== store.b2cMinDelivery">-</span>
  78. <span v-if="store.b2cMaxDelivery && store.b2cMaxDelivery !== store.b2cMinDelivery">{{store.b2cMaxDelivery}}</span>
  79. </div>
  80. <div v-if="store.minBuyQty"><span class="order-tag">订</span>{{store.minBuyQty}}起订</div>
  81. <div v-if="store.reserve"><span class="order-tag reserve-tag">库</span>{{store.reserve}}</div>
  82. <div v-if="!store.b2cMinDelivery">
  83. <span>—</span>
  84. </div>
  85. </td>
  86. </tr>
  87. </tbody>
  88. </table>
  89. </div>
  90. <div v-if="(storeList.totalElements == 0 && activeType == 'store') || (component.properties && component.properties.length == 0 && activeType == 'param')" class="no-store">
  91. <img src="/images/mobile/@2x/car@2x.png" alt="">
  92. <div v-if="activeType == 'store'">抱歉,暂无商家出售此型号!</div>
  93. <div v-if="activeType == 'store'">您可前往<strong>www.usoftmall.com</strong>网页版进行<strong>“发布求购”</strong>或<strong>“产品上架”</strong>操作!</div>
  94. <div v-if="activeType == 'param'">抱歉,暂无参数信息!</div>
  95. </div>
  96. <remind-box :title="collectResult" :timeoutCount="timeoutCount"></remind-box>
  97. <loading v-show="isSearchingMore"></loading>
  98. <login-box @onLoginBoxClose="showLoginBox = false" v-if="showLoginBox"></login-box>
  99. </div>
  100. </template>
  101. <script>
  102. import {RemindBox, Loading, LoginBox} from '~components/mobile/common'
  103. export default {
  104. data () {
  105. return {
  106. activeType: 'store',
  107. collectResult: '收藏成功',
  108. timeoutCount: 0,
  109. storeIds: [],
  110. UmallExist: false,
  111. storeExist: false,
  112. params: {
  113. count: 10,
  114. page: 1,
  115. sorting: {'minPriceRMB': 'ASC'},
  116. filter: {
  117. uuid: this.$route.params.uuid,
  118. ignoreUMall: false,
  119. ignoreStore: false,
  120. storeIds: ''
  121. }
  122. },
  123. isSearchingMore: false,
  124. searchLists: [],
  125. showLoginBox: false,
  126. isScrollOverTab: false
  127. }
  128. },
  129. components: {
  130. RemindBox,
  131. Loading,
  132. LoginBox
  133. },
  134. mounted: function () {
  135. let _this = this
  136. _this.$nextTick(function () {
  137. window.addEventListener('scroll', function () {
  138. _this.scroll()
  139. }, false)
  140. })
  141. },
  142. computed: {
  143. component () {
  144. return this.$store.state.componentDetail.detail.data
  145. },
  146. storeList () {
  147. let storeList = this.$store.state.componentInformation.information.data
  148. let _self = this
  149. if (storeList.content) {
  150. storeList.content.forEach(function (item) {
  151. _self.storeIds.push(item.storeid)
  152. })
  153. }
  154. if (this.storeIds.length > 0) {
  155. if (this.storeIds.indexOf(this.storeId) === -1) {
  156. this.storeExist = true
  157. } else {
  158. this.storeIds.splice(this.storeIds.indexOf(this.storeId), 1)
  159. if (this.storeIds.length > 0) {
  160. this.storeExist = true
  161. }
  162. this.UmallExist = true
  163. }
  164. }
  165. this.searchLists = this.searchLists.concat(storeList.content)
  166. this.isSearchingMore = false
  167. return storeList
  168. },
  169. allPage () {
  170. return this.storeList.totalPages
  171. },
  172. colList () {
  173. return this.$store.state.product.common.collectList.data
  174. },
  175. isCollect () {
  176. let id = this.component.id
  177. let store = this.colList
  178. if (store) {
  179. for (let i = 0; i < store.length; i++) {
  180. if (store[i].componentid === id) {
  181. return true
  182. }
  183. }
  184. } else {
  185. return false
  186. }
  187. },
  188. user () {
  189. return this.$store.state.option.user
  190. }
  191. },
  192. filters: {
  193. currency: function (num) {
  194. if (typeof num === 'number') {
  195. if (num <= 0.000001) {
  196. num = 0.000001
  197. } else {
  198. if (num.toString().indexOf('.') === -1) {
  199. num += '.00'
  200. } else {
  201. let inputStr = num.toString()
  202. let arr = inputStr.split('.')
  203. let floatNum = arr[1]
  204. if (floatNum.length > 6) {
  205. num = inputStr.substring(0, arr[0].length + 7)
  206. if (Number(floatNum.charAt(6)) > 4) {
  207. num = (Number(num) * 1000000 + 1) / 1000000
  208. }
  209. } else if (floatNum.length === 1) {
  210. num = num + '0'
  211. }
  212. }
  213. }
  214. }
  215. return num
  216. },
  217. storeNameFilter: function (str) {
  218. if (str === '') {
  219. return str
  220. }
  221. let len = 0
  222. let index = 0
  223. for (let i = 0; i < str.length; i++) {
  224. if (index === 0 && str.charAt(i).charCodeAt(0) > 255) {
  225. len = len + 2
  226. } else {
  227. len++
  228. }
  229. if (len > 22) {
  230. index = i
  231. break
  232. }
  233. }
  234. if (index > 0) {
  235. return str.substring(0, index) + '...'
  236. } else {
  237. return str
  238. }
  239. }
  240. },
  241. methods: {
  242. scroll: function () {
  243. let scrolled = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
  244. if (Math.ceil(scrolled + window.screen.availHeight) >= document.body.scrollHeight && !this.isSearchingMore && this.params.page < this.allPage) {
  245. this.getMoreStore()
  246. }
  247. let tbodyObj = document.getElementById('product-body')
  248. let theadObj = document.getElementById('product-head')
  249. if (theadObj) {
  250. this.isScrollOverTab = tbodyObj.getBoundingClientRect().top - theadObj.getBoundingClientRect().height - 5 <= theadObj.getBoundingClientRect().height
  251. }
  252. },
  253. getMoreStore: function () {
  254. if (!this.isSearchingMore) {
  255. this.params.page++
  256. this.isSearchingMore = true
  257. this.$store.dispatch('loadComponentInformation', this.params)
  258. }
  259. },
  260. goAttach: function (url) {
  261. if (this.user.logged) {
  262. if (url && url !== '1') {
  263. window.location.href = url
  264. }
  265. } else {
  266. this.showLoginBox = true
  267. }
  268. },
  269. collectComponent: function () {
  270. if (this.user.logged) {
  271. if (!this.isCollect) {
  272. this.$store.dispatch('product/saveEntity', {componentid: this.component.id, kind: 2})
  273. this.collectResult = '收藏成功'
  274. this.timeoutCount++
  275. } else {
  276. this.$http.post('/trade/collection/delete/cmpId', [this.component.id]).then(response => {
  277. this.collectResult = '取消成功'
  278. this.timeoutCount++
  279. this.$store.dispatch('product/saveStores')
  280. })
  281. }
  282. } else {
  283. this.showLoginBox = true
  284. }
  285. }
  286. }
  287. }
  288. </script>
  289. <style lang="scss" scoped>
  290. .component-detail {
  291. font-size: .28rem;
  292. margin-bottom: 1.2rem;
  293. background: #f7f7f7;
  294. padding-top: .2rem;
  295. .base-detail {
  296. margin: 0 .27rem .2rem .27rem;
  297. padding: .18rem .36rem 0 .36rem;
  298. border-radius: .1rem;
  299. background: url('/images/mobile/@2x/productDetail/component-desc-bg.png')no-repeat;
  300. background-size: cover;
  301. max-height: 3.17rem;
  302. position: relative;
  303. .base-detail-item {
  304. margin-top: .2rem;
  305. position: relative;
  306. color: #fff;
  307. &:nth-child(1) {
  308. margin-top: 0;
  309. }
  310. &:nth-last-child(1) {
  311. color: #999;
  312. }
  313. &.attach {
  314. display: inline-block;
  315. img {
  316. background-color: #fff;
  317. width: .36rem;
  318. height: .4rem;
  319. position: relative;
  320. bottom: .05rem;
  321. }
  322. >span >span {
  323. margin-left: .1rem;
  324. color: #418bf6;
  325. }
  326. }
  327. &:last-child {
  328. margin-bottom: 0;
  329. }
  330. &.product-description {
  331. height: 1.58rem;
  332. }
  333. .description {
  334. line-height: .4rem;
  335. max-height: 1.2rem;
  336. word-break: break-all;
  337. overflow : hidden;
  338. text-overflow: ellipsis;
  339. display: -webkit-box;
  340. -webkit-line-clamp: 3;
  341. -webkit-box-orient: vertical;
  342. color: #999;
  343. }
  344. }
  345. >i {
  346. position: absolute;
  347. font-size: .4rem;
  348. background: #fff;
  349. width: .6rem;
  350. height: .6rem;
  351. line-height: .6rem;
  352. border-radius: 100%;
  353. box-shadow: 0 0 .05rem #aaa;
  354. right: .28rem;
  355. top: .55rem;
  356. text-align: center;
  357. }
  358. }
  359. .product-switch-item {
  360. text-align: center;
  361. background: #fff;
  362. .mobile-switch-btn {
  363. background: #fff;
  364. color: #666;
  365. display: inline-block;
  366. height: .64rem;
  367. line-height: .64rem;
  368. font-size: .34rem;
  369. width: 1.4rem;
  370. &:first-child {
  371. margin-right: 1.78rem;
  372. }
  373. &.active {
  374. color: #fc5708;
  375. border-bottom: .04rem solid #fc5708;
  376. }
  377. }
  378. }
  379. .product-params {
  380. line-height: .28rem;
  381. margin-top: .2rem;
  382. .param-item {
  383. padding: .19rem .4rem;
  384. border-bottom: 0.04rem solid #eee;
  385. &:nth-child(1) {
  386. border-top: 0.04rem solid #eee;
  387. }
  388. &:nth-child(even) {
  389. background: #f9f9f9;
  390. }
  391. &:nth-child(odd) {
  392. background: #fff;
  393. }
  394. .prop-name {
  395. width: 3.72rem;
  396. display: inline-block;
  397. text-overflow: ellipsis;
  398. overflow: hidden;
  399. white-space: nowrap;
  400. }
  401. .prop-value {
  402. text-overflow: ellipsis;
  403. overflow: hidden;
  404. white-space: nowrap;
  405. display: inline-block;
  406. width: 2.69rem;
  407. float: right;
  408. text-align: right;
  409. }
  410. }
  411. }
  412. .product-store {
  413. margin: .2rem 0;
  414. table {
  415. width: 100%;
  416. font-size: .28rem;
  417. thead {
  418. background: #d5e5fb;
  419. &.active {
  420. position: fixed;
  421. top: .88rem;
  422. z-index: 2;
  423. }
  424. tr {
  425. th {
  426. font-weight: bold;
  427. text-align: center;
  428. height: .78rem;
  429. line-height: .78rem;
  430. >span {
  431. font-size: .22rem;
  432. }
  433. }
  434. }
  435. }
  436. tbody {
  437. background: #fff;
  438. tr {
  439. border-bottom: 0.2rem solid #f7f7f7;
  440. td {
  441. padding: .2rem .1rem;
  442. &.store-name {
  443. color: #418bf6;
  444. a {
  445. padding: 0;
  446. display: block;
  447. width: 1.2rem;
  448. overflow: hidden;
  449. margin-left: .16rem;
  450. }
  451. }
  452. &.price-level-wrap {
  453. text-align: center;
  454. }
  455. > div {
  456. overflow: hidden;
  457. text-overflow: ellipsis;
  458. white-space: nowrap;
  459. max-width: 1.58rem;
  460. }
  461. .price-number {
  462. display: inline-block;
  463. vertical-align: middle;
  464. margin-bottom: 0;
  465. width: .9rem;
  466. }
  467. div {
  468. margin-bottom: .2rem;
  469. text-align: left;
  470. &:last-child {
  471. margin-bottom: 0;
  472. }
  473. }
  474. &.push-date {
  475. text-align: left;
  476. div {
  477. text-align: left;
  478. }
  479. }
  480. .price-level:last-child {
  481. color: #fc5708;
  482. }
  483. .order-tag {
  484. display: inline-block;
  485. font-size: .18rem;
  486. color: #fff;
  487. font-weight: bold;
  488. background: #ee1717;
  489. height: .27rem;
  490. width: .27rem;
  491. line-height: .27rem;
  492. text-align: center;
  493. border-radius: .05rem;
  494. position: relative;
  495. top: -.05rem;
  496. margin-right: .05rem;
  497. &.reserve-tag {
  498. background: #07bb1c;
  499. }
  500. }
  501. }
  502. }
  503. }
  504. }
  505. }
  506. .no-store {
  507. background: #fff;
  508. padding-top: 1rem;
  509. img {
  510. display: block;
  511. text-align: center;
  512. margin: 0 auto;
  513. margin-bottom: .45rem;
  514. width: 3.31rem;
  515. height: 2.13rem;
  516. }
  517. div {
  518. width: 5.27rem;
  519. margin: 0 auto;
  520. text-align: center;
  521. line-height: .4rem;
  522. color: #999;
  523. .link-url {
  524. color: #01a44e;
  525. }
  526. }
  527. }
  528. }
  529. </style>