myWelfare.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view>
  3. <view class="flex bg-white align-center">
  4. <view class="title padding-lr-sm">公益勋章</view>
  5. <view class="text-sm">共解锁12个勋章,相当于2500积分</view>
  6. </view>
  7. <view class="text-center grid col-3 container">
  8. <block v-for="(item, index) in welfareList" :key="index">
  9. <view class="padding-tb" @click="select(index)">
  10. <view>
  11. <image :src="item.image" style="width: 200upx;height: 200upx;"></image>
  12. <view :class="selectShow ? item.selected ? 'theme-color cuIcon-roundcheckfill': 'text-gray cuIcon-round' : 'text-white cuIcon-round'" style="position: relative;bottom: 230upx;left: 70upx;font-size: 50upx;"></view>
  13. </view>
  14. <view class="text-bold" style="margin-top: -50upx;" v-if="!selectShow">X{{item.count}}</view>
  15. <view class="justify-center flex align-center" style="margin-top: -50upx;" v-else>
  16. <view class="" @click.stop="minus(index)"> <u-icon name="minus-circle-fill" color="#5a3ee8" size="36"></u-icon> </view>
  17. <input type="number" class="text-center input" v-model="item.count" />
  18. <view class="" @click.stop="plus(index)"> <u-icon name="plus-circle-fill" color="#5a3ee8" size="36"></u-icon> </view>
  19. </view>
  20. </view>
  21. </block>
  22. </view>
  23. <view class="footer-fixed flex align-center justify-end padding bg-white" v-if="!selectShow">
  24. <button class="cu-btn round text-white theme-bg-color" style="width: 180upx;height: 80upx;margin-right: 30upx;">公益证书</button>
  25. <button class="cu-btn round text-white theme-bg-color" style="width: 180upx;height: 80upx;" @click="selectShow = true">兑换</button>
  26. </view>
  27. <view class="footer-fixed flex align-center justify-between padding bg-white" v-else>
  28. <view class="flex align-center" @click="selectAll">
  29. <view :class="selectAllShow ? 'theme-color cuIcon-roundcheckfill':'cuIcon-round'" class="padding-right-xs" style="font-size: 50upx;"></view>
  30. <view class="text-sm padding-right-xs">全选</view>
  31. <view class="text-sm">积分 {{total}}</view>
  32. </view>
  33. <view>
  34. <button class="cu-btn round text-white theme-bg-color" style="width: 180upx;height: 80upx;margin-right: 30upx;" @click="confirm">兑换</button>
  35. <button class="cu-btn round line-gray" style="width: 180upx;height: 80upx;" @click="selectShow = false">取消</button>
  36. </view>
  37. </view>
  38. <u-popup v-model="dialogShow" mode="center" width="500" height="480" border-radius="30">
  39. <view class="bg-img text-center" style="background-image: url('/static/dialogBgImg.png');height: 600rpx;">
  40. <view style="height: 80upx;"></view>
  41. <view style="font-size: 50upx;font-family: PingFang SC;font-weight: 600;color: #ffffff;">恭喜你</view>
  42. <view class="text-bold text-black" style="padding: 80upx 0 10upx 0;">积分兑换成功!</view>
  43. <view class="text-bold text-black">{{total}}积分到账</view>
  44. <view class="padding">
  45. <u-button class="custom-style" shape="circle" @click="dialogShow = false">确定</u-button>
  46. </view>
  47. </view>
  48. </u-popup>
  49. </view>
  50. </template>
  51. <script>
  52. export default {
  53. data() {
  54. return {
  55. selectAllShow: false,
  56. selectShow: false,
  57. total: 0,
  58. welfareList: [
  59. {image: '/static/welfare/welfare1.png', count: 2, points: 200, selected: false},
  60. {image: '/static/welfare/welfare2.png', count: 3, points: 200, selected: false},
  61. {image: '/static/welfare/welfare3.png', count: 2, points: 200, selected: false},
  62. {image: '/static/welfare/welfare4.png', count: 1, points: 200, selected: false},
  63. {image: '/static/welfare/welfare5.png', count: 1, points: 200, selected: false},
  64. ],
  65. dialogShow: false,
  66. }
  67. },
  68. methods: {
  69. select(index) {
  70. this.welfareList[index].selected = !this.welfareList[index].selected;
  71. if (this.welfareList[index].selected) {
  72. this.total += this.welfareList[index].count * this.welfareList[index].points;
  73. } else {
  74. this.total -= this.welfareList[index].count * this.welfareList[index].points;
  75. }
  76. let flag = true;
  77. for (let item of this.welfareList) {
  78. if (!item.selected) {
  79. flag = false;
  80. }
  81. }
  82. this.selectAllShow = flag;
  83. },
  84. selectAll() {
  85. this.selectAllShow = !this.selectAllShow;
  86. if (this.selectAllShow) {
  87. for (let item of this.welfareList) {
  88. if (!item.selected) {
  89. this.total += item.count * item.points;
  90. }
  91. }
  92. } else {
  93. for (let item of this.welfareList) {
  94. this.total -= item.count * item.points;
  95. }
  96. }
  97. for (let item of this.welfareList) {
  98. if (this.selectAllShow) {
  99. item.selected = true;
  100. } else {
  101. item.selected = false;
  102. }
  103. }
  104. },
  105. confirm() {
  106. if (this.total == 0) {
  107. uni.showToast({
  108. title: "请至少选择一个勋章",
  109. icon: "none"
  110. })
  111. } else {
  112. this.dialogShow = true;
  113. }
  114. },
  115. //礼物+
  116. plus(count) {
  117. let tmp = count;
  118. if (count < tmp) {
  119. count++
  120. }
  121. },
  122. //礼物 -
  123. minus(count) {
  124. let tmp = count;
  125. if (count < tmp && count > 1) {
  126. count--
  127. }
  128. },
  129. }
  130. }
  131. </script>
  132. <style>
  133. .title {
  134. font-size: 32upx;
  135. font-family: PingFang SC;
  136. font-weight: 800;
  137. color: #222222;
  138. line-height: 36px;
  139. }
  140. .container {
  141. margin: 20upx;
  142. border-radius: 20upx;
  143. background-color: #ffffff;
  144. }
  145. .custom-style {
  146. background-color: #5b3ee7;
  147. width: 250upx;
  148. color: #ffffff;
  149. }
  150. .input {
  151. width: 80upx;
  152. background-color: #ffffff;
  153. text-align: center;
  154. border: none;
  155. height: 60rpx;
  156. min-height: 1.8rem;
  157. }
  158. </style>