search.vue 13 KB

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