index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 class=" flex section">
  16. <view class="item bg-white padding radius" @click="handler" 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. // 下拉刷新
  73. async refresherpulling() {
  74. await this.reset();
  75. await this.requestFunc({ method: 'get', url: `/customer/commodity/list/`, data: { name:this.value, limit: 10 } });
  76. },
  77. // 上拉加载
  78. async scroll() {
  79. await this.requestFunc({ method: 'get', url: `/customer/commodity/list/`, data: { name:this.value,limit: 10 } });
  80. },
  81. search(){
  82. debounce(this.request)();
  83. },
  84. async request(){
  85. await this.reset();
  86. await this.requestFunc({ method: 'get', url: `/customer/commodity/list/`, data: { name:this.value, limit: 10 } });
  87. },
  88. // 添加购物车
  89. async addcart() {
  90. var result = await api.shoppingCart({ quantity: this.number, commodity_details: this.value.id });
  91. if (result.code == 0) {
  92. this.number = 1;
  93. this.value = {};
  94. this.show = false;
  95. uni.showToast({
  96. title: '添加成功',
  97. icon: 'success'
  98. });
  99. }
  100. },
  101. async buyclicked() {},
  102. custom(item) {
  103. if (this.bind != 1) return false;
  104. this.value = { id: item.id, price: item.price, img: item.show_image_url };
  105. this.show = true;
  106. },
  107. },
  108. watch:{
  109. value:function(newVal,oldVal){
  110. this.search()
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang="scss" scoped>
  116. .search{
  117. .section{
  118. .item{
  119. width:calc(50vw - 30upx);
  120. .cut{
  121. text-align: justify;
  122. display: -webkit-box;
  123. overflow: hidden;
  124. text-overflow: ellipsis;
  125. -webkit-line-clamp: 2;
  126. -webkit-box-orient: vertical;
  127. }
  128. }
  129. .item:nth-child(2n+1){
  130. margin:5upx 10upx 5upx 20upx;
  131. }
  132. .item:nth-child(2n){
  133. margin:5upx 20upx 5upx 10upx;
  134. }
  135. }
  136. }
  137. </style>