recharge.vue 11 KB

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