index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <view class="vip">
  3. <view style="height: 20rpx;"></view>
  4. <view class="topCard">
  5. <view class="vipInfo">
  6. <view class="left">
  7. <view class="ownVip">当前会员:<text>{{setMealName||'普通用户'}}</text></view>
  8. <view class="endTime">会员到期时间: {{expireTime||'--'}}</view>
  9. </view>
  10. <view class="right">
  11. <image slot="icon"
  12. src="http://zswl-dev.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/Jm8VtOGY6Bqg6cf0dd7cba21cff1cf57cd5a36effe8f.png/1.png"
  13. mode="widthFix"></image>
  14. </view>
  15. </view>
  16. <view class="inputBox">
  17. <input type="text" v-model="vipQuery.activationCode" @input="handleInput" @paste="handlePaste"
  18. placeholder="请输入激活码" placeholder-class="activationIpt" />
  19. <u-button type="error " :loading="redeemload" loadingSize="20" shape="circle" text="立即兑换"
  20. @click="confirmActivation"></u-button>
  21. </view>
  22. </view>
  23. <view class="listCard">
  24. <view class="listTitle">激活记录</view>
  25. <view class="listBox" v-if="activationList.length>0">
  26. <view class="list" v-for="(item,index) in activationList" :key="item.id">
  27. <view class="vipTitle">
  28. <view class="">{{item.planningName}}</view>
  29. <view class="">已激活</view>
  30. </view>
  31. <view class="listInfo">
  32. <view class="">激活码:<text>{{item.serialNumber}}</text></view>
  33. <view class="">激活时间: {{item.useTime}}</view>
  34. </view>
  35. </view>
  36. </view>
  37. <block v-else>
  38. <u-empty mode="data" textSize="20" iconSize="120" text="暂无激活记录"></u-empty>
  39. </block>
  40. </view>
  41. <u-toast ref="uToast"></u-toast>
  42. </view>
  43. </template>
  44. <script>
  45. import {
  46. mealList
  47. } from '@/api/combo.js'
  48. import {
  49. refreshVip
  50. } from '@/api/common.js'
  51. import {
  52. selectActivationCode,
  53. getActivationList
  54. } from '@/api/vipActivation.js'
  55. import {
  56. levelImgName
  57. } from '@/utils/config.js'
  58. import {
  59. timestampToDate
  60. } from '@/utils/tool.js'
  61. export default {
  62. data() {
  63. return {
  64. expireTime: '',
  65. redeemload: false,
  66. activationList: [],
  67. list: [],
  68. userInfo: '',
  69. setMealName: '',
  70. vipQuery: {
  71. phoneNum: '',
  72. activationCode: '',
  73. }
  74. }
  75. },
  76. onShow() {},
  77. onLoad() {
  78. this.userInfo = JSON.parse(uni.getStorageSync('userInfo'))
  79. this.vipQuery.phoneNum = this.userInfo.phoneNum
  80. this.mealList()
  81. this.get_activationList()
  82. this.get_userinfo()
  83. },
  84. methods: {
  85. // 修复android粘贴出现回车问题
  86. handleInput() {
  87. this.vipQuery.activationCode = this.vipQuery.activationCode.replace(/\s/g, '');
  88. },
  89. handlePaste(event) {
  90. let pasteData = event.clipboardData.getData('text');
  91. pasteData = pasteData.replace(/\r?\n|\r/g, '');
  92. this.vipQuery.activationCode = this.vipQuery.activationCode + pasteData;
  93. },
  94. // 用户信息
  95. get_userinfo() {
  96. refreshVip().then(res => {
  97. res.content.map((item) => {
  98. this.expireTime = timestampToDate(item.expirationTime)
  99. })
  100. })
  101. },
  102. // 激活列表
  103. get_activationList() {
  104. getActivationList().then(res => {
  105. if (res.state == 'Success') {
  106. res.content.content.map((item) => {
  107. item.useTime = timestampToDate(item.useTime)
  108. })
  109. this.activationList = res.content.content
  110. }
  111. })
  112. },
  113. // 二次确认
  114. confirmActivation() {
  115. if (this.vipQuery.activationCode == '') {
  116. uni.showToast({
  117. title: '请输入激活码',
  118. icon: 'none'
  119. })
  120. return
  121. }
  122. let that = this
  123. uni.showModal({
  124. title: '提示',
  125. content: '确认兑换当前激活码吗?',
  126. success(res) {
  127. if (res.confirm) {
  128. that.redeemload = true
  129. that.select_activationCode()
  130. }
  131. }
  132. })
  133. },
  134. // 兑换激活码
  135. select_activationCode() {
  136. selectActivationCode(this.vipQuery).then(res => {
  137. this.redeemload = false
  138. if (res.state == 'Success') {
  139. uni.showToast({
  140. title: '激活成功',
  141. });
  142. this.vipQuery.activationCode = ''
  143. this.get_activationList()
  144. } else {
  145. this.$refs.uToast.show({
  146. message: res.content
  147. })
  148. }
  149. })
  150. },
  151. // 获取套餐类型
  152. mealList() {
  153. mealList({
  154. currentPage: 1,
  155. pageSize: 99,
  156. status: 1
  157. }).then(res => {
  158. if (res.state == 'Success') {
  159. this.list = res.content.records
  160. // 判断当前会员类型
  161. this.list.map(item => {
  162. if (item.setMealCode == this.userInfo.setMealCode) {
  163. this.setMealName = item.setMealName
  164. }
  165. })
  166. }
  167. })
  168. },
  169. }
  170. }
  171. </script>
  172. <style lang="scss">
  173. .vip {
  174. height: 100vh;
  175. padding: 0 24rpx;
  176. background: #F9F9F9;
  177. .topCard {
  178. background: #fff;
  179. border-radius: 8rpx;
  180. padding: 20rpx;
  181. .vipInfo {
  182. display: flex;
  183. align-items: center;
  184. justify-content: space-between;
  185. .left {
  186. .ownVip {
  187. font-size: 28rpx;
  188. color: #181818;
  189. font-weight: bold;
  190. &>text {
  191. margin-left: 10rpx;
  192. font-weight: bold;
  193. font-size: 36rpx;
  194. }
  195. }
  196. .endTime {
  197. margin-top: 20rpx;
  198. font-weight: normal;
  199. font-size: 24rpx;
  200. color: #AAAAAA;
  201. }
  202. }
  203. .right {
  204. &>image {
  205. width: 100rpx;
  206. }
  207. }
  208. }
  209. .inputBox {
  210. display: flex;
  211. align-items: center;
  212. border: #F9F9F9 4rpx solid;
  213. border-radius: 50rpx;
  214. padding: 6rpx;
  215. margin-top: 20rpx;
  216. &>input {
  217. margin-left: 16rpx;
  218. width: 1600rpx;
  219. }
  220. .activationIpt {
  221. font-size: 28rpx;
  222. color: #AAAAAA;
  223. }
  224. }
  225. }
  226. .listCard {
  227. background: #fff;
  228. border-radius: 8rpx;
  229. padding: 20rpx;
  230. margin-top: 20rpx;
  231. .listTitle {
  232. font-weight: bold;
  233. font-size: 28rpx;
  234. color: #222222;
  235. }
  236. .listBox {
  237. .list {
  238. border-bottom: 1rpx solid #F0F0F0;
  239. .vipTitle {
  240. display: flex;
  241. align-items: center;
  242. justify-content: space-between;
  243. font-weight: bold;
  244. font-size: 32rpx;
  245. margin-top: 20rpx;
  246. &>view:first-child {
  247. color: #222222;
  248. }
  249. &>view:last-child {
  250. color: #FF4A39;
  251. }
  252. }
  253. .listInfo {
  254. margin-top: 20rpx;
  255. &>view:first-child {
  256. font-weight: normal;
  257. color: #222222;
  258. font-size: 24rpx;
  259. &>text {
  260. margin-left: 10rpx;
  261. color: #AAAAAA;
  262. }
  263. }
  264. &>view:last-child {
  265. height: 64rpx;
  266. line-height: 64rpx;
  267. font-size: 24rpx;
  268. font-weight: normal;
  269. color: #222222;
  270. }
  271. }
  272. }
  273. }
  274. }
  275. }
  276. </style>