index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <view class="search">
  3. <!-- header -->
  4. <cu-custom isBack bgColor="bg-gradual-blue"><view slot="content">搜索页</view></cu-custom>
  5. <view class="cu-bar search bg-white">
  6. <view class="search-form round">
  7. <text class="cuIcon-search"></text>
  8. <input :value="value" @input="e=>value=e.detail.value" type="text" placeholder="请输入商品名字" confirm-type="search"></input>
  9. </view>
  10. <view class="action">
  11. <button @click="search" class="cu-btn bg-green shadow-blur round">搜索</button>
  12. </view>
  13. </view>
  14. <cu-scrollView @refresherpulling="refresherpulling" @scroll="scroll" :height="height" >
  15. <view style="flex-wrap: wrap;" class=" flex section">
  16. <view class="item bg-white padding radius" @click="handler(item.id)" v-for="(item, index) in ListValue" :key="index" >
  17. <!-- 图片 -->
  18. <image style="width:calc(50vw - 60upx);height:calc(50vw - 60upx);" lazy-load="true" class="image radius margin-right-sm" :src="item.show_image_url | lazyImage" mode="aspectFit"></image>
  19. <view class="content">
  20. <view style="text-align: justify;" class=" text-black cut">{{ item.name }}</view>
  21. <view class="text-gray flex margin-bottom-xs ">已售{{ item.sale_count }}件</view>
  22. <view class="flex justify-between align-center">
  23. <view>
  24. <view v-if="item.type==1" class="text-red">
  25. <cu-price :value="item.price" size="32" />
  26. </view>
  27. <view v-else>
  28. {{item.point_price}}积分
  29. </view>
  30. <view class="bg-orange light text-xs padding-lr-xs">
  31. <text class="cuIcon-vip lg">会员价</text>
  32. <text class="text-price margin-left-xs">{{ item.vip_price }}</text>
  33. </view>
  34. </view>
  35. <view @click.stop="custom(item)" class="cart"><text class="cuIcon-cart text-xl"></text></view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <!-- 状态管理 -->
  41. <view v-if="value || ListValue.length>0" class="cu-load" :class="{ loading: currentPage <= totalPage, over: currentPage > totalPage }"></view>
  42. </cu-scrollView>
  43. <!-- 工具 -->
  44. <cu-goodA :value="item" @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 {debounce} from"@/common/debounceThrottle/index.js";
  50. import { mapState, mapActions } from 'vuex';
  51. export default{
  52. data(){
  53. return {
  54. show:false,
  55. value:"",
  56. item:{},
  57. number:1,
  58. }
  59. },
  60. async onShow(){
  61. await this.reset();
  62. },
  63. computed: {
  64. ...mapState(['bind']),
  65. ...mapState('requestList', ['ListValue', 'currentPage', 'totalPage']),
  66. height() {
  67. return `calc(100vh - 100rpx - ${CustomBarHeight}px)`;
  68. }
  69. },
  70. methods:{
  71. ...mapActions('requestList', ['reset', 'requestFunc']),
  72. handler(id){
  73. uni.navigateTo({
  74. url:`/pages/detail/index?id=${id}`
  75. })
  76. },
  77. // 下拉刷新
  78. async refresherpulling() {
  79. await this.reset();
  80. await this.requestFunc({ method: 'get', url: `/customer/commodity/list/`, data: { name:this.value, limit: 10 } });
  81. },
  82. // 上拉加载
  83. async scroll() {
  84. await this.requestFunc({ method: 'get', url: `/customer/commodity/list/`, data: { name:this.value,limit: 10 } });
  85. },
  86. search(){
  87. debounce(this.request)();
  88. },
  89. async request(){
  90. await this.reset();
  91. await this.requestFunc({ method: 'get', url: `/customer/commodity/list/`, data: { name:this.value, limit: 10 } });
  92. },
  93. // 添加购物车
  94. async addcart() {
  95. var result = await api.shoppingCart({ quantity: this.number, commodity_details: this.value.id });
  96. if (result.code == 0) {
  97. this.number = 1;
  98. this.value = {};
  99. this.show = false;
  100. uni.showToast({
  101. title: '添加成功',
  102. icon: 'success'
  103. });
  104. }
  105. },
  106. async buyclicked() {
  107. },
  108. custom(item) {
  109. if (this.bind != 1) return false;
  110. this.item = {...item,img: item.show_image_url };
  111. this.show = true;
  112. },
  113. },
  114. watch:{
  115. value:function(newVal,oldVal){
  116. this.search()
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. .search{
  123. .section{
  124. .item{
  125. width:calc(50vw - 30upx);
  126. .cut{
  127. text-align: justify;
  128. display: -webkit-box;
  129. overflow: hidden;
  130. text-overflow: ellipsis;
  131. -webkit-line-clamp: 2;
  132. -webkit-box-orient: vertical;
  133. }
  134. }
  135. .item:nth-child(2n+1){
  136. margin:5upx 10upx 5upx 20upx;
  137. }
  138. .item:nth-child(2n){
  139. margin:5upx 20upx 5upx 10upx;
  140. }
  141. }
  142. }
  143. </style>