RecommendProduct.vue 11 KB

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