index.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. var app = getApp();
  2. var status = require('../../utils/index.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. waitSendNum: 0,
  9. waitSignNum: 0,
  10. waitPickNum: 0,
  11. completeNum: 0,
  12. disUserId: "",
  13. communityName: "",
  14. communityId: "",
  15. distribution: "",
  16. estimate: "",
  17. lastMonth: "",
  18. isShow: true,
  19. currentTab: 0,
  20. show_on_one:0,
  21. dialogShow: 0,
  22. effectValidOrderNum: 0,
  23. groupInfo: {
  24. group_name: '社区',
  25. owner_name: '团长'
  26. },
  27. showActionsheet: false,
  28. shareActionsheet: [
  29. { text: '发送给朋友', value: 1, share: true },
  30. { text: '生成二维码', value: 2, type: 'warn' }
  31. ]
  32. },
  33. /**
  34. * 生命周期函数--监听页面加载
  35. */
  36. onLoad: function (options) {
  37. let that = this;
  38. status.setGroupInfo().then((groupInfo) => {
  39. let owner_name = groupInfo && groupInfo.owner_name || '团长';
  40. wx.setNavigationBarTitle({
  41. title: `${owner_name}中心`,
  42. })
  43. that.setData({ groupInfo })
  44. });
  45. this.loadPage();
  46. },
  47. loadPage: function () {
  48. let that = this;
  49. status.loadStatus().then(function () {
  50. let appLoadStatus = app.globalData.appLoadStatus;
  51. if (appLoadStatus == 0) {
  52. //未登录
  53. wx.redirectTo({
  54. url: "/lionfish_comshop/pages/user/me"
  55. })
  56. } else if (appLoadStatus == 2) {
  57. // wx.redirectTo({
  58. // url: "/lionfish_comshop/pages/position/community"
  59. // })
  60. }
  61. that.setData({
  62. appLoadStatus: appLoadStatus,
  63. community: app.globalData.community
  64. })
  65. });
  66. this.load_community_data();
  67. },
  68. load_community_data:function(){
  69. var token = wx.getStorageSync('token');
  70. var that = this;
  71. app.util.request({
  72. 'url': 'entry/wxapp/user',
  73. 'data': {
  74. controller: 'community.get_community_info',
  75. 'token': token
  76. },
  77. dataType: 'json',
  78. success: function (res) {
  79. if (res.data.code == 0) {
  80. let communityData = res.data;
  81. let commission_info = communityData.commission_info;
  82. commission_info.mix_total_money = commission_info.mix_total_money.toFixed(2);
  83. let { head_today_pay_money, today_add_head_member, today_after_sale_order_count, today_invite_head_member,is_open_solitaire,is_show_community_ranking } = res.data;
  84. that.setData({
  85. member_info: communityData.member_info,
  86. community_info: communityData.community_info,
  87. commission_info: commission_info,
  88. total_order_count: communityData.total_order_count || 0,
  89. total_member_count: communityData.total_member_count || 0,
  90. today_order_count: communityData.today_order_count || 0,
  91. today_effect_order_count: communityData.today_effect_order_count || 0,
  92. today_pay_order_count: communityData.today_pay_order_count || 0,
  93. today_pre_total_money: communityData.today_pre_total_money || 0,
  94. waitSendNum: communityData.wait_send_count || 0,
  95. waitSignNum: communityData.wait_qianshou_count || 0,
  96. waitPickNum: communityData.wait_tihuo_count || 0,
  97. completeNum: communityData.has_success_count || 0,
  98. open_community_addhexiaomember: communityData.open_community_addhexiaomember,
  99. open_community_head_leve: communityData.open_community_head_leve,
  100. head_today_pay_money,
  101. today_add_head_member,
  102. today_after_sale_order_count,
  103. today_invite_head_member,
  104. is_open_solitaire,
  105. shop_index_share_title: communityData.shop_index_share_title,
  106. shop_index_share_image: communityData.shop_index_share_image,
  107. is_show_community_ranking: is_show_community_ranking || 0
  108. });
  109. } else {
  110. //is_login
  111. wx.reLaunch({
  112. url: '/lionfish_comshop/pages/user/me',
  113. })
  114. }
  115. }
  116. })
  117. },
  118. /**
  119. * 扫描
  120. */
  121. goScan: function(){
  122. wx.scanCode({
  123. success(res) {
  124. console.log(res)
  125. if (res.scanType == 'WX_CODE' && res.path != '')
  126. {
  127. wx.navigateTo({
  128. url: "/" + res.path
  129. });
  130. }
  131. }
  132. })
  133. },
  134. /**
  135. * 生命周期函数--监听页面显示
  136. */
  137. onShow: function () {
  138. var that = this;
  139. var show_on_one = this.data.show_on_one;
  140. let commiss_diy_name = wx.getStorageSync('commiss_diy_name') || '分销';
  141. if (show_on_one > 0) {
  142. this.load_community_data();
  143. }
  144. this.setData({
  145. show_on_one: 1,
  146. commiss_diy_name
  147. })
  148. },
  149. /**
  150. * 跳转订单
  151. */
  152. goOrder: function (e) {
  153. let status = e.currentTarget.dataset.status;
  154. wx.navigateTo({
  155. url: "/lionfish_comshop/moduleA/groupCenter/groupList?tab=" + status
  156. });
  157. },
  158. /**
  159. * 跳转编辑
  160. */
  161. goEdit: function () {
  162. wx.navigateTo({
  163. url: "/lionfish_comshop/moduleA/groupCenter/setting?id=" + this.data.community_info.id
  164. });
  165. },
  166. /**
  167. * 导航切换
  168. */
  169. switchNav: function (e) {
  170. if (this.data.currentTab === 1 * e.target.dataset.current) return false;
  171. this.setData({
  172. currentTab: 1 * e.target.dataset.current
  173. });
  174. },
  175. /**
  176. * 导航切换监控
  177. */
  178. bindChange: function (e) {
  179. this.setData({
  180. currentTab: 1 * e.detail.current
  181. });
  182. for (var i = 0; i < 4; i++) {
  183. if (this.data.currentTab === i) {
  184. this.setData({
  185. effectEstimate: this.data.effectList[i].estimate,
  186. effectSettle: this.data.effectList[i].settle,
  187. effectValidOrderNum: this.data.effectList[i].validOrderNum
  188. });
  189. }
  190. }
  191. },
  192. changeMycommunion: function () {
  193. let community_info = this.data.community_info;
  194. let community_id = community_info.id;
  195. console.log(community_id)
  196. var token = wx.getStorageSync('token');
  197. let that = this;
  198. community_id !== void 0 && app.util.request({
  199. url: 'entry/wxapp/index',
  200. data: {
  201. controller: 'index.addhistory_community',
  202. community_id: community_id,
  203. token: token
  204. },
  205. dataType: 'json',
  206. success: function (res) {
  207. console.log('s1')
  208. that.getCommunityInfo().then(() => {
  209. console.log('s2')
  210. app.globalData.changedCommunity = true;
  211. wx.switchTab({
  212. url: '/lionfish_comshop/pages/index/index',
  213. })
  214. });
  215. }
  216. })
  217. },
  218. getCommunityInfo: function(){
  219. return new Promise(function (resolve, reject) {
  220. var token = wx.getStorageSync('token');
  221. app.util.request({
  222. url: 'entry/wxapp/index',
  223. data: {
  224. controller: 'index.load_history_community',
  225. token: token
  226. },
  227. dataType: 'json',
  228. success: function (res) {
  229. if (res.data.code == 0) {
  230. let history_communities = res.data.list;
  231. if (Object.keys(history_communities).length > 0 || history_communities.communityId != 0) {
  232. wx.setStorageSync('community', history_communities);
  233. app.globalData.community = history_communities;
  234. resolve(history_communities);
  235. } else {
  236. resolve('');
  237. }
  238. }
  239. }
  240. })
  241. })
  242. },
  243. handleShareActionsheet: function(){
  244. // this.setData({ showActionsheet: true })
  245. this.getShareCode();
  246. },
  247. closeQrcodeModal: function(){
  248. this.setData({ showQrcodeModal: !this.data.showQrcodeModal })
  249. },
  250. getShareCode(){
  251. wx.showLoading();
  252. var token = wx.getStorageSync('token');
  253. var that = this;
  254. app.util.request({
  255. url: 'entry/wxapp/user',
  256. data: {
  257. controller: 'community.community_index_shareqrcode',
  258. token
  259. },
  260. dataType: 'json',
  261. success: function (res) {
  262. wx.hideLoading();
  263. if (res.data.code == 0) {
  264. let qrcode = res.data.qrcode;
  265. if(!qrcode) {
  266. return wx.showToast({
  267. title: '暂未生成二维码',
  268. icon: 'none'
  269. })
  270. }
  271. that.setData({ qrcode, showQrcodeModal: true })
  272. }
  273. }
  274. })
  275. },
  276. btnClick(e){
  277. let type = e.detail.value;
  278. if(type==2) {
  279. this.setData({showActionsheet: false})
  280. this.getShareCode();
  281. }
  282. },
  283. saveImgToThumb: function(){
  284. let image_path = this.data.qrcode;
  285. let that = this;
  286. wx.getImageInfo({
  287. src: image_path,
  288. success: function(res) {
  289. var real_path = res.path;
  290. wx.saveImageToPhotosAlbum({
  291. filePath: real_path,
  292. success(res) {
  293. wx.showToast({
  294. title: '图片保存成功,可以分享了',
  295. icon: 'none',
  296. duration: 2000
  297. })
  298. that.setData({
  299. showQrcodeModal: false
  300. });
  301. }
  302. })
  303. }
  304. })
  305. },
  306. confirmMessage: function(){
  307. this.setData({
  308. dialogShow: !this.data.dialogShow
  309. })
  310. },
  311. goLink: function(event){
  312. let url = event.currentTarget.dataset.link;
  313. url && wx.navigateTo({ url })
  314. },
  315. onShareAppMessage: function(res) {
  316. this.setData({ is_share_html: true });
  317. let community_info = this.data.community_info || '';
  318. let { id, community_name } = community_info;
  319. let shopname = wx.getStorageSync('shopname') || '';
  320. this.setData({ showActionsheet: false });
  321. let shop_index_share_title = this.data.shop_index_share_title || '';
  322. let shop_index_share_image = this.data.shop_index_share_image || '';
  323. let title = shop_index_share_title ? shop_index_share_title : (shopname + ' ' +community_name || '');
  324. if(!id) return;
  325. return {
  326. title,
  327. path: "lionfish_comshop/pages/index/index?community_id=" + id,
  328. imageUrl: shop_index_share_image,
  329. success: function() {},
  330. fail: function() {}
  331. };
  332. }
  333. })