RecommendList.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <template>
  2. <div class="wrap">
  3. <div class="reco-title">产品展示</div>
  4. <div class="recommend-fragment clearfix">
  5. <ul class="recommend-list clearfix">
  6. <li v-for="commodity in commodities" class="big">
  7. <div v-swiper:mySwiper="swiperOption">
  8. <div class="swiper-wrapper">
  9. <div class="swiper-slide">
  10. <a :href="commodity.batchCode ? '/store/productDetail/'+ commodity.batchCode : '#'" class="href">
  11. <div class="img">
  12. <img :src="commodity.comImg.startsWith('static')?'/'+commodity.comImg:commodity.comImg"/>
  13. </div>
  14. <div class="content">
  15. <p>{{commodity.comCode | comCodeFilter}}</p>
  16. <!-- <p class="color666" v-text="commodity.brandNameCn">PANFAEFQ</p>-->
  17. <p class="price" v-if="commodity.minPriceRMB">¥ {{commodity.minPriceRMB | currency}}</p>
  18. <!-- <p class="price" v-if="!commodity.minPriceRMB">$ {{commodity.minPriceUSD || 0}}</p>-->
  19. </div>
  20. </a>
  21. </div>
  22. </div>
  23. <div class="swiper-pagination swiper-pagination-bullets"></div>
  24. </div>
  25. <!--<a :href="commodity.batchCode ? '/store/productDetail/'+ commodity.batchCode : '#'" class="href">-->
  26. <!--<div class="img">-->
  27. <!--<img :src="commodity.comImg.startsWith('static')?'/'+commodity.comImg:commodity.comImg"/>-->
  28. <!--</div>-->
  29. <!--<div class="content">-->
  30. <!--<p>{{commodity.comCode | comCodeFilter}}</p>-->
  31. <!--&lt;!&ndash; <p class="color666" v-text="commodity.brandNameCn">PANFAEFQ</p>&ndash;&gt;-->
  32. <!--<p class="price" v-if="commodity.minPriceRMB">¥ {{commodity.minPriceRMB | currency}}</p>-->
  33. <!--&lt;!&ndash; <p class="price" v-if="!commodity.minPriceRMB">$ {{commodity.minPriceUSD || 0}}</p>&ndash;&gt;-->
  34. <!--</div>-->
  35. <!--</a>-->
  36. <!--<div class="enter-store">-->
  37. <!--<a @click="buyNow(false, commodity)">加入购物车</a>-->
  38. <!--<a @click="buyNow(true, commodity)">立即购买</a>-->
  39. <!--</div>-->
  40. </li>
  41. <li v-if="!commodities || commodities.length === 0" class="empty-show">
  42. <div class="empty">
  43. <div class="empty-img">
  44. <img src="/images/brandList/empty-cart.jpg">
  45. </div>
  46. <div class="empty-info">
  47. <p class="grey f16"> 暂无展示产品</p>
  48. <i class="iconfont" v-if="emptyShow === false">&#xe610;</i>&nbsp;<a v-if="emptyShow === false" href="/">返回首页</a>
  49. <img v-if="emptyShow === true" src="/images/brandList/upload.png">&nbsp;<a v-if="emptyShow === true" href="/vendor#/store/maintain" target="_blank">马上去上传</a>
  50. </div>
  51. </div>
  52. </li>
  53. </ul>
  54. </div>
  55. </div>
  56. </template>
  57. <script>
  58. import Buy from '~components/common/buyOrCar/buyComponent.vue'
  59. import NuxtLink from '../../../.nuxt/components/nuxt-link'
  60. export default {
  61. name: 'recommend-product',
  62. components: {
  63. NuxtLink,
  64. Buy
  65. },
  66. computed: {
  67. commodities () {
  68. return this.$store.state.shop.recommend.products.data
  69. },
  70. storeInfo () {
  71. return this.$store.state.shop.storeInfo.store.data
  72. },
  73. isConsignment () {
  74. return this.storeInfo.type === 'CONSIGNMENT'
  75. },
  76. user() {
  77. return this.$store.state.option.user
  78. },
  79. storeStatus () {
  80. return this.$store.state.option.storeStatus.data
  81. },
  82. emptyShow () {
  83. let loggedStatus = false
  84. if (this.user.logged && this.user.data.enterprise.uu) {
  85. if (this.storeStatus.uuid === this.storeInfo.uuid) {
  86. loggedStatus = true
  87. } else {
  88. loggedStatus = false
  89. }
  90. } else {
  91. loggedStatus = false
  92. }
  93. return loggedStatus
  94. },
  95. // 产品推荐轮播
  96. swiperOption () {
  97. return {
  98. autoplay: 5000,
  99. initialSlide: 0,
  100. loop: true,
  101. effect: this.effect,
  102. lazyLoading: true,
  103. // 解决点击分页器后图片就不能轮播的问题
  104. autoplayDisableOnInteraction: false,
  105. pagination: '.swiper-pagination',
  106. paginationClickable: true,
  107. paginationElement: 'li'
  108. }
  109. }
  110. },
  111. filters: {
  112. comCodeFilter: function (title) {
  113. if (title === '') {
  114. return title
  115. }
  116. let len = 0
  117. let index = 0
  118. for (let i = 0; i < title.length; i++) {
  119. if (index === 0 && title.charAt(i).charCodeAt(0) > 255) {
  120. len = len + 2
  121. } else {
  122. len++
  123. }
  124. if (len > 18) {
  125. index = i
  126. break
  127. }
  128. }
  129. if (index > 0) {
  130. return title.substring(0, index) + '...'
  131. } else {
  132. return title
  133. }
  134. },
  135. currency: function (num) {
  136. if (typeof num === 'number') {
  137. if (num <= 0.000001) {
  138. num = 0.000001
  139. } else {
  140. if (num.toString().indexOf('.') === -1) {
  141. num += '.00'
  142. } else {
  143. let inputStr = num.toString()
  144. let arr = inputStr.split('.')
  145. let floatNum = arr[1]
  146. if (floatNum.length > 6) {
  147. num = inputStr.substring(0, arr[0].length + 7)
  148. if (Number(floatNum.charAt(6)) > 4) {
  149. num = (Number(num) * 1000000 + 1) / 1000000
  150. }
  151. } else if (floatNum.length === 1) {
  152. num = num + '0'
  153. }
  154. }
  155. }
  156. }
  157. return num
  158. }
  159. },
  160. methods: {
  161. buyNow: function (isBuy, item) {
  162. if (!this.$store.state.option.user.logged) {
  163. this.$http.get('/login/page', {params: {returnUrl: window.location.href}}).then(response => {
  164. if (response.data) {
  165. window.location.href = response.data.content + '&baseUrl=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + response.data.baseUrl)
  166. }
  167. })
  168. } else {
  169. if (item) {
  170. if (isBuy) {
  171. this.$http.post('/trade/order/buyNow', [{
  172. uuid: item.comUuid,
  173. batchCode: item.batchCode,
  174. number: item.minBuyQty,
  175. storeid: item.storeId,
  176. storeUuid: item.storeUuid,
  177. currencyName: item.currency,
  178. minPackQty: item.minPackQty ? item.minPackQty : item.minBuyQty
  179. }])
  180. .then(response => {
  181. if (response.data.success) {
  182. if (response.data.message) {
  183. this.$message({
  184. message: response.data.message,
  185. type: 'success'
  186. })
  187. window.setTimeout(function () {
  188. window.location.href = '/user#/order/pay/' + this.baseUtils.enidfilter(response.data.data.orderid)
  189. }, 1000)
  190. } else {
  191. window.location.href = '/user#/order/pay/' + this.baseUtils.enidfilter(response.data.data.orderid)
  192. }
  193. } else {
  194. if (response.data.data && response.data.data.unvailable === 1) {
  195. this.$message.error('产品信息已失效,请刷新界面')
  196. } else {
  197. this.$message.error(response.data.message)
  198. }
  199. }
  200. }, err => {
  201. console.log(err)
  202. if (item.minBuyQty > item.reserve) {
  203. this.$message.error('商品' + item.code + '的库存已经不满足最小起订量')
  204. }
  205. })
  206. } else {
  207. // this.$store.dispatch('user/addCar', {uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty})
  208. this.$http.post('/trade/cart/add', {
  209. uuid: item.comUuid,
  210. batchCode: item.batchCode,
  211. number: item.minBuyQty,
  212. storeid: item.storeId,
  213. storeUuid: item.storeUuid,
  214. currencyName: item.currency,
  215. minPackQty: item.minPackQty ? item.minPackQty : item.minBuyQty
  216. })
  217. .then(response => {
  218. if (response.data.success) {
  219. if (response.data.message) {
  220. this.$message({
  221. message: '添加购物车成功,但商品信息有更新',
  222. type: 'success'
  223. })
  224. } else {
  225. this.$message({
  226. message: '添加购物车成功',
  227. type: 'success'
  228. })
  229. }
  230. } else {
  231. if (response.data.code === 2) {
  232. this.$message.error(response.data.message + ',请刷新页面')
  233. } else {
  234. this.$message.error(response.data.message)
  235. }
  236. }
  237. })
  238. }
  239. }
  240. }
  241. },
  242. enidfilter: function (str) {
  243. if (str) {
  244. let encryptStr = '' // 最终返回的加密后的字符串
  245. // 产生三位随机数
  246. let num = ''
  247. for (let i = 0; i < 3; i++) {
  248. num += Math.floor(Math.random() * 10)
  249. }
  250. encryptStr += num // 产生3位随机数
  251. // 16位加密
  252. let tempspit = ''
  253. let strspit = str.toString().toLowerCase()
  254. if (strspit.match(/^[-+]?\d*$/) === null) { // 非整数字符,对每一个字符都转换成16进制,然后拼接
  255. /**
  256. * Unicode汉字、英文字母、数字的unicode范围
  257. *汉字:[0x4e00,0x9fa5](或十进制[19968,40869])
  258. *数字:[0x30,0x39](或十进制[48, 57])
  259. *小写字母:[0x61,0x7a](或十进制[97, 122])
  260. *大写字母:[0x41,0x5a](或十进制[65, 90]
  261. * 'a'的Unicode编码:'&#97;',charCodeAt()的值是97
  262. * '码'的Unicode编码:'\u7801', new String('码').charCodeAt()的值是30721,30721的16进制表示是7801
  263. */
  264. let s = strspit.split('')
  265. for (let i = 0; i < s.length; i++) {
  266. s[i] = s[i].charCodeAt() // 先转换成Unicode编码
  267. s[i] = s[i].toString(16)
  268. // 因为在服务器是每两位当做一个字符进行解析的,所以这里每个字符的Unicode编码范围必须在0——255之间。数字和大小写满足该要求,特殊字符则不一定,如果后续有特殊字符的要求,需要重写编码器和解码器
  269. if (s[i].length === 1) {
  270. s[i] = '0' + s[i]
  271. }
  272. tempspit = tempspit + s[i]
  273. }
  274. tempspit = tempspit + '{' + 1 // 1代表字符
  275. } else { // 数字直接转换成16进制
  276. strspit = parseInt(strspit)
  277. .toString(16)
  278. tempspit = strspit + '{' + 0 // 0代表纯数字
  279. }
  280. let temp = tempspit.split('{') // 对要加密的字符转换成16进制
  281. let numLength = temp[0].length // 转换后的字符长度
  282. numLength = numLength.toString(16) // 字符长度换算成16进制
  283. if (numLength.length === 1) { // 如果是1,补一个0
  284. numLength = '0' + numLength
  285. } else if (numLength.length > 3) { // 转换后的16进制字符长度如果大于2位数,则返回,不支持
  286. return ''
  287. }
  288. encryptStr += numLength
  289. if (temp[1] === '0') {
  290. encryptStr += 0
  291. } else if (temp[1] === '1') {
  292. encryptStr += 1
  293. }
  294. encryptStr += temp[0]
  295. if (encryptStr.length < 20) { // 如果小于20位,补上随机数
  296. // 产生三位随机数
  297. let numtwo = ''
  298. for (let i = 0; i < 20 - encryptStr.length; i++) {
  299. numtwo += Math.floor(Math.random() * 10)
  300. }
  301. let ran = numtwo // 产生3位随机数
  302. encryptStr += ran
  303. }
  304. return encryptStr
  305. }
  306. }
  307. }
  308. }
  309. </script>
  310. <style lang="scss" scoped>
  311. .wrap {
  312. background: #ece9ec;
  313. padding-top: 7px;
  314. width: 100%;
  315. height: 409px;
  316. .reco-title {
  317. border-bottom: 1px solid #3975f4;
  318. width: 218px;
  319. height: 34px;
  320. line-height: 34px;
  321. color: #fff;
  322. background: #3975f4;
  323. font-size: 18px;
  324. text-align: center;
  325. border-top-left-radius: 3px;
  326. border-top-right-radius: 3px;
  327. margin: 0;
  328. }
  329. }
  330. .recommend-fragment {
  331. background: #fff;
  332. }
  333. .recommend-fragment ul{
  334. width: 100%;
  335. background: #fff;
  336. /* display: inline-block;*/
  337. -webkit-padding-start: 0;
  338. border-radius: 5px;
  339. /*padding-left: 2px;*/
  340. margin: 10px 0;
  341. padding: 0 15px;
  342. }
  343. .recommend-fragment ul li
  344. .img{
  345. height: 90px;
  346. text-align: center;
  347. line-height: 90px;
  348. img{
  349. max-width: 80px;
  350. max-height: 80px;
  351. }
  352. }
  353. .recommend-fragment ul li .content{
  354. width: 100%;
  355. margin: 0 auto;
  356. font-size: 12px;
  357. p{
  358. width: 100%;
  359. text-align: center;
  360. display: inline-block;
  361. line-height: 22px;
  362. overflow: hidden;
  363. text-overflow: ellipsis;
  364. white-space: nowrap;
  365. margin-bottom: 0;
  366. padding-left: 10px;
  367. color: #666;
  368. &.price{
  369. color: #ff002e;
  370. }
  371. }
  372. }
  373. .recommend-fragment ul li .enter-store {
  374. position: absolute;
  375. top: 178px;
  376. width: 100%;
  377. height: 30px;
  378. line-height: 30px;
  379. text-align: left;
  380. }
  381. .recommend-fragment ul li.big .enter-store a {
  382. width: 74px;
  383. height: 24px;
  384. display: inline-block;
  385. line-height: 24px;
  386. text-align: center;
  387. font-size: 13px;
  388. margin-left: 14px;
  389. border-radius: 3px;
  390. &:first-child {
  391. background-color: #fff;
  392. border: 1px solid #3b7cf4;
  393. color: #3b7cf4;
  394. }
  395. &:last-child {
  396. background-color: #ffa422;
  397. border: 1px solid #ffa422;
  398. color: #fff;
  399. }
  400. /*&:visited{
  401. .enter-store {
  402. top: 140px;
  403. left: 0px;
  404. }
  405. }*/
  406. }
  407. .recommend-fragment ul li.big {
  408. float: left;
  409. width: 190px;
  410. height: 174px;
  411. position: relative;
  412. overflow: hidden;
  413. margin: 2px 3px 0px 0px;
  414. &:nth-child(5n){
  415. margin: 2px 0px 0px 0px;
  416. }
  417. &:hover{
  418. box-shadow: 2px 0px 1px #d9d9d9, -2px 0px 1px #d9d9d9, 0px 2px 1px #d9d9d9, 0px -2px 1px #d9d9d9;
  419. .enter-store {
  420. top: 132px;
  421. left: 0px;
  422. transition: all .3s linear;
  423. }
  424. .img, .content{
  425. transform:translate(0px,-10px);
  426. -ms-transform:translate(0px,-10px); /* IE 9 */
  427. -webkit-transform:translate(0px,-10px); /* Safari and Chrome */
  428. }
  429. }
  430. }
  431. /*.recommend-fragment ul li.small .enter-store a {
  432. width: 74px;
  433. height: 24px;
  434. display: inline-block;
  435. line-height: 22px;
  436. text-align: center;
  437. font-size: 12px;
  438. margin-left: 11px;
  439. border-radius: 3px;
  440. &:first-child {
  441. background-color: #fff;
  442. border: solid 1px #3b7cf4;
  443. color: #3c7df5;
  444. }
  445. &:last-child {
  446. background-color: #ffa422;
  447. border: 1px solid #ffa422;
  448. color: #fff;
  449. }
  450. }
  451. .recommend-fragment ul li.small {
  452. float: left;
  453. width: 180px;
  454. height: 174px;
  455. position: relative;
  456. overflow: hidden;
  457. margin: 2px 8px 0px 0px;
  458. &:nth-child(5n){
  459. margin: 2px 0px 0px 0px;
  460. }
  461. &:hover, &:focus, &:active &:visited{
  462. box-shadow: 2px 0px 1px #d9d9d9, -2px 0px 1px #d9d9d9, 0px 2px 1px #d9d9d9, 0px -2px 1px #d9d9d9;
  463. .enter-store {
  464. top: 140px;
  465. left: 0px;
  466. transition: all .5s;
  467. }
  468. .img, .content{
  469. transform:translate(0px,-10px);
  470. -ms-transform:translate(0px,-10px); !* IE 9 *!
  471. -webkit-transform:translate(0px,-10px); !* Safari and Chrome *!
  472. }
  473. }
  474. }*/
  475. .recommend-fragment ul li.empty-show {
  476. width: 100%;
  477. height: 356px;
  478. padding-top: 150px;
  479. &:hover{
  480. box-shadow: 0px 0px 0px transparent;
  481. }
  482. .empty{
  483. margin: 0 auto;
  484. width: 181px;
  485. .empty-img{
  486. float: left;
  487. }
  488. .empty-info{
  489. float: left;
  490. margin: 5px 0px 0px 20px;
  491. .grey{
  492. color: #999;
  493. font-size: 14px;
  494. }
  495. i{
  496. color: #5078cb;
  497. }
  498. a{
  499. font-size: 14px;
  500. color: #5078cb;
  501. }
  502. }
  503. }
  504. }
  505. .shadow {
  506. width: 1190px;
  507. margin: 0 auto;
  508. position: relative;
  509. img {
  510. position: absolute;
  511. top: -12px;
  512. }
  513. }
  514. </style>