confirm.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <div>
  3. <van-row>
  4. <van-col span="24">
  5. <center class="title">
  6. {{this.stationName}}
  7. <p>
  8. <van-tag plain type="success">{{this.gasNum+'号枪'}}</van-tag>
  9. <van-tag plain type="success">{{this.oilName}}</van-tag>
  10. </p>
  11. </center>
  12. </van-col>
  13. </van-row>
  14. <van-cell-group>
  15. <van-cell title="订单金额">{{this.account}}</van-cell>
  16. <van-cell title="满减/立减/优惠券" value="0" />
  17. <van-cell title="实付金额">{{this.account}}</van-cell>
  18. </van-cell-group>
  19. <div class="btn-box">
  20. <van-button type="primary" round block @click="confirmOrderAndPay()">立即支付</van-button>
  21. </div>
  22. </div>
  23. </template>
  24. <script>
  25. import Vue from 'vue';
  26. import aesutil from '../utils/utils.js'
  27. import {
  28. Col,
  29. Row,
  30. Tag,
  31. Cell,
  32. CellGroup,
  33. Button,
  34. Toast
  35. } from 'vant';
  36. Vue.use(Col);
  37. Vue.use(Row);
  38. Vue.use(Tag);
  39. Vue.use(Cell);
  40. Vue.use(CellGroup);
  41. Vue.use(Button);
  42. Vue.use(Toast);
  43. Vue.prototype.$edcodeUtil = aesutil;
  44. export default Vue.extend({
  45. head() {
  46. return {
  47. title: '确认订单'
  48. }
  49. },
  50. data() {
  51. return {
  52. stationId: '',
  53. stationName: '',
  54. gasNum: '',
  55. oilName: '',
  56. account: ''
  57. };
  58. },
  59. created() {
  60. console.log(this.$route.query);
  61. this.stationId = this.$route.query.stationId;
  62. this.stationName = this.$route.query.stationName;
  63. this.gasNum = this.$route.query.gasNum;
  64. this.oilName = this.$route.query.oilName;
  65. this.account = this.$route.query.account;
  66. },
  67. mounted() {
  68. alert(this.$route.query.openId);
  69. alert(this.$route.query.orderNo);
  70. },
  71. methods: {
  72. //支付前,先进行订单确认,确认无误后,获取到订单id,作为入参,调用支付平台的下单接口,
  73. confirmOrderAndPay: function() {
  74. let openId = this.$route.query.openId;
  75. let orderNo = this.$route.query.orderNo;
  76. var record = this.$axios.get('/getPayOrderList', {
  77. params: {
  78. orderNo: orderNo,
  79. "openId": openId,
  80. "userType": "1"
  81. },
  82. });
  83. record.then(res => {
  84. if (res.data.retCode == 0) {
  85. //支付 ( 支付按钮绑定@click="confirmOrderAndPay()"事件)
  86. //根据接口返回的数据,在微信内拉起公众号支付,进行付款操作
  87. let orderId = res.data.data[0].orderId;
  88. let data = {
  89. "userType": "1",
  90. "openId": openId,
  91. "orderId": orderId,
  92. "mno": "399201207783923"
  93. }
  94. var payUrl = '/getJhPayInfo';
  95. this.$axios.post(payUrl, data)
  96. .then(function(response) {
  97. if (response.data.retCode === 0) {
  98. let data = response.data.data.respData
  99. WeixinJSBridge.invoke(
  100. "getBrandWCPayRequest", {
  101. appId: data.payAppId,
  102. timeStamp: data.payTimeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  103. nonceStr: data.paynonceStr, // 支付签名随机串,不长于 32
  104. package: data.payPackage, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
  105. signType: data.paySignType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
  106. paySign: data.paySign, // 支付签名
  107. },
  108. function(res) {
  109. //跳转到支付成功页面有这个页面
  110. // $this.$router.push({
  111. // path: "/success_page",
  112. // name: "success_page"
  113. // })
  114. console.log("支付结果是", res);
  115. if (res.err_msg === "get_brand_wcpay_request:ok") {
  116. // 使用以上方式判断前端返回,微信团队郑重提示:
  117. //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
  118. Toast('支付成功');
  119. } else {
  120. Toast('支付失败,请重试');
  121. }
  122. })
  123. // })
  124. } else {
  125. Toast({
  126. message: '获取支付信息失败,请重试',
  127. });
  128. }
  129. }).catch(function(error) {
  130. Toast({
  131. message: '获取下单信息失败,请重试',
  132. });
  133. console.log(error);
  134. });
  135. } else {}
  136. }).catch(function(error) {
  137. Toast({
  138. message: '确认订单信息失败,请重试',
  139. });
  140. console.log(error);
  141. })
  142. }
  143. //支付 ( 支付按钮绑定@click="confirmOrderAndPay()"事件)
  144. //根据接口返回的数据,在微信内拉起公众号支付,进行付款操作
  145. // goPay: function() {
  146. // var $this = this;
  147. // let openId = this.$route.query.openId;
  148. // let data = {
  149. // "userType": "1",
  150. // "token": openId,
  151. // "orderId": "37",
  152. // "mno": "399201207783923"
  153. // }
  154. // var payUrl = '/getJhPayInfo';
  155. // this.$axios.post(payUrl, data)
  156. // .then(function(response) {
  157. // if (response.data.retCode === 0) {
  158. // let data = response.data.data.respData
  159. // WeixinJSBridge.invoke(
  160. // "getBrandWCPayRequest", {
  161. // appId: data.payAppId,
  162. // timeStamp: data.payTimeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  163. // nonceStr: data.paynonceStr, // 支付签名随机串,不长于 32
  164. // package: data.payPackage, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
  165. // signType: data.paySignType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
  166. // paySign: data.paySign, // 支付签名
  167. // },
  168. // function(res) {
  169. // //跳转到支付成功页面有这个页面
  170. // // $this.$router.push({
  171. // // path: "/success_page",
  172. // // name: "success_page"
  173. // // })
  174. // console.log("支付结果是", res);
  175. // if (res.err_msg === "get_brand_wcpay_request:ok") {
  176. // // 使用以上方式判断前端返回,微信团队郑重提示:
  177. // //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
  178. // Toast('支付成功');
  179. // } else {
  180. // Toast('支付失败,请重试');
  181. // }
  182. // })
  183. // // })
  184. // } else {
  185. // Toast({
  186. // message: '获取支付信息失败,请重试',
  187. // });
  188. // }
  189. // }).catch(function(error) {
  190. // Toast({
  191. // message: '获取下单信息失败,请重试',
  192. // });
  193. // console.log(error);
  194. // });
  195. // }
  196. }
  197. })
  198. </script>
  199. <style lang="less">
  200. .title {
  201. font-size: 18px;
  202. padding: 20px 0;
  203. }
  204. .btn-box {
  205. box-sizing: border-box;
  206. width: 100%;
  207. position: fixed;
  208. bottom: 20px;
  209. left: 0;
  210. z-index: 1;
  211. padding: 0 20px;
  212. }
  213. </style>