paymoment.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. let isform = this.isform;
  117. let store_id = this.store_id;
  118. uni.redirectTo({
  119. url: `/pages/myOrder/finsh?isform=${isform}&order_id=${this.order_id}&store_id=${store_id}`
  120. })
  121. //uni.navigateBack()
  122. }
  123. }
  124. })
  125. },
  126. onChange(index) {
  127. this.radio = index;
  128. },
  129. payMoney() {
  130. if(this.radio == 0) {
  131. // 微信支付
  132. this.request({
  133. url:'/v1/payment/pay',
  134. method: 'post',
  135. data: {
  136. pay_code: 'wx',
  137. type: 1,
  138. order_id: this.order_id
  139. },
  140. success:(res) => {
  141. let { wx } = res.data.data;
  142. // uni.showLoading({
  143. // title: '支付中'
  144. // });
  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. console.log("成功")
  154. let isform = this.isform;
  155. let order_id = this.order_id;
  156. let store_id = this.store_id;
  157. uni.redirectTo({
  158. url: `/pages/myOrder/finsh?isform=${isform}&order_id=${order_id}&store_id=${store_id}`
  159. })
  160. },
  161. // fail: (err) => {
  162. // let order_id = this.order_id ;
  163. // uni.redirectTo({
  164. // url: `/pages/myOrder/order?id=${order_id}`
  165. // });
  166. // }
  167. })
  168. },
  169. fail:(res) => {
  170. let order_id = this.order_id ;
  171. uni.redirectTo({
  172. url: `/pages/myOrder/order?id=${order_id}`
  173. });
  174. }
  175. })
  176. }else {
  177. this.titles = "圈币支付";
  178. this.values = "使用圈币支付"+this.prices*this.ratio_points;
  179. this.orderCancel = true;
  180. // 圈币支付
  181. // this.request({
  182. // url:'/v1/payment/pay',
  183. // method:'POST',
  184. // data: {
  185. // pay_code: 'point',
  186. // order_id: this.order_id
  187. // },
  188. // success: (res) => {
  189. // console.log(res);
  190. // }
  191. // })
  192. }
  193. }
  194. }
  195. }
  196. </script>
  197. <style>
  198. .payMoney {
  199. width: 90%;
  200. color: #fff;
  201. background-color: #D9332E;
  202. position: fixed;
  203. text-align: center;
  204. padding: 20upx 0;
  205. bottom: 5%;
  206. left: 5%;
  207. }
  208. .changtitle {
  209. padding-left: 10upx;
  210. }
  211. </style>