index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. define([
  2. 'axios',
  3. 'layer',
  4. 'text!components/payment/index.html',
  5. 'css!components/payment/index.css'
  6. ], function(axios, layer, html) {
  7. return {
  8. props: {
  9. payment: {
  10. type: Boolean,
  11. default: false
  12. },
  13. money: {
  14. type: Number,
  15. default: 0
  16. },
  17. now_money: {
  18. type: Number,
  19. default: 0
  20. },
  21. special_id: {
  22. type: Number,
  23. default: 0
  24. },
  25. pay_type_num: {
  26. type: Number,
  27. default: -1
  28. },
  29. pinkId: {
  30. type: Number,
  31. default: 0
  32. },
  33. link_pay_uid: {
  34. type: Number,
  35. default: 0
  36. },
  37. isWechat: {
  38. type: Boolean,
  39. default: false
  40. },
  41. isAlipay: {
  42. type: Boolean,
  43. default: false
  44. },
  45. isBalance: {
  46. type: Boolean,
  47. default: false
  48. },
  49. signs: {
  50. type: Object,
  51. default: function () {
  52. return {};
  53. }
  54. },
  55. templateId: {
  56. type: String,
  57. default: ''
  58. },
  59. wxpayH5: {
  60. type: Boolean,
  61. default: true
  62. },
  63. priceId: {
  64. type: Number,
  65. default: 0
  66. }
  67. },
  68. data: function () {
  69. return {
  70. payType: ''
  71. };
  72. },
  73. mounted: function () {
  74. this.$nextTick(function () {
  75. if (this.isWechat) {
  76. // 无法使用开放标签触发WeixinOpenTagsError事件
  77. document.addEventListener('WeixinOpenTagsError', function (e) {
  78. console.error(e.detail.errMsg);
  79. });
  80. }
  81. if (this.isWechat || this.wxpayH5) {
  82. this.payType = 'weixin';
  83. } else if (!this.isWechat && !this.wxpayH5 && this.isAlipay) {
  84. this.payType = 'zhifubao';
  85. } else if (!this.isWechat && !this.wxpayH5 && !this.isAlipay && this.isBalance) {
  86. this.payType = 'yue';
  87. }
  88. });
  89. },
  90. methods: {
  91. // 立即支付
  92. onPay: function () {
  93. var index = layer.load(1);
  94. var backUrlCRshlcICwGdGY = {
  95. special_id: this.special_id,
  96. pay_type_num: this.pay_type_num,
  97. pinkId: this.pinkId,
  98. link_pay_uid: this.link_pay_uid,
  99. payType: this.payType,
  100. from: this.isWechat ? 'weixin' : 'weixinh5'
  101. };
  102. Object.assign(backUrlCRshlcICwGdGY, this.signs);
  103. // 报名信息转换为JSON字符串
  104. if (this.pay_type_num === 20) {
  105. for (var i = 0; i < backUrlCRshlcICwGdGY.event.length; i++) {
  106. if (backUrlCRshlcICwGdGY.event[i].event_type === 3) {
  107. backUrlCRshlcICwGdGY.event[i].event_value = backUrlCRshlcICwGdGY.event[i].event_value.join();
  108. }
  109. }
  110. backUrlCRshlcICwGdGY.price_id = this.priceId;
  111. }
  112. axios.post('/wap/special/create_order', backUrlCRshlcICwGdGY).then(function (res) {
  113. if (res.data.code === 200) {
  114. this.$emit('change', {
  115. action: 'pay_order',
  116. value: res.data
  117. });
  118. } else {
  119. layer.msg(res.data.msg, {
  120. anim: 0
  121. }, function () {
  122. this.$emit('change', {
  123. action: 'payClose',
  124. value: true
  125. });
  126. }.bind(this));
  127. }
  128. }.bind(this)).catch(function (error) {
  129. console.error(error);
  130. }.bind(this)).then(function () {
  131. layer.close(index);
  132. });
  133. },
  134. // 微信订阅按钮操作成功
  135. onSuccess: function (event) {
  136. if (event.detail.errMsg === 'subscribe:ok') {
  137. this.onPay();
  138. }
  139. },
  140. // 微信订阅按钮操作失败
  141. onError: function (event) {
  142. layer.msg('订阅通知模板ID错误', {
  143. anim: 0
  144. }, function () {
  145. this.onPay();
  146. }.bind(this));
  147. },
  148. // 关闭
  149. onClose: function () {
  150. this.$emit('change', {
  151. action: 'payClose',
  152. value: true
  153. });
  154. }
  155. },
  156. template: html
  157. };
  158. });