Detail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. <template>
  2. <div class="detail">
  3. <div class="item">
  4. <div class="img inline-block">
  5. <img :src="commodity.img || '/images/store/common/default.png'" alt=""/>
  6. </div>
  7. <div class="info inline-block">
  8. <p class="name">{{commodity.code}}</p>
  9. <p class="remind"><span>官方自营,品质保障</span>厂家直销,品质保证</p>
  10. <!--<div class="price-area">-->
  11. <!--<span class="left inline-block">价格<span><i>¥</i>1899.00</span></span>-->
  12. <!--<span class="right inline-block"><span>6500</span><br/>浏览数</span>-->
  13. <!--</div>-->
  14. <div class="price-level">
  15. <span class="left inline-block">
  16. <div>单价&nbsp;¥&nbsp;(含税):</div>
  17. 起订量:
  18. </span>
  19. <ul class="inline-block">
  20. <li :class="{active: getPriceLevel(fragment.num) == index}" v-for="(price, index) in commodity.prices">
  21. <span class="price"><em>{{commodity.currencyName == 'RMB' ? '¥' : '$'}}</em>{{price.rMBPrice}}</span>
  22. <div class="level" :title="price.start + '-' + price.end">{{price.start}}-{{price.end}}</div>
  23. <i class="arrow"></i>
  24. </li>
  25. </ul>
  26. </div>
  27. <div class="input-area">
  28. <!--<div class="operate-btn inline-block">-</div>
  29. <input type="text" class="form-control">
  30. <div class="operate-btn inline-block">+</div>-->
  31. <div class="operate-btn inline-block" @click="fragment.canSub ?subNum():''" :style="!fragment.canSub ?'cursor: not-allowed;':''">-</div>
  32. <input type="text" class="form-control" placeholder="数量" v-model="fragment.num" @change="inputNum()"style="padding: 0;min-width: 100px;text-align: center;"/>
  33. <div class="operate-btn inline-block" @click="fragment.canAdd ?addNum():''" :style="!fragment.canAdd ?'cursor: not-allowed;':''">+</div>
  34. <span class="reserve-info">
  35. 库存:{{commodity.reserve}}&nbsp;{{commodity.unit}}&nbsp;&nbsp;({{commodity.minBuyQty + commodity.unit}}&nbsp;起订)
  36. </span>
  37. </div>
  38. <div class="operate-area">
  39. <a class="inline-block operate-buy" @click="buy(true)">立即购买</a>
  40. <a class="inline-block" @click="buy(false)">加入购物车</a>
  41. </div>
  42. </div>
  43. <div class="shop inline-block fr">
  44. <p class="shop-info-title">
  45. 商家信息
  46. </p>
  47. <div class="shop-info">
  48. <p class="shop-name">{{storeInfo.storeName}}</p>
  49. <img class="identify" src="/images/pcb/identified.png">
  50. <div class="info-line">
  51. <span class="inline-block">电话:</span>
  52. <span class="inline-block">{{storeInfo.enterprise.enTel}}</span>
  53. </div>
  54. <div class="info-line">
  55. <span class="inline-block">传真:</span>
  56. <span class="inline-block">{{storeInfo.enterprise.enFax}}</span>
  57. </div>
  58. <div class="info-line">
  59. <span class="inline-block">地址:</span>
  60. <span class="inline-block">{{storeInfo.enterprise.enAddress}}</span>
  61. </div>
  62. <div class="link">
  63. <span class="link-btn" @click="goLink()"><img src="/images/pcb/link.png" alt="">联系卖家</span>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. <ul class="kind">
  69. <template v-if="properties && properties.length">
  70. <li class="inline-block" v-for="prop in properties">
  71. {{prop[1].labelCn}}:{{prop[0].value || '-'}}
  72. </li>
  73. </template>
  74. <li class="empty-param" v-else>
  75. <img src="/images/all/empty-cart.png" alt="">该产品暂无参数
  76. </li>
  77. </ul>
  78. <link-saler-box
  79. :tel="tel"
  80. v-if="showLinkBox"
  81. @cancelAction="showLinkBox = false">
  82. </link-saler-box>
  83. </div>
  84. </template>
  85. <script>
  86. function initFragment (commodity) {
  87. if (!commodity) {
  88. return {}
  89. }
  90. let fragment = {}
  91. let prices = commodity.prices[0]
  92. fragment.num = commodity.minBuyQty
  93. fragment.prices = prices
  94. if (commodity.currencyName !== 'USD') {
  95. fragment.currency = 'RMB'
  96. } else {
  97. fragment.currency = 'USD'
  98. }
  99. if (fragment.currency !== 'USD') {
  100. fragment.price = prices.rMBPrice
  101. } else {
  102. fragment.price = prices.uSDPrice
  103. }
  104. fragment.canAdd = true
  105. fragment.canSub = false
  106. return fragment
  107. }
  108. function getFragment (commodity, fragment) {
  109. // 判断是否小于第一分段的起订量
  110. if (commodity.prices[0].start > fragment.num) {
  111. fragment.num = commodity.prices[0].start
  112. }
  113. // 获取分段的信息
  114. let prices = commodity.prices
  115. for (let i = 0; i < prices.length; i++) {
  116. if (fragment.num <= prices[i].end) {
  117. fragment.prices = prices[i]
  118. break
  119. }
  120. }
  121. }
  122. import LinkSalerBox from '~components/common/LinkSalerBox.vue'
  123. export default {
  124. data () {
  125. return {
  126. fragment: {
  127. currency: 'RMB',
  128. num: 0,
  129. price: 0,
  130. canAdd: true,
  131. canSub: true
  132. },
  133. showLinkBox: false,
  134. tel: ''
  135. }
  136. },
  137. components: {
  138. LinkSalerBox
  139. },
  140. computed: {
  141. properties () {
  142. return this.$store.state.pcb.product.detail.data
  143. },
  144. storeInfo () {
  145. return this.$store.state.shop.storeInfo.store.data
  146. },
  147. commodity () {
  148. let commodity = this.$store.state.shop.storeInfo.commodity.data
  149. this.fragment = initFragment(commodity)
  150. return commodity
  151. }
  152. },
  153. methods: {
  154. getPriceLevel: function (num) {
  155. let prices = this.commodity.prices
  156. if (this.commodity.prices) {
  157. for (let i = 0; i < prices.length; i++) {
  158. if (num >= prices[i].start && num <= prices[i].end) {
  159. return i
  160. }
  161. }
  162. }
  163. return -1
  164. },
  165. changeNum: function (newNum) {
  166. let pack = this.commodity.perQty || this.commodity.minPackQty
  167. let buy = this.commodity.minBuyQty
  168. let reserve = this.commodity.reserve
  169. if (newNum < buy) {
  170. this.$message.error('该商品最少购买' + buy + '件')
  171. this.fragment.num = buy
  172. this.fragment.canSub = false
  173. if (this.fragment.num > reserve) {
  174. this.$message.error('库存不足')
  175. this.fragment.num = reserve - (reserve % pack)
  176. this.fragment.canAdd = false
  177. } else {
  178. if (reserve - this.fragment.num - pack < 0) {
  179. this.fragment.canAdd = false
  180. } else {
  181. this.fragment.canAdd = true
  182. }
  183. }
  184. } else {
  185. if (newNum - buy - pack < 0) {
  186. this.fragment.canSub = false
  187. } else {
  188. this.fragment.canSub = true
  189. }
  190. // console.log(newNum) 2222
  191. if (newNum % pack === 0) {
  192. this.fragment.num = newNum
  193. } else {
  194. this.fragment.num = (Math.floor(newNum / pack) + 1) * pack
  195. }
  196. if (this.fragment.num > reserve) {
  197. this.$message.error('库存不足')
  198. this.fragment.num = reserve - (reserve % pack)
  199. this.fragment.canAdd = false
  200. } else {
  201. if (reserve - this.fragment.num - pack < 0) {
  202. this.fragment.canAdd = false
  203. } else {
  204. this.fragment.canAdd = true
  205. }
  206. }
  207. }
  208. },
  209. subNum () {
  210. let pack = this.commodity.perQty || this.commodity.minPackQty
  211. let newNum = this.fragment.num - pack
  212. this.changeNum(newNum)
  213. getFragment(this.commodity, this.fragment)
  214. },
  215. addNum () {
  216. let pack = this.commodity.perQty || this.commodity.minPackQty
  217. let newNum = this.fragment.num + pack
  218. this.changeNum(newNum)
  219. getFragment(this.commodity, this.fragment)
  220. },
  221. inputNum () {
  222. if ((/^[\d]*$/).test(this.fragment.num)) {
  223. this.changeNum(this.fragment.num)
  224. getFragment(this.commodity, this.fragment)
  225. } else {
  226. this.$message.error('请输入数字')
  227. this.fragment.num = this.commodity.minBuyQty
  228. }
  229. },
  230. buy (flag) {
  231. this.baseUtils.buyOrCar(flag, null, this, this.commodity)
  232. },
  233. goLink: function () {
  234. this.baseUtils.goLinkUser(this, this.storeInfo.enUU)
  235. }
  236. }
  237. }
  238. </script>
  239. <style lang="scss" scoped>
  240. .detail {
  241. .inline-block {
  242. display: inline-block;
  243. vertical-align: middle;
  244. }
  245. .item {
  246. .img {
  247. width: 300px;
  248. height: 356px;
  249. line-height: 356px;
  250. text-align: center;
  251. box-shadow: 0 0 7px 0 rgba(199, 200, 200, .35);
  252. img {
  253. max-width: 300px;
  254. max-height: 356px;
  255. }
  256. }
  257. .info {
  258. margin-left: 17px;
  259. height: 356px;
  260. padding-top: 10px;
  261. .name {
  262. font-size: 24px;
  263. font-weight: bold;
  264. color: #666;
  265. margin-bottom: 17px;
  266. }
  267. .remind {
  268. margin: 17px 0;
  269. span {
  270. background: #e4393c;
  271. color: #fff;
  272. padding: 4px 8px;
  273. border-radius: 3px;
  274. margin-right: 10px;
  275. }
  276. }
  277. /*.price-area {
  278. width: 449px;
  279. height: 75px;
  280. background: url('/images/pcb/price-bg.png') no-repeat;
  281. .left {
  282. color: #666;
  283. margin-left: 13px;
  284. line-height: 40px;
  285. height: 40px;
  286. width: 339px;
  287. border-right: 1px solid #c8e5ff;
  288. margin-top: 18px;
  289. span {
  290. margin-left: 17px;
  291. font-size: 32px;
  292. color: #e4393c;
  293. i {
  294. font-size: 18px;
  295. font-style: normal;
  296. }
  297. }
  298. }
  299. .right {
  300. margin: 22px 0 0 30px;
  301. font-size: 12px;
  302. color: #666;
  303. span {
  304. font-size: 14px;
  305. color: #ffa133;
  306. margin-bottom: 8px;
  307. }
  308. }
  309. }*/
  310. .price-level {
  311. width: 570px;
  312. height: 87px;
  313. padding: 17px 0 0 7px;
  314. background: #fffaf1;
  315. .left {
  316. color: #999;
  317. div {
  318. margin-bottom: 19px;
  319. }
  320. }
  321. ul {
  322. margin-left: 15px;
  323. li {
  324. width: 83px;
  325. margin-right: 4px;
  326. float: left;
  327. text-align: center;
  328. .price {
  329. color: #ffb385;
  330. font-size: 22px;
  331. margin-bottom: 19px;
  332. em {
  333. font-style: normal;
  334. font-size: 13px;
  335. margin-right: 4px;
  336. }
  337. }
  338. .level {
  339. width: 82px;
  340. height: 21px;
  341. line-height: 21px;
  342. font-size: 12px;
  343. color: #999;
  344. background: #e4e4e4;
  345. margin-top: 9px;
  346. overflow: hidden;
  347. text-overflow: ellipsis;
  348. white-space: nowrap;
  349. }
  350. &.active {
  351. position: relative;
  352. .price {
  353. color: #ff7800;
  354. }
  355. .level {
  356. background: #ccc;
  357. color: #333;
  358. }
  359. .arrow {
  360. content: '';
  361. position: absolute;
  362. top: 28px;
  363. left: 37px;
  364. border: {
  365. left: 4px solid transparent;
  366. right: 4px solid transparent;
  367. bottom: 8px solid #ccc;
  368. }
  369. }
  370. }
  371. }
  372. }
  373. }
  374. .input-area {
  375. margin-top: 25px;
  376. .operate-btn {
  377. width: 33px;
  378. height: 45px;
  379. text-align: center;
  380. line-height: 45px;
  381. border: 1px solid #d9d9d9;
  382. background: #f4f4f4;
  383. cursor: pointer;
  384. font-size: 20px;
  385. user-select: none;
  386. }
  387. .form-control {
  388. border: 1px solid #d9d9d9;
  389. background: #fff;
  390. width: 77px;
  391. height: 45px;
  392. border-radius: 0;
  393. vertical-align: middle;
  394. text-align: center;
  395. }
  396. .reserve-info {
  397. color: #999;
  398. margin-left: 10px;
  399. vertical-align: bottom;
  400. }
  401. }
  402. .operate-area {
  403. margin-top: 12px;
  404. .inline-block {
  405. width: 126px;
  406. height: 45px;
  407. line-height: 45px;
  408. text-align: center;
  409. font-size: 18px;
  410. color: #fff;
  411. background: #418cf6;
  412. border: 1px solid #418cf6;
  413. &.operate-buy {
  414. color: #418cf6;
  415. background: #fff;
  416. margin-right: 8px;
  417. }
  418. }
  419. }
  420. }
  421. $base-color: #ffa133;
  422. .shop {
  423. height: 356px;
  424. width: 259px;
  425. text-align: center;
  426. .search-area {
  427. .form-control {
  428. width: 198px;
  429. height: 28px;
  430. font-size: 12px;
  431. padding: 0 14px;
  432. border: 1px solid $base-color;
  433. vertical-align: middle;
  434. border: {
  435. bottom-left-radius: 13px;
  436. top-left-radius: 13px;
  437. top-right-radius: 0;
  438. bottom-right-radius: 0;
  439. };
  440. }
  441. .search-btn {
  442. width: 60px;
  443. height: 28px;
  444. line-height: 28px;
  445. color: #fff;
  446. background: $base-color;
  447. border: 1px solid $base-color;
  448. border: {
  449. bottom-left-radius: 0;
  450. top-left-radius: 0;
  451. top-right-radius: 13px;
  452. bottom-right-radius: 13px;
  453. };
  454. cursor: pointer;
  455. }
  456. }
  457. .shop-info-title {
  458. position: relative;
  459. font-size: 16px;
  460. color: #ffa133;
  461. border: 1px solid #fee9d0;
  462. line-height: 35px;
  463. margin: 30px 0 0 0;
  464. &::before {
  465. content: '';
  466. background: #fff;
  467. width: 24px;
  468. height: 24px;
  469. position: absolute;
  470. left: -12px;
  471. top: -12px;
  472. border-right: 1px solid #fee9d0;
  473. -webkit-transform: rotate(45deg);
  474. -moz-transform: rotate(45deg);
  475. -ms-transform: rotate(45deg);
  476. -o-transform: rotate(45deg);
  477. transform: rotate(45deg);
  478. }
  479. &::after {
  480. content: '';
  481. position: absolute;
  482. left: 1px;
  483. top: 1px;
  484. border: {
  485. top: 15px solid $base-color;
  486. right: 15px solid transparent;
  487. }
  488. }
  489. }
  490. .shop-info {
  491. border: 1px solid #fee9d0;
  492. .shop-name {
  493. margin: 19px 0 9px;
  494. color: #666;
  495. }
  496. .identify {
  497. margin-bottom: 20px;
  498. }
  499. .info-line {
  500. margin-bottom: 21px;
  501. padding: 0 16px;
  502. text-align: left;
  503. .inline-block {
  504. vertical-align: top;
  505. &:first-child {
  506. color: #666;
  507. }
  508. &:last-child {
  509. max-width: 182px;
  510. }
  511. }
  512. }
  513. .link {
  514. height: 70px;
  515. width: 232px;
  516. margin: 0 auto;
  517. border-top: 1px dashed $base-color;
  518. .link-btn {
  519. display: block;
  520. margin: 23px auto 0;
  521. width: 124px;
  522. height: 26px;
  523. background: $base-color;
  524. color: #fff;
  525. line-height: 26px;
  526. border-radius: 13px;
  527. cursor: pointer;
  528. img {
  529. margin-right: 7px;
  530. }
  531. }
  532. }
  533. }
  534. }
  535. }
  536. .kind {
  537. background: #f8fbfd;
  538. margin: 38px 0 80px;
  539. border: 1px solid #d6ebfd;
  540. li {
  541. width: 25%;
  542. color: #666;
  543. height: 40px;
  544. line-height: 40px;
  545. padding-left: 47px;
  546. border-bottom: 1px solid #d6ebfd;
  547. &:nth-last-child(-n + 4) {
  548. border-bottom: none;
  549. }
  550. a {
  551. color: #418cf6;
  552. }
  553. &.empty-param {
  554. width: 100%;
  555. height: auto;
  556. text-align: center;
  557. padding: 20px 0;
  558. color: #999;
  559. font-size: 12px;
  560. }
  561. }
  562. }
  563. }
  564. </style>