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.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. <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 text-ellipse" :title="prop[0].value" 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, '/user#/order/pay/', this.fragment.num)
  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: 145px;
  325. padding:0 5px;
  326. float: left;
  327. text-align: center;
  328. .price {
  329. color: #ffb385;
  330. font-size: 20px;
  331. margin-bottom: 19px;
  332. em {
  333. font-style: normal;
  334. font-size: 13px;
  335. margin-right: 4px;
  336. }
  337. }
  338. .level {
  339. height: 21px;
  340. line-height: 21px;
  341. font-size: 12px;
  342. color: #999;
  343. background: #e4e4e4;
  344. margin-top: 9px;
  345. overflow: hidden;
  346. text-overflow: ellipsis;
  347. white-space: nowrap;
  348. }
  349. &.active {
  350. position: relative;
  351. .price {
  352. color: #ff7800;
  353. }
  354. .level {
  355. background: #ccc;
  356. color: #333;
  357. }
  358. .arrow {
  359. content: '';
  360. position: absolute;
  361. top: 28px;
  362. left: 37px;
  363. border: {
  364. left: 4px solid transparent;
  365. right: 4px solid transparent;
  366. bottom: 8px solid #ccc;
  367. }
  368. }
  369. }
  370. }
  371. }
  372. }
  373. .input-area {
  374. margin-top: 25px;
  375. .operate-btn {
  376. width: 33px;
  377. height: 45px;
  378. text-align: center;
  379. line-height: 45px;
  380. border: 1px solid #d9d9d9;
  381. background: #f4f4f4;
  382. cursor: pointer;
  383. font-size: 20px;
  384. user-select: none;
  385. }
  386. .form-control {
  387. border: 1px solid #d9d9d9;
  388. background: #fff;
  389. width: 77px;
  390. height: 45px;
  391. border-radius: 0;
  392. vertical-align: middle;
  393. text-align: center;
  394. }
  395. .reserve-info {
  396. color: #999;
  397. margin-left: 10px;
  398. vertical-align: bottom;
  399. }
  400. }
  401. .operate-area {
  402. margin-top: 12px;
  403. .inline-block {
  404. width: 126px;
  405. height: 45px;
  406. line-height: 45px;
  407. text-align: center;
  408. font-size: 18px;
  409. color: #fff;
  410. background: #418cf6;
  411. border: 1px solid #418cf6;
  412. &.operate-buy {
  413. color: #418cf6;
  414. background: #fff;
  415. margin-right: 8px;
  416. }
  417. }
  418. }
  419. }
  420. $base-color: #ffa133;
  421. .shop {
  422. height: 356px;
  423. width: 259px;
  424. text-align: center;
  425. .search-area {
  426. .form-control {
  427. width: 198px;
  428. height: 28px;
  429. font-size: 12px;
  430. padding: 0 14px;
  431. border: 1px solid $base-color;
  432. vertical-align: middle;
  433. border: {
  434. bottom-left-radius: 13px;
  435. top-left-radius: 13px;
  436. top-right-radius: 0;
  437. bottom-right-radius: 0;
  438. };
  439. }
  440. .search-btn {
  441. width: 60px;
  442. height: 28px;
  443. line-height: 28px;
  444. color: #fff;
  445. background: $base-color;
  446. border: 1px solid $base-color;
  447. border: {
  448. bottom-left-radius: 0;
  449. top-left-radius: 0;
  450. top-right-radius: 13px;
  451. bottom-right-radius: 13px;
  452. };
  453. cursor: pointer;
  454. }
  455. }
  456. .shop-info-title {
  457. position: relative;
  458. font-size: 16px;
  459. color: #ffa133;
  460. border: 1px solid #fee9d0;
  461. line-height: 35px;
  462. margin: 30px 0 0 0;
  463. &::before {
  464. content: '';
  465. background: #fff;
  466. width: 24px;
  467. height: 24px;
  468. position: absolute;
  469. left: -12px;
  470. top: -12px;
  471. border-right: 1px solid #fee9d0;
  472. -webkit-transform: rotate(45deg);
  473. -moz-transform: rotate(45deg);
  474. -ms-transform: rotate(45deg);
  475. -o-transform: rotate(45deg);
  476. transform: rotate(45deg);
  477. }
  478. &::after {
  479. content: '';
  480. position: absolute;
  481. left: 1px;
  482. top: 1px;
  483. border: {
  484. top: 15px solid $base-color;
  485. right: 15px solid transparent;
  486. }
  487. }
  488. }
  489. .shop-info {
  490. border: 1px solid #fee9d0;
  491. .shop-name {
  492. margin: 19px 0 9px;
  493. color: #666;
  494. }
  495. .identify {
  496. margin-bottom: 20px;
  497. }
  498. .info-line {
  499. margin-bottom: 21px;
  500. padding: 0 16px;
  501. text-align: left;
  502. .inline-block {
  503. vertical-align: top;
  504. &:first-child {
  505. color: #666;
  506. }
  507. &:last-child {
  508. max-width: 182px;
  509. }
  510. }
  511. }
  512. .link {
  513. height: 70px;
  514. width: 232px;
  515. margin: 0 auto;
  516. border-top: 1px dashed $base-color;
  517. .link-btn {
  518. display: block;
  519. margin: 23px auto 0;
  520. width: 124px;
  521. height: 26px;
  522. background: $base-color;
  523. color: #fff;
  524. line-height: 26px;
  525. border-radius: 13px;
  526. cursor: pointer;
  527. img {
  528. margin-right: 7px;
  529. }
  530. }
  531. }
  532. }
  533. }
  534. }
  535. .kind {
  536. background: #f8fbfd;
  537. margin: 38px 0 80px;
  538. border: 1px solid #d6ebfd;
  539. li {
  540. width: 25%;
  541. color: #666;
  542. height: 40px;
  543. line-height: 40px;
  544. padding-left: 47px;
  545. padding-right: 10px;
  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>