search-second.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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':scrollHeight+'px'}" @scrolltolower="scrolltolower" scroll-y v-if="listData.length > 0">
  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="https://static.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" @click.stop="this.$api.navigateTo('/pages/login/login')">登录查看价格></text>
  26. <text v-else-if="hasLogin && item.detailTalkFlag==2">¥详聊</text>
  27. <text v-else>¥{{ item.price | NumFormat }}</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">
  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. hasNextPage:false
  98. }
  99. },
  100. created() {
  101. this.$api.getStorage().then((resolve) => {
  102. this.userId = resolve.userId ? resolve.userId : '';
  103. this.getListFromServer()
  104. })
  105. },
  106. computed: {
  107. ...mapState(['hasLogin','userInfo'])
  108. },
  109. methods:{
  110. subMitSearch() {//搜索
  111. if (this.name == '') {
  112. this.$util.msg('请输入商品关键字',2000);
  113. }else{
  114. this.getListFromServer()
  115. // 友盟埋点二手商品搜索点击
  116. if(process.env.NODE_ENV != 'development'){
  117. this.$uma.trackEvent('Um_Event_SearchSecondProductButtonClick', {
  118. Um_Key_Keyword: `${this.listQuery.keyword}`,
  119. Um_Key_PageName: '二手商品',
  120. Um_Key_SourcePage: '搜索二手商品',
  121. })
  122. }
  123. }
  124. },
  125. getListFromServer(loadMore) {
  126. this.showLoading = true;
  127. this.loadingNow = true;
  128. this.loadingText = '加载中';
  129. this.showEmpty = false;
  130. if(loadMore) {
  131. this.pageNum += 1;
  132. }
  133. let params = {
  134. userId:this.userId,
  135. secondHandType:1,
  136. instrumentType:0,
  137. name:this.name,
  138. pageNum:this.pageNum,
  139. pageSize:this.pageSize
  140. }
  141. this.SecondService.SeconHandProductList(params).then(response =>{
  142. this.isShowWrapper = true
  143. const resData = response.data;
  144. const resList = resData.results;
  145. if(resList && resList.length > 0){
  146. this.total = resData.totalRecord;
  147. this.hasNextPage = resData.hasNextPage;
  148. this.showEmpty = false;
  149. if(loadMore) {
  150. this.listData = [...this.listData,...resList];
  151. } else {
  152. this.listData = [...resList];
  153. }
  154. // 防上拉暴滑
  155. this.pullFlag = false;
  156. setTimeout(()=>{ this.pullFlag = true; },500)
  157. // 底部提示文案
  158. if(this.hasNextPage) {
  159. this.loadingText = '上拉加载更多';
  160. } else {
  161. this.showLoading = true;
  162. this.loadingNow = false;
  163. }
  164. } else {
  165. if(!loadMore) {
  166. this.showEmpty = true;
  167. }
  168. }
  169. }).catch(error =>{
  170. this.$util.msg(error.msg,2000);
  171. })
  172. },
  173. scrolltolower() {
  174. if(this.hasNextPage && this.pullFlag) {
  175. this.getListFromServer(true);
  176. }
  177. },
  178. onShowClose () {//输入框失去焦点时触发
  179. if(this.name != ''){
  180. this.isShowClose = true;
  181. }else{
  182. this.isShowClose = false
  183. }
  184. },
  185. onFocus () { //输入框获取焦点时触发
  186. this.inputEmpty(this.searchInputVal)
  187. },
  188. inputEmpty(val){
  189. this.isShowWrapper = false
  190. if(val != ''){
  191. this.isShowClose = true
  192. }else{
  193. this.isShowClose = false
  194. }
  195. },
  196. delInputText () { //清除输入框内容
  197. this.name = ''
  198. this.isShowClose = false
  199. this.isShowWrapper = false
  200. this.getListFromServer()
  201. },
  202. keywordsClick (item) {//关键词搜索与历史搜索
  203. this.name = item;
  204. this.isShowClose = true;
  205. this.subMitSearch();
  206. },
  207. navToDetailPage(id) {
  208. this.isModallayer = true;
  209. this.$api.navigateTo(`/pages/second/product/product-details?id=${id}`);
  210. this.isModallayer = false;
  211. },
  212. setScrollHeight() {
  213. const {windowHeight, pixelRatio} = wx.getSystemInfoSync();
  214. this.windowHeight = windowHeight - 1;
  215. this.scrollHeight = windowHeight - 1;
  216. },
  217. toLoginPage() {
  218. let searchLoginType = 'search'
  219. uni.navigateTo({
  220. url:`/pages/login/login?type=${searchLoginType}`
  221. })
  222. },
  223. topBubble() {//显隐搜索项
  224. this.show = !this.show;
  225. },
  226. },
  227. onShow() {
  228. this.setScrollHeight();
  229. }
  230. }
  231. </script>
  232. <style lang="scss">
  233. @import "@/uni.scss";
  234. page{
  235. background-color:#fff;
  236. }
  237. .search-main{
  238. width: 100%;
  239. height: 88rpx;
  240. position: fixed;
  241. top: 0;
  242. left: 0;
  243. background: #FFFFFF;
  244. z-index: 1001;
  245. box-sizing: border-box;
  246. padding: 9rpx 0;
  247. .gosearch-btn{
  248. width: 702rpx;
  249. height: 100%;
  250. border-radius: 40rpx;
  251. background: #F0F0F0;
  252. margin: 0 auto;
  253. padding:0 20rpx;
  254. font-size: 28rpx;
  255. line-height: 70rpx;
  256. padding-left: 70rpx;
  257. color: #8A8A8A;
  258. background: #F7F7F7;
  259. position: relative;
  260. box-sizing: border-box;
  261. .icon-sousuo{
  262. width: 70rpx;
  263. height: 70rpx;
  264. line-height: 70rpx;
  265. text-align: center;
  266. display: block;
  267. position: absolute;
  268. left: 0;
  269. top: 0;
  270. font-size: 34rpx;
  271. color: #8A8A8A;
  272. z-index: 10;
  273. }
  274. .icon-shanchu1{
  275. font-size: 36rpx;
  276. color: #8A8A8A;
  277. position: absolute;
  278. right: 10rpx;
  279. top: 0;
  280. padding: 0 10rpx;
  281. z-index: 100;
  282. }
  283. .input{
  284. width: 400rpx;
  285. height: 100%;
  286. float: left;
  287. font-size: $font-size-24;
  288. box-sizing: border-box;
  289. padding-right: 66rpx;
  290. }
  291. }
  292. .search-btn{
  293. width: 120rpx;
  294. height: 70rpx;
  295. line-height: 70rpx;
  296. float: right;
  297. text-align: center;
  298. color: #666666;
  299. font-size: $font-size-24;
  300. }
  301. }
  302. .search-container{
  303. padding-top: 96rpx;
  304. }
  305. .s-block{
  306. background: #FFFFFF;
  307. .header{
  308. font-size: 32rpx;
  309. padding:40rpx 24rpx 22rpx 24rpx;
  310. line-height: 42rpx;
  311. font-size: 30rpx;
  312. font-weight: bold;
  313. position: relative;
  314. .icon-shanchu{
  315. font-size: 36rpx;
  316. color: #333333;
  317. float: right;
  318. padding: 0 10rpx;
  319. z-index: 10;
  320. font-weight: normal;
  321. }
  322. }
  323. .list{
  324. display: flex;
  325. flex-wrap: wrap;
  326. padding-bottom: 40rpx;
  327. view{
  328. color: #8A8A8A;
  329. font-size: 24rpx;
  330. box-sizing: border-box;
  331. text-align: center;
  332. height: 48rpx;
  333. line-height: 48rpx;
  334. border-radius: 24rpx;
  335. margin:12rpx;
  336. padding:.0 30rpx;
  337. overflow: hidden;
  338. white-space: nowrap;
  339. text-overflow: ellipsis;
  340. background-color: #F3F3F3;
  341. }
  342. }
  343. }
  344. .commodity-list-wrapper {
  345. scroll-view {
  346. height: 100%;
  347. overflow: scroll;
  348. }
  349. .Listitem{
  350. height: 202rpx;
  351. padding: 20rpx;
  352. border-bottom: 2rpx solid #F0F2F4;
  353. &.activeImg {
  354. opacity: 0.5;
  355. }
  356. .itemImg {
  357. width: 180rpx;
  358. height: 180rpx;
  359. float: left;
  360. background: #000;
  361. position: relative;
  362. .yishou_bg{
  363. width: 90rpx;
  364. height: 90rpx;
  365. position: absolute;
  366. top: 50%;
  367. left: 50%;
  368. transform: translate(-50%, -50%)
  369. }
  370. .bigImg {
  371. width: 100%;
  372. height: 100%;
  373. }
  374. }
  375. .ItemInfo {
  376. float: right;
  377. width:500rpx;
  378. .infotag{
  379. font-size: 20rpx;
  380. padding: 5rpx 15rpx;
  381. background: #f94b4b;
  382. color: #fff;
  383. position: absolute;
  384. border-radius: 6rpx;
  385. }
  386. .productname{
  387. display: inline-block;
  388. font-size: 28rpx;
  389. color: #333333;
  390. vertical-align: top;
  391. text-overflow: -o-ellipsis-lastline;
  392. overflow: hidden;
  393. text-overflow: ellipsis;
  394. display: -webkit-box;
  395. -webkit-line-clamp: 2;
  396. line-clamp: 2;
  397. -webkit-box-orient: vertical;
  398. width: 500rpx;
  399. }
  400. .targetprice {
  401. font-size: 26rpx;
  402. color: #f94b4b;
  403. cursor: pointer;
  404. margin: 15rpx 0;
  405. }
  406. .shijian{
  407. font-size: 24rpx;
  408. color: #999999;
  409. margin-top: 10rpx;
  410. .icon-shijian{
  411. font-size: 30rpx;
  412. color: #999999;
  413. margin-right: 10rpx;
  414. }
  415. }
  416. .dizhi{
  417. font-size: 24rpx;
  418. color: #999999;
  419. margin-top: 10rpx;
  420. .dizhi_left{
  421. float: left;
  422. .icon-dizhi1{
  423. font-size: 30rpx;
  424. color: #999999;
  425. margin-right: 10rpx;
  426. }
  427. }
  428. .liulan_right{
  429. float: right;
  430. margin-right: 25rpx;
  431. .icon-kejian1{
  432. font-size: 30rpx;
  433. color: #999999;
  434. margin-right: 10rpx;
  435. }
  436. }
  437. }
  438. .shijian{
  439. font-size: 24rpx;
  440. color: #999999;
  441. margin-top: 10rpx;
  442. }
  443. }
  444. }
  445. }
  446. </style>