ComponentDetail.vue 16 KB

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