ComponentDetail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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" :url="url"></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. url: ''
  128. }
  129. },
  130. components: {
  131. RemindBox,
  132. Loading,
  133. LoginBox
  134. },
  135. mounted: function () {
  136. let _this = this
  137. _this.$nextTick(function () {
  138. window.addEventListener('scroll', function () {
  139. _this.scroll()
  140. }, false)
  141. })
  142. },
  143. computed: {
  144. component () {
  145. return this.$store.state.componentDetail.detail.data
  146. },
  147. storeList () {
  148. let storeList = this.$store.state.componentInformation.information.data
  149. let _self = this
  150. if (storeList.content) {
  151. storeList.content.forEach(function (item) {
  152. _self.storeIds.push(item.storeid)
  153. })
  154. }
  155. if (this.storeIds.length > 0) {
  156. if (this.storeIds.indexOf(this.storeId) === -1) {
  157. this.storeExist = true
  158. } else {
  159. this.storeIds.splice(this.storeIds.indexOf(this.storeId), 1)
  160. if (this.storeIds.length > 0) {
  161. this.storeExist = true
  162. }
  163. this.UmallExist = true
  164. }
  165. }
  166. this.searchLists = this.searchLists.concat(storeList.content)
  167. this.isSearchingMore = false
  168. return storeList
  169. },
  170. allPage () {
  171. return this.storeList.totalPages
  172. },
  173. colList () {
  174. return this.$store.state.product.common.collectList.data
  175. },
  176. isCollect () {
  177. let id = this.component.id
  178. let store = this.colList
  179. if (store) {
  180. for (let i = 0; i < store.length; i++) {
  181. if (store[i].componentid === id) {
  182. return true
  183. }
  184. }
  185. } else {
  186. return false
  187. }
  188. },
  189. user () {
  190. return this.$store.state.option.user
  191. }
  192. },
  193. filters: {
  194. currency: function (num) {
  195. if (typeof num === 'number') {
  196. if (num <= 0.000001) {
  197. num = 0.000001
  198. } else {
  199. if (num.toString().indexOf('.') === -1) {
  200. num += '.00'
  201. } else {
  202. let inputStr = num.toString()
  203. let arr = inputStr.split('.')
  204. let floatNum = arr[1]
  205. if (floatNum.length > 6) {
  206. num = inputStr.substring(0, arr[0].length + 7)
  207. if (Number(floatNum.charAt(6)) > 4) {
  208. num = (Number(num) * 1000000 + 1) / 1000000
  209. }
  210. } else if (floatNum.length === 1) {
  211. num = num + '0'
  212. }
  213. }
  214. }
  215. }
  216. return num
  217. },
  218. storeNameFilter: function (str) {
  219. if (str === '') {
  220. return str
  221. }
  222. let len = 0
  223. let index = 0
  224. for (let i = 0; i < str.length; i++) {
  225. if (index === 0 && str.charAt(i).charCodeAt(0) > 255) {
  226. len = len + 2
  227. } else {
  228. len++
  229. }
  230. if (len > 22) {
  231. index = i
  232. break
  233. }
  234. }
  235. if (index > 0) {
  236. return str.substring(0, index) + '...'
  237. } else {
  238. return str
  239. }
  240. }
  241. },
  242. methods: {
  243. scroll: function () {
  244. let scrolled = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
  245. if (Math.ceil(scrolled + window.screen.availHeight) >= document.body.scrollHeight && !this.isSearchingMore && this.params.page < this.allPage) {
  246. this.getMoreStore()
  247. }
  248. let tbodyObj = document.getElementById('product-body')
  249. let theadObj = document.getElementById('product-head')
  250. if (theadObj) {
  251. this.isScrollOverTab = tbodyObj.getBoundingClientRect().top - theadObj.getBoundingClientRect().height - 5 <= theadObj.getBoundingClientRect().height
  252. }
  253. },
  254. getMoreStore: function () {
  255. if (!this.isSearchingMore) {
  256. this.params.page++
  257. this.isSearchingMore = true
  258. this.$store.dispatch('loadComponentInformation', this.params)
  259. }
  260. },
  261. goAttach: function (url) {
  262. if (this.user.logged) {
  263. if (url && url !== '1') {
  264. window.location.href = url
  265. }
  266. } else {
  267. this.url = this.$route.fullPath
  268. this.showLoginBox = true
  269. }
  270. },
  271. collectComponent: function () {
  272. if (this.user.logged) {
  273. if (!this.isCollect) {
  274. this.$store.dispatch('product/saveEntity', {componentid: this.component.id, kind: 2})
  275. this.collectResult = '收藏成功'
  276. this.timeoutCount++
  277. } else {
  278. this.$http.post('/trade/collection/delete/cmpId', [this.component.id]).then(response => {
  279. this.collectResult = '取消成功'
  280. this.timeoutCount++
  281. this.$store.dispatch('product/saveStores')
  282. })
  283. }
  284. } else {
  285. this.url = this.$route.fullPath
  286. this.showLoginBox = true
  287. }
  288. }
  289. }
  290. }
  291. </script>
  292. <style lang="scss" scoped>
  293. .component-detail {
  294. font-size: .28rem;
  295. margin-bottom: 1.2rem;
  296. background: #f7f7f7;
  297. padding-top: .2rem;
  298. .base-detail {
  299. margin: 0 .27rem .2rem .27rem;
  300. padding: .18rem .36rem 0 .36rem;
  301. border-radius: .1rem;
  302. background: url('/images/mobile/@2x/productDetail/component-desc-bg.png')no-repeat;
  303. background-size: cover;
  304. max-height: 3.17rem;
  305. position: relative;
  306. .base-detail-item {
  307. margin-top: .2rem;
  308. position: relative;
  309. color: #fff;
  310. &:nth-child(1) {
  311. margin-top: 0;
  312. }
  313. &:nth-last-child(1) {
  314. color: #999;
  315. }
  316. &.attach {
  317. display: inline-block;
  318. img {
  319. background-color: #fff;
  320. width: .36rem;
  321. height: .4rem;
  322. position: relative;
  323. bottom: .05rem;
  324. }
  325. >span >span {
  326. margin-left: .1rem;
  327. color: #418bf6;
  328. }
  329. }
  330. &:last-child {
  331. margin-bottom: 0;
  332. }
  333. &.product-description {
  334. height: 1.58rem;
  335. }
  336. .description {
  337. line-height: .4rem;
  338. max-height: 1.2rem;
  339. word-break: break-all;
  340. overflow : hidden;
  341. text-overflow: ellipsis;
  342. display: -webkit-box;
  343. -webkit-line-clamp: 3;
  344. -webkit-box-orient: vertical;
  345. color: #999;
  346. }
  347. }
  348. >i {
  349. position: absolute;
  350. font-size: .4rem;
  351. background: #fff;
  352. width: .6rem;
  353. height: .6rem;
  354. line-height: .6rem;
  355. border-radius: 100%;
  356. box-shadow: 0 0 .05rem #aaa;
  357. right: .28rem;
  358. top: .55rem;
  359. text-align: center;
  360. }
  361. }
  362. .product-switch-item {
  363. text-align: center;
  364. background: #fff;
  365. .mobile-switch-btn {
  366. background: #fff;
  367. color: #666;
  368. display: inline-block;
  369. height: .64rem;
  370. line-height: .64rem;
  371. font-size: .34rem;
  372. width: 1.4rem;
  373. &:first-child {
  374. margin-right: 1.78rem;
  375. }
  376. &.active {
  377. color: #fc5708;
  378. border-bottom: .04rem solid #fc5708;
  379. }
  380. }
  381. }
  382. .product-params {
  383. line-height: .28rem;
  384. margin-top: .2rem;
  385. .param-item {
  386. padding: .19rem .4rem;
  387. border-bottom: 0.04rem solid #eee;
  388. &:nth-child(1) {
  389. border-top: 0.04rem solid #eee;
  390. }
  391. &:nth-child(even) {
  392. background: #f9f9f9;
  393. }
  394. &:nth-child(odd) {
  395. background: #fff;
  396. }
  397. .prop-name {
  398. width: 3.72rem;
  399. display: inline-block;
  400. text-overflow: ellipsis;
  401. overflow: hidden;
  402. white-space: nowrap;
  403. }
  404. .prop-value {
  405. text-overflow: ellipsis;
  406. overflow: hidden;
  407. white-space: nowrap;
  408. display: inline-block;
  409. width: 2.69rem;
  410. float: right;
  411. text-align: right;
  412. }
  413. }
  414. }
  415. .product-store {
  416. margin: .2rem 0;
  417. table {
  418. width: 100%;
  419. font-size: .28rem;
  420. thead {
  421. background: #d5e5fb;
  422. &.active {
  423. position: fixed;
  424. top: .88rem;
  425. z-index: 2;
  426. }
  427. tr {
  428. th {
  429. font-weight: bold;
  430. text-align: center;
  431. height: .78rem;
  432. line-height: .78rem;
  433. >span {
  434. font-size: .22rem;
  435. }
  436. }
  437. }
  438. }
  439. tbody {
  440. background: #fff;
  441. tr {
  442. border-bottom: 0.2rem solid #f7f7f7;
  443. td {
  444. padding: .2rem .1rem;
  445. &.store-name {
  446. color: #418bf6;
  447. a {
  448. padding: 0;
  449. display: block;
  450. width: 1.2rem;
  451. overflow: hidden;
  452. margin-left: .16rem;
  453. }
  454. }
  455. &.price-level-wrap {
  456. text-align: center;
  457. }
  458. > div {
  459. overflow: hidden;
  460. text-overflow: ellipsis;
  461. white-space: nowrap;
  462. max-width: 1.58rem;
  463. }
  464. .price-number {
  465. display: inline-block;
  466. vertical-align: middle;
  467. margin-bottom: 0;
  468. width: .9rem;
  469. }
  470. div {
  471. margin-bottom: .2rem;
  472. text-align: left;
  473. &:last-child {
  474. margin-bottom: 0;
  475. }
  476. }
  477. &.push-date {
  478. text-align: left;
  479. div {
  480. text-align: left;
  481. }
  482. }
  483. .price-level:last-child {
  484. color: #fc5708;
  485. }
  486. .order-tag {
  487. display: inline-block;
  488. font-size: .18rem;
  489. color: #fff;
  490. font-weight: bold;
  491. background: #ee1717;
  492. height: .27rem;
  493. width: .27rem;
  494. line-height: .27rem;
  495. text-align: center;
  496. border-radius: .05rem;
  497. position: relative;
  498. top: -.05rem;
  499. margin-right: .05rem;
  500. &.reserve-tag {
  501. background: #07bb1c;
  502. }
  503. }
  504. }
  505. }
  506. }
  507. }
  508. }
  509. .no-store {
  510. background: #fff;
  511. padding-top: 1rem;
  512. img {
  513. display: block;
  514. text-align: center;
  515. margin: 0 auto;
  516. margin-bottom: .45rem;
  517. width: 3.31rem;
  518. height: 2.13rem;
  519. }
  520. div {
  521. width: 5.27rem;
  522. margin: 0 auto;
  523. text-align: center;
  524. line-height: .4rem;
  525. color: #999;
  526. .link-url {
  527. color: #01a44e;
  528. }
  529. }
  530. }
  531. }
  532. </style>