RecommendProduct.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. <div class="img"><a href="javascript:void(0);"><img :src="commodity.comImg || '/images/store/common/default.png'"/></a></div>
  7. <div class="content">
  8. <p v-text="commodity.comCode">MRFE6S9045NF001</p>
  9. <p class="color666" v-text="commodity.brandNameCn">PANFAEFQ</p>
  10. <p class="price" v-if="commodity.minPriceRMB">¥ {{commodity.minPriceRMB}}</p>
  11. <p class="price" v-if="!commodity.minPriceRMB">$ {{commodity.minPriceUSD || 0}}</p>
  12. </div>
  13. <div class="hover-show" :href="commodity.batchCode ? '/store/' + storeInfo.uuid + '/' + commodity.batchCode : '#'">
  14. <a :href="commodity.batchCode ? '/store/' + storeInfo.uuid + '/' + commodity.batchCode : '#'" class="href">
  15. <div class="title" v-text="commodity.comCode">MRFE6S9045NF001</div>
  16. <div class="type" v-text="commodity.brandNameCn">PANFAEFQ</div>
  17. <div class="hr"><span>抢购价</span></div>
  18. <div class="price" v-if="commodity.minPriceRMB">¥ {{commodity.minPriceRMB}}</div>
  19. <div class="price" v-if="!commodity.minPriceRMB">$ {{commodity.minPriceUSD || 0}}</div>
  20. </a>
  21. <div class="by-cart"><button title="加入购物车" @click="buy(false, commodity)"><img src="/images/store/icon/cart-blue.png"/></button></div>
  22. <div class="buy-now"><button title="立即购买" @click="buy(true, commodity)">立即购买</button></div>
  23. </div>
  24. </li>
  25. </ul>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import Buy from '~components/common/buyOrCar/BuyComponent.vue'
  31. import axios from '~/plugins/axios'
  32. import {Message} from 'element-ui'
  33. export default {
  34. name: 'recommend-product',
  35. components: {
  36. Buy
  37. },
  38. computed: {
  39. commodities () {
  40. return this.$store.state.shop.recommend.products.data
  41. },
  42. storeInfo () {
  43. return this.$store.state.shop.storeInfo.store.data
  44. }
  45. },
  46. methods: {
  47. buyNow: function (isBuy, item) {
  48. if (item) {
  49. // this.$emit('buyAction', [{uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty}])
  50. if (isBuy) {
  51. // this.$store.dispatch('user/getBuyInfo', [{uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty}])
  52. axios.post('trade/order/buyNow', [{uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty}])
  53. .then(response => {
  54. window.location.href = '/user#/order/pay/' + this.enidfilter(response.data.orderid)
  55. }, err => {
  56. console.log(err)
  57. this.$http.get('/login/page').then(response => {
  58. if (response.data) {
  59. this.$router.push('/auth/login')
  60. }
  61. })
  62. })
  63. } else {
  64. // this.$store.dispatch('user/addCar', {uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty})
  65. axios.post('trade/cart/add', {uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty})
  66. .then(response => {
  67. console.log(response.data)
  68. if (response.data.success) {
  69. Message({
  70. message: '添加购物车成功',
  71. type: 'success'
  72. })
  73. } else {
  74. Message.error(response.data.message)
  75. // console.log(response.data.message)
  76. }
  77. })
  78. }
  79. }
  80. },
  81. enidfilter: function (str) {
  82. if (str) {
  83. let encryptStr = '' // 最终返回的加密后的字符串
  84. // 产生三位随机数
  85. let num = ''
  86. for (let i = 0; i < 3; i++) {
  87. num += Math.floor(Math.random() * 10)
  88. }
  89. encryptStr += num // 产生3位随机数
  90. // 16位加密
  91. let tempspit = ''
  92. let strspit = str.toString().toLowerCase()
  93. if (strspit.match(/^[-+]?\d*$/) === null) { // 非整数字符,对每一个字符都转换成16进制,然后拼接
  94. /**
  95. * Unicode汉字、英文字母、数字的unicode范围
  96. *汉字:[0x4e00,0x9fa5](或十进制[19968,40869])
  97. *数字:[0x30,0x39](或十进制[48, 57])
  98. *小写字母:[0x61,0x7a](或十进制[97, 122])
  99. *大写字母:[0x41,0x5a](或十进制[65, 90]
  100. * 'a'的Unicode编码:'&#97;',charCodeAt()的值是97
  101. * '码'的Unicode编码:'\u7801', new String('码').charCodeAt()的值是30721,30721的16进制表示是7801
  102. */
  103. let s = strspit.split('')
  104. for (let i = 0; i < s.length; i++) {
  105. s[i] = s[i].charCodeAt() // 先转换成Unicode编码
  106. s[i] = s[i].toString(16)
  107. // 因为在服务器是每两位当做一个字符进行解析的,所以这里每个字符的Unicode编码范围必须在0——255之间。数字和大小写满足该要求,特殊字符则不一定,如果后续有特殊字符的要求,需要重写编码器和解码器
  108. if (s[i].length === 1) {
  109. s[i] = '0' + s[i]
  110. }
  111. tempspit = tempspit + s[i]
  112. }
  113. tempspit = tempspit + '{' + 1 // 1代表字符
  114. } else { // 数字直接转换成16进制
  115. strspit = parseInt(strspit)
  116. .toString(16)
  117. tempspit = strspit + '{' + 0 // 0代表纯数字
  118. }
  119. let temp = tempspit.split('{') // 对要加密的字符转换成16进制
  120. let numLength = temp[0].length // 转换后的字符长度
  121. numLength = numLength.toString(16) // 字符长度换算成16进制
  122. if (numLength.length === 1) { // 如果是1,补一个0
  123. numLength = '0' + numLength
  124. } else if (numLength.length > 3) { // 转换后的16进制字符长度如果大于2位数,则返回,不支持
  125. return ''
  126. }
  127. encryptStr += numLength
  128. if (temp[1] === '0') {
  129. encryptStr += 0
  130. } else if (temp[1] === '1') {
  131. encryptStr += 1
  132. }
  133. encryptStr += temp[0]
  134. if (encryptStr.length < 20) { // 如果小于20位,补上随机数
  135. // 产生三位随机数
  136. let numtwo = ''
  137. for (let i = 0; i < 20 - encryptStr.length; i++) {
  138. numtwo += Math.floor(Math.random() * 10)
  139. }
  140. let ran = numtwo // 产生3位随机数
  141. encryptStr += ran
  142. }
  143. return encryptStr
  144. }
  145. }
  146. }
  147. }
  148. </script>
  149. <style scoped>
  150. #recommend-fragment{
  151. width: 1190px;
  152. margin: 0 auto;
  153. }
  154. .recommend-list{
  155. width: 100%;
  156. margin: 0 auto;
  157. display: inline-block;
  158. }
  159. #recommend-fragment ul{
  160. width: 100%;
  161. margin: 0 auto;
  162. display: inline-block;
  163. -webkit-padding-start: 0;
  164. }
  165. #recommend-fragment ul li{
  166. float: left;
  167. width: 218px;
  168. height: 260px;
  169. border: #d2d2d2 1px solid;
  170. position: relative;
  171. overflow: hidden;
  172. margin-right: 25px;
  173. margin-bottom: 20px;
  174. }
  175. #recommend-fragment ul li:nth-child(5n){
  176. margin-right: 0;
  177. }
  178. #recommend-fragment ul li .img{
  179. height: 175px;
  180. text-align: center;
  181. line-height: 170px;
  182. }
  183. #recommend-fragment ul li .img img{
  184. max-width: 120px;
  185. max-height: 120px;
  186. }
  187. #recommend-fragment ul li .content{
  188. width: 100%;
  189. margin: 0 auto;
  190. }
  191. #recommend-fragment ul li .content p{
  192. width: 90%;
  193. display: inline-block;
  194. line-height: 22px;
  195. font-size: 14px;
  196. overflow: hidden;
  197. text-overflow: ellipsis;
  198. white-space: nowrap;
  199. margin-bottom: 0;
  200. padding-left: 10px;
  201. }
  202. #recommend-fragment ul li .content p.price{
  203. color: #ff9000;
  204. font-size: 16px;
  205. font-weight: bold;
  206. }
  207. .color666{
  208. color: #666;
  209. }
  210. #recommend-fragment ul li .hover-show{
  211. width: 100%;
  212. height: 100%;
  213. position: absolute;
  214. top: 100%;
  215. left: 0;
  216. background: rgba(80,120,203,.85);
  217. padding: 30px 10px;
  218. }
  219. #recommend-fragment ul li:hover .hover-show{
  220. top: 0;
  221. transition: top .5s ease-in;
  222. }
  223. #recommend-fragment ul li .hover-show div{
  224. width: 100%;
  225. margin: 0 auto;
  226. text-align: left;
  227. color: #fff;
  228. line-height: 25px;
  229. display: block;
  230. text-overflow: ellipsis;
  231. overflow: hidden;
  232. white-space: nowrap;
  233. }
  234. #recommend-fragment ul li .hover-show .title{
  235. font-size: 18px;
  236. margin-top: 8px;
  237. text-overflow: ellipsis;
  238. white-space: nowrap;
  239. overflow: hidden;
  240. margin-bottom: 0;
  241. }
  242. #recommend-fragment ul li .hover-show .type{
  243. font-size: 14px;
  244. }
  245. #recommend-fragment ul li .hover-show .hr{
  246. text-align: center;
  247. margin-top: 5px;
  248. }
  249. #recommend-fragment ul li .hover-show .hr span{
  250. font-size: 16px;
  251. position: relative;
  252. }
  253. #recommend-fragment ul li .hover-show .hr span:before,#recommend-fragment ul li .hover-show .hr span:after{
  254. content: '';
  255. position: absolute;
  256. display: inline-block;
  257. width: 65px;
  258. height: 1px;
  259. background: #fff;
  260. top: 10px;
  261. }
  262. #recommend-fragment ul li .hover-show .hr span:before{
  263. left: 53px;
  264. }
  265. #recommend-fragment ul li .hover-show .hr span:after{
  266. right: 53px;
  267. }
  268. #recommend-fragment ul li .hover-show .price{
  269. font-size: 20px;
  270. text-align: center;
  271. line-height: 48px;
  272. }
  273. #recommend-fragment ul li .hover-show .by-cart,#recommend-fragment ul li .hover-show .buy-now{
  274. text-align: center;
  275. position: absolute;
  276. left: 0;
  277. }
  278. #recommend-fragment ul li .hover-show .by-cart{
  279. bottom: 50px;
  280. }
  281. #recommend-fragment ul li .hover-show .buy-now{
  282. bottom: 15px;
  283. }
  284. #recommend-fragment ul li .hover-show .by-cart button{
  285. display: inline-block;
  286. width: 38px;
  287. height: 38px;
  288. border-radius: 100%;
  289. background: #fff;
  290. line-height: 38px;
  291. margin-bottom: 5px;
  292. cursor: pointer;
  293. border: none;
  294. z-index: 100;
  295. position: relative;
  296. }
  297. #recommend-fragment ul li .hover-show .buy-now button{
  298. display: inline-block;
  299. width: 90px;
  300. height: 34px;
  301. text-align: center;
  302. font-size: 14px;
  303. border-radius: 4px;
  304. background: #df1b0f;
  305. line-height: 34px;
  306. color: #fff;
  307. cursor: pointer;
  308. border: none;
  309. z-index: 100;
  310. position: relative;
  311. }
  312. #recommend-fragment ul li .hover-show .buy-now button:hover{
  313. background: #f00;
  314. }
  315. #recommend-fragment ul li a.href{
  316. display: inline-block;
  317. position: relative;
  318. z-index: 10;
  319. width: 100%;
  320. text-align: center;
  321. height: 260px;
  322. }
  323. </style>