RecommendProduct.vue 14 KB

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