cashier.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <view class="container" v-if="userInfo.id">
  3. <view class="account-panel dis-flex flex-y-center">
  4. <view class="panel-lable">
  5. <text>会员账户余额</text>
  6. </view>
  7. <view class="panel-balance flex-box">
  8. <text>¥{{ userInfo.balance }}</text>
  9. </view>
  10. </view>
  11. <view class="recharge-panel">
  12. <!-- 收款金额输入框 -->
  13. <view class="recharge-input">
  14. <view class="label">收款金额</view>
  15. <text class="uni">¥</text>
  16. <input type="number" class="uni-input" placeholder="请输入收款金额(单位:元)" placeholder-class="placeholder" v-model="inputValue" @input="onChangeMoney" />
  17. </view>
  18. <view class="remark-input">
  19. <view class="label">备注信息</view>
  20. <input type="text" v-model="remark" placeholder-class="placeholder" placeholder="请输入收款备注"/>
  21. </view>
  22. <!-- 确认按钮 -->
  23. <view class="recharge-submit btn-submit">
  24. <form @submit="onSubmit">
  25. <button class="button" formType="submit" :disabled="disabled">立即收款</button>
  26. </form>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import * as UserApi from '@/api/user'
  33. import * as BalanceApi from '@/api/balance'
  34. import * as SettlementApi from '@/api/settlement'
  35. import { wxPayment } from '@/utils/app'
  36. export default {
  37. data() {
  38. return {
  39. // 正在加载
  40. isLoading: true,
  41. // 会员二维码
  42. userCode: "",
  43. // 会员信息
  44. userInfo: {},
  45. // 按钮禁用
  46. disabled: false,
  47. // 收款备注
  48. remark: '',
  49. // 自定义金额
  50. inputValue: '',
  51. }
  52. },
  53. /**
  54. * 生命周期函数--监听页面加载
  55. */
  56. onLoad(options) {
  57. this.userCode = options.code
  58. // 获取页面数据
  59. this.getPageData()
  60. },
  61. methods: {
  62. // 收款金额输入框
  63. onChangeMoney(e) {
  64. this.inputValue = e.target.value;
  65. this.rechargeAmount = 0;
  66. },
  67. // 获取页面数据
  68. getPageData() {
  69. const app = this
  70. app.isLoading = true
  71. Promise.all([app.getUserInfo()])
  72. .then(() => app.isLoading = false)
  73. },
  74. // 获取会员信息
  75. getUserInfo() {
  76. const app = this
  77. return new Promise((resolve, reject) => {
  78. UserApi.info({ code: app.userCode })
  79. .then(result => {
  80. app.userInfo = result.data.userInfo;
  81. resolve(app.userInfo);
  82. })
  83. })
  84. },
  85. // 立即收款
  86. onSubmit(e) {
  87. const app = this
  88. if (app.inputValue.length < 1) {
  89. app.$error('请输入收款金额!');
  90. return false;
  91. }
  92. // 按钮禁用
  93. app.disabled = true
  94. // 提交到后端
  95. SettlementApi.doCashier({ type: 'payment', cashierPayAmount: app.inputValue, cashierDiscountAmount: 0, payType: 'BALANCE', userId: app.userInfo.id, remark: app.remark })
  96. .then(result => app.onSubmitCallback(result))
  97. .catch(err => {
  98. if (err.result) {
  99. const errData = err.result.data;
  100. if (errData) {
  101. return false;
  102. }
  103. }
  104. })
  105. },
  106. // 收款回调
  107. onSubmitCallback(result) {
  108. const app = this
  109. if (result.code != '200') {
  110. app.$error(result.message ? result.message : '收款失败');
  111. app.disabled = false;
  112. return false;
  113. }
  114. uni.showModal({
  115. title: '收款结果',
  116. content: '收款成功!',
  117. showCancel: false,
  118. success(o) {
  119. if (o.confirm) {
  120. app.inputValue = '';
  121. app.remark = '';
  122. app.disabled = false;
  123. app.getPageData();
  124. }
  125. }
  126. })
  127. }
  128. }
  129. }
  130. </script>
  131. <style>
  132. .placeholder {
  133. color: #ccc;
  134. font-size: 28rpx;
  135. font-weight: normal;
  136. }
  137. </style>
  138. <style lang="scss" scoped>
  139. page,
  140. .container {
  141. background: #fff;
  142. }
  143. .container {
  144. padding-bottom: 70rpx;
  145. }
  146. /* 账户面板 */
  147. .account-panel {
  148. width: 650rpx;
  149. height: 180rpx;
  150. margin: 50rpx auto;
  151. padding: 0 60rpx;
  152. box-sizing: border-box;
  153. border-radius: 8rpx;
  154. color: #fff;
  155. background: $fuint-theme;
  156. box-shadow: 0 5px 22px 0 rgba(0, 0, 0, 0.26);
  157. }
  158. .panel-lable {
  159. font-size: 32rpx;
  160. }
  161. .recharge-label {
  162. color: rgb(51, 51, 51);
  163. font-size: 32rpx;
  164. margin-bottom: 25rpx;
  165. }
  166. .panel-balance {
  167. text-align: right;
  168. font-size: 46rpx;
  169. }
  170. .recharge-panel {
  171. margin-top: 60rpx;
  172. padding: 0 60rpx;
  173. }
  174. .recharge-input {
  175. margin-top: 25rpx;
  176. .label {
  177. margin-bottom: 10rpx;
  178. }
  179. .uni {
  180. font-weight: bold;
  181. font-size: 32rpx;
  182. }
  183. input {
  184. border: 1rpx solid rgb(228, 228, 228);
  185. border-radius: 6rpx;
  186. padding: 20rpx;
  187. font-weight: bold;
  188. font-size: 58rpx;
  189. }
  190. }
  191. .remark-input {
  192. .label {
  193. margin-bottom: 10rpx;
  194. }
  195. margin-top: 50rpx;
  196. input {
  197. border: 1rpx solid rgb(228, 228, 228);
  198. border-radius: 6rpx;
  199. padding: 20rpx;
  200. font-size: 26rpx;
  201. }
  202. }
  203. /* 立即充值 */
  204. .recharge-submit {
  205. margin-top: 70rpx;
  206. }
  207. .btn-submit {
  208. .button {
  209. font-size: 30rpx;
  210. background: linear-gradient(to right, #f9211c, #ff6335);
  211. border: none;
  212. color: white;
  213. border-radius: 40rpx;
  214. padding: 0 120rpx;
  215. line-height: 3;
  216. }
  217. .button[disabled] {
  218. background: #ff6335;
  219. border-color: #ff6335;
  220. color: white;
  221. }
  222. }
  223. </style>