paymoment.vue 4.8 KB

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