myWelfare.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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") || -1;
  70. this.getMineMedal()
  71. },
  72. methods: {
  73. getMineMedal(){
  74. this.$u.api.medal.list({userId:this.userId}).then(res=>{
  75. this.welfareList=res.records
  76. this.welfareList.forEach(item=>{
  77. item.selected=false
  78. item.exCount=item.count
  79. this.totalCount +=item.count
  80. this.totalPoints += item.count * item.medal.pointsValue;
  81. })
  82. })
  83. },
  84. select(item) {
  85. item.selected = !item.selected;
  86. if (item.selected) {
  87. this.total += item.exCount * item.medal.pointsValue;
  88. } else {
  89. this.total -= item.exCount * item.medal.pointsValue;
  90. }
  91. let flag = true;
  92. for (let item of this.welfareList) {
  93. if (!item.selected) {
  94. flag = false;
  95. }
  96. }
  97. this.selectAllShow = flag;
  98. },
  99. selectAll() {
  100. this.selectAllShow = !this.selectAllShow;
  101. if (this.selectAllShow) {
  102. for (let item of this.welfareList) {
  103. if (!item.selected) {
  104. this.total += item.exCount * item.medal.pointsValue;
  105. }
  106. }
  107. } else {
  108. for (let item of this.welfareList) {
  109. this.total -= item.exCount * item.medal.pointsValue;
  110. }
  111. }
  112. for (let item of this.welfareList) {
  113. if (this.selectAllShow) {
  114. item.selected = true;
  115. } else {
  116. item.selected = false;
  117. }
  118. }
  119. },
  120. confirm() {
  121. if (this.total == 0) {
  122. uni.showToast({
  123. title: "请至少选择一个勋章",
  124. icon: "none"
  125. })
  126. return
  127. }
  128. let params= this.getExchangeList()
  129. this.$u.api.medal.exchange(params).then(res=>{
  130. if (!this.$u.test.isEmpty(res)) {
  131. this.dialogShow=true
  132. }
  133. })
  134. },
  135. dialogConfirm(){
  136. this.dialogShow=false
  137. this.getMineMedal()
  138. this.selectAllShow=false
  139. this.selectShow=false
  140. this.total=0
  141. },
  142. //礼物+
  143. plus(item) {
  144. if (item.exCount<item.count) {
  145. item.exCount++
  146. }
  147. this.reCalculate()
  148. this.$forceUpdate()
  149. },
  150. //礼物 -
  151. minus(item) {
  152. if (item.exCount>1) {
  153. item.exCount--
  154. }
  155. this.reCalculate()
  156. this.$forceUpdate()
  157. },
  158. //重新计算总积分值
  159. reCalculate(){
  160. this.total=0
  161. this.welfareList.forEach(item=>{
  162. if (item.selected) {
  163. this.total += item.exCount * item.medal.pointsValue;
  164. }
  165. })
  166. },
  167. getExchangeList(){
  168. let newList=[]
  169. this.welfareList.forEach(item=>{
  170. if (item.selected) {
  171. let obj={
  172. id:item.id,
  173. userId:item.userId,
  174. medalId:item.medalId,
  175. activityIds:item.activityIds,
  176. count:item.exCount
  177. }
  178. newList.push(obj)
  179. }
  180. })
  181. return newList
  182. }
  183. }
  184. }
  185. </script>
  186. <style>
  187. .title {
  188. font-size: 32upx;
  189. font-family: PingFang SC;
  190. font-weight: 800;
  191. color: #222222;
  192. line-height: 36px;
  193. }
  194. .container {
  195. margin: 20upx;
  196. border-radius: 20upx;
  197. background-color: #ffffff;
  198. }
  199. .custom-style {
  200. background-color: #5b3ee7;
  201. width: 250upx;
  202. color: #ffffff;
  203. }
  204. .input {
  205. width: 80upx;
  206. background-color: #ffffff;
  207. text-align: center;
  208. border: none;
  209. height: 60rpx;
  210. min-height: 1.8rem;
  211. }
  212. </style>