RecommendProduct.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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.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. this.$message.error(response.data.message)
  144. }
  145. })
  146. }
  147. }
  148. }
  149. },
  150. enidfilter: function (str) {
  151. if (str) {
  152. let encryptStr = '' // 最终返回的加密后的字符串
  153. // 产生三位随机数
  154. let num = ''
  155. for (let i = 0; i < 3; i++) {
  156. num += Math.floor(Math.random() * 10)
  157. }
  158. encryptStr += num // 产生3位随机数
  159. // 16位加密
  160. let tempspit = ''
  161. let strspit = str.toString().toLowerCase()
  162. if (strspit.match(/^[-+]?\d*$/) === null) { // 非整数字符,对每一个字符都转换成16进制,然后拼接
  163. /**
  164. * Unicode汉字、英文字母、数字的unicode范围
  165. *汉字:[0x4e00,0x9fa5](或十进制[19968,40869])
  166. *数字:[0x30,0x39](或十进制[48, 57])
  167. *小写字母:[0x61,0x7a](或十进制[97, 122])
  168. *大写字母:[0x41,0x5a](或十进制[65, 90]
  169. * 'a'的Unicode编码:'&#97;',charCodeAt()的值是97
  170. * '码'的Unicode编码:'\u7801', new String('码').charCodeAt()的值是30721,30721的16进制表示是7801
  171. */
  172. let s = strspit.split('')
  173. for (let i = 0; i < s.length; i++) {
  174. s[i] = s[i].charCodeAt() // 先转换成Unicode编码
  175. s[i] = s[i].toString(16)
  176. // 因为在服务器是每两位当做一个字符进行解析的,所以这里每个字符的Unicode编码范围必须在0——255之间。数字和大小写满足该要求,特殊字符则不一定,如果后续有特殊字符的要求,需要重写编码器和解码器
  177. if (s[i].length === 1) {
  178. s[i] = '0' + s[i]
  179. }
  180. tempspit = tempspit + s[i]
  181. }
  182. tempspit = tempspit + '{' + 1 // 1代表字符
  183. } else { // 数字直接转换成16进制
  184. strspit = parseInt(strspit)
  185. .toString(16)
  186. tempspit = strspit + '{' + 0 // 0代表纯数字
  187. }
  188. let temp = tempspit.split('{') // 对要加密的字符转换成16进制
  189. let numLength = temp[0].length // 转换后的字符长度
  190. numLength = numLength.toString(16) // 字符长度换算成16进制
  191. if (numLength.length === 1) { // 如果是1,补一个0
  192. numLength = '0' + numLength
  193. } else if (numLength.length > 3) { // 转换后的16进制字符长度如果大于2位数,则返回,不支持
  194. return ''
  195. }
  196. encryptStr += numLength
  197. if (temp[1] === '0') {
  198. encryptStr += 0
  199. } else if (temp[1] === '1') {
  200. encryptStr += 1
  201. }
  202. encryptStr += temp[0]
  203. if (encryptStr.length < 20) { // 如果小于20位,补上随机数
  204. // 产生三位随机数
  205. let numtwo = ''
  206. for (let i = 0; i < 20 - encryptStr.length; i++) {
  207. numtwo += Math.floor(Math.random() * 10)
  208. }
  209. let ran = numtwo // 产生3位随机数
  210. encryptStr += ran
  211. }
  212. return encryptStr
  213. }
  214. }
  215. }
  216. }
  217. </script>
  218. <style scoped>
  219. #recommend-fragment{
  220. width: 1190px;
  221. margin: 0 auto;
  222. }
  223. .recommend-list{
  224. width: 100%;
  225. margin: 0 auto;
  226. display: inline-block;
  227. }
  228. #recommend-fragment ul{
  229. width: 100%;
  230. margin: 0 auto;
  231. display: inline-block;
  232. -webkit-padding-start: 0;
  233. }
  234. #recommend-fragment ul li{
  235. float: left;
  236. width: 218px;
  237. height: 260px;
  238. border: #d2d2d2 1px solid;
  239. position: relative;
  240. overflow: hidden;
  241. margin-right: 25px;
  242. margin-bottom: 20px;
  243. }
  244. #recommend-fragment ul li:nth-child(5n){
  245. margin-right: 0;
  246. }
  247. #recommend-fragment ul li .img{
  248. height: 175px;
  249. text-align: center;
  250. line-height: 170px;
  251. }
  252. #recommend-fragment ul li .img img{
  253. max-width: 120px;
  254. max-height: 120px;
  255. }
  256. #recommend-fragment ul li .content{
  257. width: 100%;
  258. margin: 0 auto;
  259. }
  260. #recommend-fragment ul li .content p{
  261. width: 90%;
  262. display: inline-block;
  263. line-height: 22px;
  264. font-size: 14px;
  265. overflow: hidden;
  266. text-overflow: ellipsis;
  267. white-space: nowrap;
  268. margin-bottom: 0;
  269. padding-left: 10px;
  270. }
  271. #recommend-fragment ul li .content p.price{
  272. color: #ff9000;
  273. font-size: 16px;
  274. font-weight: bold;
  275. }
  276. .color666{
  277. color: #666;
  278. }
  279. #recommend-fragment ul li .hover-show{
  280. width: 100%;
  281. height: 100%;
  282. position: absolute;
  283. top: 100%;
  284. left: 0;
  285. background: rgba(80,120,203,.85);
  286. padding: 30px 10px;
  287. }
  288. #recommend-fragment ul li:hover .hover-show{
  289. top: 0;
  290. transition: top .5s ease-in;
  291. }
  292. #recommend-fragment ul li .hover-show div{
  293. width: 100%;
  294. margin: 0 auto;
  295. text-align: left;
  296. color: #fff;
  297. line-height: 25px;
  298. display: block;
  299. text-overflow: ellipsis;
  300. overflow: hidden;
  301. white-space: nowrap;
  302. }
  303. #recommend-fragment ul li .hover-show .title{
  304. font-size: 18px;
  305. margin-top: 8px;
  306. text-overflow: ellipsis;
  307. white-space: nowrap;
  308. overflow: hidden;
  309. margin-bottom: 0;
  310. }
  311. #recommend-fragment ul li .hover-show .type{
  312. font-size: 14px;
  313. }
  314. #recommend-fragment ul li .hover-show .hr{
  315. text-align: center;
  316. margin-top: 5px;
  317. }
  318. #recommend-fragment ul li .hover-show .hr span{
  319. font-size: 16px;
  320. position: relative;
  321. }
  322. #recommend-fragment ul li .hover-show .hr span:before,#recommend-fragment ul li .hover-show .hr span:after{
  323. content: '';
  324. position: absolute;
  325. display: inline-block;
  326. width: 65px;
  327. height: 1px;
  328. background: #fff;
  329. top: 10px;
  330. }
  331. #recommend-fragment ul li .hover-show .hr span:before{
  332. left: 53px;
  333. }
  334. #recommend-fragment ul li .hover-show .hr span:after{
  335. right: 53px;
  336. }
  337. #recommend-fragment ul li .hover-show .price{
  338. font-size: 20px;
  339. text-align: center;
  340. line-height: 48px;
  341. }
  342. #recommend-fragment ul li .hover-show .by-cart,#recommend-fragment ul li .hover-show .buy-now{
  343. text-align: center;
  344. position: absolute;
  345. left: 0;
  346. }
  347. #recommend-fragment ul li .hover-show .by-cart{
  348. bottom: 50px;
  349. }
  350. #recommend-fragment ul li .hover-show .buy-now{
  351. bottom: 15px;
  352. }
  353. #recommend-fragment ul li .hover-show .by-cart button{
  354. display: inline-block;
  355. width: 38px;
  356. height: 38px;
  357. border-radius: 100%;
  358. background: #fff;
  359. line-height: 38px;
  360. margin-bottom: 5px;
  361. cursor: pointer;
  362. border: none;
  363. z-index: 100;
  364. position: relative;
  365. }
  366. #recommend-fragment ul li .hover-show .buy-now button{
  367. display: inline-block;
  368. width: 90px;
  369. height: 34px;
  370. text-align: center;
  371. font-size: 14px;
  372. border-radius: 4px;
  373. background: #df1b0f;
  374. line-height: 34px;
  375. color: #fff;
  376. cursor: pointer;
  377. border: none;
  378. z-index: 100;
  379. position: relative;
  380. }
  381. #recommend-fragment ul li .hover-show .buy-now button:hover{
  382. background: #f00;
  383. }
  384. #recommend-fragment ul li a.href{
  385. display: inline-block;
  386. position: relative;
  387. z-index: 10;
  388. width: 100%;
  389. text-align: center;
  390. height: 260px;
  391. }
  392. </style>