index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <app-layout>
  3. <app-tab-nav :tabList="tabList" :activeItem="activeTab" @click="tabStatus" :theme="theme"></app-tab-nav>
  4. <view v-if="list.length == 0" class="tip">暂无相关优惠券</view>
  5. <view v-else class="list">
  6. <view @click="toDetail(item.id)" v-for="item in list" :key="item.id">
  7. <view class="list-item">
  8. <image src="./../image/img-coupon-bg-0.png" v-if="activeTab == 1"></image>
  9. <image src="./../image/img-coupon-bg-1.png" v-else></image>
  10. <image class="status" src="./../image/img-coupon-status-icon-1.png" v-if="activeTab == 2"></image>
  11. <image class="status" src="./../image/img-coupon-status-icon-2.png" v-if="activeTab == 3"></image>
  12. <view class="item-left dir-top-nowrap main-center">
  13. <view class="coupon-price t-omit" v-if="item.coupon.type == 2">¥{{item.coupon.sub_price | reservedNum}}</view>
  14. <view class="coupon-price t-omit" v-else>{{item.coupon.discount | reservedNum}}折</view>
  15. <view style="font-size: 10px" class="t-omit" v-if="item.coupon_min_price > 0">满{{item.coupon_min_price | reservedNum}}可用</view>
  16. <view style="font-size: 10px" v-else>无门槛使用</view>
  17. <view style="font-size: 10px" v-if="item.discount_limit">优惠上限:¥{{item.discount_limit | reservedNum}}</view>
  18. </view>
  19. <view class="item-right">
  20. <view class="item-name t-omit t-large t-large-color">{{item.coupon.name}}</view>
  21. <view class="t-small-color time-area">{{item.start_time}}~{{item.end_time}}</view>
  22. <view v-if="item.coupon.appoint_type == 3">全场通用</view>
  23. <view v-else-if="item.coupon.appoint_type == 4">仅限当面付活动使用</view>
  24. <view v-else>限品类</view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. <view :class="[`footer-space`,iphone_x? `iphone_x`:``]"></view>
  30. <view :class="[`coupon-footer`,iphone_x? `iphone_x`:``]" @click="toList">去领券</view>
  31. </app-layout>
  32. </template>
  33. <script>
  34. import appTabNav from "../../../components/basic-component/app-tab-nav/app-tab-nav.vue";
  35. import { mapState } from "vuex";
  36. export default {
  37. data() {
  38. return {
  39. list: [],
  40. iphone_x: false,
  41. tabList: [
  42. {id:1, name: '未使用'},
  43. {id:2, name: '已使用'},
  44. {id:3, name: '已过期'}
  45. ],
  46. activeTab: 1,
  47. first: false,
  48. page: 2,
  49. }
  50. },
  51. components: {
  52. "app-tab-nav": appTabNav
  53. },
  54. computed: {
  55. ...mapState({
  56. theme: state => state.mallConfig.theme,
  57. })
  58. },
  59. methods: {
  60. tabStatus(e) {
  61. this.list = [];
  62. this.page = 2;
  63. this.activeTab = e.currentTarget.dataset.id;
  64. uni.showLoading({
  65. title: '加载中...'
  66. });
  67. this.getList();
  68. },
  69. getList() {
  70. let that = this;
  71. that.first = true;
  72. that.$request({
  73. url: that.$api.coupon.user_coupon,
  74. data: {
  75. status: that.activeTab
  76. }
  77. }).then(response=>{
  78. uni.hideLoading();
  79. that.$hideLoading();
  80. if(response.code == 0) {
  81. that.list = response.data.list;
  82. that.page = 2;
  83. }else {
  84. uni.showToast({
  85. title: response.msg,
  86. icon: 'none',
  87. duration: 1000
  88. });
  89. }
  90. }).catch(response => {
  91. uni.hideLoading();
  92. that.$hideLoading();
  93. that.$event.on(that.$const.EVENT_USER_LOGIN).then(()=>{
  94. that.getList();
  95. });
  96. });
  97. },
  98. getMore() {
  99. let that = this;
  100. uni.showLoading({
  101. title: '加载中...'
  102. });
  103. that.$request({
  104. url: that.$api.coupon.user_coupon,
  105. data: {
  106. status: that.activeTab,
  107. page: that.page
  108. }
  109. }).then(response=>{
  110. uni.hideLoading();
  111. if(response.code == 0) {
  112. if(response.data.list.length > 0) {
  113. that.list = that.list.concat(response.data.list);
  114. that.page++;
  115. }
  116. }else {
  117. uni.showToast({
  118. title: response.msg,
  119. icon: 'none',
  120. duration: 1000
  121. });
  122. }
  123. }).catch(e => {
  124. uni.hideLoading();
  125. });
  126. },
  127. toDetail(id) {
  128. uni.navigateTo({
  129. url: '/pages/coupon/details/details?person=1&id=' + id
  130. });
  131. },
  132. toList() {
  133. uni.navigateTo({
  134. url: '/pages/coupon/list/list'
  135. });
  136. },
  137. },
  138. onLoad() {
  139. let that = this;
  140. uni.getSystemInfo({
  141. success: function (res) {
  142. if(res.model.indexOf('iPhone X') > -1 || res.model.indexOf('iPhone 11') > -1 || res.model.indexOf('iPhone11') > -1 || res.model.indexOf('iPhone12') > -1 || res.model.indexOf('Unknown Device') > -1) {
  143. that.iphone_x = true;
  144. }
  145. }
  146. })
  147. that.$showLoading({
  148. text: '加载中...'
  149. });
  150. that.getList();
  151. },
  152. onShow() {
  153. if(this.first) {
  154. this.getList();
  155. }
  156. },
  157. onReachBottom() {
  158. this.getMore();
  159. },
  160. filters: {
  161. reservedNum(data) {
  162. return Number(data);
  163. }
  164. }
  165. }
  166. </script>
  167. <style scoped lang="scss">
  168. .footer-space {
  169. height: #{100rpx};
  170. }
  171. .footer-space.iphone_x {
  172. height: #{150rpx};
  173. }
  174. .time-area {
  175. padding:#{7rpx} 0;
  176. }
  177. .list {
  178. padding: #{32rpx} #{35rpx};
  179. background-color: #f7f7f7;
  180. }
  181. .list-item {
  182. height: #{152rpx};
  183. width: 100%;
  184. position: relative;
  185. margin-bottom: #{25rpx};
  186. }
  187. .list-item image {
  188. width: 100%;
  189. height: 100%;
  190. }
  191. .item-left {
  192. position: absolute;
  193. left: 0;
  194. top: 0;
  195. height:100%;
  196. width: #{190rpx};
  197. text-align: center;
  198. font-size: #{24rpx};
  199. color: #fff;
  200. padding-top: #{8rpx};
  201. }
  202. .coupon-price {
  203. font-size: #{36rpx};
  204. padding-bottom: #{16rpx};
  205. }
  206. .item-right {
  207. position: absolute;
  208. left: #{220rpx};
  209. top: #{15rpx};
  210. width: 65%;
  211. color: #6f6e6d;
  212. font-size: #{20rpx};
  213. }
  214. .item-name {
  215. font-size: #{32rpx};
  216. color: #353535;
  217. }
  218. .item-right view {
  219. margin-bottom: #{4rpx};
  220. }
  221. .coupon-footer {
  222. position: fixed;
  223. bottom: 0;
  224. left: 0;
  225. right: 0;
  226. width: 100%;
  227. height: #{100rpx};
  228. line-height: #{100rpx};
  229. text-align: center;
  230. background-color: #fff;
  231. z-index: 2;
  232. }
  233. .coupon-footer.iphone_x {
  234. height: #{150rpx};
  235. padding-bottom: #{50rpx};
  236. }
  237. .list-item .status {
  238. position: absolute;
  239. top: 0;
  240. right: 0;
  241. height: #{98rpx};
  242. width: #{140rpx};
  243. z-index: 2;
  244. }
  245. .tip {
  246. margin-top: 20%;
  247. text-align: center;
  248. color: #686868;
  249. }
  250. .t-omit {
  251. display: inline-block;
  252. white-space: nowrap;
  253. width: 100%;
  254. overflow: hidden;
  255. text-overflow: ellipsis;
  256. }
  257. .t-omit-two {
  258. word-break: break-all;
  259. text-overflow: ellipsis;
  260. display: -webkit-box;
  261. -webkit-box-orient: vertical;
  262. -webkit-line-clamp: 2;
  263. overflow: hidden;
  264. }
  265. </style>