family.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. import constant from '../../utils/constant';
  4. const app = getApp();
  5. Page({
  6. data: {
  7. HelpList:constant.arrFamilyHelpList,
  8. PanelType:0,
  9. },
  10. onPullDownRefresh: function () {
  11. var that = this;
  12. if (that.data.PanelType==0){
  13. app.globalData.FamilyUsers=[];
  14. var url = "GetUserFamily?UserID=" + app.globalData.userInfo.UserID + "&IsWeb=false";
  15. main.getData(url, function (data) {
  16. if (data) {
  17. if (data.length > 0) {
  18. app.globalData.FamilyUsers = data;
  19. wx.redirectTo({
  20. url: 'family',
  21. })
  22. }
  23. }
  24. });
  25. }
  26. wx.stopPullDownRefresh();
  27. },
  28. onShow: function (options) {
  29. var that = this;
  30. if (app.globalData.userInfo.isShow == 1) {
  31. var today=wx.getStorageSync("AccreditLimitTime");
  32. if (common.formatTime(new Date(),"-")>today){
  33. wx.navigateTo({
  34. url: '../index/accredit?Type=family',
  35. });
  36. }
  37. }
  38. },
  39. onLoad: function (options) {
  40. var that = this;
  41. var panelType=0;
  42. if (options.PanelType)
  43. panelType=options.PanelType;
  44. that.setData({
  45. Containnerheight: main.getWindowHeight(),
  46. FamilyUsers:app.globalData.FamilyUsers,
  47. IsMember:app.globalData.userInfo.IsMember,
  48. PanelType:panelType,
  49. });
  50. wx.setNavigationBarColor({
  51. frontColor: "#000000",
  52. backgroundColor: "#ffffff"
  53. });
  54. if (panelType==1){
  55. that.setData({
  56. MainUserID:options.MainUserID,
  57. NickName:options.NickName,
  58. HelpList:constant.arrFamilyHelpListAccept,
  59. Time:options.Time,
  60. });
  61. that.download(options.AvatarUrl);
  62. wx.setNavigationBarTitle({
  63. title: '邀请函',
  64. });
  65. }
  66. },
  67. download: function (avatarUrl) {
  68. var that = this;
  69. wx.downloadFile({
  70. url: avatarUrl,
  71. success(res) {
  72. if (res.statusCode === 200) {
  73. that.setData({
  74. AvatarUrl: res.tempFilePath,
  75. });
  76. }
  77. }
  78. });
  79. },
  80. showHelp:function(e){
  81. var index=e.currentTarget.dataset.index;
  82. var expand=e.currentTarget.dataset.expand;
  83. this.data.HelpList[index].IsExpand=!this.data.HelpList[index].IsExpand;
  84. this.setData({
  85. HelpList:this.data.HelpList,
  86. });
  87. },
  88. gotoReLaunch: function (e) {
  89. var url = e.currentTarget.dataset.url;
  90. wx.reLaunch({
  91. url: url,
  92. });
  93. },
  94. addUser:function(e){
  95. var that=this;
  96. if (!app.globalData.userInfo.IsMember){
  97. wx.showModal({
  98. title: '添加失败',
  99. content: '只有秒过续费用户可使用。未续费和已过期的不能使用。',
  100. showCancel: false,
  101. confirmText: "知道了",
  102. success(res) {},
  103. });
  104. }
  105. else if (that.data.FamilyUsers.length>=2){
  106. wx.showModal({
  107. title: '添加失败',
  108. content: '最多添加2名用户。如要替换请解除后重新添加。',
  109. showCancel: false,
  110. confirmText: "知道了",
  111. success(res) {},
  112. });
  113. }
  114. },
  115. addUser2:function(e){
  116. setTimeout(function () {
  117. wx.showModal({
  118. title: '等待对方接受邀请',
  119. content: '请尽快与对方联系确认邀请',
  120. showCancel: false,
  121. confirmText: "知道了",
  122. });
  123. }, 3000);
  124. },
  125. removeUser:function(e){
  126. var that=this;
  127. if (that.data.FamilyUsers.length==0){
  128. wx.showModal({
  129. title: '解除失败',
  130. content: '尚未添加用户,不能解除。',
  131. showCancel: false,
  132. confirmText: "知道了",
  133. success(res) {},
  134. });
  135. }
  136. else{
  137. wx.showModal({
  138. title: '解除家庭用户吗',
  139. content: '解除后重启小程序。对方不能再使用您的秒过。可重新添加用户。',
  140. showCancel: true,
  141. confirmText: "解除",
  142. success(res) {
  143. if (res.confirm) {
  144. main.getData("updateMiaoguoFamily?UpdateType=delete&UserID=" + app.globalData.userInfo.UserID, function (data) {
  145. app.globalData.FamilyUsers=[];
  146. wx.reLaunch({
  147. url: '../index/index?type=family',
  148. });
  149. });
  150. }
  151. },
  152. });
  153. }
  154. },
  155. accept:function(){
  156. var that=this;
  157. if (!app.globalData.userInfo.IsMember){
  158. wx.showModal({
  159. title: '接受失败',
  160. content: '未续费的和有效期已过期的用户不能加入「家庭用户」。请先续费再接受邀请。',
  161. showCancel: false,
  162. confirmText: "知道了",
  163. success(res) {},
  164. });
  165. }
  166. else if (app.globalData.userInfo.ChildUserID>0){
  167. wx.showModal({
  168. title: '接受失败',
  169. content: '「帐号绑定」的子账号不能加入「家庭用户」。只有有效期内的续费用户才能加入。',
  170. showCancel: false,
  171. confirmText: "知道了",
  172. success(res) {},
  173. });
  174. }
  175. else if (that.data.FamilyUsers.length>=2){
  176. wx.showModal({
  177. title: '接受失败',
  178. content: '最多添加2名用户。如要替换请解除后重新添加。',
  179. showCancel: false,
  180. confirmText: "知道了",
  181. success(res) {},
  182. });
  183. }
  184. else if (that.data.MainUserID==app.globalData.userInfo.UserID){
  185. wx.showModal({
  186. title: '接受失败',
  187. content: '不能自己和自己建立家庭帐号,请发给另外一个微信号。',
  188. showCancel: false,
  189. confirmText: "知道了",
  190. success(res) {},
  191. });
  192. }
  193. else{
  194. wx.showModal({
  195. title: '接受邀请吗',
  196. content: '接受后重启小程序。对方可使用您的秒过。',
  197. showCancel: true,
  198. confirmText: "接受",
  199. success(res) {
  200. if (res.confirm) {
  201. main.getData("updateMiaoguoFamily?UpdateType=add&Time="+that.data.Time+"&UserID=" + that.data.MainUserID+"&NewUserID=" + app.globalData.userInfo.UserID, function (data) {
  202. if (data==0){
  203. app.globalData.FamilyUsers=[];
  204. wx.reLaunch({
  205. url: '../index/index?type=family',
  206. });
  207. }
  208. else if (data<0){
  209. var content="";
  210. if (data==-1)
  211. content="本邀请已过期,请联系对方重新设置。";
  212. else if (data==-2)
  213. content="您已经加入该「家庭用户」了。重启小程序后,在首页即可切换帐号。";
  214. else if (data==-3)
  215. content="对方的「家庭用户」名额已满,请联系对方重新设置。";
  216. wx.showModal({
  217. title: '接受失败',
  218. content: content,
  219. showCancel: false,
  220. confirmText: "知道了",
  221. success(res) {
  222. if (data==-2){
  223. app.globalData.FamilyUsers=[];
  224. wx.reLaunch({
  225. url: '../index/index?type=family',
  226. });
  227. }
  228. },
  229. });
  230. }
  231. });
  232. }
  233. },
  234. });
  235. }
  236. },
  237. onShareAppMessage: function () {
  238. if (this.data.PanelType==0 && this.data.FamilyUsers.length<2 && this.data.IsMember==1) {
  239. var path=app.globalData.SharePath + '?type=family&PanelType=1&MainUserID=' + app.globalData.userInfo.UserID;
  240. path += "&Time=" + common.formatTime(new Date(),"-");
  241. path += "&NickName=" + app.globalData.userInfo.NickName;
  242. path += "&AvatarUrl=" + app.globalData.userInfo.AvatarUrl;
  243. return {
  244. title: app.globalData.ShareTitle,
  245. path: path,
  246. imageUrl: app.globalData.uploadImageUrl +"web/program_screenshot_jtyh.png",
  247. }
  248. }
  249. else{
  250. return {
  251. title: app.globalData.ShareTitle,
  252. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  253. imageUrl: app.globalData.ShareImage,
  254. }
  255. }
  256. },
  257. })