likeProduct.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <view>
  3. <view class="like-title">
  4. <image src="/static/images/like.png" mode=""></image>
  5. <text class="text">猜你喜欢</text>
  6. </view>
  7. <view class="like-list">
  8. <view class="item" v-for="(item,index) in list" :key="index" @click="showProduct(item)">
  9. <view class="img-box">
  10. <image :src="item.image" mode=""></image>
  11. </view>
  12. <view class="info-box">
  13. <view class="title ellipsis2">{{ item.productName }}</view>
  14. <view class="price-box">
  15. <view class="now">
  16. <text class="unit">¥</text>
  17. <text class="num" v-if="userinfoa.isShow==1&&isuser==false">{{item.price.toFixed(2)}}</text>
  18. <text class="num" v-else>{{item.otPrice.toFixed(2)}}</text>
  19. </view>
  20. <view class="old">¥{{item.otPrice.toFixed(2)}}</view>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. <Loading :loaded="loaded" :loading="loading"></Loading>
  26. </view>
  27. </template>
  28. <script>
  29. import {getGoodsProducts} from '@/api/product'
  30. import {getUserInfo} from '@/api/user'
  31. import Loading from "@/components/Loading";
  32. export default {
  33. components: {Loading },
  34. name: "likeProduct",
  35. data() {
  36. return {
  37. page:{
  38. page: 1,
  39. pageSize: 10
  40. },
  41. total:0,
  42. list:[],
  43. loaded: false,
  44. loading: false,
  45. userinfoa:[],
  46. isuser:false,
  47. };
  48. },
  49. created() {
  50. },
  51. mounted() {
  52. this.getGoodsProducts();
  53. if(uni.getStorageSync('AppToken')){
  54. this.getUserInfos()
  55. }else{
  56. this.isuser=true
  57. }
  58. },
  59. methods: {
  60. getUserInfos(){
  61. getUserInfo().then(res => {
  62. if(res.code==200){
  63. if(res.user!=null){
  64. this.userinfoa=res.user
  65. console.log(this.userinfoa.isShow,78787)
  66. }
  67. }else{
  68. uni.showToast({
  69. icon:'none',
  70. title: "请求失败",
  71. });
  72. }
  73. },
  74. rej => {}
  75. );
  76. },
  77. getGoodsProducts(){
  78. console.log(1)
  79. var that=this;
  80. if (that.loaded == true || that.loading == true) return;
  81. that.loading = true;
  82. uni.showLoading({
  83. title:"加载中..."
  84. })
  85. getGoodsProducts(that.page).then(
  86. res => {
  87. if(res.code==200){
  88. that.total=res.data.total;
  89. that.list.push.apply(that.list, res.data.list);
  90. that.loading = false;
  91. that.loaded = that.list.length<that.total?false:true;
  92. that.page.page = that.page.page + 1;
  93. uni.hideLoading()
  94. }
  95. },
  96. err => {
  97. uni.hideLoading()
  98. uni.showToast({
  99. title: err.msg ,
  100. icon: 'none',
  101. duration: 2000
  102. });
  103. }
  104. );
  105. },
  106. showProduct(item){
  107. uni.navigateTo({
  108. url: '/pages/shopping/productDetails?productId='+item.productId
  109. })
  110. },
  111. }
  112. };
  113. </script>
  114. <style lang="scss">
  115. .like-title{
  116. display: flex;
  117. align-items: center;
  118. justify-content: center;
  119. padding: 30upx 0;
  120. image{
  121. width: 37upx;
  122. height: 37upx;
  123. margin-right: 20upx;
  124. }
  125. .text{
  126. font-size: 36upx;
  127. font-family: PingFang SC;
  128. font-weight: bold;
  129. color: #111111;
  130. line-height: 1;
  131. }
  132. }
  133. .like-list{
  134. display: flex;
  135. flex-wrap: wrap;
  136. .item{
  137. margin-right: 20rpx;
  138. margin-bottom: 20rpx;
  139. width: 345rpx;
  140. background: #FFFFFF;
  141. box-shadow: 0px 0px 10rpx 4rpx rgba(199, 199, 199, 0.22);
  142. border-radius: 20rpx;
  143. overflow: hidden;
  144. &:nth-child(2n) {
  145. margin-right: 0;
  146. }
  147. .img-box{
  148. width: 100%;
  149. height: 334upx;
  150. image{
  151. width: 100%;
  152. height: 100%;
  153. }
  154. }
  155. .info-box{
  156. box-sizing: border-box;
  157. height: 182upx;
  158. padding: 20upx 20upx 30upx;
  159. display: flex;
  160. flex-direction: column;
  161. justify-content: space-between;
  162. .title{
  163. font-size: 26upx;
  164. font-family: PingFang SC;
  165. font-weight: 500;
  166. color: #111111;
  167. line-height: 40upx;
  168. }
  169. .price-box{
  170. display: flex;
  171. align-items: flex-end;
  172. .now{
  173. display: flex;
  174. align-items: flex-end;
  175. margin-right: 20upx;
  176. .unit{
  177. font-size: 24upx;
  178. font-family: PingFang SC;
  179. font-weight: 500;
  180. color: #FF6633;
  181. line-height: 1.2;
  182. margin-right: 4upx;
  183. }
  184. .num{
  185. font-size: 36upx;
  186. font-family: PingFang SC;
  187. font-weight: bold;
  188. color: #FF6633;
  189. line-height: 1;
  190. }
  191. }
  192. .old{
  193. font-size: 26upx;
  194. font-family: PingFang SC;
  195. font-weight: 500;
  196. text-decoration: line-through;
  197. color: #BBBBBB;
  198. line-height: 1.1;
  199. }
  200. }
  201. }
  202. }
  203. }
  204. </style>