paymoment.vue 4.7 KB

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