index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. define([
  2. 'require',
  3. 'axios',
  4. 'text!./index.html',
  5. 'css!./index.css',
  6. 'layer'
  7. ], function (require, axios, html) {
  8. return {
  9. props: {
  10. open: {
  11. type: Boolean,
  12. default: false
  13. },
  14. money: {
  15. type: Number,
  16. default: 0
  17. },
  18. now_money: {
  19. type: Number,
  20. default: 0
  21. },
  22. special_id: {
  23. type: Number,
  24. default: 0
  25. },
  26. pay_type_num: {
  27. type: Number,
  28. default: -1
  29. },
  30. pinkId: {
  31. type: Number,
  32. default: 0
  33. },
  34. link_pay_uid: {
  35. type: Number,
  36. default: 0
  37. },
  38. isWechat: {
  39. type: Boolean,
  40. default: false
  41. },
  42. isAlipay: {
  43. type: Boolean,
  44. default: false
  45. },
  46. isBalance: {
  47. type: Boolean,
  48. default: false
  49. },
  50. signs: {
  51. type: Object,
  52. default: function () {
  53. return {};
  54. }
  55. },
  56. templateId: {
  57. type: String,
  58. default: ''
  59. },
  60. wxpayH5: {
  61. type: Boolean,
  62. default: true
  63. },
  64. priceId: {
  65. type: Number,
  66. default: 0
  67. },
  68. useGold: {
  69. type: Boolean,
  70. default: false
  71. },
  72. isMember: [Boolean, Number],
  73. memberMoney: {
  74. type: Number,
  75. default: 0
  76. },
  77. memberLink: {
  78. type: String,
  79. default: ''
  80. }
  81. },
  82. data: function () {
  83. return {
  84. payOptions: [
  85. {
  86. id: 1,
  87. name: '微信支付',
  88. icon: require.toUrl('./svg/wxpay.svg'),
  89. value: 'weixin',
  90. canuse: this.isWechat || this.wxpayH5
  91. },
  92. {
  93. id: 2,
  94. name: '支付宝支付',
  95. icon: require.toUrl('./svg/alipay.svg'),
  96. value: 'zhifubao',
  97. canuse: this.isAlipay
  98. },
  99. {
  100. id: 3,
  101. name: '余额支付',
  102. icon: require.toUrl('./svg/yue.svg'),
  103. value: 'yue',
  104. canuse: this.isBalance
  105. }
  106. ],
  107. payChecked: '',
  108. WeixinOpenTagsError: false // 无法使用微信开放标签
  109. };
  110. },
  111. created: function () {
  112. var find = this.payOptions.find(function (option) {
  113. return option.canuse;
  114. });
  115. if (find) {
  116. this.payChecked = find.value;
  117. }
  118. if (this.isWechat) {
  119. // 无法使用微信开放标签触发WeixinOpenTagsError事件
  120. document.addEventListener('WeixinOpenTagsError', function () {
  121. this.WeixinOpenTagsError = true;
  122. }.bind(this));
  123. }
  124. },
  125. methods: {
  126. // 支付
  127. onPay: function () {
  128. var index = layer.load(1),
  129. backUrlCRshlcICwGdGY = {
  130. special_id: this.special_id,
  131. pay_type_num: this.pay_type_num,
  132. pinkId: this.pinkId,
  133. link_pay_uid: this.link_pay_uid,
  134. payType: this.payChecked,
  135. from: this.isWechat ? 'weixin' : 'weixinh5'
  136. };
  137. Object.assign(backUrlCRshlcICwGdGY, this.signs);
  138. // 报名信息转JSON字符串
  139. if (this.pay_type_num === 20) {
  140. backUrlCRshlcICwGdGY.price_id = this.priceId;
  141. backUrlCRshlcICwGdGY.event.forEach(function (item) {
  142. if (item.event_type === 3) {
  143. item.event_value = item.event_value.join();
  144. }
  145. });
  146. }
  147. if (this.pay_type_num === 40) {
  148. backUrlCRshlcICwGdGY.useGold = this.useGold;
  149. }
  150. // 创建订单
  151. let url = '/wap/special/create_order';
  152. if (this.pay_type_num == 7) url = '/wap/studyplan/create_order';
  153. axios.post(url, backUrlCRshlcICwGdGY).then(function (res) {
  154. if (res.data.code === 200) {
  155. this.$emit('change', {
  156. action: 'pay_order',
  157. value: res.data
  158. });
  159. } else {
  160. layer.msg(res.data.msg, {
  161. anim: 0
  162. }, function () {
  163. this.$emit('update:open', false);
  164. }.bind(this));
  165. }
  166. }.bind(this)).catch(function (error) {
  167. console.error(error);
  168. }.bind(this)).then(function () {
  169. layer.close(index);
  170. });
  171. },
  172. // 订阅按钮操作失败事件
  173. subscribeError: function (event) {
  174. this.onPay();
  175. }
  176. },
  177. template: html
  178. };
  179. });