scanPay.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <view>
  3. <!-- 个人信息 -->
  4. <view class="minec">
  5. <image :src="paymentUserInfo.avatar ? paymentUserInfo.avatar : '../merchant/static/images/user.png'" mode="aspectFill" class="user" />
  6. <view class="mines">
  7. <view class="mines_top">
  8. <view class="title">{{ paymentUserInfo.nickName }}</view>
  9. </view>
  10. <view class="edu">{{ paymentUserInfo.phone ? paymentUserInfo.phone : '' }}</view>
  11. </view>
  12. </view>
  13. <!-- 余额 -->
  14. <view class="card">
  15. <view class="card-header">
  16. <view :class="'money-list ddflex' + (balanceList.length == 3 || balanceList.length == 5 ? ' money-list3':'')" v-if="balanceList.length>0">
  17. <view class="li" v-for="(item,index) in balanceList" :key="index">
  18. <text>{{item.name}}</text>{{item.balance}}
  19. </view>
  20. </view>
  21. <block v-else>
  22. <view class="money-text">
  23. 账户余额
  24. </view>
  25. <view class="money-number">{{ paymentUserInfo.balance ? paymentUserInfo.balance : '0.00' }}</view>
  26. </block>
  27. </view>
  28. <view class="card-center">
  29. <view>扣除金额</view>
  30. <view class="money-input">
  31. <text class="symbol">¥</text>
  32. <input disabled="true" v-model="moneyPay" type="digit" @click="open()" />
  33. </view>
  34. </view>
  35. <view class="card-bottom">
  36. <view class="notice">{{ notice }}</view>
  37. <view class="add-remark" @click="showPop">{{ notice ? '修改' : '添加备注' }}</view>
  38. </view>
  39. </view>
  40. <input-popup ref="inpurPop" @onsuccess="getContent"></input-popup>
  41. <cu-keyboard ref="cukeyboard" @change="change" @confirm="confirm" @hide="hide"></cu-keyboard>
  42. </view>
  43. </template>
  44. <script>
  45. const route = require('../utils/route.js');
  46. const req = require('../utils/request');
  47. import inputPopup from './components/input-popup/index.vue';
  48. export default {
  49. data() {
  50. return {
  51. moneyPay: '',
  52. notice: '',
  53. code: '',
  54. paymentUserInfo: '',
  55. balanceList: []
  56. };
  57. },
  58. components: {
  59. inputPopup
  60. },
  61. onLoad(opt) {
  62. // this.code = opt.code;
  63. this.code = opt.scene;
  64. this.paymentUserInfoRequest();
  65. this.open();
  66. },
  67. onUnload() {
  68. console.log('页面onUnload');
  69. req.removeStorage('paymentUserInfo_key');
  70. },
  71. onHide() {
  72. console.log('页面onHide');
  73. req.removeStorage('paymentUserInfo_key');
  74. },
  75. methods: {
  76. showPop() {
  77. this.$refs.inpurPop.showFilters();
  78. this.$refs.inpurPop.setContent(this.notice);
  79. },
  80. getContent(e) {
  81. this.notice = e;
  82. },
  83. paymentUserInfoRequest() {
  84. // req.getRequest('/api/v3/payment/user/info/scan', { code: this.code }, data => {
  85. // this.paymentUserInfo = data;
  86. // });
  87. if(req.getStorage('paymentUserInfo_key')){
  88. this.getPaymentUserInfo();
  89. }else{
  90. req.getRequest('/api/v3/payment/user/info/scan', { code: this.code }, data => {
  91. console.log('报错')
  92. this.paymentUserInfo = data;
  93. req.setStorage('paymentUserInfo_key',data);
  94. this.paymentUserInfo.balance = parseFloat(this.paymentUserInfo.balance).toFixed(2);
  95. if(this.paymentUserInfo.payAccountTypes&&this.paymentUserInfo.payAccountTypes.length>0){
  96. this.getBalance(this.paymentUserInfo.userId);
  97. }
  98. });
  99. }
  100. },
  101. getPaymentUserInfo(){
  102. this.paymentUserInfo = req.getStorage('paymentUserInfo_key');
  103. this.paymentUserInfo.balance = parseFloat(this.paymentUserInfo.balance).toFixed(2);
  104. if(this.paymentUserInfo.payAccountTypes&&this.paymentUserInfo.payAccountTypes.length>0){
  105. this.getBalance(this.paymentUserInfo.userId);
  106. }
  107. },
  108. getBalance(userId){
  109. req.getRequest('/api/v3/payment/getBalance',{userId: userId},data=>{
  110. let arr = []
  111. this.paymentUserInfo.payAccountTypes.map(it=>{
  112. data.map(its=>{
  113. if(it == its.code){
  114. arr.push(its);
  115. }
  116. })
  117. })
  118. let balance = 0;
  119. arr.map(it=>{
  120. balance += it.balance;
  121. })
  122. this.balanceList = arr;
  123. this.paymentUserInfo.balance = parseFloat(balance).toFixed(2);
  124. console.log('balance==',this.paymentUserInfo.balance)
  125. })
  126. },
  127. change(e) {
  128. this.moneyPay = e;
  129. console.log('数字改变', e);
  130. },
  131. open() {
  132. console.log('打开键盘');
  133. this.$refs.cukeyboard.open();
  134. this.$refs.cukeyboard.value = this.moneyPay;
  135. },
  136. confirm(e) {
  137. console.log('付款', e);
  138. let userInfo = req.getStorage('userInfo');
  139. if(!userInfo.isStaff) return req.msg('暂无权限');
  140. if (Number(this.moneyPay) > Number(this.paymentUserInfo.balance)) {
  141. req.msg('余额不足扣除金额');
  142. return;
  143. }
  144. if (!this.moneyPay && this.moneyPay <= 0) {
  145. req.msg('请输入扣除金额');
  146. return;
  147. }
  148. this.hide();
  149. this.pay();
  150. },
  151. hide() {
  152. console.log('关闭键盘');
  153. },
  154. pay() {
  155. var tha = this;
  156. console.log('支付')
  157. req.postRequest(
  158. '/api/v3/payment/deduction',
  159. { money: this.moneyPay, note: this.notice, userId: this.paymentUserInfo.userId,code:this.code },
  160. data => {
  161. console.log('data==',data)
  162. uni.showModal({
  163. title: '提示',
  164. content: '成功扣除' + tha.moneyPay + '元',
  165. confirmText: '确定',
  166. showCancel: false,
  167. success(res) {
  168. if (res.confirm) {
  169. uni.navigateBack();
  170. }
  171. }
  172. });
  173. this.paymentUserInfo.balance = parseFloat(this.paymentUserInfo.balance - this.moneyPay).toFixed(2);
  174. },
  175. true
  176. );
  177. }
  178. }
  179. };
  180. </script>
  181. <style>
  182. .minec {
  183. position: relative;
  184. z-index: 1;
  185. display: flex;
  186. display: -webkit-flex;
  187. align-items: center;
  188. margin: 30rpx;
  189. }
  190. .user {
  191. display: block;
  192. width: 100rpx;
  193. height: 100rpx;
  194. border-radius: 50%;
  195. background: #fff;
  196. margin-right: 20rpx;
  197. }
  198. .mines {
  199. flex: 1;
  200. -webkit-flex: 1;
  201. margin-right: 20rpx;
  202. }
  203. .mines_top {
  204. width: 204px;
  205. display: flex;
  206. align-items: center;
  207. overflow: hidden;
  208. text-overflow: ellipsis;
  209. white-space: nowrap;
  210. }
  211. .title {
  212. font-size: 30rpx;
  213. font-weight: bold;
  214. color: #333;
  215. overflow: hidden;
  216. text-overflow: ellipsis;
  217. white-space: nowrap;
  218. }
  219. .edu {
  220. display: block;
  221. font-size: 24rpx;
  222. color: #999999;
  223. margin: 5px 0 0;
  224. }
  225. .card {
  226. margin: 30rpx;
  227. border-radius: 20rpx 20rpx 0 0;
  228. }
  229. .card .card-header {
  230. border-radius: 30rpx 30rpx 0 0;
  231. background-color: #0091fe;
  232. color: #ffffff;
  233. padding: 30rpx 40rpx;
  234. }
  235. .card .card-header .money-text {
  236. font-size: 28rpx;
  237. }
  238. .money-text text{margin-right: 20rpx;}
  239. .card .card-header .money-number {
  240. font-size: 46rpx;
  241. }
  242. .card .card-center {
  243. background-color: #fff;
  244. padding: 30rpx 40rpx;
  245. }
  246. .card .card-center .money-input {
  247. display: flex;
  248. border-bottom: 1px solid #dedede;
  249. padding: 30rpx 0;
  250. }
  251. .card .card-center .money-input .symbol {
  252. color: #414149;
  253. font-size: 65rpx;
  254. font-weight: bold;
  255. margin-right: 10rpx;
  256. }
  257. .card .card-center .money-input input {
  258. color: #414149;
  259. font-size: 90rpx;
  260. font-weight: bold;
  261. height: 120rpx;
  262. }
  263. .card .card-bottom {
  264. background-color: #fff;
  265. padding: 10rpx 40rpx;
  266. height: 450rpx;
  267. }
  268. .card .card-bottom .notice {
  269. white-space: pre-wrap;
  270. }
  271. .card .add-remark {
  272. font-size: 24rpx;
  273. color: #587fa2;
  274. margin-top: 10rpx;
  275. display: inline-block;
  276. }
  277. .money-list{flex-wrap: wrap;}
  278. .money-list .li{font-size: 42rpx;color: #fff;width: 50%;padding: 10rpx 0;}
  279. .money-list3 .li{width: 33.33%;}
  280. .money-list .li text{display: block;font-size: 28rpx;opacity: .8;margin-bottom: 15rpx;}
  281. </style>