discounts.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <view class="wrap">
  3. <view class="title">可用优惠券 <view class="title_i">{{allData.total}}张</view></view>
  4. <view class="discounts_list">
  5. <view class="discounts_item clear" @tap="select(item,index)" v-for="item,index in allData.arr" :key="index">
  6. <view class="item_lf">
  7. <view class="money">¥<view class="money_i">{{item.money}}</view></view>
  8. <view class="full">{{item.moneyTips}}</view>
  9. </view>
  10. <view class="middle">
  11. <view class="middle_title">{{item.name}}</view>
  12. <view class="open_shop">{{item.nameTips}}</view>
  13. <view class="open_shop">{{item.validity}}</view>
  14. </view>
  15. <view class="radio" v-if="item.active == 0">
  16. <image src="https://wx.fujinyangche.com/nvrnetwork/images/no_select.png"></image>
  17. </view>
  18. <view class="radio" v-if="item.active == 1">
  19. <image src="https://wx.fujinyangche.com/nvrnetwork/images/select.png"></image>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="footer">
  24. <button class="submit" @tap="confirm">确定</button>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. let app = getApp();
  30. import api from "../../../../api.js";
  31. export default {
  32. data() {
  33. return {
  34. total:'',//优惠券个数
  35. allData:null,//页面所有数据
  36. money:0,//计算优惠钱数
  37. ids:[],//所选择优惠券id
  38. }
  39. },
  40. onLoad() {
  41. this.getData();
  42. },
  43. methods: {
  44. //加载数据
  45. getData(){
  46. let data = {
  47. token:app.globalData.token,
  48. status:0
  49. }
  50. api.getUserAllDiscount(data).then((res)=>{
  51. console.log(res);
  52. this.allData = res.data.data;
  53. })
  54. },
  55. //优惠券选择
  56. select(item,index){
  57. let money = this.money;
  58. if(this.allData.arr[index].active == 0){
  59. money += item.money;
  60. if(money>300){
  61. uni.showToast({
  62. icon:'none',
  63. duration:2000,
  64. title:'所用优惠券金额不能大于300'
  65. })
  66. return false;
  67. }
  68. this.money = money;
  69. this.allData.arr[index].active = 1;
  70. this.ids.push(item.id);
  71. }else{
  72. this.allData.arr[index].active = 0;
  73. this.money -= item.money;
  74. this.ids.splice(index,1);
  75. }
  76. },
  77. //确定按钮
  78. confirm(){
  79. console.log(this.money,this.ids);
  80. let ids = this.ids;
  81. let disMoney = this.money;
  82. const pages = getCurrentPages();
  83. const prevPage = pages[pages.length - 2] // 上一页
  84. // 调用上一个页面的setData 方法,将数据存储
  85. prevPage.disMoney = disMoney;
  86. prevPage.ids = ids;
  87. uni.navigateBack({
  88. delta:1,
  89. })
  90. }
  91. }
  92. }
  93. </script>
  94. <style>
  95. page{
  96. width:100%;
  97. height:100%;
  98. padding:0 30rpx;
  99. box-sizing: border-box;
  100. background-color: #f9f9f9;
  101. }
  102. .title{
  103. font-size: 30rpx;
  104. color:#666666;
  105. margin:30rpx 0 30rpx 0;
  106. }
  107. .title_i{
  108. display: inline-block;
  109. color:#222222;
  110. font-weight: bold;
  111. }
  112. .discounts_list{
  113. width:100%;
  114. padding-bottom: 100rpx;
  115. overflow: hidden;
  116. }
  117. .discounts_item{
  118. height:186rpx;
  119. margin-bottom: 20rpx;
  120. background-color:#ffffff;
  121. }
  122. .item_lf{
  123. width:200rpx;
  124. height:186rpx;
  125. float:left;
  126. position: relative;
  127. background-image: url('http://web.jzdsh.com/images/card01.png');
  128. background-size: 100% 100%;
  129. background-repeat: no-repeat;
  130. }
  131. .money{
  132. color:#ffffff;
  133. font-size: 32rpx;
  134. font-weight: bold;
  135. text-align: center;
  136. margin-top:32rpx;
  137. }
  138. .money_i{
  139. font-size: 64rpx;
  140. display: inline-block;
  141. }
  142. .full{
  143. text-align: center;
  144. font-size: 22rpx;
  145. color:#ffffff;
  146. }
  147. .middle{
  148. width:50%;
  149. height:186rpx;
  150. float:left;
  151. padding:28rpx 0 26rpx 20rpx;
  152. box-sizing: border-box;
  153. }
  154. .middle_title{
  155. font-size: 32rpx;
  156. color:#333333;
  157. font-weight: bold;
  158. }
  159. .open_shop{
  160. font-size: 22rpx;
  161. color:#A4A4A7;
  162. margin-top:12rpx;
  163. }
  164. .radio{
  165. width:40rpx;
  166. height:40rpx;
  167. float:right;
  168. margin: 74rpx 30rpx 0 0;
  169. }
  170. .radio image{
  171. display: block;
  172. width:100%;
  173. height:100%;
  174. }
  175. .footer{
  176. width:100%;
  177. height:100rpx;
  178. background:rgba(255,255,255,1);
  179. box-shadow:0px 4rpx 8rpx 0px rgba(0,0,0,0.5);
  180. position: fixed;
  181. bottom:0;
  182. left:0;
  183. }
  184. .submit{
  185. width:690rpx;
  186. height:80rpx;
  187. background:linear-gradient(270deg,rgba(254,107,21,1) 0%,rgba(254,163,48,1) 100%);
  188. border-radius:40rpx;
  189. text-align: center;
  190. font-size: 32rpx;
  191. color:#ffffff;
  192. position: absolute;
  193. top:10rpx;
  194. left:50%;
  195. transform: translateX(-50%)
  196. }
  197. </style>