search.vue 14 KB

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