myWelfare.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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">可解锁{{totalCount}}个勋章,总值{{totalPoints}}积分</view>
  6. </view>
  7. <view v-if="!$u.test.isEmpty(welfareList)" class="text-center grid col-3 container">
  8. <block v-for="(item, index) in welfareList" :key="index">
  9. <view class="padding-tb" @click="select(item)">
  10. <view>
  11. <image :src="item.medal.icon" 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.exCount}}</view>
  15. <view class="justify-center flex align-center" style="margin-top: -50upx;" v-else>
  16. <view class="" @click.stop="minus(item)"> <u-icon name="minus-circle-fill" color="#5a3ee8" size="36"></u-icon> </view>
  17. <input type="number" class="text-center input" v-model="item.exCount" />
  18. <view class="" @click.stop="plus(item)"> <u-icon name="plus-circle-fill" color="#5a3ee8" size="36"></u-icon> </view>
  19. </view>
  20. </view>
  21. </block>
  22. </view>
  23. <u-empty mode="data" iconSize="150" margin-top="300" v-else></u-empty>
  24. <block v-if="!$u.test.isEmpty(welfareList)">
  25. <view class="footer-fixed flex align-center justify-end padding bg-white" v-if="!selectShow">
  26. <button class="cu-btn round text-white theme-bg-color" style="width: 180upx;height: 80upx;margin-right: 30upx;">公益证书</button>
  27. <button class="cu-btn round text-white theme-bg-color" style="width: 180upx;height: 80upx;" @click="selectShow=true">兑换</button>
  28. </view>
  29. <view class="footer-fixed flex align-center justify-between padding bg-white" v-else>
  30. <view class="flex align-center" @click="selectAll">
  31. <view :class="selectAllShow ? 'theme-color cuIcon-roundcheckfill':'cuIcon-round'" class="padding-right-xs" style="font-size: 50upx;"></view>
  32. <view class="text-sm padding-right-xs">全选</view>
  33. <view class="text-sm">积分 {{total}}</view>
  34. </view>
  35. <view>
  36. <button class="cu-btn round text-white theme-bg-color" style="width: 180upx;height: 80upx;margin-right: 30upx;" @click="confirm">兑换</button>
  37. <button class="cu-btn round line-gray" style="width: 180upx;height: 80upx;" @click="selectShow = false">取消</button>
  38. </view>
  39. </view>
  40. </block>
  41. <u-popup v-model="dialogShow" mode="center" width="500" height="480" border-radius="30">
  42. <view class="bg-img text-center" style="background-image: url('https://upload-file-data.obs.cn-south-1.myhuaweicloud.com/e914f556be414767aca011a30961560a-dialogBgImg.png');height: 600rpx;">
  43. <view style="height: 80upx;"></view>
  44. <view style="font-size: 50upx;font-family: PingFang SC;font-weight: 600;color: #ffffff;">恭喜你</view>
  45. <view class="text-bold text-black" style="padding: 80upx 0 10upx 0;">积分兑换成功!</view>
  46. <view class="text-bold text-black">{{total}}积分到账</view>
  47. <view class="padding">
  48. <u-button class="custom-style" shape="circle" @click="dialogConfirm">确定</u-button>
  49. </view>
  50. </view>
  51. </u-popup>
  52. </view>
  53. </template>
  54. <script>
  55. export default {
  56. data() {
  57. return {
  58. userId:'',
  59. welfareList:[],
  60. totalCount:0,
  61. totalPoints:0,
  62. selectAllShow: false,
  63. selectShow: false,
  64. total: 0,
  65. dialogShow: false,
  66. }
  67. },
  68. onLoad() {
  69. this.userId = uni.getStorageSync("userId");
  70. if (this.$u.test.isEmpty(this.userId)) {
  71. this.$u.toast("用户未登录")
  72. return
  73. }
  74. this.getMineMedal()
  75. },
  76. methods: {
  77. getMineMedal(){
  78. this.$u.api.medal.list({userId:this.userId}).then(res=>{
  79. this.welfareList=res.records
  80. this.welfareList.forEach(item=>{
  81. item.selected=false
  82. item.exCount=item.count
  83. this.totalCount +=item.count
  84. this.totalPoints += item.count * item.medal.pointsValue;
  85. })
  86. })
  87. },
  88. select(item) {
  89. item.selected = !item.selected;
  90. if (item.selected) {
  91. this.total += item.exCount * item.medal.pointsValue;
  92. } else {
  93. this.total -= item.exCount * item.medal.pointsValue;
  94. }
  95. let flag = true;
  96. for (let item of this.welfareList) {
  97. if (!item.selected) {
  98. flag = false;
  99. }
  100. }
  101. this.selectAllShow = flag;
  102. },
  103. selectAll() {
  104. this.selectAllShow = !this.selectAllShow;
  105. if (this.selectAllShow) {
  106. for (let item of this.welfareList) {
  107. if (!item.selected) {
  108. this.total += item.exCount * item.medal.pointsValue;
  109. }
  110. }
  111. } else {
  112. for (let item of this.welfareList) {
  113. this.total -= item.exCount * item.medal.pointsValue;
  114. }
  115. }
  116. for (let item of this.welfareList) {
  117. if (this.selectAllShow) {
  118. item.selected = true;
  119. } else {
  120. item.selected = false;
  121. }
  122. }
  123. },
  124. confirm() {
  125. if (this.total == 0) {
  126. uni.showToast({
  127. title: "请至少选择一个勋章",
  128. icon: "none"
  129. })
  130. return
  131. }
  132. let params= this.getExchangeList()
  133. this.$u.api.medal.exchange(params).then(res=>{
  134. if (!this.$u.test.isEmpty(res)) {
  135. this.dialogShow=true
  136. }
  137. })
  138. },
  139. dialogConfirm(){
  140. this.dialogShow=false
  141. this.getMineMedal()
  142. this.selectAllShow=false
  143. this.selectShow=false
  144. this.total=0
  145. },
  146. //礼物+
  147. plus(item) {
  148. if (item.exCount<item.count) {
  149. item.exCount++
  150. }
  151. this.reCalculate()
  152. this.$forceUpdate()
  153. },
  154. //礼物 -
  155. minus(item) {
  156. if (item.exCount>1) {
  157. item.exCount--
  158. }
  159. this.reCalculate()
  160. this.$forceUpdate()
  161. },
  162. //重新计算总积分值
  163. reCalculate(){
  164. this.total=0
  165. this.welfareList.forEach(item=>{
  166. if (item.selected) {
  167. this.total += item.exCount * item.medal.pointsValue;
  168. }
  169. })
  170. },
  171. getExchangeList(){
  172. let newList=[]
  173. this.welfareList.forEach(item=>{
  174. if (item.selected) {
  175. let obj={
  176. id:item.id,
  177. userId:item.userId,
  178. medalId:item.medalId,
  179. activityIds:item.activityIds,
  180. count:item.exCount
  181. }
  182. newList.push(obj)
  183. }
  184. })
  185. return newList
  186. }
  187. }
  188. }
  189. </script>
  190. <style>
  191. .title {
  192. font-size: 32upx;
  193. font-family: PingFang SC;
  194. font-weight: 800;
  195. color: #222222;
  196. line-height: 36px;
  197. }
  198. .container {
  199. margin: 20upx;
  200. border-radius: 20upx;
  201. background-color: #ffffff;
  202. }
  203. .custom-style {
  204. background-color: #5b3ee7;
  205. width: 250upx;
  206. color: #ffffff;
  207. }
  208. .input {
  209. width: 80upx;
  210. background-color: #ffffff;
  211. text-align: center;
  212. border: none;
  213. height: 60rpx;
  214. min-height: 1.8rem;
  215. }
  216. </style>