search.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. <template>
  2. <view class="search-container">
  3. <view class="search-main">
  4. <view class="search-input">
  5. <text class="iconfont icon-iconfonticonfontsousuo1"></text>
  6. <input maxlength="20" focus type="text" value="" confirm-type="search" @focus="onFocus" @input="onShowClose" @confirm="subMitSearch()" placeholder="请输入商品关键词" v-model.trim="searchInputVal"/>
  7. <text class="iconfont icon-shanchu1" v-if="isShowClose" @click="delInputText()"></text>
  8. </view>
  9. <view class="search-btn" @click="subMitSearch()">搜索</view>
  10. </view>
  11. <view class="search-container-history" v-if="!isShowWrapper">
  12. <view :class="'s-' + themeClass" v-if="serachRecordList.length>0">
  13. <view class="header">
  14. 搜索历史
  15. <text class="iconfont icon-shanchu" @click="confirmDetele"></text>
  16. </view>
  17. <view class="list">
  18. <view v-for="(item,index) in serachRecordList" :key="index" @click="keywordsClick(item.searchWord)">{{item.searchWord}}</view>
  19. </view>
  20. </view>
  21. </view>
  22. <!-- <go-search :theme="themeClass" @subMitSearch="subMitSearch"></go-search> -->
  23. <view v-else class="commodity-list-wrapper" :style="{'overflow':'auto','height':(commodityList.length>4? windowHeight + 'px' : 'auto')}">
  24. <scroll-view :style="{'height':(commodityList.length>4? scrollHeight+'px' : 'auto')}" @scrolltolower="scrolltolower" scroll-y v-if="!showEmpty">
  25. <view v-for="(item,index) in commodityList" :key="index" :id="item.id" class="all-type-list-content commodity-list" @click.stop="navToDetailPage(item.productID)">
  26. <image mode='widthFix' :src="item.mainImage" class="list-img" alt="list-img"></image>
  27. <view class="list-details-info">
  28. <text class="list-details-title">{{item.name}}</text>
  29. <text class="list-details-specs">规格:{{item.unit}}</text>
  30. <text class="list-details-miniQuantity" v-if="fromRegularPurchasePage">起订量:{{item.minBuyNumber}}</text>
  31. <view class="list-details-price">
  32. <view v-if="!hasLogin" class="list-login-now">
  33. <text class="p-no">价格:</text>
  34. <uni-stars :stars="parseInt(item.price1Grade)" :font-size='36' :width-info="180"></uni-stars>
  35. </view>
  36. <view class="list-price" v-else>
  37. <view class="price-larger" v-if="item.price1TextFlag == '1'">
  38. <text class="txt">该商品尚未公开价格</text>
  39. <text class="txt">购买请致电:0755-22907771</text>
  40. </view>
  41. <text v-else>¥<text class="price-larger">{{item.retailPrice.toFixed(2)}}</text></text>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. <view v-if="showLoading && commodityList.length > 4">
  47. <view class="loading-wrapper loading-wrapper-now" v-if="loadingNow">{{loadingText}}<text v-if="loadingText === '已至底部'">‧ ‧ ‧</text></view>
  48. <view class="loading-wrapper loading-wrapper-btm" v-else>———<text class="btm-text">已至底部</text>———</view>
  49. </view>
  50. </scroll-view>
  51. <view class="empty-container" v-if="showEmpty">
  52. <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/8D/Cmis215XHXWAHCoqAAELHadZ9Xg365.png"></image>
  53. <text class="error-text">抱歉,没有相关商品!</text>
  54. </view>
  55. </view>
  56. <!-- 透明模态层 -->
  57. <modal-layer v-if='isModallayer'></modal-layer>
  58. </view>
  59. </template>
  60. <script>
  61. import { mapState,mapMutations } from 'vuex'
  62. import goSearch from '@/components/uni-search/go-search.vue'
  63. import modalLayer from "@/components/modal-layer"
  64. import uniStars from '@/components/uni-stars/uni-stars.vue'
  65. import authorize from '@/common/config/authorize.js'
  66. import { querySearchProduct , querySearchHistory,clearSearchHistory } from "@/api/product.js"
  67. export default {
  68. components: {
  69. // goSearch,
  70. modalLayer,
  71. uniStars
  72. },
  73. data() {
  74. return {
  75. userID:'',
  76. themeClass: 'block',
  77. searchInputVal:'', //搜索关键词
  78. isShowClose:false, //是否显示清空输入框图标
  79. isSearchHistory:false, //是都显示搜索历史
  80. serachRecordList:[], //历史搜索记录
  81. isShowWrapper:false,
  82. isModallayer:false,
  83. windowHeight: '',
  84. showEmpty: false,
  85. scrollHeight: '',
  86. commodityList: [],
  87. showLoading: false,
  88. loadingNow: true,
  89. loadingText: '上拉加载更多',
  90. pageSize: 10,
  91. pageNum: 1,
  92. hasNextPage: false,
  93. totalPage: 1,
  94. pullFlag: true,
  95. }
  96. },
  97. onLoad() {
  98. this.initGetSerachRecord()
  99. },
  100. computed: {
  101. ...mapState(['hasLogin','userInfo'])
  102. },
  103. methods:{
  104. initGetSerachRecord(){
  105. this.$api.getStorage().then((resolve) =>{
  106. this.userID = resolve.userID ? resolve.userID : '';
  107. querySearchHistory({userId:this.userID}).then(response =>{
  108. if(response.code == 0){
  109. this.serachRecordList = response.data
  110. }
  111. })
  112. })
  113. },
  114. subMitSearch() {
  115. if (this.searchInputVal == '') {
  116. this.$util.msg('请输入商品关键词',2000);
  117. }else{
  118. this.commodityList =[]
  119. this.getListFromServer(false)
  120. }
  121. },
  122. scrolltolower() {
  123. if(this.hasNextPage && this.pullFlag) {
  124. this.getListFromServer(true);
  125. }
  126. },
  127. getListFromServer(loadMore) {
  128. this.showLoading = true;
  129. this.loadingNow = true;
  130. this.loadingText = '加载中';
  131. this.showEmpty = false;
  132. if(loadMore) {
  133. this.pageNum += 1;
  134. }
  135. let params = {userId:this.userID,searchWord:this.searchInputVal,pageNum:this.pageNum,pageSize:this.pageSize}
  136. querySearchProduct(params).then(response =>{
  137. this.isShowWrapper = true
  138. const resData = response.data;
  139. const resList = resData.results;
  140. if(resList && resList.length > 0){
  141. this.hasNextPage = resData.hasNextPage;
  142. this.totalPage = resData.totalPage;
  143. this.showEmpty = false;
  144. if(loadMore) {
  145. this.commodityList = [...this.commodityList,...resList];
  146. } else {
  147. this.commodityList = [...resList];
  148. }
  149. // 防上拉暴滑
  150. this.pullFlag = false;
  151. setTimeout(()=>{
  152. this.pullFlag = true;
  153. },500)
  154. // 底部提示文案
  155. if(this.hasNextPage) {
  156. this.loadingText = '上拉加载更多';
  157. } else {
  158. this.showLoading = true;
  159. this.loadingNow = false;
  160. }
  161. } else {
  162. if(!loadMore) {
  163. this.showEmpty = true;
  164. }
  165. }
  166. }).catch(response =>{
  167. this.$util.msg(response.msg,3000);
  168. })
  169. },
  170. onShowClose () {//输入框失去焦点时触发
  171. this.inputEmpty(this.searchInputVal)
  172. },
  173. onFocus () { //输入框获取焦点时触发
  174. this.inputEmpty(this.searchInputVal)
  175. this.initGetSerachRecord()
  176. },
  177. delInputText () { //清除输入框内容
  178. this.searchInputVal = ''
  179. this.isShowClose = false
  180. this.isShowWrapper = false
  181. this.inputEmpty(this.searchInputVal)
  182. this.initGetSerachRecord()
  183. },
  184. keywordsClick (item) {//关键词搜索与历史搜索
  185. this.searchInputVal = item;
  186. this.isShowClose = true;
  187. this.subMitSearch();
  188. },
  189. confirmDetele() {//清空历史记录
  190. this.$util.modal('提示','确定删除历史记录?','确定','取消',true,() =>{
  191. clearSearchHistory({userId:this.userID}).then(response =>{
  192. this.$util.msg('删除成功',2000,true,'success')
  193. this.serachRecordList=[];
  194. }).catch(response =>{
  195. this.$util.msg(response.msg,2000)
  196. })
  197. })
  198. },
  199. inputEmpty(val){
  200. this.isShowWrapper = false
  201. if(val != ''){
  202. this.isShowClose = true
  203. }else{
  204. this.isShowClose = false
  205. }
  206. },
  207. navToDetailPage(id) {
  208. this.isModallayer = true;
  209. this.$api.navigateTo(`/pages/goods/product?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-accont?type=${searchLoginType}`
  221. })
  222. }
  223. },
  224. onShow() {
  225. this.setScrollHeight();
  226. }
  227. }
  228. </script>
  229. <style lang="scss">
  230. @import "@/uni.scss";
  231. page{
  232. background-color: #F7F7F7 !important;
  233. }
  234. .search-main{
  235. width: 702rpx;
  236. height: 80rpx;
  237. padding: 12rpx 24rpx;
  238. border-bottom: 1px solid #F0F0F0;
  239. position: fixed;
  240. top: 0;
  241. left: 0;
  242. background: #FFFFFF;
  243. z-index: 1001;
  244. .search-input{
  245. width: 448rpx;
  246. height: 80rpx;
  247. padding: 0 68rpx;
  248. line-height: 80rpx;
  249. border-radius: 40rpx;
  250. position: relative;
  251. background: #F0F0F0;
  252. float: left;
  253. .icon-iconfonticonfontsousuo1{
  254. font-size: 36rpx;
  255. color: #8A8A8A;
  256. position: absolute;
  257. left: 24rpx;
  258. z-index: 10;
  259. }
  260. .icon-shanchu1{
  261. font-size: 36rpx;
  262. color: #8A8A8A;
  263. position: absolute;
  264. right: 24rpx;
  265. top: 0;
  266. padding: 0 10rpx;
  267. z-index: 10;
  268. }
  269. input{
  270. width: 448rpx;
  271. height: 80rpx;
  272. background-color: #F0F0F0;
  273. font-size: 26rpx;
  274. }
  275. }
  276. .search-btn{
  277. width: 118rpx;
  278. height: 80rpx;
  279. line-height: 80rpx;
  280. color: $color-system;
  281. font-size: 30rpx;
  282. text-align: center;
  283. float: left;
  284. }
  285. .voice-icon{
  286. width: 36rpx;
  287. height: 36rpx;
  288. padding: 16rpx 20rpx 16rpx 0;
  289. position: absolute;
  290. left: 16rpx;
  291. top: 4rpx;
  292. z-index: 10;
  293. }
  294. }
  295. .search-container{
  296. padding-top: 106rpx;
  297. }
  298. .s-block{
  299. background: #FFFFFF;
  300. .header{
  301. font-size: 32rpx;
  302. padding:40rpx 24rpx 22rpx 24rpx;
  303. line-height: 42rpx;
  304. font-size: 30rpx;
  305. font-weight: bold;
  306. position: relative;
  307. .icon-shanchu{
  308. font-size: 36rpx;
  309. color: #333333;
  310. float: right;
  311. padding: 0 10rpx;
  312. z-index: 10;
  313. font-weight: normal;
  314. }
  315. }
  316. .list{
  317. display: flex;
  318. flex-wrap: wrap;
  319. padding-bottom: 40rpx;
  320. view{
  321. color: #8A8A8A;
  322. font-size: 24rpx;
  323. box-sizing: border-box;
  324. text-align: center;
  325. height: 48rpx;
  326. line-height: 48rpx;
  327. border-radius: 24rpx;
  328. margin:12rpx;
  329. padding:.0 30rpx;
  330. overflow: hidden;
  331. white-space: nowrap;
  332. text-overflow: ellipsis;
  333. background-color: #F3F3F3;
  334. }
  335. }
  336. }
  337. .s-circle{
  338. margin-top: 30rpx;
  339. .header{
  340. font-size: 32rpx;
  341. padding: 30rpx;
  342. border-bottom: 2rpx solid #F9F9F9;
  343. position: relative;
  344. image{
  345. width: 36rpx;
  346. height: 36rpx;
  347. padding: 10rpx;
  348. position: absolute;
  349. right: 40rpx;
  350. top: 24rpx;
  351. }
  352. }
  353. .list{
  354. display: flex;
  355. flex-wrap: wrap;
  356. padding: 0 30rpx 20rpx;
  357. view{
  358. padding: 8rpx 30rpx;
  359. margin: 20rpx 30rpx 0 0;
  360. font-size: 28rpx;
  361. color: #8A8A8A;
  362. background-color: #F7F7F7;
  363. box-sizing: border-box;
  364. text-align: center;
  365. border-radius: 20rpx;
  366. }
  367. }
  368. }
  369. .wanted-block{
  370. margin-top: 30rpx;
  371. .header{
  372. font-size: 32rpx;
  373. padding: 30rpx;
  374. }
  375. .list{
  376. display: flex;
  377. flex-wrap: wrap;
  378. view{
  379. width: 50%;
  380. color: #8A8A8A;
  381. font-size: 28rpx;
  382. box-sizing: border-box;
  383. text-align: center;
  384. padding: 20rpx 0;
  385. border-top: 2rpx solid #FFF;
  386. border-left: 2rpx solid #FFF;
  387. background-color: #F7F7F7;
  388. overflow: hidden;
  389. white-space: nowrap;
  390. text-overflow: ellipsis;
  391. }
  392. }
  393. }
  394. .wanted-circle{
  395. margin-top: 30rpx;
  396. .header{
  397. font-size: 32rpx;
  398. padding: 30rpx;
  399. }
  400. .list{
  401. display: flex;
  402. flex-wrap: wrap;
  403. padding: 0 30rpx 20rpx;
  404. view{
  405. padding: 8rpx 30rpx;
  406. margin: 20rpx 30rpx 0 0;
  407. font-size: 28rpx;
  408. color: #8A8A8A;
  409. background-color: #F7F7F7;
  410. box-sizing: border-box;
  411. text-align: center;
  412. border-radius: 20rpx;
  413. }
  414. }
  415. }
  416. .commodity-list-wrapper {
  417. scroll-view {
  418. height: 100%;
  419. overflow: scroll;
  420. }
  421. .empty-container-image {
  422. margin-top: -300rpx;
  423. }
  424. .toIndexPage {
  425. bottom: 390rpx;
  426. }
  427. .show-more-btn {
  428. width: 276rpx;
  429. height: 52rpx;
  430. line-height: 52rpx;
  431. border: 2rpx solid #D8D8D8;
  432. background: #F7F7F7;
  433. font-size: 26rpx;
  434. margin: 26rpx 0;
  435. position: absolute;
  436. left: 50%;
  437. margin-left: -138rpx;
  438. }
  439. }
  440. .all-type-list-content {
  441. height: 216rpx;
  442. padding: 24rpx;
  443. background: #fff;
  444. margin-bottom: 2rpx;
  445. display: flex;
  446. flex-direction: row;
  447. box-sizing: content-box;
  448. .list-img {
  449. width: 210rpx;
  450. height: 218rpx !important;
  451. margin-right: 26rpx;
  452. border-radius: 10rpx;
  453. border: 2rpx solid #f3f3f3;
  454. }
  455. }
  456. .list-details-info {
  457. width: 466rpx;
  458. display: flex;
  459. flex-direction: column;
  460. font-size: 26rpx;
  461. position: relative;
  462. .list-details-title {
  463. line-height: 38rpx;
  464. text-overflow: ellipsis;
  465. overflow: hidden;
  466. display: -webkit-box;
  467. -webkit-line-clamp: 2;
  468. line-clamp: 2;
  469. -webkit-box-orient: vertical;
  470. }
  471. .list-details-specs {
  472. margin-top: 8rpx;
  473. color: #999999;
  474. }
  475. .list-details-miniQuantity {
  476. margin-top: 7rpx;
  477. }
  478. }
  479. .list-details-price {
  480. width: 100%;
  481. display: flex;
  482. flex-direction: row;
  483. justify-content: space-between;
  484. position: absolute;
  485. bottom: 0;
  486. right: 0;
  487. .price-icon {
  488. width: 22rpx;
  489. height: 28rpx;
  490. vertical-align: middle;
  491. margin-right: 10rpx;
  492. }
  493. .price-icon + text {
  494. font-size: 25rpx;
  495. vertical-align: middle;
  496. }
  497. .list-login-now {
  498. width: 375rpx;
  499. color: #F8C499;
  500. position: absolute;
  501. bottom: 0;
  502. .p-no{
  503. float: left;
  504. font-size: $font-size-24;
  505. color: $color-system;
  506. margin-right: 10rpx;
  507. }
  508. }
  509. .login-now {
  510. padding: 10rpx 10rpx 10rpx 0;
  511. }
  512. .list-price {
  513. color: #FF2A2A;
  514. .price-larger {
  515. font-size: 32rpx;
  516. .txt{
  517. font-size: $font-size-24;
  518. display: inline-block;
  519. line-height: 30rpx;
  520. text-align: left;
  521. }
  522. }
  523. }
  524. }
  525. </style>