order-pay.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. var app = new Vue({
  2. 'el': '#app',
  3. 'data': {
  4. // 详情
  5. info: {},
  6. memberInfo: {},
  7. // 参数
  8. params: {
  9. page: 1,
  10. pageSize: 10,
  11. },
  12. payType: 1,
  13. timeText: '00:00',
  14. timeId: null,
  15. },
  16. created: function () {
  17. var _this = this;
  18. _this.getInfo();
  19. _this.getMemberInfo();
  20. _this.type = getParam('type');
  21. setInterval(function(){
  22. _this.getMemberInfo();
  23. }, 8000);
  24. },
  25. mounted: function () {
  26. var _this = this;
  27. $(".weui-cells_checkbox .weui-check").change(function () {
  28. _this.payType = $(this).index('.weui-cells_checkbox .weui-check') + 1;
  29. })
  30. },
  31. methods: {
  32. // 获取会员信息
  33. getMemberInfo: function(){
  34. var _this = this;
  35. $.post('/weixin/member/getMemberInfo', function (res) {
  36. if (res.code == 'success') {
  37. _this.memberInfo = res.data
  38. } else if (res.code == 'login') {
  39. login(res.data.url);
  40. } else {
  41. $.toast(res.message, 'text');
  42. }
  43. }, "json");
  44. },
  45. // 获取列表数据
  46. getInfo: function () {
  47. var _this = this;
  48. var id = getParam('id');
  49. if (id <= 0 || id == '') {
  50. $.showLoading("结算订单参数错误...");
  51. setTimeout(function () {
  52. location.href = '/weixin/member/index';
  53. }, 500)
  54. return false;
  55. }
  56. $.showLoading("数据加载中...");
  57. $.post('/weixin/order/getInfo', {id: id}, function (res) {
  58. $.hideLoading();
  59. if (res.code == 'success') {
  60. _this.info = res.data
  61. _this.timeLock();
  62. } else if (res.code == 'login') {
  63. login(res.data.url);
  64. } else {
  65. $.showLoading(res.message);
  66. setTimeout(function () {
  67. location.href = '/weixin/member/index';
  68. }, 800)
  69. }
  70. }, "json");
  71. },
  72. timeLock: function () {
  73. var _this = this;
  74. var time = _this.info.endTime;
  75. if (time > 0) {
  76. _this.timeId = setInterval(function () {
  77. time--;
  78. if (time > 0) {
  79. var minute = Math.floor(time / 60) % 60;
  80. var second = time % 60;
  81. minute = minute < 10 ? '0' + minute : minute;
  82. second = second < 10 ? '0' + second : second;
  83. _this.timeText = minute + ':' + second;
  84. } else {
  85. _this.timeText = '00:00';
  86. clearInterval(_this.timeId);
  87. _this.getInfo();
  88. }
  89. }, 1000);
  90. } else {
  91. location.href = '/weixin/print/index';
  92. }
  93. },
  94. paySubmit: function () {
  95. var _this = this;
  96. if (_this.payType == 0) {
  97. $.toast('请选择支付方式');
  98. return false;
  99. }
  100. var id = _this.info.id;
  101. if (id <= 0) {
  102. $.toast('支付订单参数错误,请刷新重试');
  103. return false;
  104. }
  105. if (_this.payType == 1) {
  106. $.showLoading("支付提交中...");
  107. $.post('/weixin/payment/index', {id: id, payType: _this.payType}, function (res) {
  108. $.hideLoading();
  109. if (res.code == 'success') {
  110. // TODO 2.调起微信支付
  111. if (typeof WeixinJSBridge == "undefined") {
  112. $.toast('请在微信环境中使用...', "text");
  113. if (document.addEventListener) {
  114. document.addEventListener('WeixinJSBridgeReady', function(){
  115. _this.weixinPay(res.data);
  116. }, false);
  117. } else if (document.attachEvent) {
  118. document.attachEvent('WeixinJSBridgeReady', function(){
  119. _this.weixinPay(res.data);
  120. });
  121. document.attachEvent('onWeixinJSBridgeReady', function(){
  122. _this.weixinPay(res.data);
  123. });
  124. }
  125. } else {
  126. _this.weixinPay(res.data);
  127. }
  128. } else if (res.code == 'login') {
  129. login(res.data.url);
  130. } else {
  131. $.toast(res.message, 'text');
  132. }
  133. }, "json");
  134. } else if (_this.payType == 2) {
  135. $.confirm({
  136. title: '确认支付',
  137. text: '确认使用余额支付' + _this.info.total + '元?',
  138. onOK: function () {
  139. $.showLoading("支付提交中...");
  140. $.post('/weixin/payment/index', {id: id, payType: _this.payType}, function (res) {
  141. $.hideLoading();
  142. if (res.code == 'success') {
  143. if(res.data.type == 2){
  144. $.showLoading(res.message);
  145. setTimeout(function () {
  146. location.href = '/weixin/order/collage';
  147. })
  148. }else{
  149. $.showLoading(res.message);
  150. setTimeout(function () {
  151. location.href = '/weixin/order/complete?id=' + id;
  152. })
  153. }
  154. } else if (res.code == 'login') {
  155. login(res.data.url);
  156. } else {
  157. $.toast(res.message, 'text');
  158. }
  159. }, "json");
  160. },
  161. onCancel: function () {
  162. return false;
  163. }
  164. });
  165. }
  166. },
  167. // 发起微信支付
  168. weixinPay: function (params) {
  169. var _this = this;
  170. WeixinJSBridge.invoke(
  171. 'getBrandWCPayRequest', {
  172. "appId": params.appId, //公众号名称,由商户传入
  173. "timeStamp": params.timeStamp, //时间戳,自1970年以来的秒数
  174. "nonceStr": params.nonceStr, //随机串
  175. "package": params.package,
  176. "signType": params.signType, //微信签名方式:
  177. "paySign": params.sign, //微信签名
  178. },
  179. function (res) {
  180. if (res.err_msg == "get_brand_wcpay_request:ok") {
  181. setTimeout(function () {
  182. if(params.type == 2){
  183. location.href = '/weixin/order/collage';
  184. }else{
  185. location.href = '/weixin/order/complete?id=' + _this.info.id;
  186. }
  187. }, 800)
  188. }
  189. }
  190. );
  191. }
  192. }
  193. })