RecommendProduct.vue 14 KB

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