paymoment.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <view>
  3. <van-radio-group>
  4. <van-cell-group v-for="(item, index) in list" :key="index">
  5. <van-cell title-class="changtitle" :title="item.title" @click="onChange(index)">
  6. <template slot="icon" style="padding-right: 10upx;">
  7. <van-radio-group :value="radio" >
  8. <van-radio checked-color="#D9332E" :name="index" >
  9. </van-radio>
  10. </van-radio-group>
  11. </template>
  12. </van-cell>
  13. </van-cell-group>
  14. </van-radio-group>
  15. <view class="payMoney" @click="payMoney" v-if="radio == 1">支付(圈币{{parseFloat}})</view>
  16. <view class="payMoney" @click="payMoney" v-if="radio == 0">支付(¥{{prices}})</view>
  17. <Dialog :orderCancel="orderCancel"
  18. :titles="titles"
  19. :values="values"
  20. @colseDialog="cancelDialog"
  21. @confirmPay="confirmOrder"
  22. />
  23. </view>
  24. </template>
  25. <script>
  26. import Dialog from '@/component/Dialog.vue'
  27. export default {
  28. components: {
  29. Dialog
  30. },
  31. data() {
  32. return {
  33. values:'',
  34. orderCancel: false,
  35. titles:'',
  36. list:[
  37. {title:'微信支付'},
  38. {title:'圈币支付'}
  39. ],
  40. radio: 0,
  41. prices: '',
  42. order_id:'',
  43. isform: 0,
  44. ratio_points: 2,
  45. store_id: '',
  46. }
  47. },
  48. onLoad(e) {
  49. this.prices = e.prices;
  50. this.order_id = e.order_id;
  51. this.store_id = e.store_id;
  52. this.getuserInfo();
  53. this.isform = e.isform;
  54. },
  55. methods: {
  56. //获取用户信息
  57. getuserInfo() {
  58. this.request({
  59. url: '/v2/member/info',
  60. method:'post',
  61. success: (res) => {
  62. this.ratio_points = res.data.data.ratio_points;
  63. if(this.ratio_points > 0) {
  64. this.list = [
  65. {title:'微信支付'},
  66. {title:'圈币支付'}
  67. ];
  68. }else {
  69. this.list = [
  70. {title:'微信支付'}
  71. ];
  72. }
  73. }
  74. })
  75. },
  76. // 圈币取消支付
  77. cancelDialog() {
  78. this.orderCancel = false;
  79. },
  80. // 圈币确定支付
  81. confirmOrder() {
  82. this.orderCancel = false;
  83. uni.showLoading({
  84. title: '支付中'
  85. });
  86. this.request({
  87. url:'/v1/payment/pay',
  88. method:'POST',
  89. data: {
  90. pay_code: 'point',
  91. order_id: this.order_id
  92. },
  93. success: (res) => {
  94. if(res.data.code == 1000) {
  95. uni.hideLoading();
  96. let isform = this.isform;
  97. let store_id = this.store_id;
  98. uni.redirectTo({
  99. url: `/pages/myOrder/finsh?isform=${isform}&order_id=${this.order_id}&store_id=${store_id}`
  100. })
  101. }
  102. }
  103. })
  104. },
  105. onChange(index) {
  106. this.radio = index;
  107. },
  108. payMoney() {
  109. if(this.radio == 0) {
  110. this.request({
  111. url:'/v1/payment/pay',
  112. method: 'post',
  113. data: {
  114. pay_code: 'wx',
  115. type: 1,
  116. order_id: this.order_id
  117. },
  118. success:(res) => {
  119. let { wx } = res.data.data;
  120. uni.requestPayment({
  121. provider: 'wxpay',
  122. timeStamp: wx.timeStamp,
  123. nonceStr: wx.nonceStr,
  124. package: wx.package,
  125. signType: 'MD5',
  126. paySign: wx.paySign,
  127. success: (res) => {
  128. let isform = this.isform;
  129. let order_id = this.order_id;
  130. let store_id = this.store_id;
  131. uni.redirectTo({
  132. url: `/pages/myOrder/finsh?isform=${isform}&order_id=${order_id}&store_id=${store_id}`
  133. })
  134. },
  135. fail: (err) => {
  136. let order_id = this.order_id ;
  137. uni.redirectTo({
  138. url: `/pages/myOrder/order?id=${order_id}`
  139. });
  140. }
  141. })
  142. },
  143. fail:(res) => {
  144. let order_id = this.order_id ;
  145. uni.redirectTo({
  146. url: `/pages/myOrder/order?id=${order_id}`
  147. });
  148. }
  149. })
  150. }else {
  151. this.titles = "圈币支付";
  152. this.values = "使用圈币支付"+this.prices*this.ratio_points;
  153. this.orderCancel = true;
  154. }
  155. }
  156. },
  157. computed:{
  158. parseFloat(){
  159. return parseInt(this.prices*this.ratio_points)
  160. }
  161. }
  162. }
  163. </script>
  164. <style>
  165. .payMoney {
  166. width: 90%;
  167. color: #fff;
  168. background-color: #D9332E;
  169. position: fixed;
  170. text-align: center;
  171. padding: 20upx 0;
  172. bottom: 5%;
  173. left: 5%;
  174. }
  175. .changtitle {
  176. padding-left: 10upx;
  177. }
  178. </style>