paymoment.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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">支付(圈币{{prices*ratio_points}})</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. console.log(e);
  50. console.log("支付");
  51. this.prices = e.prices;
  52. this.order_id = e.order_id;
  53. this.store_id = e.store_id;
  54. this.getuserInfo();
  55. this.isform = e.isform;
  56. //this.ratio_points = e.ratio_points;
  57. // this.isform = e.isform; // 1 dingdanfukuanguolai
  58. // if(this.ratio_points > 0) {
  59. // this.list = [
  60. // {title:'微信支付'},
  61. // {title:'圈币支付'}
  62. // ];
  63. // }else {
  64. // this.list = [
  65. // {title:'微信支付'}
  66. // ];
  67. // }
  68. },
  69. methods: {
  70. //获取用户信息
  71. getuserInfo() {
  72. this.request({
  73. url: '/v2/member/info',
  74. method:'post',
  75. success: (res) => {
  76. this.ratio_points = res.data.data.ratio_points;
  77. if(this.ratio_points > 0) {
  78. this.list = [
  79. {title:'微信支付'},
  80. {title:'圈币支付'}
  81. ];
  82. }else {
  83. this.list = [
  84. {title:'微信支付'}
  85. ];
  86. }
  87. }
  88. })
  89. },
  90. // 圈币取消支付
  91. cancelDialog() {
  92. this.orderCancel = false;
  93. },
  94. // 圈币确定支付
  95. confirmOrder() {
  96. this.orderCancel = false;
  97. uni.showLoading({
  98. title: '支付中'
  99. });
  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. if(res.data.code == 1000) {
  109. uni.hideLoading();
  110. let isform = this.isform;
  111. let store_id = this.store_id;
  112. uni.redirectTo({
  113. url: `/pages/myOrder/finsh?isform=${isform}&order_id=${this.order_id}&store_id=${store_id}`
  114. })
  115. }
  116. }
  117. })
  118. },
  119. onChange(index) {
  120. this.radio = index;
  121. },
  122. payMoney() {
  123. if(this.radio == 0) {
  124. // 微信支付
  125. // uni.showLoading({
  126. // title: '支付中'
  127. // });
  128. this.request({
  129. url:'/v1/payment/pay',
  130. method: 'post',
  131. data: {
  132. pay_code: 'wx',
  133. type: 1,
  134. order_id: this.order_id
  135. },
  136. success:(res) => {
  137. let { wx } = res.data.data;
  138. uni.requestPayment({
  139. provider: 'wxpay',
  140. timeStamp: wx.timeStamp,
  141. nonceStr: wx.nonceStr,
  142. package: wx.package,
  143. signType: 'MD5',
  144. paySign: wx.paySign,
  145. success: (res) => {
  146. let isform = this.isform;
  147. let order_id = this.order_id;
  148. let store_id = this.store_id;
  149. uni.redirectTo({
  150. url: `/pages/myOrder/finsh?isform=${isform}&order_id=${order_id}&store_id=${store_id}`
  151. })
  152. },
  153. fail: (err) => {
  154. let order_id = this.order_id ;
  155. uni.redirectTo({
  156. url: `/pages/myOrder/order?id=${order_id}`
  157. });
  158. }
  159. })
  160. },
  161. fail:(res) => {
  162. let order_id = this.order_id ;
  163. uni.redirectTo({
  164. url: `/pages/myOrder/order?id=${order_id}`
  165. });
  166. }
  167. })
  168. }else {
  169. this.titles = "圈币支付";
  170. this.values = "使用圈币支付"+this.prices*this.ratio_points;
  171. this.orderCancel = true;
  172. // 圈币支付
  173. // this.request({
  174. // url:'/v1/payment/pay',
  175. // method:'POST',
  176. // data: {
  177. // pay_code: 'point',
  178. // order_id: this.order_id
  179. // },
  180. // success: (res) => {
  181. // console.log(res);
  182. // }
  183. // })
  184. }
  185. }
  186. }
  187. }
  188. </script>
  189. <style>
  190. .payMoney {
  191. width: 90%;
  192. color: #fff;
  193. background-color: #D9332E;
  194. position: fixed;
  195. text-align: center;
  196. padding: 20upx 0;
  197. bottom: 5%;
  198. left: 5%;
  199. }
  200. .changtitle {
  201. padding-left: 10upx;
  202. }
  203. </style>