coupon.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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"
  47. :data-coupon="coupon">
  48. 分享领取
  49. </button>
  50. </view>
  51. </view>
  52. </view>
  53. <view class="list-cell-time">{{ coupon.startDate }} - {{ coupon.endDate }}</view>
  54. </view>
  55. </view>
  56. <!--加载loadding-->
  57. <tui-loadmore :visible="loadding" :index="3" type="black" />
  58. <tui-nomore :visible="!pullUpOn" :backgroundColor="'#F7F7F7'" :text="nomoreText" />
  59. <!--加载loadding-->
  60. </template>
  61. <view class="empty-container" v-else>
  62. <image class="empty-container-image" :src="StaticUrl + '/icon/icon-coupon-empty@2x.png'"></image>
  63. <text class="error-text">暂无优惠券~</text>
  64. </view>
  65. </view>
  66. </view>
  67. </template>
  68. <script>
  69. import { mapState, mapMutations } from 'vuex'
  70. import { COUPON_TEXT_MAP } from '@/utils/coupon.share.js'
  71. import couponTabs from '@/components/cm-module/coupon/tui-tabs.vue'
  72. export default {
  73. components: {
  74. couponTabs
  75. },
  76. data() {
  77. return {
  78. StaticUrl: this.$Static,
  79. isIphoneX: this.$store.state.isIphoneX,
  80. listQuery: {
  81. userId: 0,
  82. pageNum: 1,
  83. pageSize: 10
  84. },
  85. shareUserId:'',
  86. coupinList: [],
  87. skeletonShow: true,
  88. nomoreText: '上拉显示更多',
  89. hasNextPage: false,
  90. loadding: false,
  91. pullUpOn: true,
  92. pullFlag: true,
  93. isReceiveLoading: false, //领券操作状态
  94. }
  95. },
  96. onLoad() {
  97. uni.hideShareMenu()
  98. this.initGetStotage()
  99. },
  100. filters: {
  101. TypeFormat(value) {
  102. switch (value) {
  103. case 0:
  104. return '活动券'
  105. break
  106. case 1:
  107. return '品类券'
  108. break
  109. case 2:
  110. return '用户专享券'
  111. break
  112. case 3:
  113. return '店铺券'
  114. break
  115. case 4:
  116. return '新用户券'
  117. break
  118. }
  119. }
  120. },
  121. computed: {
  122. ...mapState(['hasLogin', 'userInfo', 'identity', 'isActivity'])
  123. },
  124. methods: {
  125. async initGetStotage() {
  126. const userInfo = await this.$api.getStorage()
  127. this.shareUserId = userInfo.userId
  128. this.QueryCouponList()
  129. setTimeout(() => {
  130. this.skeletonShow = false
  131. }, 500)
  132. },
  133. async QueryCouponList() {
  134. // 初始化查询优惠券列表
  135. try {
  136. this.coupinList = []
  137. this.listQuery.pageNum = 1
  138. const res = await this.ProductService.QueryCouponCollarList(this.listQuery)
  139. const data = res.data
  140. if (data.list && data.list.length > 0) {
  141. this.hasNextPage = data.hasNextPage
  142. this.coupinList = data.list
  143. this.pullFlag = false
  144. setTimeout(() => {
  145. this.pullFlag = true
  146. }, 500)
  147. if (this.hasNextPage) {
  148. this.pullUpOn = false
  149. this.nomoreText = '上拉显示更多'
  150. } else {
  151. if (this.coupinList.length < 8) {
  152. this.pullUpOn = true
  153. } else {
  154. this.pullUpOn = false
  155. this.loadding = false
  156. this.nomoreText = '已至底部'
  157. }
  158. }
  159. }
  160. } catch (error) {
  161. this.$util.msg(error.msg, 2000)
  162. }
  163. },
  164. async getOnReachBottomData() {
  165. // 上滑加载分页
  166. try {
  167. this.listQuery.pageNum += 1
  168. const res = await this.ProductService.QueryCouponCollarList(this.listQuery)
  169. const data = res.data
  170. if (data.list && data.list.length > 0) {
  171. this.hasNextPage = data.hasNextPage
  172. this.coupinList = this.coupinList.concat(data.list)
  173. this.pullFlag = false // 防上拉暴滑
  174. setTimeout(() => {
  175. this.pullFlag = true
  176. }, 500)
  177. if (this.hasNextPage) {
  178. this.pullUpOn = false
  179. this.nomoreText = '上拉显示更多'
  180. } else {
  181. this.pullUpOn = false
  182. this.loadding = false
  183. this.nomoreText = '已至底部'
  184. }
  185. }
  186. } catch (error) {
  187. this.$util.msg(error.msg, 2000)
  188. }
  189. },
  190. navigator(url) {
  191. this.$api.navigateTo(url)
  192. }
  193. },
  194. onShareAppMessage(res) {
  195. //分享购买优惠券
  196. const coupon = res.target.dataset.coupon
  197. if (res.from === 'button') {
  198. const randomIndex = Math.floor(Math.random() * COUPON_TEXT_MAP.length)
  199. const shareTitle = coupon.moneyCouponFlag === 1 ?
  200. `${coupon.moneyCouponPrice}抵${coupon.couponAmount},限时优惠券等您抢购~` :
  201. COUPON_TEXT_MAP[randomIndex]
  202. return {
  203. title: shareTitle,
  204. path: `pages/user/coupon/coupon-details?couponId=${coupon.couponId}&shareUserId=${this.shareUserId}`,
  205. imageUrl: '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>