RecommendProduct.vue 12 KB

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