recharge.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <app-layout>
  3. <view class="dir-top-nowrap recharge" v-if="pageShow">
  4. <view class="account">我的账户</view>
  5. <view :style="{'background-image': `url(${appImg.mall.balance_recharge})`}"
  6. class="dir-left-nowrap bg cross-center">
  7. <image class="image box-grow-0" src="/static/image/icon/icon-balance.png"></image>
  8. <view class="balance-text box-grow-1">余额</view>
  9. <view class="balance-price box-grow-0">{{balance}}</view>
  10. </view>
  11. <view class="amount-text">充值金额</view>
  12. <view class="dir-left-wrap select">
  13. <view v-for="(item,index) in list" :key="index" @click="setPrice(index)"
  14. class="dir-top-nowrap cross-center main-center box" :class="index === selected? 'active':''">
  15. <view class="price">充{{item.pay_price}}元</view>
  16. <view class="send" v-if="item.send_price > 0">送{{item.send_price}}元</view>
  17. <view class="send" v-if="item.send_integral > 0">送{{item.send_integral}}积分</view>
  18. </view>
  19. </view>
  20. <view class="input" :class="selected === -1 && getFocus ? `red`: `grey`" v-if="setting.type === `1`">
  21. <input @focus="bindFocus" placeholder-style="color:#bbbbbb" v-model="pay_price" type="digit"
  22. :focus="getFocus"
  23. @blur="bludBlur"
  24. @input="changeInput"
  25. placeholder="手动输入充值金额"/>
  26. </view>
  27. <view class="btn">
  28. <app-button @click="submit" round color="#FFFFFF" height="88" background="#FF4544">立即充值</app-button>
  29. </view>
  30. <view class="account">充值说明</view>
  31. <text class="text" space="nbsp">{{setting.explain}}</text>
  32. </view>
  33. </app-layout>
  34. </template>
  35. <script>
  36. import {mapState} from 'vuex';
  37. export default {
  38. name: "recharge",
  39. computed: {
  40. ...mapState({
  41. theme: state => state.mallConfig.theme,
  42. appImg: state => state.mallConfig.__wxapp_img,
  43. }),
  44. },
  45. data() {
  46. return {
  47. setting: null,
  48. list: null,
  49. pay_price: '',
  50. balance: '¥',
  51. selected: -1,
  52. getFocus: false,
  53. pageShow: false,
  54. }
  55. },
  56. onShow: function () {
  57. this.loadData();
  58. },
  59. watch: {
  60. pay_price: {
  61. handler: function (newData, oldData) {
  62. if (newData) {
  63. this.selected = -1;
  64. }
  65. }
  66. }
  67. },
  68. methods: {
  69. getSetting: function () {
  70. const self = this;
  71. self.$request({
  72. url: self.$api.balance.index,
  73. }).then(info => {
  74. if (info.code === 0) {
  75. self.pageShow = true;
  76. if (info.data.setting.status === `1`) {
  77. self.setting = info.data.setting;
  78. self.balance = '¥' + info.data.balance;
  79. } else {
  80. uni.showModal({
  81. title: '提示',
  82. content: '尚未开启余额功能',
  83. showCancel: false,
  84. confirmText: '确定',
  85. success(e) {
  86. if (e.confirm) {
  87. uni.navigateBack({delta: 1})
  88. }
  89. }
  90. });
  91. }
  92. }
  93. })
  94. },
  95. loadData: function () {
  96. const self = this;
  97. self.getSetting();
  98. self.$showLoading({title: `加载中`});
  99. self.$request({
  100. url: self.$api.recharge.index,
  101. }).then(info => {
  102. self.$hideLoading();
  103. if (info.code === 0) {
  104. self.list = info.data.list;
  105. }
  106. }).catch(info => {
  107. self.$hideLoading();
  108. })
  109. },
  110. bindFocus: function () {
  111. this.selected = -1;
  112. this.getFocus = true;
  113. },
  114. bludBlur: function () {
  115. this.getFocus = false;
  116. },
  117. changeInput(e) {
  118. },
  119. setPrice: function (index) {
  120. this.pay_price = '';
  121. this.selected = index;
  122. },
  123. submit: function () {
  124. const self = this;
  125. let para;
  126. if (self.selected === -1) {
  127. if (self.pay_price > 0) {
  128. para = {
  129. id: 0,
  130. pay_price: self.pay_price,
  131. send_price: 0
  132. };
  133. } else {
  134. uni.showToast({
  135. title: '金额不能为空',
  136. icon: 'none',
  137. });
  138. return;
  139. }
  140. } else {
  141. para = {
  142. id: self.list[self.selected].id,
  143. pay_price: self.list[self.selected].pay_price,
  144. send_price: self.list[self.selected].send_price,
  145. }
  146. }
  147. self.$showLoading({title: `加载中`});
  148. self.$request({
  149. url: self.$api.recharge.balance_recharge,
  150. data: para,
  151. method: 'POST',
  152. }).then(info => {
  153. self.$hideLoading();
  154. if (info.code === 0) {
  155. self.$payment.pay(info.data.pay_id).then(e => {
  156. uni.showModal({
  157. title: '提示',
  158. content: '充值成功!',
  159. showCancel: false,
  160. confirmText: '确定',
  161. success(e) {
  162. if (e.confirm) {
  163. uni.navigateBack({delta: 1})
  164. }
  165. }
  166. });
  167. }).catch(e => {
  168. uni.showToast({'title': e, icon: 'none'});
  169. });
  170. } else {
  171. uni.showToast({'title': info.msg, icon: 'none'});
  172. }
  173. }).catch(info => {
  174. self.$hideLoading();
  175. })
  176. }
  177. }
  178. }
  179. </script>
  180. <style lang="scss">
  181. page {
  182. background: #FFFFFF;
  183. }
  184. </style>
  185. <style scoped lang="scss">
  186. .recharge {
  187. background: #FFFFFF;
  188. padding: #{40rpx} #{24rpx} 0;
  189. .account {
  190. font-size: #{24rpx};
  191. border-left: #{6rpx} solid #ff4544;
  192. padding-left: #{24rpx};
  193. color:#666666;
  194. margin-bottom: #{32}rpx;
  195. }
  196. .bg {
  197. background-repeat: no-repeat;
  198. background-size: #{702rpx} #{160rpx};
  199. height: #{160rpx};
  200. width: #{702rpx};
  201. color: #666666;
  202. .image {
  203. width: #{72rpx};
  204. height: #{72rpx};
  205. margin-left: #{40rpx};
  206. }
  207. .balance-text {
  208. font-size: #{42rpx};
  209. margin-left: #{20rpx}
  210. }
  211. .balance-price {
  212. font-size: #{46rpx};
  213. margin-right: #{56rpx};
  214. }
  215. }
  216. .amount-text {
  217. font-size: #{24rpx};
  218. color: #999999;
  219. margin-top: #{56rpx};
  220. }
  221. .select {
  222. margin: 0 #{-12rpx};
  223. .box {
  224. height: #{140rpx};
  225. width: #{214rpx};
  226. margin: #{24rpx} #{12rpx} 0 #{12rpx};
  227. border: #{1px} solid #cccccc;
  228. border-radius: #{16rpx};
  229. .price {
  230. font-size: #{24rpx};
  231. color: #999999;
  232. }
  233. .send {
  234. font-size: #{24rpx};
  235. color: #999999;
  236. }
  237. }
  238. .active {
  239. border: #{1px} solid #ff4544;
  240. .price {
  241. color: #ff4544
  242. }
  243. .send {
  244. color: #ff4544;
  245. }
  246. }
  247. }
  248. .input {
  249. margin-top: #{40rpx};
  250. border-radius: #{14rpx};
  251. input {
  252. color: #666666;
  253. height: #{88rpx};
  254. padding: 0 #{12rpx};
  255. }
  256. }
  257. .input.red {
  258. border: #{1px} solid #ff4544;
  259. }
  260. .input.grey {
  261. border: #{1px} solid #cccccc;
  262. }
  263. .btn {
  264. margin-top: #{56rpx};
  265. margin-bottom: #{72rpx};
  266. }
  267. .text {
  268. margin-top: -8rpx;
  269. word-break: break-all;
  270. text-align: justify;
  271. font-size: #{24rpx};
  272. color: #666666;
  273. }
  274. }
  275. </style>