goods-coupon-list-search.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <view class="good-coupon-list-search">
  3. <!-- 搜索 -->
  4. <view class="search">
  5. <sui-search
  6. placeholder="请输入商品关键词"
  7. :radius="30"
  8. :focus="true"
  9. class="sui-search"
  10. :value="inputValue"
  11. @search="searchBlur"
  12. @onFocus="searchFocus"
  13. @clear="searchClear"
  14. ></sui-search>
  15. <view class="search-btn" @click="handleSearch">搜索</view>
  16. </view>
  17. <!-- 历史关键词 -->
  18. <template v-if="serachRecordList.length > 0">
  19. <view class="history-keywords" v-show="resetType">
  20. <view class="line"></view>
  21. <view class="row history-title">
  22. <view class="title">搜索历史</view>
  23. <view class="iconfont icon-shanchu delete" @click="handleDetele"></view>
  24. </view>
  25. <view class="row keyword-list">
  26. <view
  27. class="keyword"
  28. v-for="(keyword, index) in serachRecordList"
  29. :key="index"
  30. @click="keywordsClick(keyword)"
  31. >{{ keyword }}
  32. </view>
  33. </view>
  34. </view>
  35. </template>
  36. <!-- 列表为空 -->
  37. <cm-empty
  38. v-if="productList.length <= 0 && !resetType"
  39. message="暂无搜索结果~"
  40. :image="baseUrl + 'icon-empty-search.png'"
  41. :offset="90"
  42. ></cm-empty>
  43. <!-- 商品列表 -->
  44. <view class="product-list" v-show="!resetType">
  45. <view class="product" v-for="(product, index) in productList" :key="index">
  46. <image class="product-image" :src="product.mainImage"></image>
  47. <view class="product-info">
  48. <view class="name tui-ellipsis-2">{{ product.name }}</view>
  49. <view class="unit">规格:{{ product.unit }}</view>
  50. <view class="tags">
  51. <text class="tag type2" v-if="product.activeStatus === 1">活动价</text>
  52. <text class="tag type2" v-if="product.couponsLogo">优惠券</text>
  53. </view>
  54. <view class="footer">
  55. <view class="price">¥{{ product.price | priceFormat }}</view>
  56. <text class="carts-add iconfont icon-gouwuche" @click.stop="handAddCarts(product)"></text>
  57. </view>
  58. </view>
  59. </view>
  60. <!-- 加载更多 -->
  61. <template v-if="productList.length > 6">
  62. <tui-loadmore :index="2" :visible="isRequest"></tui-loadmore>
  63. <tui-nomore :text="loadingText" :visible="!isRequest" backgroundColor="#fff"></tui-nomore>
  64. </template>
  65. </view>
  66. <!-- 侧边 -->
  67. <scroll-top :isScrollTop="isScrollTop" :bottom="160"></scroll-top>
  68. <!-- 可拖动悬浮按钮 -->
  69. <cm-drag :cartNum="kindCount" :isDock="true" :existTabBar="true" @btnClick="btnClick"> </cm-drag>
  70. <!-- 操作弹窗 -->
  71. <tui-modal
  72. :show="showModal"
  73. @click="handleConfirm"
  74. @cancel="showModal = false"
  75. :content="contentModalText"
  76. color="#333"
  77. :size="32"
  78. shape="circle"
  79. :maskClosable="false"
  80. ></tui-modal>
  81. </view>
  82. </template>
  83. <script>
  84. import SuiSearch from '@/components/sui-search/sui-search.vue'
  85. import CmEmpty from '@/components/cm-module/cm-empty/cm-empty.vue'
  86. import CmDrag from '@/components/cm-module/cm-drag/cm-drag'
  87. import { mapGetters, mapActions } from 'vuex'
  88. export default {
  89. components: {
  90. SuiSearch,
  91. CmEmpty,
  92. CmDrag
  93. },
  94. data() {
  95. return {
  96. baseUrl: this.$Static,
  97. showModal: false,
  98. productList: [], //商品列表
  99. serachRecordList: [],
  100. listQuery: {
  101. userId: '',
  102. couponId: 48,
  103. pageNum: 1,
  104. pageSize: 10,
  105. productName: ''
  106. },
  107. inputValue: '',
  108. hasNextPage: false,
  109. isScrollTop: false,
  110. isRequest: true,
  111. timer: null,
  112. isSticky: false,
  113. isFocus: true,
  114. resetType: true, // true 重新搜索 false 上拉加载
  115. contentModalText: '确定删除历史记录?'
  116. }
  117. },
  118. computed: {
  119. ...mapGetters(['hasLogin', 'userInfo', 'userId', 'kindCount']),
  120. loadingText() {
  121. return this.hasNextPage ? '上拉加载' : '没有更多了'
  122. }
  123. },
  124. // 监听页面滚动事件
  125. onPageScroll(e) {
  126. this.isSticky = e.scrollTop > 0
  127. this.isScrollTop = e.scrollTop > 400
  128. },
  129. onReachBottom() {
  130. if (!this.hasNextPage) return
  131. clearTimeout(this.timer)
  132. this.timer = setTimeout(() => {
  133. console.log('触底了')
  134. this.fetchProductList()
  135. }, 200)
  136. },
  137. onReady() {
  138. this.getetSerachRecord()
  139. },
  140. methods: {
  141. ...mapActions('cart', ['addToCart']),
  142. // 获取商品列表
  143. fetchProductList() {
  144. this.listQuery.userId = this.userId
  145. this.CouponService.ProductInfoByCoupon(this.listQuery)
  146. .then(response => {
  147. let data = response.data
  148. if (this.resetType) {
  149. this.productList = data.list
  150. } else {
  151. this.productList = [...this.productList, ...data.list]
  152. }
  153. this.hasNextPage = data.hasNextPage
  154. this.listQuery.pageNum++
  155. this.resetType = false
  156. this.isRequest = false
  157. })
  158. .catch(error => {
  159. this.$util.msg(error.msg, 2000)
  160. })
  161. },
  162. //查询搜索历史记录
  163. getetSerachRecord() {
  164. this.ProductService.GetProductSearchHistory({ userId: this.userId }).then(response => {
  165. if (response.code == 0) {
  166. this.serachRecordList = response.data
  167. }
  168. })
  169. },
  170. // 搜索按钮事件
  171. handleSearch() {
  172. if (!this.listQuery.productName) return this.$util.msg('商品名称不能为空', 2000)
  173. this.listQuery.pageNum = 1
  174. this.productList = []
  175. this.fetchProductList()
  176. },
  177. // 点击关键词
  178. keywordsClick(keyword) {
  179. this.listQuery.productName = keyword
  180. this.inputValue = keyword
  181. this.handleSearch()
  182. },
  183. // 加入购物车
  184. handAddCarts(product) {
  185. this.addToCart({ productId: product.productId })
  186. },
  187. // 跳转购物车
  188. btnClick() {
  189. this.$api.navigateTo('/pages/goods/cart')
  190. },
  191. // 搜索框失去焦点
  192. searchBlur(val) {
  193. console.log('失去焦点')
  194. this.listQuery.productName = val
  195. this.isFocus = false
  196. },
  197. // 搜索框获取焦点
  198. searchFocus() {
  199. console.log('获取焦点')
  200. this.getetSerachRecord()
  201. this.resetType = true // 重新搜索
  202. this.isFocus = true
  203. },
  204. // 清空搜索
  205. searchClear() {
  206. this.inputValue = ''
  207. this.resetType = true // 重新搜索
  208. this.isFocus = true
  209. this.getetSerachRecord()
  210. },
  211. //清空历史记录
  212. handleDetele() {
  213. this.showModal = true
  214. },
  215. // 确认事件
  216. handleConfirm(e) {
  217. if (e.index === 1) this.removeAllKeywords()
  218. this.showModal = false
  219. },
  220. // 清空关键词
  221. removeAllKeywords() {
  222. this.ProductService.GetDeleteProductSearchHistory({ userId: this.userId })
  223. .then(response => {
  224. this.$util.msg('删除成功', 2000, true, 'success')
  225. this.serachRecordList = []
  226. })
  227. .catch(error => {
  228. this.$util.msg(error.msg, 2000)
  229. })
  230. }
  231. }
  232. }
  233. </script>
  234. <style lang="scss" scoped>
  235. .good-coupon-list-search {
  236. min-height: 100vh;
  237. padding-top: 124rpx;
  238. background: #f7f7f7;
  239. overflow: hidden;
  240. box-sizing: border-box;
  241. }
  242. .search {
  243. display: flex;
  244. position: fixed;
  245. justify-content: space-between;
  246. align-items: center;
  247. width: 100%;
  248. top: 0;
  249. left: 0;
  250. z-index: 999;
  251. padding-right: 24rpx;
  252. box-sizing: border-box;
  253. background: #fff;
  254. // &.fixed {
  255. // position: fixed;
  256. // }
  257. .sui-search {
  258. flex: 1;
  259. }
  260. .search-btn {
  261. font-size: 26rpx;
  262. color: #666;
  263. }
  264. }
  265. .history-keywords {
  266. background: #fff;
  267. // padding: 0 24rpx;
  268. .line {
  269. height: 1rpx;
  270. margin: 0 24rpx;
  271. background: #e1e1e1;
  272. }
  273. .history-title {
  274. margin: 48rpx 24rpx 24rpx;
  275. display: flex;
  276. justify-content: space-between;
  277. align-items: center;
  278. .title {
  279. height: 42rpx;
  280. line-height: 42rpx;
  281. font-size: 30rpx;
  282. font-weight: bold;
  283. color: #333333;
  284. }
  285. .delete {
  286. width: 32rpx;
  287. height: 32rpx;
  288. font-size: 32rpx;
  289. color: #999999;
  290. }
  291. }
  292. .keyword-list {
  293. display: flex;
  294. flex-wrap: wrap;
  295. align-items: center;
  296. padding: 0 12rpx;
  297. .keyword {
  298. height: 44rpx;
  299. padding: 0 12rpx;
  300. margin: 24rpx 12rpx;
  301. font-size: 26rpx;
  302. line-height: 44rpx;
  303. border-radius: 22rpx;
  304. color: #999999;
  305. text-align: center;
  306. background: #f7f7f7;
  307. }
  308. }
  309. }
  310. .product-list {
  311. padding: 0 24rpx;
  312. background: #fff;
  313. overflow: hidden;
  314. .product {
  315. display: flex;
  316. justify-content: space-between;
  317. align-items: center;
  318. padding: 32rpx 0;
  319. border-bottom: 1px solid #e1e1e1;
  320. overflow: hidden;
  321. &:last-child {
  322. border-bottom: 0;
  323. }
  324. .product-image {
  325. display: block;
  326. width: 180rpx;
  327. height: 180rpx;
  328. border-radius: 8rpx;
  329. border: 1px solid #e1e1e1;
  330. border-radius: 8rpx;
  331. box-sizing: border-box;
  332. }
  333. .product-info {
  334. width: 495rpx;
  335. .name {
  336. height: 72rpx;
  337. line-height: 36rpx;
  338. font-size: $font-size-26;
  339. color: #333333;
  340. text-align: justify;
  341. }
  342. .unit,
  343. .tags,
  344. .footer {
  345. margin-top: 8rpx;
  346. }
  347. .unit {
  348. width: 100%;
  349. height: 28rpx;
  350. text-align: left;
  351. line-height: 28rpx;
  352. font-size: $font-size-20;
  353. color: #999999;
  354. }
  355. .tags {
  356. display: flex;
  357. justify-content: flex-start;
  358. align-items: center;
  359. width: 100%;
  360. height: 30rpx;
  361. .tag {
  362. margin-right: 8rpx;
  363. font-size: 22rpx;
  364. height: 30rpx;
  365. line-height: 30rpx;
  366. text-align: center;
  367. &.type2 {
  368. width: 80rpx;
  369. color: #f83c6c;
  370. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-active.png) top center
  371. no-repeat;
  372. background-size: contain;
  373. }
  374. }
  375. }
  376. .footer {
  377. display: flex;
  378. justify-content: space-between;
  379. align-items: flex-end;
  380. height: $font-size-26;
  381. .price {
  382. font-size: $font-size-26;
  383. color: #f83c6c;
  384. font-weight: bold;
  385. line-height: $font-size-26;
  386. }
  387. .carts-add {
  388. width: 44rpx;
  389. height: 44rpx;
  390. line-height: 44rpx;
  391. border-radius: 50%;
  392. text-align: center;
  393. font-size: 32rpx;
  394. color: #ffffff;
  395. background-color: #ff457b;
  396. }
  397. }
  398. }
  399. }
  400. }
  401. </style>