payment.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. import {Component, Vue} from 'vue-property-decorator';
  2. import Http from '../../extend/Http';
  3. import Utils from '../../extend/Utils';
  4. import wx from 'weixin-jsapi';
  5. import router from '@/router';
  6. import {MessageBox} from 'element-ui';
  7. // import 'vue-router/types/vue';
  8. @Component({
  9. components: {}
  10. })
  11. export default class UserIndex extends Vue {
  12. public data: any = {
  13. hour: 0,
  14. minute: 0,
  15. second: 0,
  16. orderSn: '0',
  17. totalCharge: '0',
  18. payment: 'weixin',
  19. model: false,
  20. html:'',
  21. zhifupay:true,
  22. isShowA:true,
  23. isShowB: false,
  24. isShowC: true,
  25. recharfe: true
  26. };
  27. private closeTime: string = '0';
  28. private timer: number = 0;
  29. async created() {
  30. let url = Utils.getInstance().getParams(location.href);
  31. console.log(url)
  32. if(url.tip == 'yes'){
  33. this.data.model = true;
  34. }else{
  35. this.data.model = false;
  36. }
  37. let isWeiXin = () => { return navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1 }
  38. if (isWeiXin()) {
  39. this.data.zhifupay = false
  40. }
  41. }
  42. mounted() {
  43. if( this.$route.params.type == '1'){
  44. let info = JSON.parse(localStorage.getItem('order_paying') as string);
  45. // this.closeTime = info.close_timestamp;
  46. this.data.totalCharge = info.total_charge;
  47. this.data.orderSn = info.order_sn;
  48. }else{
  49. let info = JSON.parse(localStorage.getItem('order_payings') as string);
  50. // this.closeTime = info.close_timestamp;
  51. this.data.totalCharge = info.total_charge;
  52. this.data.orderSn = info.order_sn;
  53. }
  54. if (this.$route.params.recharfe) {
  55. this.data.recharfe = false
  56. }
  57. }
  58. hideModel() {
  59. this.data.model = false;
  60. router.replace({
  61. name: 'olist'
  62. });
  63. }
  64. open() {
  65. // @ts-ignore
  66. MessageBox.alert('<a href="tel:' + Http.PHONE + '">' + Http.PHONE + '</a>', '请联系客服', {
  67. dangerouslyUseHTMLString: true,
  68. confirmButtonText: "拨打" ,
  69. beforeClose: (action, instance, done) => {
  70. window.location.href = 'tel://' +Http.PHONE;
  71. done()
  72. }
  73. }).then(action =>{
  74. });
  75. }
  76. weixin(){
  77. this.data.isShowA = !this.data.isShowA;
  78. this.data.isShowB = false
  79. }
  80. zhifubao(){
  81. this.data.isShowB = !this.data.isShowB;
  82. this.data.isShowA = false
  83. }
  84. gzhweixin(){
  85. this.data.isShowC = true
  86. }
  87. zongpay(){
  88. let isWeiXin = () => { return navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1 }
  89. if (isWeiXin()) {
  90. this.weixinpayment()
  91. }else {
  92. if( this.data.isShowA == true ){
  93. this.payment();
  94. }
  95. if(this.data.isShowB == true){
  96. this.alipayment();
  97. }
  98. }
  99. }
  100. async payment() {
  101. // let res = await Http.getInstance().payOrder({
  102. // order_sn: this.data.orderSn, platform: platform, remark: '订单支付'
  103. // });
  104. // let res = await Http.getInstance().getWeixin({
  105. // order_sn: this.data.orderSn,
  106. // platform: 'weixin',
  107. // pay:'wappay'
  108. // });
  109. // 社保支付
  110. // let res = await Http.getInstance().getWeixin({
  111. // order_sn: this.data.orderSn,
  112. // platform: 'weixin',
  113. // pay:'wappay'
  114. // });
  115. // 合并
  116. let res
  117. if (this.data.recharfe) {
  118. res = await Http.getInstance().getWeixin({
  119. order_sn: this.data.orderSn,
  120. platform: 'weixin',
  121. pay:'wappay'
  122. });
  123. // console.log('社保支付',res)
  124. } else {
  125. res = await Http.getInstance().RechargeOrderPay({
  126. order_sn: this.data.orderSn,
  127. platform: 'weixin',
  128. pay:'wappay'
  129. });
  130. // console.log('卡支付',res)
  131. }
  132. window.location.replace(
  133. res.data.mweb_url+'&redirect_url='+encodeURIComponent(window.location.href+'?tip=yes'))
  134. // console.log(this.data.orderSn)
  135. // this.data.model = true;
  136. // this.data.payment = platform;
  137. // switch (platform) {
  138. // case 'weixin':
  139. // // this.wxpay(res.data);
  140. // this.data.payment = 'weixin';
  141. // break;
  142. // case 'alipay':
  143. // // this.alipay(res.data);
  144. // break;
  145. // case 'union':
  146. // // this.unionpay(res.data);
  147. // break;
  148. // }
  149. }
  150. async alipayment() {
  151. // 社保
  152. // let res = await Http.getInstance().getAlipay({
  153. // order_sn: this.data.orderSn,
  154. // platform: 'alipay',
  155. // pay:'wappay'
  156. // });
  157. // 合并后
  158. let res
  159. if (this.data.recharfe) {
  160. res = await Http.getInstance().getAlipay({
  161. order_sn: this.data.orderSn,
  162. platform: 'alipay',
  163. pay:'wappay'
  164. });
  165. } else {
  166. res = await Http.getInstance().RechargeOrderPay({
  167. order_sn: this.data.orderSn,
  168. platform: 'alipay',
  169. pay:'wappay'
  170. });
  171. }
  172. console.log(res.data)
  173. this.data.model = true;
  174. this.data.html = res.data
  175. let form= res.data;
  176. const div = document.createElement('div')
  177. div.innerHTML = form//此处form就是后台返回接收到的数据
  178. document.body.appendChild(div)
  179. document.forms[0].submit()
  180. }
  181. async weixinpayment() {
  182. let openid = localStorage.getItem('openid');
  183. let res
  184. if (this.data.recharfe) {
  185. console.log(123);
  186. res = await Http.getInstance().getWeixin({
  187. order_sn: this.data.orderSn, platform: 'weixin', pay: 'wxpay', openid: openid
  188. });
  189. } else {
  190. console.log(111);
  191. res = await Http.getInstance().RechargeOrderPay({
  192. order_sn: this.data.orderSn, platform: 'weixin', pay: 'wxpay', openid: openid
  193. });
  194. }
  195. res.data.jsApiList = ['chooseWXPay'];
  196. console.log(res.data)
  197. //wx.config(res.data);
  198. wx.config({
  199. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  200. appId: res.data.appId, // 必填,公众号的唯一标识
  201. timestamp: res.data.timeStamp, // 必填,生成签名的时间戳
  202. nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
  203. signature: res.data.paySign,// 必填,签名,见附录1 https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115
  204. jsApiList: ['chooseWXPay']//['chooseWXPay'] // getBrandWCPayquest 必填,需要使用的JS接口列表,这里只写支付的
  205. });
  206. wx.ready(() => {
  207. wx.chooseWXPay({
  208. timestamp: res.data.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  209. nonceStr: res.data.nonceStr, // 支付签名随机串,不长于 32 位
  210. package: res.data.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***)
  211. signType: res.data.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
  212. paySign: res.data.paySign, // 支付签名
  213. success: (r) => {
  214. // alert('支付成功');
  215. if (r.errMsg == "chooseWXPay:ok") {
  216. alert('支付成功');
  217. if (this.data.recharfe) {
  218. router.replace('/order/list');
  219. } else {
  220. router.replace('/recharge/list');
  221. }
  222. } else {
  223. alert('支付失败')
  224. if (this.data.recharfe) {
  225. router.replace('/order/list');
  226. } else {
  227. router.replace('/recharge/list');
  228. }
  229. }
  230. },
  231. cancel: (r) => {
  232. //支付取消
  233. alert('支付取消')
  234. if (this.data.recharfe) {
  235. router.replace('/order/list');
  236. } else {
  237. router.replace('/recharge/list');
  238. }
  239. },
  240. fail: (res) => {
  241. alert('支付失败');
  242. if (this.data.recharfe) {
  243. router.replace('/order/list');
  244. } else {
  245. router.replace('/recharge/list');
  246. }
  247. }
  248. });
  249. });
  250. }
  251. private countTime(datetime: any): any {
  252. this.timer = setInterval(() => {
  253. // 获取当前时间
  254. let now = new Date().getTime();
  255. // 设置截止时间
  256. let end = new Date(datetime).getTime();
  257. // 时间差
  258. let left = end - now;
  259. if (left > 0) {
  260. this.data.hour = Utils.getInstance().prefixInteger(Math.floor(left / 3600000));
  261. this.data.minute = Utils.getInstance().prefixInteger(Math.floor((left / 60000) % 60));
  262. this.data.second = Utils.getInstance().prefixInteger(Math.floor((left / 1000) % 60));
  263. } else {
  264. clearInterval(this.timer);
  265. router.replace({
  266. name: 'olist',
  267. });
  268. }
  269. }, 1000);
  270. }
  271. async wxpay(data: any) {
  272. // let info = JSON.parse(localStorage.getItem('order_paying') || '');
  273. // console.log('info');
  274. // let resss = await Http.getInstance().getConfig({
  275. // platform: 'weixin',
  276. // order_sn: info.order_sn,
  277. // url: location.href.slice(0, -7)
  278. // });
  279. // console.log(resss)
  280. let openid = localStorage.getItem('openid');
  281. let res = await Http.getInstance().getWeixin({
  282. order_sn: this.data.orderSn,
  283. platform: 'weixin',
  284. pay:'wxpay',
  285. openid:openid
  286. });
  287. res.data.jsApiList = ['chooseWXPay'];
  288. wx.config(res.data);
  289. wx.ready(() => {
  290. wx.chooseWXPay({
  291. timestamp: res.data.timestamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  292. nonceStr: res.data.nonceStr, // 支付签名随机串,不长于 32 位
  293. package: res.data.prepay_id, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
  294. signType: res.data.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
  295. paySign: res.data.paySign, // 支付签名
  296. success: (res: any) => {
  297. alert(res);
  298. if (res) {
  299. // localStorage.removeItem('order_paying');
  300. // router.replace('orderList');
  301. } else {
  302. }
  303. }
  304. });
  305. });
  306. wx.error((err: any) => {
  307. alert(JSON.stringify(err));
  308. });
  309. }
  310. private alipay(data: any) {
  311. }
  312. private unionpay(data: any) {
  313. }
  314. }