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