index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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="res=>changeSelect(res.id)" :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-sm flex align-center 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;letter-space:2upx;" class=" text-black cut">{{ item.name }}</view>
  19. <view class="text-gray margin-bottom-xs ">已售{{ item.sale_count }}件</view>
  20. <view class="flex justify-between align-center">
  21. <view>
  22. <view v-if="item.type==1" class="text-red">
  23. <cu-price :value="item.price" size="32" />
  24. </view>
  25. <view class="text-yellow" v-else>
  26. {{item.point_price}}积分
  27. </view>
  28. <view class="bg-orange light text-xs padding-lr-xs">
  29. <text class="cuIcon-vip lg">会员价</text>
  30. <text class="text-price margin-left-xs">{{ item.vip_price }}</text>
  31. </view>
  32. </view>
  33. <view @click.stop="custom(item)" class="cart"><text class="cuIcon-cart text-xl"></text></view>
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 状态管理 -->
  38. <view class="cu-load" :class="{ loading: currentPage <= totalPage, over: currentPage > totalPage }"></view>
  39. </cu-scrollView>
  40. </cu-treeSelectB>
  41. <!-- footer -->
  42. <cu-bar active="1" />
  43. <!-- 工具 -->
  44. <cu-goodA :value="value" @addcart="addcart" @buyclicked="buyclicked" :number="number" @changeNum="val => (number = val)" :show.sync="show" />
  45. </view>
  46. </template>
  47. <script>
  48. import { CustomBarHeight } from '@/common/device/index.js';
  49. import { mapState, mapActions } from 'vuex';
  50. import api from './api.js';
  51. export default {
  52. data() {
  53. return {
  54. number: 1,
  55. value: {},
  56. show: false,
  57. label: [],
  58. activeId: ''
  59. };
  60. },
  61. computed: {
  62. ...mapState(['bind']),
  63. ...mapState('requestList', ['ListValue', 'currentPage', 'totalPage']),
  64. height() {
  65. return `calc(100vh - 200rpx - ${CustomBarHeight}px)`;
  66. }
  67. },
  68. async onShow() {
  69. var result = await api.typeList();
  70. if (result.code != 0) return false;
  71. this.label = result.data;
  72. await this.reset();
  73. if(this.activeId=='') this.activeId = result['data'][0]['id'];
  74. await this.requestFunc({ method: 'get', url: `/customer/commodity/list/`, data: { category: this.activeId, limit: 10 } });
  75. },
  76. methods: {
  77. ...mapActions('requestList', ['reset', 'requestFunc']),
  78. custom(item) {
  79. if (this.bind != 1) return false;
  80. item=JSON.parse(JSON.stringify(item));
  81. item['img']=item.show_image_url;
  82. delete item['show_image_url'];
  83. this.value = item;
  84. this.number=1;
  85. this.show = true;
  86. },
  87. // 添加购物车
  88. async addcart() {
  89. var result = await api.shoppingCart({ quantity: this.number, commodity_details: this.value.id });
  90. if (result.code == 0) {
  91. this.show = false;
  92. uni.showToast({
  93. title: '添加成功',
  94. icon: 'success'
  95. });
  96. }
  97. },
  98. async buyclicked() {
  99. let arr=[{...this.value,count:this.number}];
  100. this.show=false;
  101. uni.navigateTo({
  102. url:`/indexPages/pay/index?list=${JSON.stringify(arr)}`
  103. })
  104. },
  105. // 改变类型
  106. async changeSelect(id) {
  107. await this.reset();
  108. this.activeId = id;
  109. await this.requestFunc({ method: 'get', url: `/customer/commodity/list/`, data: { category: this.activeId , limit: 10 } });
  110. },
  111. // 下拉刷新
  112. async refresherpulling() {
  113. await this.reset();
  114. await this.requestFunc({ method: 'get', url: `/customer/commodity/list/`, data: { category: this.activeId, limit: 10 } });
  115. },
  116. // 上拉加载
  117. async scroll() {
  118. await this.requestFunc({ method: 'get', url: `/customer/commodity/list/`, data: { category: this.activeId, limit: 10 } });
  119. },
  120. // 商品详情
  121. detailFunc(item) {
  122. uni.navigateTo({
  123. url: `/pages/detail/index?id=${item.id}`
  124. });
  125. },
  126. searchFunc() {
  127. uni.navigateTo({
  128. url: '/commodityPages/search/index'
  129. });
  130. }
  131. },
  132. watch:{
  133. }
  134. };
  135. </script>
  136. <style lang="scss" scoped>
  137. .section-right {
  138. .item {
  139. .cut {
  140. display: -webkit-box;
  141. overflow: hidden;
  142. text-overflow: ellipsis;
  143. -webkit-line-clamp:1;
  144. -webkit-box-orient: vertical;
  145. }
  146. .image {
  147. width: 160upx;
  148. min-width: 160upx;
  149. background-color: #f1f1f1;
  150. height: 160upx;
  151. background-size: cover;
  152. background-position: center;
  153. }
  154. .content {
  155. flex: auto;
  156. .cart {
  157. float: right;
  158. }
  159. }
  160. }
  161. }
  162. </style>