search.vue 16 KB

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