coupon.vue 16 KB

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