order.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. define(['jquery', 'bootstrap', 'frontend', 'frontend-ebook', 'layer', 'config'], function ($, undefined, Frontend, Ebook, Layer, Config) {
  2. var Controller = {
  3. index: function () {
  4. },
  5. pay: function () {
  6. this.info();
  7. },
  8. info: function () {
  9. console.log(1332);
  10. $(document).on('click', '#payorder', function () {
  11. if (Config.invokejson) {
  12. WeixinJSBridge.invoke('getBrandWCPayRequest', Config.invokejson,
  13. function (res) {
  14. if (res.err_msg == "get_brand_wcpay_request:ok") {
  15. layer.msg('支付成功!', {}, function () {
  16. location.href = "/ebook/shelf";
  17. });
  18. }
  19. }
  20. );
  21. } else {
  22. Layer.msg("请使用微信扫描上方二维码支付!");
  23. }
  24. });
  25. $(document).on('click', '#deleteorder', function () {
  26. var that = this;
  27. layer.confirm('确认取消订单?', {
  28. btn: ['确定', '取消'] //按钮
  29. }, function () {
  30. Layer.load();
  31. $.ajax({
  32. url: 'service/delete_order',
  33. data: {id: $(that).attr("book-id"), order_id: $(that).attr("order-id")},
  34. type: 'post',
  35. success: function (ret) {
  36. Layer.closeAll('loading');
  37. if (ret == 'success') {
  38. Layer.msg("取消订单成功!", {icon: 1}, function () {
  39. location.href = '/ebook/shelf';
  40. });
  41. } else {
  42. Ebook.popMessage("取消订单失败!");
  43. }
  44. }, error: function () {
  45. Layer.closeAll('loading');
  46. Ebook.popMessage("操作失败!请重试!");
  47. }
  48. })
  49. }, function () {
  50. });
  51. });
  52. if (Config.invokejson) {
  53. var onBridgeReady = function () {
  54. if (Config.paynow == 1) {
  55. $('#payorder').trigger('click');
  56. }
  57. }
  58. if (typeof WeixinJSBridge == "undefined") {
  59. if (document.addEventListener) {
  60. document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
  61. } else if (document.attachEvent) {
  62. document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
  63. document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
  64. }
  65. } else {
  66. onBridgeReady();
  67. }
  68. } else {
  69. if (Config.paynow == 1) {
  70. $('#payorder').trigger('click');
  71. }
  72. }
  73. }
  74. };
  75. return Controller;
  76. });