exchange.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <view class="pos-r padding-lr-sm" v-if="fetch && fetch.info">
  3. <use-tabbar :tabbar="false" />
  4. <view class="border-radius bg-main padding margin-top-sm">
  5. <view class="fwbd fs">{{fetch.info.name}}兑换</view>
  6. <!-- 金额选项 -->
  7. <view class="dflex money-area flex-wrap">
  8. <view class="item dflex-c dflex-flow-c" :class="{ active: config === index }"
  9. v-for="(item, index) in fetch.config" :key="index" @click="setConfig(index)">
  10. <view class="price">{{ item.name }}</view>
  11. <text class="fs-xs">{{ item.tip }}</text>
  12. </view>
  13. </view>
  14. <!-- 输入其他金额 -->
  15. <input class="w-full padding border-radius-sm bg-drak" type="number" placeholder="请输入兑换数值" v-model="number" @input="setValue"
  16. maxlength="140"/>
  17. <text class="margin-left-xs tip padding-tb">余额:{{fetch.user.yue_text}}</text>
  18. <text class="margin-left-xs tip padding-tb">可兑换:{{value}}</text>
  19. <!-- 马上充值按钮 -->
  20. <view class="dflex-c w-full margin-tb" @click="act">
  21. <view class="dflex-c dflex-flow-c border-radius-lg padding-tb-sm fwb line-height-1 cur_bgcolor"
  22. style="width: 70vw;">
  23. <text>马上兑换</text>
  24. <text class="fs-xxs margin-top-xs ft-dark-4">并同意积分服务协议</text>
  25. </view>
  26. </view>
  27. <!-- 协议提示 -->
  28. <view class="margin-top dflex-c" @click="Dever.location('tool/page?title=积分服务协议')">
  29. <text class="cur_color margin-left-xs fs-xs padding-tb">积分服务协议</text>
  30. </view>
  31. </view>
  32. <!-- 记录列表 -->
  33. <view class="record-list margin-top-sm" v-if="fetch">
  34. <view class="record-title fs fwbd ft-black margin-bottom-sm">兑换记录</view>
  35. <view v-if="fetch['list_' + current] && fetch['list_' + current].length > 0">
  36. <view class="record-item" v-for="(item, index) in fetch['list_' + current]" :key="index">
  37. <view class="record-left">
  38. <view class="record-name">{{ item.action_name }}</view>
  39. <view class="record-desc" v-if="item.desc">{{ item.desc }}</view>
  40. <view class="record-time">{{ item.cdate }}</view>
  41. </view>
  42. <view class="record-amount" :class="{ income: item.amount > 0, expense: item.amount < 0 }">
  43. {{ item.amount > 0 ? '+' : '' }}{{ item.amount }}
  44. </view>
  45. </view>
  46. </view>
  47. <view v-else class="empty-record">
  48. <u-empty mode="data"></u-empty>
  49. </view>
  50. </view>
  51. <view class="safe-area-inset-bottom"></view>
  52. </view>
  53. </template>
  54. <script>
  55. export default {
  56. data() {
  57. return {
  58. config: 0, // 默认选中第一个
  59. fetch: {},
  60. id: 0,
  61. current: 0,
  62. number: '',
  63. value: 0,
  64. };
  65. },
  66. onLoad(options) {
  67. if (options && options.id) {
  68. this.id = options.id;
  69. } else {
  70. this.Dever.location('source/home');
  71. return;
  72. }
  73. },
  74. onShow() {
  75. this.loadData();
  76. this.loadList(1);
  77. },
  78. //下拉刷新
  79. onPullDownRefresh() {
  80. this.loadList(1);
  81. },
  82. //加载更多
  83. onReachBottom() {
  84. this.loadList(2);
  85. },
  86. methods: {
  87. setConfig(index) {
  88. this.config = index;
  89. this.loadValue()
  90. },
  91. loadData() {
  92. this.DeverApi.get(this, 'score.exchange', {
  93. id: this.id
  94. }, res => {
  95. this.loadValue()
  96. });
  97. },
  98. loadList(page) {
  99. this.DeverApi.page([page, 'list_' + this.current], this, 'score.exchangeLog', {
  100. id: this.id
  101. });
  102. },
  103. setValue() {
  104. this.loadValue()
  105. },
  106. loadValue() {
  107. if (!this.number) {
  108. var number = this.fetch.user.yue
  109. } else {
  110. var number = this.number
  111. }
  112. var config = this.fetch.config[this.config]
  113. this.value = (parseFloat(number) * parseFloat(config.value)).toFixed(2).toString()
  114. if (config.symbol_location == 1) {
  115. this.value = config.symbol + this.value;
  116. } else {
  117. this.value = this.value + config.symbol;
  118. }
  119. },
  120. act() {
  121. var number = this.number;
  122. if (number) {
  123. number = parseFloat(number);
  124. } else {
  125. number = 0;
  126. }
  127. if (number <= 0) {
  128. return this.Dever.alert('请输入要兑换的数值');
  129. }
  130. var yue = parseFloat(this.fetch.user.yue);
  131. if (yue <= number) {
  132. return this.Dever.alert('余额不足');
  133. }
  134. if (this.config < 0) {
  135. return this.Dever.alert('请选择要兑换的积分');
  136. }
  137. var config = this.fetch.config[this.config];
  138. this.Dever.confirm('确认申请兑换吗?', () => {
  139. this.DeverApi.post('score.exchangeAct', {id: this.id, config:config.id, number:number}, r => {
  140. this.number = '';
  141. this.loadData();
  142. this.loadList(1);
  143. this.Dever.success('兑换成功');
  144. });
  145. });
  146. },
  147. },
  148. };
  149. </script>
  150. <style lang="scss">
  151. .money-area {
  152. margin-top: 28rpx;
  153. margin-bottom: 18rpx;
  154. display: flex;
  155. flex-wrap: wrap;
  156. gap: 18rpx;
  157. /* 加这个 */
  158. .item {
  159. width: calc((100% - 2 * 18rpx) / 3);
  160. /* 3个元素,间隔2个gap */
  161. height: 152rpx;
  162. background: #f5f5f5;
  163. border-radius: 12rpx;
  164. box-sizing: border-box;
  165. padding: 20rpx;
  166. text-align: center;
  167. .price {
  168. color: #333;
  169. margin-bottom: 8rpx;
  170. }
  171. text {
  172. color: #9a9a9a;
  173. }
  174. }
  175. .active {
  176. background: #ffbc49;
  177. color: #fff;
  178. .price,
  179. text {
  180. color: #fff !important;
  181. }
  182. }
  183. }
  184. .record-list {
  185. background: #ffffff;
  186. border-radius: 20rpx;
  187. padding: 30rpx;
  188. .record-title {
  189. font-size: 30rpx;
  190. font-weight: bold;
  191. color: #333;
  192. }
  193. .record-item {
  194. display: flex;
  195. justify-content: space-between;
  196. align-items: center;
  197. padding: 20rpx 0;
  198. border-bottom: 1px solid #f0f0f0;
  199. &:last-child {
  200. border-bottom: none;
  201. }
  202. .record-left {
  203. display: flex;
  204. flex-direction: column;
  205. .record-name {
  206. font-size: 28rpx;
  207. color: #333;
  208. }
  209. .record-desc {
  210. font-size: 28rpx;
  211. color: #999;
  212. }
  213. .record-time {
  214. font-size: 24rpx;
  215. color: #999;
  216. margin-top: 6rpx;
  217. }
  218. }
  219. .record-amount {
  220. font-size: 28rpx;
  221. font-weight: bold;
  222. &.income {
  223. color: #4caf50;
  224. }
  225. &.expense {
  226. color: #f44336;
  227. }
  228. }
  229. }
  230. }
  231. .empty-record {
  232. text-align: center;
  233. padding: 60rpx 0;
  234. .empty-icon {
  235. width: 160rpx;
  236. height: 160rpx;
  237. margin-bottom: 20rpx;
  238. opacity: 0.6;
  239. }
  240. .empty-text {
  241. font-size: 28rpx;
  242. color: #999;
  243. }
  244. }
  245. .cur_bgcolor {
  246. background: #ffbc49;
  247. color: #fff;
  248. }
  249. .cur_color {
  250. color: #ffbc49;
  251. }
  252. .tip {
  253. font-size: 24rpx;
  254. color: #00aaff;
  255. margin-top: 6rpx;
  256. }
  257. </style>