index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <view class="commodity">
  3. <!-- header -->
  4. <cu-custom custom bgColor="bg-gradual-blue"><view slot="content">商品列表</view></cu-custom>
  5. <view class="cu-bar search bg-white border">
  6. <view @click="searchFunc" class="search-form round flex justify-center">
  7. <text class="cuIcon-search"></text>
  8. <text class="text-grey">搜索</text>
  9. </view>
  10. </view>
  11. <!-- section -->
  12. <cu-treeSelectB @change="changeSelect" :value="label" :height="height">
  13. <cu-scrollView @refresherpulling="refresherpulling" @scroll="scroll" :height="height" class="section-right">
  14. <view @click="detailFunc(item)" v-for="(item,index) in ListValue" :key="index" class="item bg-white radius padding flex margin-tb-sm margin-right">
  15. <!-- 图片 -->
  16. <image lazy-load="true" class="image radius margin-right-sm" :src="item.show_image_url | lazyImage" mode="aspectFit"></image>
  17. <view class="content">
  18. <view style="text-align: justify;" class=" text-black cut">{{item.name}}</view>
  19. <view class="text-gray">
  20. 销量:{{item.sale_count}}
  21. </view>
  22. <view class="flex justify-between align-end">
  23. <view class="text-red">¥<cu-price :value="item.price" size="32" /></view>
  24. <view @click.stop="custom(item)" class="cart">
  25. <text class="cuIcon-cart text-xl"></text>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. <!-- 状态管理 -->
  31. <view class="cu-load" :class="{'loading':currentPage<=totalPage,'over':currentPage>totalPage}"></view>
  32. </cu-scrollView>
  33. </cu-treeSelectB>
  34. <!-- footer -->
  35. <cu-bar active="1" />
  36. <!-- 工具 -->
  37. <!-- 工具 -->
  38. <cu-goodA :value="value" @addcart="addcart" @buyclicked="buyclicked" :number="number" @changeNum="val=>number=val" :show.sync="show" />
  39. </view>
  40. </template>
  41. <script>
  42. import { CustomBarHeight } from '@/common/device/index.js';
  43. import { mapState,mapActions } from 'vuex';
  44. import api from "./api.js";
  45. export default {
  46. data() {
  47. return {
  48. number:1,
  49. value:{},
  50. show:false,
  51. label: [],
  52. activeId:''
  53. };
  54. },
  55. computed: {
  56. ...mapState(['bind']),
  57. ...mapState('requestList', ['ListValue','currentPage','totalPage']),
  58. height() {
  59. return `calc(100vh - 200rpx - ${CustomBarHeight}px)`;
  60. }
  61. },
  62. async onLoad() {
  63. var result =await api.typeList();
  64. if(result.code!=0) return false;
  65. this.label=result.data;
  66. await this.reset();
  67. this.activeId=result['data'][0]['id'];
  68. await this.requestFunc({method:"get",url:`/customer/commodity/list/`,data:{category:result['data'][0]['id'],limit:10}})
  69. },
  70. methods: {
  71. ...mapActions('requestList', ['reset','requestFunc']),
  72. custom(item){
  73. if(this.bind!=1) return false;
  74. this.value={id:item.id,price:item.price,img:item.show_image_url};
  75. this.show=true;
  76. },
  77. // 添加购物车
  78. async addcart(){
  79. var result= await api.shoppingCart({quantity:this.number,commodity_details:this.value.id});
  80. if(result.code==0){
  81. this.number=1;
  82. this.value={};
  83. this.show=false;
  84. uni.showToast({
  85. title:"添加成功",
  86. icon:'success'
  87. })
  88. }
  89. },
  90. async buyclicked(){},
  91. // 改变类型
  92. async changeSelect(item) {
  93. await this.reset();
  94. this.activeId=item.id;
  95. await this.requestFunc({method:"get",url:`/customer/commodity/list/`,data:{category:item.id,limit:10}})
  96. },
  97. // 下拉刷新
  98. async refresherpulling(){
  99. await this.reset();
  100. await this.requestFunc({method:"get",url:`/customer/commodity/list/`,data:{category:this.activeId,limit:10}})
  101. },
  102. // 上拉加载
  103. async scroll(){
  104. await this.requestFunc({method:"get",url:`/customer/commodity/list/`,data:{category:this.activeId,limit:10}})
  105. },
  106. // 商品详情
  107. detailFunc(item){
  108. uni.navigateTo({
  109. url:`/pages/detail/index?id=${item.id}`
  110. })
  111. },
  112. searchFunc(){
  113. uni.navigateTo({
  114. url:"/commodityPages/search/index"
  115. })
  116. }
  117. },
  118. onShareAppMessage() {
  119. return {};
  120. },
  121. onShareTimeline() {
  122. return {};
  123. }
  124. };
  125. </script>
  126. <style lang="scss" scoped>
  127. .section-right {
  128. .item {
  129. .cut{
  130. display: -webkit-box;
  131. overflow: hidden;
  132. text-overflow: ellipsis;
  133. -webkit-line-clamp: 2;
  134. -webkit-box-orient: vertical;
  135. }
  136. .image {
  137. width: 160upx;
  138. min-width: 160upx;
  139. background-color: #f1f1f1;
  140. height: 160upx;
  141. background-size: cover;
  142. background-position: center;
  143. }
  144. .content{
  145. flex: auto;
  146. .cart{
  147. float: right;
  148. }
  149. }
  150. }
  151. }
  152. </style>