Detail.vue 17 KB

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