search.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <view class="search-container">
  3. <go-search :theme="themeClass" @getSearchText="getSearchText"></go-search>
  4. <view class="container commodity-list-wrapper" v-if="isShowWrapper" :style="{'overflow':'auto','height': 'auto'}">
  5. <scroll-view :style="{'height':scrollHeight+'px'}" @scrolltolower="toLower" scroll-y v-if="!showEmpty">
  6. <view v-for="(item,index) in commodityList" :key="index" :id="item.id" class="all-type-list-content commodity-list" @click.stop="navToDetailPage(item.id)">
  7. <image mode='widthFix' :src="item.mainImage" class="list-img" alt="list-img"></image>
  8. <view class="list-details-info">
  9. <text class="list-details-title">{{item.name}}</text>
  10. <text class="list-details-specs">规格:{{item.unit}}</text>
  11. <text class="list-details-miniQuantity" v-if="fromRegularPurchasePage">起订量:{{item.minBuyNumber}}</text>
  12. <view class="list-details-price">
  13. <view v-if="!loginStatus" class="list-login-now">
  14. <text @click.stop="toLoginPage" class="login-now">登录查看价格<text class="iconfont icon-xiayibu" style="font-size: 22rpx;margin: 0 6rpx;"></text></text>
  15. </view>
  16. <view class="list-price" v-else>
  17. <text>¥<text class="price-larger">{{item.retailPrice.toFixed(2)}}</text></text>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. <view v-if="showLoading && commodityList.length > 4">
  23. <view class="loading-wrapper loading-wrapper-now" v-if="loadingNow">{{loadingText}}<text v-if="loadingText === '已至底部'">‧ ‧ ‧</text></view>
  24. <view class="loading-wrapper loading-wrapper-btm" v-else>———<text class="btm-text">已至底部</text>———</view>
  25. </view>
  26. </scroll-view>
  27. <view class="empty-container" v-if="showEmpty">
  28. <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/8D/Cmis215XHXWAHCoqAAELHadZ9Xg365.png"></image>
  29. <text class="error-text">抱歉,没有相关商品!</text>
  30. </view>
  31. <!-- 透明模态层 -->
  32. <modal-layer v-if='isModallayer'></modal-layer>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import goSearch from '@/components/uni-search/go-search.vue'
  38. import modalLayer from "@/components/modal-layer"
  39. import authorize from '@/config/authorize.js'
  40. export default {
  41. components: {
  42. goSearch,
  43. modalLayer
  44. },
  45. data() {
  46. return {
  47. themeClass: 'block',
  48. searchInputVal:'',
  49. isShowWrapper:false,
  50. isModallayer:false,
  51. windowHeight: '',
  52. showSkeleton: true,
  53. showEmpty: false,
  54. userID: '',
  55. loginStatus: true,
  56. scrollHeight: '',
  57. commodityList: [],
  58. showLoading: false,
  59. loadingNow: true,
  60. loadingText: '上拉加载更多',
  61. pageSize: 10,
  62. pageNum: 1,
  63. hasNextPage: false,
  64. totalPage: 1,
  65. pullFlag: true,
  66. }
  67. },
  68. created() {
  69. let self = this;
  70. self.$api.getStorage().then((resolve) =>{
  71. self.userID = resolve.userID
  72. })
  73. self.setScrollHeight();
  74. self.$api.loginStatus().then((resolveData) => {
  75. self.loginStatus = resolveData;
  76. });
  77. },
  78. onLoad() {
  79. },
  80. methods:{
  81. getSearchText(e) {
  82. this.searchInputVal = e
  83. this.getListFromServer(false)
  84. },
  85. toLoginPage() {
  86. const {lastPageType, lastPageVal} = this.$parent;
  87. uni.navigateTo({
  88. url:`/pages/login/login?listType=${lastPageType}&listVal=${lastPageVal}`
  89. })
  90. },
  91. toLower() {
  92. // 第一次加载排除常用商品
  93. if(this.hasNextPage && this.pullFlag) {
  94. this.getListFromServer(true);
  95. }
  96. },
  97. setScrollHeight() {
  98. const {windowHeight, pixelRatio} = wx.getSystemInfoSync();
  99. this.windowHeight = windowHeight - 1;
  100. this.scrollHeight = windowHeight - 1;
  101. },
  102. getListFromServer(loadMore) {
  103. let self = this;
  104. self.showLoading = true;
  105. self.loadingNow = true;
  106. self.loadingText = '加载中';
  107. self.showEmpty = false;
  108. if(loadMore) {
  109. self.pageNum += 1;
  110. }
  111. authorize.getCode('weixin').then(wechatcode =>{
  112. let params = {code:wechatcode,searchWord:self.searchInputVal,index:self.pageNum,pageSize:self.pageSize,organizeID:self.userOrganizeID}
  113. self.$api.lodingGet('/search/product',params,
  114. response => {
  115. if(response.code == '1') {
  116. this.isShowWrapper = true
  117. const resData = response.data;
  118. const resList = resData.results;
  119. if(resList && resList.length > 0){
  120. self.hasNextPage = resData.hasNextPage;
  121. self.totalPage = resData.totalPage;
  122. self.showEmpty = false;
  123. if(loadMore) {
  124. self.commodityList = [...self.commodityList,...resList];
  125. } else {
  126. self.commodityList =[];
  127. self.commodityList = [...resList];
  128. self.showSkeleton = false;
  129. }
  130. console.log(self.commodityList)
  131. // 防上拉暴滑
  132. self.pullFlag = false;
  133. setTimeout(()=>{
  134. self.pullFlag = true;
  135. },500)
  136. // 底部提示文案
  137. if(self.hasNextPage) {
  138. self.loadingText = '上拉加载更多';
  139. } else {
  140. self.showLoading = true;
  141. self.loadingNow = false;
  142. }
  143. } else {
  144. if(!loadMore) {
  145. self.showEmpty = true;
  146. }
  147. }
  148. } else {
  149. this.$util.msg(response.msg,3000);
  150. }
  151. }
  152. )
  153. })
  154. },
  155. navToDetailPage(id) {
  156. this.isModallayer = true;
  157. this.$api.navigateTo(`/pages/goods/product?id=${id}`);
  158. this.isModallayer = false;
  159. }
  160. }
  161. }
  162. </script>
  163. <style lang="scss">
  164. page{
  165. background-color: #F7F7F7 !important;
  166. }
  167. .commodity-list-wrapper {
  168. scroll-view {
  169. height: 100%;
  170. }
  171. .empty-container-image {
  172. margin-top: -300rpx;
  173. }
  174. .toIndexPage {
  175. bottom: 390rpx;
  176. }
  177. .show-more-btn {
  178. width: 276rpx;
  179. height: 52rpx;
  180. line-height: 52rpx;
  181. border: 2rpx solid #D8D8D8;
  182. background: #F7F7F7;
  183. font-size: 26rpx;
  184. margin: 26rpx 0;
  185. position: absolute;
  186. left: 50%;
  187. margin-left: -138rpx;
  188. }
  189. }
  190. .all-type-list-content {
  191. height: 216rpx;
  192. padding: 24rpx;
  193. background: #fff;
  194. margin-bottom: 2rpx;
  195. display: flex;
  196. flex-direction: row;
  197. box-sizing: content-box;
  198. .list-img {
  199. width: 210rpx;
  200. height: 218rpx !important;
  201. margin-right: 26rpx;
  202. border-radius: 10rpx;
  203. border: 2rpx solid #f3f3f3;
  204. }
  205. }
  206. .list-details-info {
  207. width: 466rpx;
  208. display: flex;
  209. flex-direction: column;
  210. font-size: 26rpx;
  211. position: relative;
  212. .list-details-title {
  213. line-height: 38rpx;
  214. text-overflow: ellipsis;
  215. overflow: hidden;
  216. display: -webkit-box;
  217. -webkit-line-clamp: 2;
  218. line-clamp: 2;
  219. -webkit-box-orient: vertical;
  220. }
  221. .list-details-specs {
  222. margin-top: 8rpx;
  223. color: #999999;
  224. }
  225. .list-details-miniQuantity {
  226. margin-top: 7rpx;
  227. }
  228. }
  229. .list-details-price {
  230. width: 100%;
  231. display: flex;
  232. flex-direction: row;
  233. justify-content: space-between;
  234. position: absolute;
  235. bottom: 0;
  236. right: 0;
  237. .price-icon {
  238. width: 22rpx;
  239. height: 28rpx;
  240. vertical-align: middle;
  241. margin-right: 10rpx;
  242. }
  243. .price-icon + text {
  244. font-size: 25rpx;
  245. vertical-align: middle;
  246. }
  247. .list-login-now {
  248. color: #F8C499;
  249. position: absolute;
  250. bottom: 0;
  251. }
  252. .login-now {
  253. padding: 10rpx 10rpx 10rpx 0;
  254. }
  255. .list-price {
  256. color: #FF2A2A;
  257. .price-larger {
  258. font-size: 32rpx;
  259. }
  260. }
  261. }
  262. </style>