pay.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <view>
  3. <!-- 扫一扫错误回调 -->
  4. <u-modal title="扫描异常" confirm-color="#dc9b21" v-model="scanNotify.scan" :content="scanNotify.scanMessage"></u-modal>
  5. <view class="data">
  6. <text style="color: #000;">收款金额</text>
  7. <view class="price">
  8. <view class="input-bar center" @tap="show">
  9. <view class="icon center">¥</view>
  10. <view class="input" style="display: flex; align-items: center;">
  11. <view style="font-size: 80rpx;font-weight: 800;">{{filterMoney(money)}}</view>
  12. <view class="cusor"></view>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. <amountInput ref="amountInput" confirmText="收款" btnColor="#ff9900"
  18. placeholder="请输入交易金额" @change="change"
  19. @confirm="scanCode"></amountInput>
  20. </view>
  21. </template>
  22. <script>
  23. import amountInput from '@/components/amountInput/amountInput.vue';
  24. export default {
  25. components: {
  26. amountInput
  27. },
  28. data() {
  29. return {
  30. scanNotify:{scan: false,scanMessage:'扫描错误,请稍后重试!' },
  31. money:'',
  32. //向哪个用户收款
  33. secret:'',
  34. userId:''
  35. }
  36. },
  37. onLoad(options) {
  38. },
  39. methods: {
  40. scanCode(){
  41. const _this = this;
  42. uni.scanCode({
  43. onlyFromCamera:true,
  44. scanType: ['barCode'],
  45. success: function (res) {
  46. //用户id
  47. _this.secret=res.result
  48. _this.userId=_this.secret.substr(0,19)
  49. //处理支付
  50. _this.handelPay()
  51. },
  52. fail: (res) => {
  53. if(res.errMsg!='scanCode:fail cancel'){
  54. _this.scanNotify = {scan: true,scanMessage: res.errMsg};
  55. }
  56. }
  57. });
  58. },
  59. async handelPay(){
  60. let res=await this.getPointPayType()
  61. this.payBefore(res.data)
  62. },
  63. //获取积分策略
  64. async getPointPayType(){
  65. let params={
  66. shopId: this.vuex_shopId,
  67. loginUserId: this.userId,
  68. money: this.money
  69. }
  70. let res=await this.$api.shop.getPointPayType(params)
  71. return res
  72. },
  73. async payBefore(pointPayType){
  74. let expireTime=this.$dateTime.getExpireTime(5)
  75. let params={
  76. shopId:this.vuex_shopId,
  77. money:this.money,
  78. billsTitle:'用户支付',
  79. expireTime,
  80. appId:this.$global.wxParams.clientAppId,
  81. secret:this.userId,
  82. type:2,
  83. pointPayType
  84. }
  85. let resp=await this.$api.shop.payBefore(params)
  86. if (!resp.success) {
  87. this.$u.toast(resp.msg)
  88. return
  89. }
  90. //发送通讯
  91. this.sendInfo()
  92. this.$dialog.showModal('扫描成功,等待用户付款',false).then(()=>{
  93. this.backToIndex()
  94. })
  95. },
  96. //通知c端去支付
  97. sendInfo(){
  98. let msg={
  99. sid:this.userId,
  100. content:this.$global.socketMessage.payForPaymentCode,
  101. }
  102. this.$api.webSocket.sendInfo(msg)
  103. },
  104. backToIndex(){
  105. let prePage=this.$util.getPageCtx(1)
  106. prePage.setData({
  107. "isOpenSocket":true
  108. })
  109. uni.navigateBack({
  110. delta:1
  111. })
  112. },
  113. show(){
  114. this.$refs.amountInput.show()
  115. },
  116. change(e){
  117. if (!e) {
  118. this.money=0
  119. }else{
  120. this.money=e
  121. }
  122. },
  123. filterMoney(value) {
  124. value=value.toString()
  125. if (!value) {
  126. return ''
  127. } else {
  128. value = value.replace(/\$\s?|(,*)/g, '')
  129. return value.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
  130. }
  131. },
  132. }
  133. }
  134. </script>
  135. <style>
  136. page{
  137. background-color: #FFFFFF;
  138. }
  139. </style>
  140. <style lang="scss" scoped>
  141. .data{
  142. padding: 50rpx;
  143. display: flex;
  144. justify-content: flex-start;
  145. flex-direction: column;
  146. .price{
  147. &-icon{
  148. font-size: 40rpx;
  149. font-weight: 800;
  150. }
  151. }
  152. }
  153. .center{
  154. display: flex;
  155. justify-content: center;
  156. align-items: center;
  157. }
  158. .input-bar {
  159. height: 150rpx;
  160. border-bottom: 1rpx solid #DDDDDD;
  161. .icon {
  162. width: 15%;
  163. font-size: 70rpx;
  164. font-weight: 900;
  165. height: 100%;
  166. }
  167. .input {
  168. width: 85%;
  169. height: 100%;
  170. overflow: hidden;
  171. font-size: 70rpx;
  172. }
  173. .cusor {
  174. margin-left: 10rpx;
  175. width: 6rpx;
  176. border-radius: 20rpx;
  177. height: 60%;
  178. background-color: #ff9900;
  179. animation: blink 1200ms infinite ease-in-out;
  180. }
  181. }
  182. @keyframes blink {
  183. from {
  184. opacity: 0;
  185. }
  186. }
  187. </style>