payment.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view>
  3. <view class="top">
  4. <view class="title">付款给:<text>{{title}}</text></view>
  5. <view class="shop">{{options.merchantName ? options.merchantName : ''}}<text v-if="options.merchantName&&options.name">/</text>{{options.name ? options.name : ''}}</view>
  6. </view>
  7. <view class="con">
  8. <view class="tits">付款金额</view>
  9. <view class="money ddflex">
  10. <text>¥</text>
  11. <input v-model="money" :disabled="unEdit?true:false" type="digit" class="fflex" />
  12. </view>
  13. <view class="bz">
  14. <textarea v-model="remarks" placeholder="填写备注" placeholder-class="placeholder" class="bzcon"></textarea>
  15. </view>
  16. <view class="btn" @click="pays()">马上付款</view>
  17. <navigator :url="'/payment/paymentList/paymentList?openId=' + openId" hover-class="none" class="jilu">买单记录</navigator>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. const req = require('../../utils/request.js');
  23. const api = require('../../utils/api.js');
  24. const util = require('../../utils/util.js');
  25. const app = getApp();
  26. export default {
  27. data() {
  28. return {
  29. options: {},
  30. title: '',
  31. openId: '',
  32. money: '',
  33. remarks: '',
  34. scene: '',
  35. unEdit:false,//扫码带金额进来则不允许修改
  36. };
  37. },
  38. async onLoad(options) {
  39. console.log('options==', options)
  40. this.options = options;
  41. app.globalData.getCheckSessoin(json => {
  42. this.openId = json.openid;
  43. });
  44. await req.silenceLogin(options.userId, '');
  45. if(options.scene){
  46. this.scene = decodeURIComponent(options.scene);
  47. await this.loadCodeParams();
  48. }else{
  49. await this.getConfig();
  50. if(options.merchantId && options.merchantId != 'null' && options.merchantId != ''){
  51. await this.getMerchant();
  52. }
  53. if(this.options.uid){
  54. await this.getUserInfo();
  55. }
  56. }
  57. },
  58. onShow(){
  59. },
  60. methods: {
  61. getConfig() {
  62. var _this = this;
  63. return new Promise((resolve,reject)=>{
  64. req.getRequest('/api/config', {}, function(res) {
  65. _this.title = res.CONFIG_PROJECT_TITLE;
  66. uni.setNavigationBarTitle({
  67. title: _this.title + '收银台'
  68. })
  69. resolve();
  70. })
  71. })
  72. },
  73. getMerchant(){
  74. return new Promise((resolve,reject)=>{
  75. req.getRequest('/api/merchant/getMerchant',{id: this.options.merchantId},res=>{
  76. this.options.merchantName = res.title;
  77. resolve();
  78. })
  79. })
  80. },
  81. getUserInfo(){
  82. return new Promise((resolve,reject)=>{
  83. req.getRequest('/api/user/getInfo',{userId: this.options.uid},res=>{
  84. this.options.name = res.realName ? res.realName : res.nickName;
  85. resolve();
  86. })
  87. })
  88. },
  89. pays(){
  90. let params = {};
  91. var keys = unescape(this.scene).split('=');
  92. let apiUrl = '';
  93. if(keys[0] == 'id'){
  94. params = {
  95. openId: this.openId,
  96. money: this.money,
  97. id: keys[1]
  98. }
  99. if(this.remarks){
  100. params.note = this.remarks;
  101. }
  102. apiUrl = '/api/v3/collection/create';
  103. }else{
  104. params = {
  105. openId: this.openId,
  106. initiator: this.options.uid,
  107. money: this.money,
  108. merchantId: this.options.merchantId,
  109. type: this.options.type
  110. }
  111. if(this.remarks){
  112. params.remarks = this.remarks
  113. }
  114. apiUrl = '/api/receipt/initiateCollection';
  115. }
  116. req.postRequest(apiUrl,params,res=>{
  117. this.payOrder(res)
  118. })
  119. },
  120. payOrder(res) {
  121. var keys = unescape(this.scene).split('=');
  122. if(keys[0] == 'id'){
  123. req.payOrder(res, success => {
  124. uni.redirectTo({
  125. url: '/payment/success/success?openId=' + this.openId
  126. })
  127. },'payment')
  128. }else{
  129. req.receipt(res, success => {
  130. uni.redirectTo({
  131. url: '/payment/success/success?openId=' + this.openId
  132. })
  133. })
  134. }
  135. },
  136. loadCodeParams() {
  137. let _ts = this;
  138. return new Promise((resolve, reject) => {
  139. var keys = unescape(_ts.scene).split('=');
  140. let form = {
  141. id: keys[1]
  142. };
  143. req.getRequest('/api/v3/collection/params', form, data => {
  144. this.title = data.authName;
  145. this.options.merchantName = data.merchantName;
  146. this.options.name = data.userName;
  147. if(data.money != 0){
  148. this.money = data.money;
  149. if(data.money) this.unEdit = true
  150. }
  151. this.options.remarks = data.note ? data.note : '';
  152. resolve();
  153. });
  154. });
  155. },
  156. }
  157. };
  158. </script>
  159. <style>
  160. @import "./payment.css";
  161. </style>