search.vue 14 KB

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