RecommendProduct.vue 12 KB

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