RecommendProduct.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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="buyNow(false, commodity)"><img src="/images/store/icon/cart-blue.png"/></button></div>
  22. <div class="buy-now"><button title="立即购买" @click="buyNow(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. // data () {
  39. // return {
  40. // commodities: {},
  41. // storeInfo: {}
  42. // }
  43. // },
  44. // mounted () {
  45. // axios.get('/api/store/recommend/products', {params: {StoreUuid: this.$route.params.uuid}})
  46. // .then(response => {
  47. // this.commodities = response.data ? JSON.parse(response.data) : []
  48. // })
  49. // axios.get('/api/store-service/stores', {params: {StoreUuid: this.$route.params.uuid}})
  50. // .then(response => {
  51. // this.storeInfo = response.data
  52. // })
  53. // },
  54. computed: {
  55. commodities () {
  56. return this.$store.state.shop.recommend.products.data
  57. },
  58. storeInfo () {
  59. return this.$store.state.shop.storeInfo.store.data
  60. }
  61. },
  62. methods: {
  63. buyNow: function (isBuy, item) {
  64. if (!this.$store.state.option.user.logged) {
  65. this.$http.get('/login/page').then(response => {
  66. if (response.data) {
  67. this.$router.push('/auth/login')
  68. }
  69. })
  70. } else {
  71. if (item) {
  72. // this.$emit('buyAction', [{uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty}])
  73. if (isBuy) {
  74. // this.$store.dispatch('user/getBuyInfo', [{uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty}])
  75. axios.post('trade/order/buyNow', [{uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty}])
  76. .then(response => {
  77. window.location.href = '/user#/order/pay/' + this.enidfilter(response.data.orderid)
  78. }, err => {
  79. Message.error('以下器件null对应的商品不存在,请您重新选择')
  80. console.log(err)
  81. })
  82. } else {
  83. // this.$store.dispatch('user/addCar', {uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty})
  84. axios.post('trade/cart/add', {uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty})
  85. .then(response => {
  86. console.log(response.data)
  87. if (response.data.success) {
  88. Message({
  89. message: '添加购物车成功',
  90. type: 'success'
  91. })
  92. } else {
  93. Message.error(response.data.message)
  94. // console.log(response.data.message)
  95. }
  96. })
  97. }
  98. }
  99. }
  100. },
  101. enidfilter: function (str) {
  102. if (str) {
  103. let encryptStr = '' // 最终返回的加密后的字符串
  104. // 产生三位随机数
  105. let num = ''
  106. for (let i = 0; i < 3; i++) {
  107. num += Math.floor(Math.random() * 10)
  108. }
  109. encryptStr += num // 产生3位随机数
  110. // 16位加密
  111. let tempspit = ''
  112. let strspit = str.toString().toLowerCase()
  113. if (strspit.match(/^[-+]?\d*$/) === null) { // 非整数字符,对每一个字符都转换成16进制,然后拼接
  114. /**
  115. * Unicode汉字、英文字母、数字的unicode范围
  116. *汉字:[0x4e00,0x9fa5](或十进制[19968,40869])
  117. *数字:[0x30,0x39](或十进制[48, 57])
  118. *小写字母:[0x61,0x7a](或十进制[97, 122])
  119. *大写字母:[0x41,0x5a](或十进制[65, 90]
  120. * 'a'的Unicode编码:'&#97;',charCodeAt()的值是97
  121. * '码'的Unicode编码:'\u7801', new String('码').charCodeAt()的值是30721,30721的16进制表示是7801
  122. */
  123. let s = strspit.split('')
  124. for (let i = 0; i < s.length; i++) {
  125. s[i] = s[i].charCodeAt() // 先转换成Unicode编码
  126. s[i] = s[i].toString(16)
  127. // 因为在服务器是每两位当做一个字符进行解析的,所以这里每个字符的Unicode编码范围必须在0——255之间。数字和大小写满足该要求,特殊字符则不一定,如果后续有特殊字符的要求,需要重写编码器和解码器
  128. if (s[i].length === 1) {
  129. s[i] = '0' + s[i]
  130. }
  131. tempspit = tempspit + s[i]
  132. }
  133. tempspit = tempspit + '{' + 1 // 1代表字符
  134. } else { // 数字直接转换成16进制
  135. strspit = parseInt(strspit)
  136. .toString(16)
  137. tempspit = strspit + '{' + 0 // 0代表纯数字
  138. }
  139. let temp = tempspit.split('{') // 对要加密的字符转换成16进制
  140. let numLength = temp[0].length // 转换后的字符长度
  141. numLength = numLength.toString(16) // 字符长度换算成16进制
  142. if (numLength.length === 1) { // 如果是1,补一个0
  143. numLength = '0' + numLength
  144. } else if (numLength.length > 3) { // 转换后的16进制字符长度如果大于2位数,则返回,不支持
  145. return ''
  146. }
  147. encryptStr += numLength
  148. if (temp[1] === '0') {
  149. encryptStr += 0
  150. } else if (temp[1] === '1') {
  151. encryptStr += 1
  152. }
  153. encryptStr += temp[0]
  154. if (encryptStr.length < 20) { // 如果小于20位,补上随机数
  155. // 产生三位随机数
  156. let numtwo = ''
  157. for (let i = 0; i < 20 - encryptStr.length; i++) {
  158. numtwo += Math.floor(Math.random() * 10)
  159. }
  160. let ran = numtwo // 产生3位随机数
  161. encryptStr += ran
  162. }
  163. return encryptStr
  164. }
  165. }
  166. }
  167. }
  168. </script>
  169. <style scoped>
  170. #recommend-fragment{
  171. width: 1190px;
  172. margin: 0 auto;
  173. }
  174. .recommend-list{
  175. width: 100%;
  176. margin: 0 auto;
  177. display: inline-block;
  178. }
  179. #recommend-fragment ul{
  180. width: 100%;
  181. margin: 0 auto;
  182. display: inline-block;
  183. -webkit-padding-start: 0;
  184. }
  185. #recommend-fragment ul li{
  186. float: left;
  187. width: 218px;
  188. height: 260px;
  189. border: #d2d2d2 1px solid;
  190. position: relative;
  191. overflow: hidden;
  192. margin-right: 25px;
  193. margin-bottom: 20px;
  194. }
  195. #recommend-fragment ul li:nth-child(5n){
  196. margin-right: 0;
  197. }
  198. #recommend-fragment ul li .img{
  199. height: 175px;
  200. text-align: center;
  201. line-height: 170px;
  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. </style>