search.vue 14 KB

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