subscribe.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import storage from './storage';
  2. export default {
  3. getSubscribeTemplate(field=null){
  4. let cache = storage.getJson('template');
  5. if(field == null){
  6. return cache;
  7. }
  8. return cache[field] != undefined ? cache[field] : null;
  9. },
  10. order(){
  11. let that = this;
  12. // #ifdef MP-WEIXIN
  13. let subscribeTemplate = this.getSubscribeTemplate();
  14. if(Object.keys(subscribeTemplate).length > 0){
  15. wx.getSetting({
  16. withSubscriptions: true,
  17. success(res){
  18. if(res.subscriptionsSetting && res.subscriptionsSetting.mainSwitch){
  19. let delivery_notice = that.getSubscribeTemplate("delivery_notice");
  20. let order_complete = that.getSubscribeTemplate("order_complete");
  21. let order_pay_success = that.getSubscribeTemplate("order_pay_success");
  22. let flag = true;
  23. let arr = [];
  24. if (!res.subscriptionsSetting.itemSettings) {
  25. arr.push(delivery_notice);
  26. arr.push(order_complete);
  27. arr.push(order_pay_success);
  28. }else if(res.subscriptionsSetting.itemSettings){
  29. if(!res.subscriptionsSetting.itemSettings[delivery_notice]){
  30. arr.push(delivery_notice);
  31. }
  32. if(!res.subscriptionsSetting.itemSettings[order_complete]){
  33. arr.push(order_complete);
  34. }
  35. if(!res.subscriptionsSetting.itemSettings[order_pay_success]){
  36. arr.push(order_pay_success);
  37. }
  38. if(arr.length <= 0){
  39. flag = false;
  40. }
  41. }
  42. if(flag){
  43. wx.showModal({
  44. title: "授权",
  45. content: "订阅消息授权",
  46. success(res){
  47. if (res.confirm) {
  48. wx.requestSubscribeMessage({
  49. tmplIds: arr,
  50. success(res){
  51. console.log(res)
  52. }
  53. });
  54. }
  55. }
  56. });
  57. }
  58. }
  59. }
  60. });
  61. }
  62. // #endif
  63. },
  64. refund(){
  65. let that = this;
  66. // #ifdef MP-WEIXIN
  67. if(this.getSubscribeTemplate("refund_notice") != null){
  68. wx.getSetting({
  69. withSubscriptions: true,
  70. success(res){
  71. if(res.subscriptionsSetting && res.subscriptionsSetting.mainSwitch){
  72. let refund_notice = that.getSubscribeTemplate("refund_notice");
  73. let flag = true;
  74. let arr = [];
  75. if (!res.subscriptionsSetting.itemSettings) {
  76. arr.push(refund_notice);
  77. }else if(res.subscriptionsSetting.itemSettings){
  78. if(!res.subscriptionsSetting.itemSettings[refund_notice]){
  79. arr.push(refund_notice);
  80. }
  81. if(arr.length <= 0){
  82. flag = false;
  83. }
  84. }
  85. if(flag){
  86. wx.showModal({
  87. title: "授权",
  88. content: "订阅消息授权",
  89. success(res){
  90. if (res.confirm) {
  91. wx.requestSubscribeMessage({
  92. tmplIds: arr,
  93. success(res){
  94. console.log(res)
  95. }
  96. });
  97. }
  98. }
  99. });
  100. }
  101. }
  102. }
  103. })
  104. }
  105. // #endif
  106. }
  107. }