Detail.vue 17 KB

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