RecommendProduct.vue 13 KB

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