coupon.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <template>
  2. <view class="container clearfix">
  3. <tui-skeleton v-if="skeletonShow" backgroundColor="#fafafa" borderRadius="10rpx" :isLoading="true"
  4. :loadingType="5" />
  5. <view class="container-list" v-else>
  6. <template v-if="coupinList.length > 0">
  7. <view v-for="(coupon, index) in coupinList" :key="index" :id="coupon.id" class="coupon-list">
  8. <view class="list-cell-le">
  9. <view class="coupon-maxMoney"> <text class="small">¥</text> {{ coupon.couponAmount }} </view>
  10. <view class="coupon-minMoney"> 满{{ coupon.touchPrice }}可用 </view>
  11. </view>
  12. <view class="list-cell-ri">
  13. <view class="list-cell-top">
  14. <view class="list-cell-type">
  15. <view class="list-cell-tags">
  16. <template v-if="coupon.moneyCouponFlag == 1">
  17. <text class="tags"
  18. v-if="coupon.moneyCouponType == 1">意向{{ coupon.couponType | TypeFormat }}</text>
  19. <text class="tags" v-else>定向{{ coupon.couponType | TypeFormat }}</text>
  20. </template>
  21. <template v-else>
  22. <text class="tags">{{ coupon.couponType | TypeFormat }}</text>
  23. </template>
  24. </view>
  25. <view class="list-cell-texts">
  26. <text v-if="coupon.couponType == 0">
  27. {{
  28. coupon.productType && coupon.productType == 1
  29. ? '全商城商品通用'
  30. : '仅可购买指定商品'
  31. }}
  32. </text>
  33. <text v-if="coupon.couponType == 1">
  34. {{ coupon.categoryType == 1 ? '仅限购买产品类商品' : '仅限购买仪器类商品' }}
  35. </text>
  36. <text v-if="coupon.couponType == 3">仅限购买店铺【{{ coupon.shopName }}】的商品</text>
  37. <text v-if="coupon.couponType == 4 || coupon.couponType == 2">全商城商品通用</text>
  38. </view>
  39. </view>
  40. <view class="list-cell-btn">
  41. <view class="icon-used">
  42. <button v-if="coupon.moneyCouponFlag === 1" open-type="share"
  43. class="icon-used-btn receive" :data-coupon="coupon">
  44. 分享购买
  45. </button>
  46. <button v-else open-type="share" class="icon-used-btn share" :data-coupon="coupon">
  47. 分享领取
  48. </button>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="list-cell-time">{{ coupon.startDate }} - {{ coupon.endDate }}</view>
  53. </view>
  54. </view>
  55. <!--加载loadding-->
  56. <tui-loadmore :visible="loadding" :index="3" type="black" />
  57. <tui-nomore :visible="!pullUpOn" :backgroundColor="'#F7F7F7'" :text="nomoreText" />
  58. <!--加载loadding-->
  59. </template>
  60. <view class="empty-container" v-else>
  61. <image class="empty-container-image" :src="StaticUrl + '/icon/icon-coupon-empty@2x.png'"></image>
  62. <text class="error-text">暂无优惠券~</text>
  63. </view>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import { mapState, mapMutations } from 'vuex'
  69. import { COUPON_TEXT_MAP } from '@/utils/coupon.share.js'
  70. import couponTabs from '@/components/cm-module/coupon/tui-tabs.vue'
  71. export default {
  72. components: {
  73. couponTabs
  74. },
  75. data() {
  76. return {
  77. StaticUrl: this.$Static,
  78. isIphoneX: this.$store.state.isIphoneX,
  79. listQuery: {
  80. userId: 0,
  81. pageNum: 1,
  82. pageSize: 10
  83. },
  84. shareUserId: '',
  85. coupinList: [],
  86. skeletonShow: true,
  87. nomoreText: '上拉显示更多',
  88. hasNextPage: false,
  89. loadding: false,
  90. pullUpOn: true,
  91. pullFlag: true,
  92. isReceiveLoading: false, //领券操作状态
  93. }
  94. },
  95. onLoad() {
  96. uni.hideShareMenu()
  97. this.initGetStotage()
  98. },
  99. filters: {
  100. TypeFormat(value) {
  101. switch (value) {
  102. case 0:
  103. return '活动券'
  104. break
  105. case 1:
  106. return '品类券'
  107. break
  108. case 2:
  109. return '用户专享券'
  110. break
  111. case 3:
  112. return '店铺券'
  113. break
  114. case 4:
  115. return '新用户券'
  116. break
  117. }
  118. }
  119. },
  120. computed: {
  121. ...mapState(['hasLogin', 'userInfo', 'identity', 'isActivity'])
  122. },
  123. methods: {
  124. async initGetStotage() {
  125. const userInfo = await this.$api.getStorage()
  126. this.shareUserId = userInfo.userId
  127. this.QueryCouponList()
  128. setTimeout(() => {
  129. this.skeletonShow = false
  130. }, 500)
  131. },
  132. async QueryCouponList() {
  133. // 初始化查询优惠券列表
  134. try {
  135. this.coupinList = []
  136. this.listQuery.pageNum = 1
  137. const res = await this.ProductService.QueryCouponCollarList(this.listQuery)
  138. const data = res.data
  139. if (data.list && data.list.length > 0) {
  140. this.hasNextPage = data.hasNextPage
  141. this.coupinList = data.list
  142. this.pullFlag = false
  143. setTimeout(() => {
  144. this.pullFlag = true
  145. }, 500)
  146. if (this.hasNextPage) {
  147. this.pullUpOn = false
  148. this.nomoreText = '上拉显示更多'
  149. } else {
  150. if (this.coupinList.length < 8) {
  151. this.pullUpOn = true
  152. } else {
  153. this.pullUpOn = false
  154. this.loadding = false
  155. this.nomoreText = '已至底部'
  156. }
  157. }
  158. }
  159. } catch (error) {
  160. this.$util.msg(error.msg, 2000)
  161. }
  162. },
  163. async getOnReachBottomData() {
  164. // 上滑加载分页
  165. try {
  166. this.listQuery.pageNum += 1
  167. const res = await this.ProductService.QueryCouponCollarList(this.listQuery)
  168. const data = res.data
  169. if (data.list && data.list.length > 0) {
  170. this.hasNextPage = data.hasNextPage
  171. this.coupinList = this.coupinList.concat(data.list)
  172. this.pullFlag = false // 防上拉暴滑
  173. setTimeout(() => {
  174. this.pullFlag = true
  175. }, 500)
  176. if (this.hasNextPage) {
  177. this.pullUpOn = false
  178. this.nomoreText = '上拉显示更多'
  179. } else {
  180. this.pullUpOn = false
  181. this.loadding = false
  182. this.nomoreText = '已至底部'
  183. }
  184. }
  185. } catch (error) {
  186. this.$util.msg(error.msg, 2000)
  187. }
  188. },
  189. navigator(url) {
  190. this.$api.navigateTo(url)
  191. }
  192. },
  193. onShareAppMessage(res) {
  194. //分享购买优惠券
  195. const coupon = res.target.dataset.coupon
  196. if (res.from === 'button') {
  197. const randomIndex = Math.floor(Math.random() * COUPON_TEXT_MAP.length)
  198. const shareTitle = coupon.moneyCouponFlag === 1 ?
  199. `${coupon.moneyCouponPrice}抵${coupon.couponAmount},限时优惠券等您抢购~` :
  200. COUPON_TEXT_MAP[randomIndex]
  201. return {
  202. title: coupon.shareCouponTopic ? `${coupon.shareCouponTopic}` : shareTitle,
  203. path: `pages/user/coupon/coupon-details?couponId=${coupon.couponId}&shareUserId=${this.shareUserId}`,
  204. imageUrl: coupon.shareCouponImage ? `${coupon.shareCouponImage}` :
  205. 'https://static.caimei365.com/app/img/icon/icon-shareCoupon@2x.png'
  206. }
  207. }
  208. },
  209. onPullDownRefresh() {
  210. setTimeout(() => {
  211. this.QueryCouponList()
  212. uni.stopPullDownRefresh()
  213. }, 200)
  214. },
  215. onReachBottom() {
  216. if (this.hasNextPage) {
  217. this.loadding = true
  218. this.pullUpOn = true
  219. this.getOnReachBottomData()
  220. }
  221. },
  222. onShow() {}
  223. }
  224. </script>
  225. <style lang="scss">
  226. page {
  227. background-color: #f7f7f7;
  228. }
  229. .container {
  230. width: 100%;
  231. height: auto;
  232. }
  233. .container-list {
  234. box-sizing: border-box;
  235. padding: 24rpx;
  236. .empty-container-image {
  237. width: 260rpx;
  238. height: 260rpx;
  239. margin-top: -300rpx;
  240. }
  241. .toIndexPage {
  242. bottom: 390rpx;
  243. }
  244. .coupon-list {
  245. width: 100%;
  246. height: 200rpx;
  247. margin-bottom: 24rpx;
  248. box-sizing: border-box;
  249. background: url(https://static.caimei365.com/app/img/icon/icon-coupon-uesb@2x.png);
  250. background-size: cover;
  251. position: relative;
  252. .list-cell-le {
  253. width: 224rpx;
  254. height: 100%;
  255. box-sizing: border-box;
  256. padding: 37rpx 0;
  257. float: left;
  258. .coupon-maxMoney {
  259. width: 100%;
  260. height: 78rpx;
  261. line-height: 78rpx;
  262. font-size: 56rpx;
  263. color: #ffffff;
  264. text-align: center;
  265. .small {
  266. font-size: $font-size-24;
  267. }
  268. }
  269. .coupon-minMoney {
  270. width: 100%;
  271. height: 33rpx;
  272. line-height: 33rpx;
  273. font-size: $font-size-24;
  274. color: #ffffff;
  275. text-align: center;
  276. }
  277. }
  278. .list-cell-ri {
  279. width: 478rpx;
  280. height: 100%;
  281. box-sizing: border-box;
  282. padding: 20rpx 24rpx 0 24rpx;
  283. float: right;
  284. .list-cell-top {
  285. width: 100%;
  286. height: 121rpx;
  287. float: left;
  288. border-bottom: 1px solid #e1e1e1;
  289. .list-cell-type {
  290. width: 286rpx;
  291. height: 100%;
  292. float: left;
  293. .list-cell-tags {
  294. width: 100%;
  295. height: 32rpx;
  296. margin-bottom: 7rpx;
  297. .tags {
  298. display: inline-block;
  299. padding: 0 10rpx;
  300. height: 32rpx;
  301. line-height: 32rpx;
  302. background-color: #ffdcce;
  303. color: #f94b4b;
  304. font-size: $font-size-20;
  305. border-radius: 8rpx;
  306. text-align: center;
  307. float: left;
  308. }
  309. }
  310. .list-cell-texts {
  311. width: 100%;
  312. height: auto;
  313. line-height: 35rpx;
  314. text-overflow: ellipsis;
  315. display: -webkit-box;
  316. word-break: break-all;
  317. -webkit-box-orient: vertical;
  318. -webkit-line-clamp: 2;
  319. overflow: hidden;
  320. font-size: 26rpx;
  321. color: #333333;
  322. }
  323. }
  324. .list-cell-btn {
  325. width: 128rpx;
  326. height: 100%;
  327. float: right;
  328. .icon-used {
  329. width: 100%;
  330. height: 100%;
  331. box-sizing: border-box;
  332. padding-top: 57rpx;
  333. .icon-used-btn {
  334. width: 128rpx;
  335. height: 48rpx;
  336. border-radius: 28rpx;
  337. line-height: 48rpx;
  338. font-size: $font-size-24;
  339. text-align: center;
  340. &.receive {
  341. background-image: linear-gradient(270deg, #f94b4b 0%, #feb673 100%);
  342. color: #ffffff;
  343. }
  344. &.share {
  345. background-image: linear-gradient(315deg, #6772FF 0, #00F9E5 100%);
  346. color: #ffffff;
  347. }
  348. }
  349. }
  350. }
  351. }
  352. .list-cell-time {
  353. width: 100%;
  354. height: 58rpx;
  355. line-height: 58rpx;
  356. text-align: left;
  357. font-size: $font-size-20;
  358. color: #999999;
  359. }
  360. }
  361. }
  362. }
  363. </style>