Detail.vue 16 KB

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