goods-coupon-list-search.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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. filters: {
  119. priceFormat: function(price) {
  120. //处理金额
  121. return Number(price).toFixed(2)
  122. }
  123. },
  124. computed: {
  125. ...mapGetters(['hasLogin', 'userInfo', 'userId', 'kindCount']),
  126. loadingText() {
  127. return this.hasNextPage ? '上拉加载' : '没有更多了'
  128. }
  129. },
  130. // 监听页面滚动事件
  131. onPageScroll(e) {
  132. this.isSticky = e.scrollTop > 0
  133. this.isScrollTop = e.scrollTop > 400
  134. },
  135. onReachBottom() {
  136. if (!this.hasNextPage) return
  137. clearTimeout(this.timer)
  138. this.timer = setTimeout(() => {
  139. console.log('触底了')
  140. this.fetchProductList()
  141. }, 200)
  142. },
  143. onReady() {
  144. this.getetSerachRecord()
  145. },
  146. methods: {
  147. ...mapActions('cart', ['addToCart']),
  148. // 获取商品列表
  149. fetchProductList() {
  150. this.listQuery.userId = this.userId
  151. this.CouponService.ProductInfoByCoupon(this.listQuery)
  152. .then(response => {
  153. let data = response.data
  154. if (this.resetType) {
  155. this.productList = data.list
  156. } else {
  157. this.productList = [...this.productList, ...data.list]
  158. }
  159. this.hasNextPage = data.hasNextPage
  160. this.listQuery.pageNum++
  161. this.resetType = false
  162. this.isRequest = false
  163. })
  164. .catch(error => {
  165. this.$util.msg(error.msg, 2000)
  166. })
  167. },
  168. //查询搜索历史记录
  169. getetSerachRecord() {
  170. this.ProductService.GetProductSearchHistory({ userId: this.userId }).then(response => {
  171. if (response.code == 0) {
  172. this.serachRecordList = response.data
  173. }
  174. })
  175. },
  176. // 搜索按钮事件
  177. handleSearch() {
  178. if (!this.listQuery.productName) return this.$util.msg('商品名称不能为空', 2000)
  179. this.listQuery.pageNum = 1
  180. this.productList = []
  181. this.fetchProductList()
  182. },
  183. // 点击关键词
  184. keywordsClick(keyword) {
  185. this.listQuery.productName = keyword
  186. this.inputValue = keyword
  187. this.handleSearch()
  188. },
  189. // 加入购物车
  190. handAddCarts(product) {
  191. this.addToCart({ productId: product.productId })
  192. },
  193. // 跳转购物车
  194. btnClick() {
  195. this.$api.navigateTo('/pages/goods/cart')
  196. },
  197. // 搜索框失去焦点
  198. searchBlur(val) {
  199. console.log('失去焦点')
  200. this.listQuery.productName = val
  201. this.isFocus = false
  202. },
  203. // 搜索框获取焦点
  204. searchFocus() {
  205. console.log('获取焦点')
  206. this.getetSerachRecord()
  207. this.resetType = true // 重新搜索
  208. this.isFocus = true
  209. },
  210. // 清空搜索
  211. searchClear() {
  212. this.inputValue = ''
  213. this.resetType = true // 重新搜索
  214. this.isFocus = true
  215. this.getetSerachRecord()
  216. },
  217. //清空历史记录
  218. handleDetele() {
  219. this.showModal = true
  220. },
  221. // 确认事件
  222. handleConfirm(e) {
  223. if (e.index === 1) this.removeAllKeywords()
  224. this.showModal = false
  225. },
  226. // 清空关键词
  227. removeAllKeywords() {
  228. this.ProductService.GetDeleteProductSearchHistory({ userId: this.userId })
  229. .then(response => {
  230. this.$util.msg('删除成功', 2000, true, 'success')
  231. this.serachRecordList = []
  232. })
  233. .catch(error => {
  234. this.$util.msg(error.msg, 2000)
  235. })
  236. }
  237. }
  238. }
  239. </script>
  240. <style lang="scss" scoped>
  241. .good-coupon-list-search {
  242. min-height: 100vh;
  243. padding-top: 124rpx;
  244. background: #f7f7f7;
  245. overflow: hidden;
  246. box-sizing: border-box;
  247. }
  248. .search {
  249. display: flex;
  250. position: fixed;
  251. justify-content: space-between;
  252. align-items: center;
  253. width: 100%;
  254. top: 0;
  255. left: 0;
  256. z-index: 999;
  257. padding-right: 24rpx;
  258. box-sizing: border-box;
  259. background: #fff;
  260. // &.fixed {
  261. // position: fixed;
  262. // }
  263. .sui-search {
  264. flex: 1;
  265. }
  266. .search-btn {
  267. font-size: 26rpx;
  268. color: #666;
  269. }
  270. }
  271. .history-keywords {
  272. background: #fff;
  273. // padding: 0 24rpx;
  274. .line {
  275. height: 1rpx;
  276. margin: 0 24rpx;
  277. background: #e1e1e1;
  278. }
  279. .history-title {
  280. margin: 48rpx 24rpx 24rpx;
  281. display: flex;
  282. justify-content: space-between;
  283. align-items: center;
  284. .title {
  285. height: 42rpx;
  286. line-height: 42rpx;
  287. font-size: 30rpx;
  288. font-weight: bold;
  289. color: #333333;
  290. }
  291. .delete {
  292. width: 32rpx;
  293. height: 32rpx;
  294. font-size: 32rpx;
  295. color: #999999;
  296. }
  297. }
  298. .keyword-list {
  299. display: flex;
  300. flex-wrap: wrap;
  301. align-items: center;
  302. padding: 0 12rpx;
  303. .keyword {
  304. height: 44rpx;
  305. padding: 0 12rpx;
  306. margin: 24rpx 12rpx;
  307. font-size: 26rpx;
  308. line-height: 44rpx;
  309. border-radius: 22rpx;
  310. color: #999999;
  311. text-align: center;
  312. background: #f7f7f7;
  313. }
  314. }
  315. }
  316. .product-list {
  317. padding: 0 24rpx;
  318. background: #fff;
  319. overflow: hidden;
  320. .product {
  321. display: flex;
  322. justify-content: space-between;
  323. align-items: center;
  324. padding: 32rpx 0;
  325. border-bottom: 1px solid #e1e1e1;
  326. overflow: hidden;
  327. &:last-child {
  328. border-bottom: 0;
  329. }
  330. .product-image {
  331. display: block;
  332. width: 180rpx;
  333. height: 180rpx;
  334. border-radius: 8rpx;
  335. border: 1px solid #e1e1e1;
  336. border-radius: 8rpx;
  337. box-sizing: border-box;
  338. }
  339. .product-info {
  340. width: 495rpx;
  341. .name {
  342. height: 72rpx;
  343. line-height: 36rpx;
  344. font-size: $font-size-26;
  345. color: #333333;
  346. text-align: justify;
  347. }
  348. .unit,
  349. .tags,
  350. .footer {
  351. margin-top: 8rpx;
  352. }
  353. .unit {
  354. width: 100%;
  355. height: 28rpx;
  356. text-align: left;
  357. line-height: 28rpx;
  358. font-size: $font-size-20;
  359. color: #999999;
  360. }
  361. .tags {
  362. display: flex;
  363. justify-content: flex-start;
  364. align-items: center;
  365. width: 100%;
  366. height: 30rpx;
  367. .tag {
  368. margin-right: 8rpx;
  369. font-size: 22rpx;
  370. height: 30rpx;
  371. line-height: 30rpx;
  372. text-align: center;
  373. &.type2 {
  374. width: 80rpx;
  375. color: #f83c6c;
  376. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-active.png) top center
  377. no-repeat;
  378. background-size: contain;
  379. }
  380. }
  381. }
  382. .footer {
  383. display: flex;
  384. justify-content: space-between;
  385. align-items: flex-end;
  386. height: $font-size-26;
  387. .price {
  388. font-size: $font-size-26;
  389. color: #f83c6c;
  390. font-weight: bold;
  391. line-height: $font-size-26;
  392. }
  393. .carts-add {
  394. width: 44rpx;
  395. height: 44rpx;
  396. line-height: 44rpx;
  397. border-radius: 50%;
  398. text-align: center;
  399. font-size: 32rpx;
  400. color: #ffffff;
  401. background-color: #ff457b;
  402. }
  403. }
  404. }
  405. }
  406. }
  407. </style>