index.vue 4.7 KB

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