search-second.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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" @input="onShowClose" @focus="onFocus" @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. onShowClose () {//输入框失去焦点时触发
  165. if(this.name != ''){
  166. this.isShowClose = true;
  167. }else{
  168. this.isShowClose = false
  169. }
  170. },
  171. onFocus () { //输入框获取焦点时触发
  172. this.inputEmpty(this.searchInputVal)
  173. },
  174. delInputText () { //清除输入框内容
  175. this.name = ''
  176. this.isShowClose = false
  177. this.isShowWrapper = false
  178. this.getListFromServer()
  179. },
  180. keywordsClick (item) {//关键词搜索与历史搜索
  181. this.name = item;
  182. this.isShowClose = true;
  183. this.subMitSearch();
  184. },
  185. navToDetailPage(id) {
  186. this.isModallayer = true;
  187. this.$api.navigateTo(`/second/pages/product/product-details?id=${id}`);
  188. this.isModallayer = false;
  189. },
  190. setScrollHeight() {
  191. const {windowHeight, pixelRatio} = wx.getSystemInfoSync();
  192. this.windowHeight = windowHeight - 1;
  193. this.scrollHeight = windowHeight - 1;
  194. },
  195. toLoginPage() {
  196. let searchLoginType = 'search'
  197. uni.navigateTo({
  198. url:`/pages/login/login?type=${searchLoginType}`
  199. })
  200. },
  201. topBubble() {//显隐搜索项
  202. this.show = !this.show;
  203. },
  204. },
  205. onShow() {
  206. this.setScrollHeight();
  207. }
  208. }
  209. </script>
  210. <style lang="scss">
  211. @import "@/uni.scss";
  212. page{
  213. background-color:#fff;
  214. }
  215. .search-main{
  216. width: 100%;
  217. height: 88rpx;
  218. position: fixed;
  219. top: 0;
  220. left: 0;
  221. background: #FFFFFF;
  222. z-index: 1001;
  223. box-sizing: border-box;
  224. padding: 9rpx 0;
  225. .gosearch-btn{
  226. width: 702rpx;
  227. height: 100%;
  228. border-radius: 40rpx;
  229. background: #F0F0F0;
  230. margin: 0 auto;
  231. padding:0 20rpx;
  232. font-size: 28rpx;
  233. line-height: 70rpx;
  234. padding-left: 70rpx;
  235. color: #8A8A8A;
  236. background: #F7F7F7;
  237. position: relative;
  238. box-sizing: border-box;
  239. .icon-sousuo{
  240. width: 70rpx;
  241. height: 70rpx;
  242. line-height: 70rpx;
  243. text-align: center;
  244. display: block;
  245. position: absolute;
  246. left: 0;
  247. top: 0;
  248. font-size: 34rpx;
  249. color: #8A8A8A;
  250. z-index: 10;
  251. }
  252. .icon-shanchu1{
  253. font-size: 36rpx;
  254. color: #8A8A8A;
  255. position: absolute;
  256. right: 10rpx;
  257. top: 0;
  258. padding: 0 10rpx;
  259. z-index: 100;
  260. }
  261. .input{
  262. width: 400rpx;
  263. height: 100%;
  264. float: left;
  265. font-size: $font-size-24;
  266. box-sizing: border-box;
  267. padding-right: 66rpx;
  268. }
  269. }
  270. .search-btn{
  271. width: 120rpx;
  272. height: 70rpx;
  273. line-height: 70rpx;
  274. float: right;
  275. text-align: center;
  276. color: #666666;
  277. font-size: $font-size-24;
  278. }
  279. }
  280. .search-container{
  281. padding-top: 96rpx;
  282. }
  283. .s-block{
  284. background: #FFFFFF;
  285. .header{
  286. font-size: 32rpx;
  287. padding:40rpx 24rpx 22rpx 24rpx;
  288. line-height: 42rpx;
  289. font-size: 30rpx;
  290. font-weight: bold;
  291. position: relative;
  292. .icon-shanchu{
  293. font-size: 36rpx;
  294. color: #333333;
  295. float: right;
  296. padding: 0 10rpx;
  297. z-index: 10;
  298. font-weight: normal;
  299. }
  300. }
  301. .list{
  302. display: flex;
  303. flex-wrap: wrap;
  304. padding-bottom: 40rpx;
  305. view{
  306. color: #8A8A8A;
  307. font-size: 24rpx;
  308. box-sizing: border-box;
  309. text-align: center;
  310. height: 48rpx;
  311. line-height: 48rpx;
  312. border-radius: 24rpx;
  313. margin:12rpx;
  314. padding:.0 30rpx;
  315. overflow: hidden;
  316. white-space: nowrap;
  317. text-overflow: ellipsis;
  318. background-color: #F3F3F3;
  319. }
  320. }
  321. }
  322. .commodity-list-wrapper {
  323. scroll-view {
  324. height: 100%;
  325. overflow: scroll;
  326. }
  327. .Listitem{
  328. height: 202rpx;
  329. padding: 20rpx;
  330. border-bottom: 2rpx solid #F0F2F4;
  331. &.activeImg {
  332. opacity: 0.5;
  333. }
  334. .itemImg {
  335. width: 180rpx;
  336. height: 180rpx;
  337. float: left;
  338. background: #000;
  339. position: relative;
  340. .yishou_bg{
  341. width: 90rpx;
  342. height: 90rpx;
  343. position: absolute;
  344. top: 50%;
  345. left: 50%;
  346. transform: translate(-50%, -50%)
  347. }
  348. .bigImg {
  349. width: 100%;
  350. height: 100%;
  351. }
  352. }
  353. .ItemInfo {
  354. float: right;
  355. width:500rpx;
  356. .infotag{
  357. font-size: 20rpx;
  358. padding: 5rpx 15rpx;
  359. background: #f94b4b;
  360. color: #fff;
  361. position: absolute;
  362. border-radius: 6rpx;
  363. }
  364. .productname{
  365. display: inline-block;
  366. font-size: 28rpx;
  367. color: #333333;
  368. vertical-align: top;
  369. text-overflow: -o-ellipsis-lastline;
  370. overflow: hidden;
  371. text-overflow: ellipsis;
  372. display: -webkit-box;
  373. -webkit-line-clamp: 2;
  374. line-clamp: 2;
  375. -webkit-box-orient: vertical;
  376. width: 500rpx;
  377. }
  378. .targetprice {
  379. font-size: 26rpx;
  380. color: #f94b4b;
  381. cursor: pointer;
  382. margin: 15rpx 0;
  383. }
  384. .shijian{
  385. font-size: 24rpx;
  386. color: #999999;
  387. margin-top: 10rpx;
  388. .icon-shijian{
  389. font-size: 30rpx;
  390. color: #999999;
  391. margin-right: 10rpx;
  392. }
  393. }
  394. .dizhi{
  395. font-size: 24rpx;
  396. color: #999999;
  397. margin-top: 10rpx;
  398. .dizhi_left{
  399. float: left;
  400. .icon-dizhi1{
  401. font-size: 30rpx;
  402. color: #999999;
  403. margin-right: 10rpx;
  404. }
  405. }
  406. .liulan_right{
  407. float: right;
  408. margin-right: 25rpx;
  409. .icon-kejian1{
  410. font-size: 30rpx;
  411. color: #999999;
  412. margin-right: 10rpx;
  413. }
  414. }
  415. }
  416. .shijian{
  417. font-size: 24rpx;
  418. color: #999999;
  419. margin-top: 10rpx;
  420. }
  421. }
  422. }
  423. }
  424. </style>