RecommendProduct.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. // window.location.href = '/user#/order/pay/' + this.enidfilter(response.data.orderid)
  101. if (response.data.success) {
  102. if (response.data.message) {
  103. this.$message({
  104. message: response.data.message,
  105. type: 'success'
  106. })
  107. let _self = this
  108. window.setTimeout(function () {
  109. window.location.href = '/user#/order/pay/' + _self.enidfilter(response.data.data.orderid)
  110. }, 1000)
  111. } else {
  112. window.location.href = '/user#/order/pay/' + this.enidfilter(response.data.data.orderid)
  113. }
  114. } else {
  115. if (response.data.data && response.data.data.unvailable === 1) {
  116. this.$message.error('产品信息已失效,请刷新界面')
  117. } else {
  118. this.$message.error(response.data.message)
  119. }
  120. }
  121. }, err => {
  122. console.log(err)
  123. if (item.minBuyQty > item.reserve) {
  124. this.$message.error('商品' + item.code + '的库存已经不满足起订量')
  125. }
  126. })
  127. } else {
  128. // this.$store.dispatch('user/addCar', {uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty})
  129. this.$http.post('trade/cart/add', {
  130. uuid: item.comUuid,
  131. batchCode: item.batchCode,
  132. number: item.minBuyQty,
  133. storeid: item.storeId,
  134. storeUuid: item.storeUuid,
  135. currencyName: item.currency,
  136. minPackQty: item.minPackQty ? item.minPackQty : item.minBuyQty
  137. })
  138. .then(response => {
  139. if (response.data.success) {
  140. if (response.data.message) {
  141. this.$message({
  142. message: '添加购物车成功,但商品信息有更新',
  143. type: 'success'
  144. })
  145. } else {
  146. this.$message({
  147. message: '添加购物车成功',
  148. type: 'success'
  149. })
  150. }
  151. } else {
  152. if (response.data.code === 2) {
  153. this.$message.error(response.data.message + ',请刷新页面')
  154. } else {
  155. this.$message.error(response.data.message)
  156. }
  157. }
  158. })
  159. }
  160. }
  161. }
  162. },
  163. enidfilter: function (str) {
  164. if (str) {
  165. let encryptStr = '' // 最终返回的加密后的字符串
  166. // 产生三位随机数
  167. let num = ''
  168. for (let i = 0; i < 3; i++) {
  169. num += Math.floor(Math.random() * 10)
  170. }
  171. encryptStr += num // 产生3位随机数
  172. // 16位加密
  173. let tempspit = ''
  174. let strspit = str.toString().toLowerCase()
  175. if (strspit.match(/^[-+]?\d*$/) === null) { // 非整数字符,对每一个字符都转换成16进制,然后拼接
  176. /**
  177. * Unicode汉字、英文字母、数字的unicode范围
  178. *汉字:[0x4e00,0x9fa5](或十进制[19968,40869])
  179. *数字:[0x30,0x39](或十进制[48, 57])
  180. *小写字母:[0x61,0x7a](或十进制[97, 122])
  181. *大写字母:[0x41,0x5a](或十进制[65, 90]
  182. * 'a'的Unicode编码:'&#97;',charCodeAt()的值是97
  183. * '码'的Unicode编码:'\u7801', new String('码').charCodeAt()的值是30721,30721的16进制表示是7801
  184. */
  185. let s = strspit.split('')
  186. for (let i = 0; i < s.length; i++) {
  187. s[i] = s[i].charCodeAt() // 先转换成Unicode编码
  188. s[i] = s[i].toString(16)
  189. // 因为在服务器是每两位当做一个字符进行解析的,所以这里每个字符的Unicode编码范围必须在0——255之间。数字和大小写满足该要求,特殊字符则不一定,如果后续有特殊字符的要求,需要重写编码器和解码器
  190. if (s[i].length === 1) {
  191. s[i] = '0' + s[i]
  192. }
  193. tempspit = tempspit + s[i]
  194. }
  195. tempspit = tempspit + '{' + 1 // 1代表字符
  196. } else { // 数字直接转换成16进制
  197. strspit = parseInt(strspit)
  198. .toString(16)
  199. tempspit = strspit + '{' + 0 // 0代表纯数字
  200. }
  201. let temp = tempspit.split('{') // 对要加密的字符转换成16进制
  202. let numLength = temp[0].length // 转换后的字符长度
  203. numLength = numLength.toString(16) // 字符长度换算成16进制
  204. if (numLength.length === 1) { // 如果是1,补一个0
  205. numLength = '0' + numLength
  206. } else if (numLength.length > 3) { // 转换后的16进制字符长度如果大于2位数,则返回,不支持
  207. return ''
  208. }
  209. encryptStr += numLength
  210. if (temp[1] === '0') {
  211. encryptStr += 0
  212. } else if (temp[1] === '1') {
  213. encryptStr += 1
  214. }
  215. encryptStr += temp[0]
  216. if (encryptStr.length < 20) { // 如果小于20位,补上随机数
  217. // 产生三位随机数
  218. let numtwo = ''
  219. for (let i = 0; i < 20 - encryptStr.length; i++) {
  220. numtwo += Math.floor(Math.random() * 10)
  221. }
  222. let ran = numtwo // 产生3位随机数
  223. encryptStr += ran
  224. }
  225. return encryptStr
  226. }
  227. }
  228. }
  229. }
  230. </script>
  231. <style scoped>
  232. #recommend-fragment{
  233. width: 1190px;
  234. margin: 0 auto;
  235. }
  236. .recommend-list{
  237. width: 100%;
  238. margin: 0 auto;
  239. display: inline-block;
  240. }
  241. #recommend-fragment ul{
  242. width: 100%;
  243. margin: 0 auto;
  244. display: inline-block;
  245. -webkit-padding-start: 0;
  246. }
  247. #recommend-fragment ul li{
  248. float: left;
  249. width: 218px;
  250. height: 260px;
  251. border: #d2d2d2 1px solid;
  252. position: relative;
  253. overflow: hidden;
  254. margin-right: 25px;
  255. margin-bottom: 20px;
  256. }
  257. #recommend-fragment ul li:nth-child(5n){
  258. margin-right: 0;
  259. }
  260. #recommend-fragment ul li .img{
  261. height: 175px;
  262. text-align: center;
  263. line-height: 170px;
  264. }
  265. #recommend-fragment ul li .specific-img {
  266. position: absolute;
  267. left: 0;
  268. top: 0;
  269. }
  270. #recommend-fragment ul li .img img{
  271. max-width: 120px;
  272. max-height: 120px;
  273. }
  274. #recommend-fragment ul li .content{
  275. width: 100%;
  276. margin: 0 auto;
  277. }
  278. #recommend-fragment ul li .content p{
  279. width: 90%;
  280. display: inline-block;
  281. line-height: 22px;
  282. font-size: 14px;
  283. overflow: hidden;
  284. text-overflow: ellipsis;
  285. white-space: nowrap;
  286. margin-bottom: 0;
  287. padding-left: 10px;
  288. }
  289. #recommend-fragment ul li .content p.price{
  290. color: #ff9000;
  291. font-size: 16px;
  292. font-weight: bold;
  293. }
  294. .color666{
  295. color: #666;
  296. }
  297. #recommend-fragment ul li .hover-show{
  298. width: 100%;
  299. height: 100%;
  300. position: absolute;
  301. top: 100%;
  302. left: 0;
  303. background: rgba(80,120,203,.85);
  304. padding: 30px 10px;
  305. }
  306. #recommend-fragment ul li:hover .hover-show{
  307. top: 0;
  308. transition: top .5s ease-in;
  309. }
  310. #recommend-fragment ul li .hover-show div{
  311. width: 100%;
  312. margin: 0 auto;
  313. text-align: left;
  314. color: #fff;
  315. line-height: 25px;
  316. display: block;
  317. text-overflow: ellipsis;
  318. overflow: hidden;
  319. white-space: nowrap;
  320. }
  321. #recommend-fragment ul li .hover-show .title{
  322. font-size: 18px;
  323. margin-top: 8px;
  324. text-overflow: ellipsis;
  325. white-space: nowrap;
  326. overflow: hidden;
  327. margin-bottom: 0;
  328. }
  329. #recommend-fragment ul li .hover-show .type{
  330. font-size: 14px;
  331. }
  332. #recommend-fragment ul li .hover-show .hr{
  333. text-align: center;
  334. margin-top: 5px;
  335. }
  336. #recommend-fragment ul li .hover-show .hr span{
  337. font-size: 16px;
  338. position: relative;
  339. }
  340. #recommend-fragment ul li .hover-show .hr span:before,#recommend-fragment ul li .hover-show .hr span:after{
  341. content: '';
  342. position: absolute;
  343. display: inline-block;
  344. width: 65px;
  345. height: 1px;
  346. background: #fff;
  347. top: 10px;
  348. }
  349. #recommend-fragment ul li .hover-show .hr span:before{
  350. left: 53px;
  351. }
  352. #recommend-fragment ul li .hover-show .hr span:after{
  353. right: 53px;
  354. }
  355. #recommend-fragment ul li .hover-show .price{
  356. font-size: 20px;
  357. text-align: center;
  358. line-height: 48px;
  359. }
  360. #recommend-fragment ul li .hover-show .by-cart,#recommend-fragment ul li .hover-show .buy-now{
  361. text-align: center;
  362. position: absolute;
  363. left: 0;
  364. }
  365. #recommend-fragment ul li .hover-show .by-cart{
  366. bottom: 50px;
  367. }
  368. #recommend-fragment ul li .hover-show .buy-now{
  369. bottom: 15px;
  370. }
  371. #recommend-fragment ul li .hover-show .by-cart button{
  372. display: inline-block;
  373. width: 38px;
  374. height: 38px;
  375. border-radius: 100%;
  376. background: #fff;
  377. line-height: 38px;
  378. margin-bottom: 5px;
  379. cursor: pointer;
  380. border: none;
  381. z-index: 100;
  382. position: relative;
  383. }
  384. #recommend-fragment ul li .hover-show .buy-now button{
  385. display: inline-block;
  386. width: 90px;
  387. height: 34px;
  388. text-align: center;
  389. font-size: 14px;
  390. border-radius: 4px;
  391. background: #df1b0f;
  392. line-height: 34px;
  393. color: #fff;
  394. cursor: pointer;
  395. border: none;
  396. z-index: 100;
  397. position: relative;
  398. }
  399. #recommend-fragment ul li .hover-show .buy-now button:hover{
  400. background: #f00;
  401. }
  402. #recommend-fragment ul li a.href{
  403. display: inline-block;
  404. position: relative;
  405. z-index: 10;
  406. width: 100%;
  407. text-align: center;
  408. height: 260px;
  409. }
  410. #recommend-fragment ul li .recommend-sellout {
  411. position: absolute;
  412. right: 0;
  413. bottom: 0;
  414. }
  415. </style>