share.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. var app = getApp();
  2. var status = require('../../utils/index.js');
  3. var util = require('../../utils/util.js');
  4. Page({
  5. mixins: [require('../../mixin/globalMixin.js'), require('../../mixin/compoentCartMixin.js')],
  6. data: {
  7. members: '',
  8. order_goods_list: [],
  9. orders: '',
  10. cartNum: 0,
  11. groupInfo: {
  12. group_name: '社区',
  13. owner_name: '团长'
  14. },
  15. },
  16. isFirst: 1,
  17. onLoad: function (options) {
  18. let order_id = options.order_id || '';
  19. if (!order_id) {
  20. wx.showModal({
  21. title: '提示',
  22. content: '参数错误',
  23. showCancel: false,
  24. confirmColor: '#F75451',
  25. success(res) {
  26. if (res.confirm) {
  27. wx.redirectTo({
  28. url: '/lionfish_comshop/pages/index/index',
  29. })
  30. }
  31. }
  32. })
  33. return false;
  34. }
  35. status.setGroupInfo().then((groupInfo) => { this.setData({ groupInfo }) });
  36. this.getData(order_id);
  37. },
  38. getData: function (order_id) {
  39. wx.showLoading();
  40. let token = wx.getStorageSync('token');
  41. app.util.ProReq('order.share_order', {
  42. token,
  43. order_id
  44. }).then(res => {
  45. wx.hideLoading();
  46. let {
  47. members,
  48. order_goods_list,
  49. orders
  50. } = res.data;
  51. this.setData({
  52. members,
  53. order_goods_list,
  54. orders
  55. })
  56. if(this.isFirst==1) this.compareCommunity(orders.head_info);
  57. this.isFirst++;
  58. }).catch(err => {
  59. console.log(err)
  60. app.util.message(err.msg || '请求出错', 'switchTo:/lionfish_comshop/pages/user/me', 'error');
  61. })
  62. },
  63. changeNotListCartNum: function (t) {
  64. let that = this;
  65. let e = t.detail;
  66. (0, status.cartNum)(that.setData({
  67. cartNum: e
  68. }));
  69. },
  70. /**
  71. * 比较社区
  72. * shareCommunity: 这个接龙的所属社区
  73. */
  74. compareCommunity: function (shareCommunity='') {
  75. console.log('shareCommunity', shareCommunity)
  76. let that = this;
  77. // 原来社区
  78. let currentCommunity = wx.getStorageSync('community');
  79. let currentCommunityId = currentCommunity.communityId || '';
  80. const token = wx.getStorageSync('token');
  81. let {
  82. groupInfo
  83. } = that.data;
  84. let shareCommunityId = shareCommunity.id || '';
  85. shareCommunityId && util.getCommunityById(shareCommunityId).then(res => {
  86. let {
  87. hide_community_change_btn,
  88. default_head_info
  89. } = res;
  90. if (res.open_danhead_model == 1) {
  91. // 开启单社区
  92. app.globalData.community = default_head_info;
  93. app.globalData.changedCommunity = true;
  94. wx.setStorage({
  95. key: "community",
  96. data: default_head_info
  97. })
  98. token && util.addhistory(default_head_info);
  99. if (shareCommunityId != default_head_info.communityId) {
  100. let {
  101. groupInfo
  102. } = that.data;
  103. console.log('开启单社区');
  104. app.util.message(`您只能访问自己${groupInfo.group_name}`, 'switchTo:/lionfish_comshop/pages/index/index', 'error', '知道了');
  105. return;
  106. }
  107. } else {
  108. // 社区是否存在
  109. if (currentCommunityId != '' && shareCommunityId) {
  110. // 存在并且不相同
  111. console.log('currentCommunityId存在 比较社区')
  112. if (currentCommunityId != shareCommunityId) {
  113. console.log('currentCommunityId存在 社区不同')
  114. console.log('禁止切换');
  115. app.util.message(`您只能访问自己${groupInfo.group_name}`, 'switchTo:/lionfish_comshop/pages/index/index', 'error', '知道了');
  116. return;
  117. }
  118. } else {
  119. // 不存在社区id
  120. //token 是否存在
  121. if (token) {
  122. util.getCommunityInfo().then(function (ret) {
  123. //比较社区
  124. console.log('token存在 比较社区')
  125. if (ret.community_id && ret.community_id != shareCommunityId) {
  126. app.util.message(`您只能访问自己${groupInfo.group_name}`, 'switchTo:/lionfish_comshop/pages/index/index', 'error', '知道了');
  127. return;
  128. }
  129. }).catch((param) => {
  130. console.log('step4 新人')
  131. if (Object.keys(param) != '') util.addhistory(param, true);
  132. });
  133. } else {
  134. console.log('token不存在 存社区')
  135. // 直接存本地
  136. app.globalData.community = res.data;
  137. app.globalData.changedCommunity = true;
  138. wx.setStorage({
  139. key: "community",
  140. data: res.data
  141. })
  142. }
  143. }
  144. }
  145. });
  146. },
  147. /**
  148. * 切换提示
  149. */
  150. confrimChangeCommunity: function () {
  151. let community = this.data.changeCommunity;
  152. let token = wx.getStorageSync('token');
  153. app.globalData.community = community;
  154. app.globalData.changedCommunity = true;
  155. wx.setStorage({
  156. key: "community",
  157. data: community
  158. })
  159. token && util.addhistory(community);
  160. this.setData({
  161. showChangeCommunity: false
  162. })
  163. console.log('用户点击确定')
  164. },
  165. /**
  166. * 取消切换
  167. */
  168. cancelChangeCommunity: function () {
  169. let {
  170. groupInfo
  171. } = this.data;
  172. wx.showModal({
  173. title: '提示',
  174. content: `此订单在您所属${groupInfo.group_name}不可参与`,
  175. showCancel: false,
  176. confirmColor: '#ff5041',
  177. success(res) {
  178. if (res.confirm) {
  179. wx.switchTab({
  180. url: `/lionfish_comshop/pages/index/index`
  181. })
  182. }
  183. }
  184. });
  185. },
  186. })