search.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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="toLower" 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. this.$api.getStorage().then((resolve) =>{
  103. this.userID = resolve.userID
  104. })
  105. this.setScrollHeight();
  106. this.$api.loginStatus().then((resolveData) => {
  107. this.loginStatus = resolveData;
  108. });
  109. },
  110. onLoad() {
  111. this.initGetSerachRecord()
  112. },
  113. methods:{
  114. initGetSerachRecord(){
  115. authorize.getCode('weixin').then(wechatcode =>{
  116. // console.log(wechatcode);
  117. this.$api.get('/search/record',{organizeID:this.userOrganizeID,code:wechatcode},
  118. response =>{
  119. // console.log(response);
  120. if(response.code == '1'){
  121. this.serachRecordList = response.data
  122. }else{
  123. this.$util.msg(response.msg,2000)
  124. }
  125. }
  126. )
  127. })
  128. },
  129. subMitSearch() {
  130. if (this.searchInputVal == '') {
  131. this.$util.msg('请输入商品关键词',2000);
  132. }else{
  133. this.commodityList =[]
  134. this.getListFromServer(false)
  135. }
  136. },
  137. toLower() {
  138. // 第一次加载排除常用商品
  139. if(this.hasNextPage && this.pullFlag) {
  140. this.getListFromServer(true);
  141. }
  142. },
  143. getListFromServer(loadMore) {
  144. this.showLoading = true;
  145. this.loadingNow = true;
  146. this.loadingText = '加载中';
  147. this.showEmpty = false;
  148. if(loadMore) {
  149. this.pageNum += 1;
  150. }
  151. authorize.getCode('weixin').then(wechatcode =>{
  152. let params = {code:wechatcode,searchWord:this.searchInputVal,index:this.pageNum,pageSize:this.pageSize,organizeID:this.userOrganizeID}
  153. this.$api.lodingGet('/search/product',params,
  154. response => {
  155. if(response.code == '1') {
  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. this.showSkeleton = false;
  166. } else {
  167. this.commodityList = [...resList];
  168. this.showSkeleton = true;
  169. console.log(this.showSkeleton)
  170. }
  171. // 防上拉暴滑
  172. this.pullFlag = false;
  173. setTimeout(()=>{
  174. this.pullFlag = true;
  175. },500)
  176. // 底部提示文案
  177. if(this.hasNextPage) {
  178. this.loadingText = '上拉加载更多';
  179. } else {
  180. this.showLoading = true;
  181. this.loadingNow = false;
  182. }
  183. } else {
  184. if(!loadMore) {
  185. this.showEmpty = true;
  186. }
  187. }
  188. } else {
  189. this.$util.msg(response.msg,3000);
  190. }
  191. }
  192. )
  193. })
  194. },
  195. onShowClose () { //输入框失去焦点时触发
  196. this.inputEmpty(this.searchInputVal)
  197. },
  198. onFocus () { //输入框获取焦点时触发
  199. this.inputEmpty(this.searchInputVal)
  200. this.initGetSerachRecord()
  201. },
  202. delInputText () { //清除输入框内容
  203. this.searchInputVal = ''
  204. this.isShowClose = false
  205. this.isShowWrapper = false
  206. this.inputEmpty(this.searchInputVal)
  207. this.initGetSerachRecord()
  208. },
  209. keywordsClick (item) { //关键词搜索与历史搜索
  210. this.searchInputVal = item;
  211. this.isShowClose = true;
  212. this.subMitSearch();
  213. },
  214. delhistory () { //清空历史记录
  215. this.isShowDelModal = true;
  216. },
  217. confirmDetele() {
  218. this.isShowDelModal = false;
  219. authorize.getCode('weixin').then(wechatcode =>{
  220. // console.log(wechatcode);
  221. this.$api.get('/search/delete',{organizeID:this.userOrganizeID,code:wechatcode},
  222. response =>{
  223. // console.log(response);
  224. if(response.code == '1'){
  225. this.serachRecordList=[];
  226. }else{
  227. this.$util.msg(response.msg,2000)
  228. }
  229. }
  230. )
  231. })
  232. },
  233. inputEmpty(val){
  234. this.isShowWrapper = false
  235. if(val != ''){
  236. this.isShowClose = true
  237. }else{
  238. this.isShowClose = false
  239. }
  240. },
  241. navToDetailPage(id) {
  242. this.isModallayer = true;
  243. this.$api.navigateTo(`/pages/goods/product?id=${id}`);
  244. this.isModallayer = false;
  245. },
  246. setScrollHeight() {
  247. const {windowHeight, pixelRatio} = wx.getSystemInfoSync();
  248. this.windowHeight = windowHeight - 1;
  249. this.scrollHeight = windowHeight - 1;
  250. },
  251. toLoginPage() {
  252. let searchLoginType = 'search'
  253. uni.navigateTo({
  254. url:`/pages/login/login?type=${searchLoginType}`
  255. })
  256. }
  257. }
  258. }
  259. </script>
  260. <style lang="scss">
  261. @import "@/uni.scss";
  262. page{
  263. background-color: #F7F7F7 !important;
  264. }
  265. .search{
  266. width: 702rpx;
  267. height: 80rpx;
  268. padding: 12rpx 24rpx;
  269. border-bottom: 1px solid #F0F0F0;
  270. position: fixed;
  271. top: 0;
  272. left: 0;
  273. background: #FFFFFF;
  274. z-index: 999;
  275. .search-input{
  276. width: 448rpx;
  277. height: 80rpx;
  278. padding: 0 68rpx;
  279. line-height: 80rpx;
  280. border-radius: 40rpx;
  281. position: relative;
  282. background: #F0F0F0;
  283. float: left;
  284. .icon-iconfonticonfontsousuo1{
  285. font-size: 36rpx;
  286. color: #8A8A8A;
  287. position: absolute;
  288. left: 24rpx;
  289. z-index: 10;
  290. }
  291. .icon-shanchu1{
  292. font-size: 36rpx;
  293. color: #8A8A8A;
  294. position: absolute;
  295. right: 24rpx;
  296. top: 0;
  297. padding: 0 10rpx;
  298. z-index: 10;
  299. }
  300. input{
  301. width: 448rpx;
  302. height: 80rpx;
  303. background-color: #F0F0F0;
  304. font-size: 26rpx;
  305. }
  306. }
  307. .search-btn{
  308. width: 118rpx;
  309. height: 80rpx;
  310. line-height: 80rpx;
  311. color: $color-system;
  312. font-size: 30rpx;
  313. text-align: center;
  314. float: left;
  315. }
  316. .voice-icon{
  317. width: 36rpx;
  318. height: 36rpx;
  319. padding: 16rpx 20rpx 16rpx 0;
  320. position: absolute;
  321. left: 16rpx;
  322. top: 4rpx;
  323. z-index: 10;
  324. }
  325. }
  326. .search-container{
  327. padding-top: 106rpx;
  328. }
  329. .s-block{
  330. background: #FFFFFF;
  331. .header{
  332. font-size: 32rpx;
  333. padding:40rpx 24rpx 22rpx 24rpx;
  334. line-height: 42rpx;
  335. font-size: 30rpx;
  336. font-weight: bold;
  337. position: relative;
  338. .icon-shanchu{
  339. font-size: 36rpx;
  340. color: #333333;
  341. float: right;
  342. padding: 0 10rpx;
  343. z-index: 10;
  344. font-weight: normal;
  345. }
  346. }
  347. .list{
  348. display: flex;
  349. flex-wrap: wrap;
  350. padding-bottom: 40rpx;
  351. view{
  352. color: #8A8A8A;
  353. font-size: 24rpx;
  354. box-sizing: border-box;
  355. text-align: center;
  356. height: 48rpx;
  357. line-height: 48rpx;
  358. border-radius: 24rpx;
  359. margin:12rpx;
  360. padding:.0 30rpx;
  361. overflow: hidden;
  362. white-space: nowrap;
  363. text-overflow: ellipsis;
  364. background-color: #F3F3F3;
  365. }
  366. }
  367. }
  368. .s-circle{
  369. margin-top: 30rpx;
  370. .header{
  371. font-size: 32rpx;
  372. padding: 30rpx;
  373. border-bottom: 2rpx solid #F9F9F9;
  374. position: relative;
  375. image{
  376. width: 36rpx;
  377. height: 36rpx;
  378. padding: 10rpx;
  379. position: absolute;
  380. right: 40rpx;
  381. top: 24rpx;
  382. }
  383. }
  384. .list{
  385. display: flex;
  386. flex-wrap: wrap;
  387. padding: 0 30rpx 20rpx;
  388. view{
  389. padding: 8rpx 30rpx;
  390. margin: 20rpx 30rpx 0 0;
  391. font-size: 28rpx;
  392. color: #8A8A8A;
  393. background-color: #F7F7F7;
  394. box-sizing: border-box;
  395. text-align: center;
  396. border-radius: 20rpx;
  397. }
  398. }
  399. }
  400. .wanted-block{
  401. margin-top: 30rpx;
  402. .header{
  403. font-size: 32rpx;
  404. padding: 30rpx;
  405. }
  406. .list{
  407. display: flex;
  408. flex-wrap: wrap;
  409. view{
  410. width: 50%;
  411. color: #8A8A8A;
  412. font-size: 28rpx;
  413. box-sizing: border-box;
  414. text-align: center;
  415. padding: 20rpx 0;
  416. border-top: 2rpx solid #FFF;
  417. border-left: 2rpx solid #FFF;
  418. background-color: #F7F7F7;
  419. overflow: hidden;
  420. white-space: nowrap;
  421. text-overflow: ellipsis;
  422. }
  423. }
  424. }
  425. .wanted-circle{
  426. margin-top: 30rpx;
  427. .header{
  428. font-size: 32rpx;
  429. padding: 30rpx;
  430. }
  431. .list{
  432. display: flex;
  433. flex-wrap: wrap;
  434. padding: 0 30rpx 20rpx;
  435. view{
  436. padding: 8rpx 30rpx;
  437. margin: 20rpx 30rpx 0 0;
  438. font-size: 28rpx;
  439. color: #8A8A8A;
  440. background-color: #F7F7F7;
  441. box-sizing: border-box;
  442. text-align: center;
  443. border-radius: 20rpx;
  444. }
  445. }
  446. }
  447. .commodity-list-wrapper {
  448. scroll-view {
  449. height: 100%;
  450. }
  451. .empty-container-image {
  452. margin-top: -300rpx;
  453. }
  454. .toIndexPage {
  455. bottom: 390rpx;
  456. }
  457. .show-more-btn {
  458. width: 276rpx;
  459. height: 52rpx;
  460. line-height: 52rpx;
  461. border: 2rpx solid #D8D8D8;
  462. background: #F7F7F7;
  463. font-size: 26rpx;
  464. margin: 26rpx 0;
  465. position: absolute;
  466. left: 50%;
  467. margin-left: -138rpx;
  468. }
  469. }
  470. .all-type-list-content {
  471. height: 216rpx;
  472. padding: 24rpx;
  473. background: #fff;
  474. margin-bottom: 2rpx;
  475. display: flex;
  476. flex-direction: row;
  477. box-sizing: content-box;
  478. .list-img {
  479. width: 210rpx;
  480. height: 218rpx !important;
  481. margin-right: 26rpx;
  482. border-radius: 10rpx;
  483. border: 2rpx solid #f3f3f3;
  484. }
  485. }
  486. .list-details-info {
  487. width: 466rpx;
  488. display: flex;
  489. flex-direction: column;
  490. font-size: 26rpx;
  491. position: relative;
  492. .list-details-title {
  493. line-height: 38rpx;
  494. text-overflow: ellipsis;
  495. overflow: hidden;
  496. display: -webkit-box;
  497. -webkit-line-clamp: 2;
  498. line-clamp: 2;
  499. -webkit-box-orient: vertical;
  500. }
  501. .list-details-specs {
  502. margin-top: 8rpx;
  503. color: #999999;
  504. }
  505. .list-details-miniQuantity {
  506. margin-top: 7rpx;
  507. }
  508. }
  509. .list-details-price {
  510. width: 100%;
  511. display: flex;
  512. flex-direction: row;
  513. justify-content: space-between;
  514. position: absolute;
  515. bottom: 0;
  516. right: 0;
  517. .price-icon {
  518. width: 22rpx;
  519. height: 28rpx;
  520. vertical-align: middle;
  521. margin-right: 10rpx;
  522. }
  523. .price-icon + text {
  524. font-size: 25rpx;
  525. vertical-align: middle;
  526. }
  527. .list-login-now {
  528. color: #F8C499;
  529. position: absolute;
  530. bottom: 0;
  531. }
  532. .login-now {
  533. padding: 10rpx 10rpx 10rpx 0;
  534. }
  535. .list-price {
  536. color: #FF2A2A;
  537. .price-larger {
  538. font-size: 32rpx;
  539. }
  540. }
  541. }
  542. </style>