search-second.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <template>
  2. <view class="search-container">
  3. <view class="search-main">
  4. <view class="gosearch-btn">
  5. <text class="iconfont icon-sousuo"></text>
  6. <input class="input" maxlength="20" type="text" value="" confirm-type="search" @confirm="subMitSearch()" placeholder="请输入关键词" v-model.trim="name"/>
  7. <text class="iconfont icon-shanchu1" v-if="isShowClose" @click.stop="delInputText()"></text>
  8. </view>
  9. </view>
  10. <view class="commodity-list-wrapper" :style="{'overflow':'auto','height':(listData.length>4? windowHeight + 'px' : 'auto')}">
  11. <scroll-view :style="{'height':(listData.length>4? scrollHeight+'px' : 'auto')}" @scrolltolower="scrolltolower" scroll-y v-if="!showEmpty">
  12. <view class="Listitem" v-for="(item, index) in listData" :key="index" :class="item.sold==1?'activeImg':''"
  13. :productid="item.productID" @click.stop="navToDetailPage(item.productID)">
  14. <view class="itemImg onhref" >
  15. <image :src="item.imageList[0]" class="bigImg"></image>
  16. <image src="http://static-b.caimei365.com/app/img/icon/yishou.png" class="yishou_bg" v-if="item.sold==1&&item.newAdded==1||item.sold==1&&item.newAdded==0"></image>
  17. </view>
  18. <view class="ItemInfo">
  19. <text class="infotag news" v-if="item.sold==0&&item.newAdded==1">新</text>
  20. <view class="productname" href="" :style="item.sold==0&&item.newAdded==1?'text-indent:60rpx':''">
  21. {{item.name}}
  22. </view>
  23. <view class="targetprice" >
  24. <text v-if="item.detailTalkFlag ==2 && hasLogin==false">价格详聊</text>
  25. <text v-else-if="!hasLogin" class="priceparam">登录查看价格</text>
  26. <text v-else-if="hasLogin && item.detailTalkFlag==2">价格详聊</text>
  27. <text v-else>¥{{item.price1Str}}</text>
  28. </view>
  29. <view class="shijian">
  30. <text class="iconfont icon-shijian"></text> {{item.onLineDateStr}}
  31. </view>
  32. <view class="dizhi">
  33. <view class="dizhi_left">
  34. <text class="iconfont icon-dizhi1"></text>
  35. {{item.provinceCityDistrict}}
  36. </view>
  37. <view class="liulan_right">
  38. <text class="iconfont icon-kejian1"></text>
  39. {{item.viewingNum}}
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. <view v-if="showLoading && listData.length > 4">
  45. <view class="loading-wrapper loading-wrapper-now" v-if="loadingNow">{{loadingText}}<text v-if="loadingText === '已至底部'">‧ ‧ ‧</text></view>
  46. <view class="loading-wrapper loading-wrapper-btm" v-else>———<text class="btm-text">已至底部</text>———</view>
  47. </view>
  48. </scroll-view>
  49. <view class="empty-container" v-if="showEmpty">
  50. <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/8D/Cmis215XHXWAHCoqAAELHadZ9Xg365.png"></image>
  51. <text class="error-text">抱歉,没有相关商品!</text>
  52. </view>
  53. </view>
  54. <!-- 透明模态层 -->
  55. <modal-layer v-if='isModallayer'></modal-layer>
  56. </view>
  57. </template>
  58. <script>
  59. import { mapState,mapMutations } from 'vuex'
  60. import modalLayer from "@/components/modal-layer"
  61. import uniGrader from '@/components/uni-grade/uni-grade.vue'
  62. import authorize from '@/common/config/authorize.js'
  63. export default {
  64. components: {
  65. modalLayer,
  66. uniGrader
  67. },
  68. data() {
  69. return {
  70. shopId:0,
  71. userID:0,
  72. themeClass: 'block',
  73. show:false,
  74. userIdentity:'',
  75. identity:2,
  76. searchKeyType:1,
  77. isShowClose:false, //是否显示清空输入框图标
  78. isSearchHistory:false,//是都显示搜索历史
  79. isShowWrapper:false,
  80. isModallayer:false,
  81. isFocus:false,
  82. priceLoading:true,
  83. windowHeight: '',
  84. showEmpty: false,
  85. scrollHeight: '',
  86. listData: [],
  87. showLoading: false,
  88. loadingNow: true,
  89. loadingText: '上拉加载更多',
  90. pullFlag: true,
  91. pageNum: 1,
  92. pageSize: 10,
  93. secondHandType:1,
  94. instrumentType:0,
  95. name:'',
  96. total:0
  97. }
  98. },
  99. onLoad(option) {
  100. this.getListFromServer()
  101. },
  102. computed: {
  103. ...mapState(['hasLogin','userInfo'])
  104. },
  105. methods:{
  106. subMitSearch() {//搜索
  107. if (this.name == '') {
  108. this.$util.msg('请输入商品关键词',2000);
  109. }else{
  110. this.getListFromServer()
  111. }
  112. },
  113. scrolltolower() {
  114. if(this.total>this.listData.length && this.pullFlag) {
  115. this.getListFromServer(true);
  116. }
  117. },
  118. getListFromServer(loadMore) {
  119. this.showLoading = true;
  120. this.loadingNow = true;
  121. this.loadingText = '加载中';
  122. this.showEmpty = false;
  123. if(loadMore) {
  124. this.pageNum += 1;
  125. }
  126. let params = {
  127. secondHandType:1,
  128. instrumentType:0,
  129. name:this.name,
  130. pageNum:this.pageNum,
  131. pageSize:this.pageSize
  132. }
  133. this.SecondService.SeconHandProductList(params).then(response =>{
  134. this.isShowWrapper = true
  135. const resData = response.data;
  136. const resList = resData.results;
  137. if(resList && resList.length > 0){
  138. this.total = resData.totalRecord;
  139. this.showEmpty = false;
  140. if(loadMore) {
  141. this.listData = [...this.listData,...resList];
  142. } else {
  143. this.listData = [...resList];
  144. }
  145. // 防上拉暴滑
  146. this.pullFlag = false;
  147. setTimeout(()=>{ this.pullFlag = true; },500)
  148. // 底部提示文案
  149. if(this.totalPage>this.listData.length) {
  150. this.loadingText = '上拉加载更多';
  151. } else {
  152. this.showLoading = true;
  153. this.loadingNow = false;
  154. }
  155. } else {
  156. if(!loadMore) {
  157. this.showEmpty = true;
  158. }
  159. }
  160. }).catch(error =>{
  161. this.$util.msg(error.msg,2000);
  162. })
  163. },
  164. delInputText () { //清除输入框内容
  165. this.name = ''
  166. this.isShowClose = false
  167. this.isShowWrapper = false
  168. this.getListFromServer()
  169. },
  170. keywordsClick (item) {//关键词搜索与历史搜索
  171. this.name = item;
  172. this.isShowClose = true;
  173. this.subMitSearch();
  174. },
  175. navToDetailPage(id) {
  176. this.isModallayer = true;
  177. this.$api.navigateTo(`/second/pages/product/product-details?id=${id}`);
  178. this.isModallayer = false;
  179. },
  180. setScrollHeight() {
  181. const {windowHeight, pixelRatio} = wx.getSystemInfoSync();
  182. this.windowHeight = windowHeight - 1;
  183. this.scrollHeight = windowHeight - 1;
  184. },
  185. toLoginPage() {
  186. let searchLoginType = 'search'
  187. uni.navigateTo({
  188. url:`/pages/login/login?type=${searchLoginType}`
  189. })
  190. },
  191. topBubble() {//显隐搜索项
  192. this.show = !this.show;
  193. },
  194. },
  195. onShow() {
  196. this.setScrollHeight();
  197. }
  198. }
  199. </script>
  200. <style lang="scss">
  201. @import "@/uni.scss";
  202. page{
  203. background-color:#fff;
  204. }
  205. .search-main{
  206. width: 100%;
  207. height: 88rpx;
  208. position: fixed;
  209. top: 0;
  210. left: 0;
  211. background: #FFFFFF;
  212. z-index: 1001;
  213. box-sizing: border-box;
  214. padding: 9rpx 0;
  215. .gosearch-btn{
  216. width: 702rpx;
  217. height: 100%;
  218. border-radius: 40rpx;
  219. background: #F0F0F0;
  220. margin: 0 auto;
  221. padding:0 20rpx;
  222. font-size: 28rpx;
  223. line-height: 70rpx;
  224. padding-left: 70rpx;
  225. color: #8A8A8A;
  226. background: #F7F7F7;
  227. position: relative;
  228. box-sizing: border-box;
  229. .icon-sousuo{
  230. width: 70rpx;
  231. height: 70rpx;
  232. line-height: 70rpx;
  233. text-align: center;
  234. display: block;
  235. position: absolute;
  236. left: 0;
  237. top: 0;
  238. font-size: 34rpx;
  239. color: #8A8A8A;
  240. z-index: 10;
  241. }
  242. .icon-shanchu1{
  243. font-size: 36rpx;
  244. color: #8A8A8A;
  245. position: absolute;
  246. right: 10rpx;
  247. top: 0;
  248. padding: 0 10rpx;
  249. z-index: 100;
  250. }
  251. .input{
  252. width: 400rpx;
  253. height: 100%;
  254. float: left;
  255. font-size: $font-size-24;
  256. box-sizing: border-box;
  257. padding-right: 66rpx;
  258. }
  259. }
  260. .search-btn{
  261. width: 120rpx;
  262. height: 70rpx;
  263. line-height: 70rpx;
  264. float: right;
  265. text-align: center;
  266. color: #666666;
  267. font-size: $font-size-24;
  268. }
  269. }
  270. .search-container{
  271. padding-top: 96rpx;
  272. }
  273. .s-block{
  274. background: #FFFFFF;
  275. .header{
  276. font-size: 32rpx;
  277. padding:40rpx 24rpx 22rpx 24rpx;
  278. line-height: 42rpx;
  279. font-size: 30rpx;
  280. font-weight: bold;
  281. position: relative;
  282. .icon-shanchu{
  283. font-size: 36rpx;
  284. color: #333333;
  285. float: right;
  286. padding: 0 10rpx;
  287. z-index: 10;
  288. font-weight: normal;
  289. }
  290. }
  291. .list{
  292. display: flex;
  293. flex-wrap: wrap;
  294. padding-bottom: 40rpx;
  295. view{
  296. color: #8A8A8A;
  297. font-size: 24rpx;
  298. box-sizing: border-box;
  299. text-align: center;
  300. height: 48rpx;
  301. line-height: 48rpx;
  302. border-radius: 24rpx;
  303. margin:12rpx;
  304. padding:.0 30rpx;
  305. overflow: hidden;
  306. white-space: nowrap;
  307. text-overflow: ellipsis;
  308. background-color: #F3F3F3;
  309. }
  310. }
  311. }
  312. .commodity-list-wrapper {
  313. scroll-view {
  314. height: 100%;
  315. overflow: scroll;
  316. }
  317. .Listitem{
  318. height: 202rpx;
  319. padding: 20rpx;
  320. border-bottom: 2rpx solid #F0F2F4;
  321. &.activeImg {
  322. opacity: 0.5;
  323. }
  324. .itemImg {
  325. width: 180rpx;
  326. height: 180rpx;
  327. float: left;
  328. background: #000;
  329. position: relative;
  330. .yishou_bg{
  331. width: 90rpx;
  332. height: 90rpx;
  333. position: absolute;
  334. top: 50%;
  335. left: 50%;
  336. transform: translate(-50%, -50%)
  337. }
  338. .bigImg {
  339. width: 100%;
  340. height: 100%;
  341. }
  342. }
  343. .ItemInfo {
  344. float: right;
  345. width:500rpx;
  346. .infotag{
  347. font-size: 20rpx;
  348. padding: 5rpx 15rpx;
  349. background: #f94b4b;
  350. color: #fff;
  351. position: absolute;
  352. border-radius: 6rpx;
  353. }
  354. .productname{
  355. display: inline-block;
  356. font-size: 28rpx;
  357. color: #333333;
  358. vertical-align: top;
  359. text-overflow: -o-ellipsis-lastline;
  360. overflow: hidden;
  361. text-overflow: ellipsis;
  362. display: -webkit-box;
  363. -webkit-line-clamp: 2;
  364. line-clamp: 2;
  365. -webkit-box-orient: vertical;
  366. width: 500rpx;
  367. }
  368. .targetprice {
  369. font-size: 26rpx;
  370. color: #f94b4b;
  371. cursor: pointer;
  372. margin: 15rpx 0;
  373. }
  374. .shijian{
  375. font-size: 24rpx;
  376. color: #999999;
  377. margin-top: 10rpx;
  378. .icon-shijian{
  379. font-size: 30rpx;
  380. color: #999999;
  381. margin-right: 10rpx;
  382. }
  383. }
  384. .dizhi{
  385. font-size: 24rpx;
  386. color: #999999;
  387. margin-top: 10rpx;
  388. .dizhi_left{
  389. float: left;
  390. .icon-dizhi1{
  391. font-size: 30rpx;
  392. color: #999999;
  393. margin-right: 10rpx;
  394. }
  395. }
  396. .liulan_right{
  397. float: right;
  398. margin-right: 25rpx;
  399. .icon-kejian1{
  400. font-size: 30rpx;
  401. color: #999999;
  402. margin-right: 10rpx;
  403. }
  404. }
  405. }
  406. .shijian{
  407. font-size: 24rpx;
  408. color: #999999;
  409. margin-top: 10rpx;
  410. }
  411. }
  412. }
  413. }
  414. </style>