likeProduct.vue 4.6 KB

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