search.vue 14 KB

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