Detail.vue 17 KB

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