RecommendProduct.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <div id="recommend-fragment" v-if="commodities && commodities.length > 0">
  3. <div class="recommend-list">
  4. <ul>
  5. <li v-for="commodity in commodities">
  6. <img v-if="isConsignment" class="specific-img" src="/images/floor/specificPrice-home.png" alt="">
  7. <div class="img">
  8. <a href="javascript:void(0);">
  9. <img :src="commodity.comImg.startsWith('static')?'/'+commodity.comImg:commodity.comImg"/>
  10. </a>
  11. </div>
  12. <div class="content">
  13. <p v-text="commodity.comCode">MRFE6S9045NF001</p>
  14. <p class="color666" v-text="commodity.brandNameCn">PANFAEFQ</p>
  15. <p class="price" v-if="commodity.minPriceRMB">¥ {{commodity.minPriceRMB | currency}}</p>
  16. <p class="price" v-if="!commodity.minPriceRMB">$ {{commodity.minPriceUSD | currency}}</p>
  17. </div>
  18. <div class="hover-show">
  19. <nuxt-link :to="commodity.batchCode ? '/store/productDetail/' + commodity.batchCode : ''" class="href">
  20. <div class="title" v-text="commodity.comCode">MRFE6S9045NF001</div>
  21. <div class="type" v-text="commodity.brandNameCn">PANFAEFQ</div>
  22. <div class="hr"><span>抢购价</span></div>
  23. <div class="price" v-if="commodity.minPriceRMB">¥ {{commodity.minPriceRMB | currency}}</div>
  24. <div class="price" v-if="!commodity.minPriceRMB">$ {{commodity.minPriceUSD | currency}}</div>
  25. </nuxt-link>
  26. <div class="by-cart"><button title="加入购物车" @click="buyNow(false, commodity)"><img src="/images/store/icon/cart-blue.png"/></button></div>
  27. <div class="buy-now"><button title="立即购买" @click="buyNow(true, commodity)">立即购买</button></div>
  28. </div>
  29. <img class="recommend-sellout" v-if="commodity.status == 602" src="/images/store/isSellOut.png" alt="">
  30. </li>
  31. </ul>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. import Buy from '~components/common/buyOrCar/buyComponent.vue'
  37. export default {
  38. name: 'recommend-product',
  39. components: {
  40. Buy
  41. },
  42. computed: {
  43. commodities () {
  44. return this.$store.state.shop.recommend.products.data
  45. },
  46. storeInfo () {
  47. return this.$store.state.shop.storeInfo.store.data
  48. },
  49. isConsignment () {
  50. return this.storeInfo.type === 'CONSIGNMENT'
  51. }
  52. },
  53. filters: {
  54. currency: function (num) {
  55. if (typeof num === 'number') {
  56. if (num <= 0.000001) {
  57. num = 0.000001
  58. } else {
  59. if (num.toString().indexOf('.') === -1) {
  60. num += '.00'
  61. } else {
  62. let inputStr = num.toString()
  63. let arr = inputStr.split('.')
  64. let floatNum = arr[1]
  65. if (floatNum.length > 6) {
  66. num = inputStr.substring(0, arr[0].length + 7)
  67. if (Number(floatNum.charAt(6)) > 4) {
  68. num = (Number(num) * 1000000 + 1) / 1000000
  69. }
  70. } else if (floatNum.length === 1) {
  71. num = num + '0'
  72. }
  73. }
  74. }
  75. }
  76. return num
  77. }
  78. },
  79. methods: {
  80. buyNow: function (isBuy, item) {
  81. if (!this.$store.state.option.user.logged) {
  82. this.$http.get('/login/page', {params: {returnUrl: window.location.href}}).then(response => {
  83. if (response.data) {
  84. window.location.href = response.data.content + '&baseUrl=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + response.data.baseUrl)
  85. }
  86. })
  87. } else {
  88. if (item) {
  89. if (isBuy) {
  90. this.$http.post('/trade/order/buyNow', [{
  91. uuid: item.comUuid,
  92. batchCode: item.batchCode,
  93. number: item.minBuyQty,
  94. storeid: item.storeId,
  95. storeUuid: item.storeUuid,
  96. currencyName: item.currency,
  97. minPackQty: item.minPackQty ? item.minPackQty : item.minBuyQty
  98. }])
  99. .then(response => {
  100. if (response.data.success) {
  101. if (response.data.message) {
  102. this.$message({
  103. message: response.data.message,
  104. type: 'success'
  105. })
  106. window.setTimeout(function () {
  107. window.location.href = '/user#/order/pay/' + this.baseUtils.enidfilter(response.data.data.orderid)
  108. }, 1000)
  109. } else {
  110. window.location.href = '/user#/order/pay/' + this.baseUtils.enidfilter(response.data.data.orderid)
  111. }
  112. } else {
  113. if (response.data.data && response.data.data.unvailable === 1) {
  114. this.$message.error('产品信息已失效,请刷新界面')
  115. } else {
  116. this.$message.error(response.data.message)
  117. }
  118. }
  119. }, err => {
  120. console.log(err)
  121. if (item.minBuyQty > item.reserve) {
  122. this.$message.error('商品' + item.code + '的库存已经不满足最小起订量')
  123. }
  124. })
  125. } else {
  126. // this.$store.dispatch('user/addCar', {uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty})
  127. this.$http.post('/trade/cart/add', {
  128. uuid: item.comUuid,
  129. batchCode: item.batchCode,
  130. number: item.minBuyQty,
  131. storeid: item.storeId,
  132. storeUuid: item.storeUuid,
  133. currencyName: item.currency,
  134. minPackQty: item.minPackQty ? item.minPackQty : item.minBuyQty
  135. })
  136. .then(response => {
  137. if (response.data.success) {
  138. if (response.data.message) {
  139. this.$message({
  140. message: '添加购物车成功,但商品信息有更新',
  141. type: 'success'
  142. })
  143. } else {
  144. this.$message({
  145. message: '添加购物车成功',
  146. type: 'success'
  147. })
  148. }
  149. } else {
  150. if (response.data.code === 2) {
  151. this.$message.error(response.data.message + ',请刷新页面')
  152. } else {
  153. this.$message.error(response.data.message)
  154. }
  155. }
  156. })
  157. }
  158. }
  159. }
  160. }
  161. }
  162. }
  163. </script>
  164. <style scoped>
  165. #recommend-fragment{
  166. width: 1190px;
  167. margin: 0 auto;
  168. }
  169. .recommend-list{
  170. width: 100%;
  171. margin: 0 auto;
  172. display: inline-block;
  173. }
  174. #recommend-fragment ul{
  175. width: 100%;
  176. margin: 0 auto;
  177. display: inline-block;
  178. -webkit-padding-start: 0;
  179. }
  180. #recommend-fragment ul li{
  181. float: left;
  182. width: 218px;
  183. height: 260px;
  184. border: #d2d2d2 1px solid;
  185. position: relative;
  186. overflow: hidden;
  187. margin-right: 25px;
  188. margin-bottom: 20px;
  189. }
  190. #recommend-fragment ul li:nth-child(5n){
  191. margin-right: 0;
  192. }
  193. #recommend-fragment ul li .img{
  194. height: 175px;
  195. text-align: center;
  196. line-height: 170px;
  197. }
  198. #recommend-fragment ul li .specific-img {
  199. position: absolute;
  200. left: 0;
  201. top: 0;
  202. }
  203. #recommend-fragment ul li .img img{
  204. max-width: 120px;
  205. max-height: 120px;
  206. }
  207. #recommend-fragment ul li .content{
  208. width: 100%;
  209. margin: 0 auto;
  210. }
  211. #recommend-fragment ul li .content p{
  212. width: 90%;
  213. display: inline-block;
  214. line-height: 22px;
  215. font-size: 14px;
  216. overflow: hidden;
  217. text-overflow: ellipsis;
  218. white-space: nowrap;
  219. margin-bottom: 0;
  220. padding-left: 10px;
  221. }
  222. #recommend-fragment ul li .content p.price{
  223. color: #ff9000;
  224. font-size: 16px;
  225. font-weight: bold;
  226. }
  227. .color666{
  228. color: #666;
  229. }
  230. #recommend-fragment ul li .hover-show{
  231. width: 100%;
  232. height: 100%;
  233. position: absolute;
  234. top: 100%;
  235. left: 0;
  236. background: rgba(80,120,203,.85);
  237. padding: 30px 10px;
  238. }
  239. #recommend-fragment ul li:hover .hover-show{
  240. top: 0;
  241. transition: top .5s ease-in;
  242. }
  243. #recommend-fragment ul li .hover-show div{
  244. width: 100%;
  245. margin: 0 auto;
  246. text-align: left;
  247. color: #fff;
  248. line-height: 25px;
  249. display: block;
  250. text-overflow: ellipsis;
  251. overflow: hidden;
  252. white-space: nowrap;
  253. }
  254. #recommend-fragment ul li .hover-show .title{
  255. font-size: 18px;
  256. margin-top: 8px;
  257. text-overflow: ellipsis;
  258. white-space: nowrap;
  259. overflow: hidden;
  260. margin-bottom: 0;
  261. }
  262. #recommend-fragment ul li .hover-show .type{
  263. font-size: 14px;
  264. }
  265. #recommend-fragment ul li .hover-show .hr{
  266. text-align: center;
  267. margin-top: 5px;
  268. }
  269. #recommend-fragment ul li .hover-show .hr span{
  270. font-size: 16px;
  271. position: relative;
  272. }
  273. #recommend-fragment ul li .hover-show .hr span:before,#recommend-fragment ul li .hover-show .hr span:after{
  274. content: '';
  275. position: absolute;
  276. display: inline-block;
  277. width: 65px;
  278. height: 1px;
  279. background: #fff;
  280. top: 10px;
  281. }
  282. #recommend-fragment ul li .hover-show .hr span:before{
  283. left: 53px;
  284. }
  285. #recommend-fragment ul li .hover-show .hr span:after{
  286. right: 53px;
  287. }
  288. #recommend-fragment ul li .hover-show .price{
  289. font-size: 20px;
  290. text-align: center;
  291. line-height: 48px;
  292. }
  293. #recommend-fragment ul li .hover-show .by-cart,#recommend-fragment ul li .hover-show .buy-now{
  294. text-align: center;
  295. position: absolute;
  296. left: 0;
  297. }
  298. #recommend-fragment ul li .hover-show .by-cart{
  299. bottom: 50px;
  300. }
  301. #recommend-fragment ul li .hover-show .buy-now{
  302. bottom: 15px;
  303. }
  304. #recommend-fragment ul li .hover-show .by-cart button{
  305. display: inline-block;
  306. width: 38px;
  307. height: 38px;
  308. border-radius: 100%;
  309. background: #fff;
  310. line-height: 38px;
  311. margin-bottom: 5px;
  312. cursor: pointer;
  313. border: none;
  314. z-index: 100;
  315. position: relative;
  316. }
  317. #recommend-fragment ul li .hover-show .buy-now button{
  318. display: inline-block;
  319. width: 90px;
  320. height: 34px;
  321. text-align: center;
  322. font-size: 14px;
  323. border-radius: 4px;
  324. background: #df1b0f;
  325. line-height: 34px;
  326. color: #fff;
  327. cursor: pointer;
  328. border: none;
  329. z-index: 100;
  330. position: relative;
  331. }
  332. #recommend-fragment ul li .hover-show .buy-now button:hover{
  333. background: #f00;
  334. }
  335. #recommend-fragment ul li a.href{
  336. display: inline-block;
  337. position: relative;
  338. z-index: 10;
  339. width: 100%;
  340. text-align: center;
  341. height: 260px;
  342. }
  343. #recommend-fragment ul li .recommend-sellout {
  344. position: absolute;
  345. right: 0;
  346. bottom: 0;
  347. }
  348. </style>