index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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.value = {};
  92. this.show = false;
  93. uni.showToast({
  94. title: '添加成功',
  95. icon: 'success'
  96. });
  97. }
  98. },
  99. async buyclicked() {
  100. let arr=[{...this.value,count:this.number}];
  101. this.value={};
  102. this.show=false;
  103. uni.navigateTo({
  104. url:`/indexPages/pay/index?list=${JSON.stringify(arr)}`
  105. })
  106. },
  107. // 改变类型
  108. async changeSelect(id) {
  109. await this.reset();
  110. this.activeId = id;
  111. await this.requestFunc({ method: 'get', url: `/customer/commodity/list/`, data: { category: this.activeId , limit: 10 } });
  112. },
  113. // 下拉刷新
  114. async refresherpulling() {
  115. await this.reset();
  116. await this.requestFunc({ method: 'get', url: `/customer/commodity/list/`, data: { category: this.activeId, limit: 10 } });
  117. },
  118. // 上拉加载
  119. async scroll() {
  120. await this.requestFunc({ method: 'get', url: `/customer/commodity/list/`, data: { category: this.activeId, limit: 10 } });
  121. },
  122. // 商品详情
  123. detailFunc(item) {
  124. uni.navigateTo({
  125. url: `/pages/detail/index?id=${item.id}`
  126. });
  127. },
  128. searchFunc() {
  129. uni.navigateTo({
  130. url: '/commodityPages/search/index'
  131. });
  132. }
  133. },
  134. watch:{
  135. }
  136. };
  137. </script>
  138. <style lang="scss" scoped>
  139. .section-right {
  140. .item {
  141. .cut {
  142. display: -webkit-box;
  143. overflow: hidden;
  144. text-overflow: ellipsis;
  145. -webkit-line-clamp:1;
  146. -webkit-box-orient: vertical;
  147. }
  148. .image {
  149. width: 160upx;
  150. min-width: 160upx;
  151. background-color: #f1f1f1;
  152. height: 160upx;
  153. background-size: cover;
  154. background-position: center;
  155. }
  156. .content {
  157. flex: auto;
  158. .cart {
  159. float: right;
  160. }
  161. }
  162. }
  163. }
  164. </style>