paymoment.vue 4.3 KB

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