apply.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. var util = require('../../utils/util.js');
  2. var status = require('../../utils/index.js');
  3. var locat = require('../../utils/Location.js');
  4. var app = getApp()
  5. var clearTime = null;
  6. Page({
  7. mixins: [require('../../mixin/globalMixin.js')],
  8. data: {
  9. pass: -2,
  10. canSubmit: false,
  11. region: ['选择地址', '', ''],
  12. addr_detail: '',
  13. lon_lat: '',
  14. focus_mobile: false,
  15. showCountDown: true,
  16. timeStamp: 60,
  17. apply_complete: false,
  18. wechat: '',
  19. needAuth: false,
  20. member_info: {
  21. is_head: 0
  22. },
  23. groupInfo: {
  24. group_name: '社区',
  25. owner_name: '团长'
  26. }
  27. },
  28. is_show:false,
  29. community_id: '',
  30. cansub: true,
  31. bindRegionChange: function(e) {
  32. this.setData({
  33. region: e.detail.value.replace(/^\s*|\s*$/g, "")
  34. })
  35. },
  36. inputAddress: function(e) {
  37. this.setData({
  38. addr_detail: e.detail.value.replace(/^\s*|\s*$/g, "")
  39. })
  40. },
  41. inputCommunity: function(e) {
  42. this.setData({
  43. community_name: e.detail.value.replace(/^\s*|\s*$/g, "")
  44. })
  45. },
  46. inputMobile: function(e) {
  47. this.setData({
  48. mobile_detail: e.detail.value.replace(/^\s*|\s*$/g, "")
  49. })
  50. },
  51. inputRealName: function(e) {
  52. this.setData({
  53. head_name: e.detail.value.replace(/^\s*|\s*$/g, "")
  54. })
  55. },
  56. inputWechat: function(e) {
  57. this.setData({
  58. wechat: e.detail.value.replace(/^\s*|\s*$/g, "")
  59. })
  60. },
  61. chose_location: function() {
  62. var that = this;
  63. wx.chooseLocation({
  64. success: function(e) {
  65. var lon_lat = e.longitude + ',' + e.latitude;
  66. var path = e.address;
  67. var s_region = that.data.region;
  68. var dol_path = '';
  69. var str = path;
  70. var patt = new RegExp("(.*?省)(.*?市)(.*?区)", "g");
  71. var result = patt.exec(str);
  72. if (!result) {
  73. patt = new RegExp("(.*?省)(.*?市)(.*?市)", "g");
  74. result = patt.exec(str);
  75. if (!result) {
  76. patt = new RegExp("(.*?省)(.*?市)(.*县)", "g");
  77. result = patt.exec(str);
  78. if (result) {
  79. s_region[0] = result[1];
  80. s_region[1] = result[2];
  81. s_region[2] = result[3];
  82. dol_path = path.replace(result[0], '');
  83. }
  84. } else {
  85. s_region[0] = result[1];
  86. s_region[1] = result[2];
  87. s_region[2] = result[3];
  88. dol_path = path.replace(result[0], '');
  89. }
  90. } else {
  91. s_region[0] = result[1];
  92. s_region[1] = result[2];
  93. s_region[2] = result[3];
  94. dol_path = path.replace(result[0], '');
  95. }
  96. var filename = dol_path + e.name;
  97. let addr_detail = filename;
  98. let address_component = '';
  99. locat.getGpsLocation(e.latitude, e.longitude).then((res) => {
  100. console.log(res)
  101. address_component = res;
  102. if (address_component) {
  103. s_region[0] = address_component.province;
  104. s_region[1] = address_component.city;
  105. s_region[2] = address_component.district;
  106. s_region[3] = address_component.town;
  107. addr_detail = filename || address_component.street;
  108. }
  109. that.setData({
  110. region: s_region,
  111. lon_lat: lon_lat,
  112. addr_detail
  113. })
  114. });
  115. if (s_region[0] == '省') {
  116. wx.showToast({
  117. title: '请重新选择省市区',
  118. icon: 'none',
  119. })
  120. }
  121. },
  122. fail: function(e) {
  123. console.log('地址获取失败', e)
  124. }
  125. })
  126. },
  127. /**
  128. * 订阅消息
  129. */
  130. subscriptionNotice: function() {
  131. console.log('subscriptionNotice')
  132. let that = this;
  133. return new Promise((resolve, reject)=>{
  134. let obj = that.data.need_subscript_template;
  135. let tmplIds = Object.keys(obj).map(key => obj[key]); // 订阅消息模版id
  136. if (wx.requestSubscribeMessage) {
  137. tmplIds.length && wx.requestSubscribeMessage({
  138. tmplIds: tmplIds,
  139. success(res) {
  140. let is_need_subscript = 1;
  141. let acceptId = [];
  142. Object.keys(obj).forEach(item=>{
  143. if (res[obj[item]] == 'accept') {
  144. //用户同意了订阅,添加进数据库
  145. acceptId.push(item);
  146. } else {
  147. //用户拒绝了订阅或当前游戏被禁用订阅消息
  148. is_need_subscript = 0;
  149. }
  150. })
  151. if(acceptId.length) {
  152. that.addAccept(acceptId);
  153. }
  154. that.setData({ is_need_subscript })
  155. resolve();
  156. },
  157. fail() {
  158. reject();
  159. }
  160. })
  161. } else {
  162. // 兼容处理
  163. reject();
  164. }
  165. })
  166. },
  167. // 用户点击订阅添加到数据库
  168. addAccept: function (acceptId) {
  169. let token = wx.getStorageSync('token');
  170. let type = acceptId.join(',');
  171. app.util.request({
  172. url: 'entry/wxapp/user',
  173. data: {
  174. controller: 'user.collect_subscriptmsg',
  175. token,
  176. type
  177. },
  178. dataType: 'json',
  179. method: 'POST',
  180. success: function () {}
  181. })
  182. },
  183. submit: function() {
  184. if (!this.authModal()) return;
  185. let that = this;
  186. var token = wx.getStorageSync('token');
  187. var province_name = this.data.region[0];
  188. var city_name = this.data.region[1];
  189. var area_name = this.data.region[2];
  190. let country_name = this.data.region[3] || '';
  191. var addr_detail = this.data.addr_detail;
  192. var community_name = this.data.community_name;
  193. var mobile = this.data.mobile_detail;
  194. var lon_lat = this.data.lon_lat;
  195. var head_name = this.data.head_name;
  196. var wechat = this.data.wechat;
  197. let member_info = this.data.member_info;
  198. if (head_name == '' || head_name === void 0) {
  199. wx.showToast({
  200. title: '请填写姓名',
  201. icon: 'none'
  202. })
  203. return false;
  204. }
  205. if (mobile == '' || !(/^1(3|4|5|6|7|8|9)\d{9}$/.test(mobile))) {
  206. this.setData({
  207. focus_mobile: true
  208. })
  209. wx.showToast({
  210. title: '手机号码有误',
  211. icon: 'none'
  212. })
  213. return false;
  214. }
  215. // if (wechat == '' || wechat === void 0) {
  216. // wx.showToast({
  217. // title: '请填写' + (member_info.wechat_div?member_info.wechat_div:'微信号'),
  218. // icon: 'none'
  219. // })
  220. // return false;
  221. // }
  222. if (community_name == '' || community_name === void 0) {
  223. wx.showToast({
  224. title: '请填写小区名称',
  225. icon: 'none'
  226. })
  227. return false;
  228. }
  229. if (province_name == '省' && city_name == '市' && area_name == '区') {
  230. wx.showToast({
  231. title: '请选择地区',
  232. icon: 'none'
  233. })
  234. return false;
  235. }
  236. if (lon_lat == '' || lon_lat === void 0) {
  237. wx.showToast({
  238. title: '请选择地图位置',
  239. icon: 'none'
  240. })
  241. return false;
  242. }
  243. if (addr_detail == '' || addr_detail === void 0) {
  244. wx.showToast({
  245. title: '请填写详细地址',
  246. icon: 'none'
  247. })
  248. return false;
  249. }
  250. var s_data = {
  251. province_name,
  252. city_name,
  253. area_name,
  254. lon_lat,
  255. addr_detail,
  256. community_name,
  257. mobile,
  258. head_name,
  259. wechat,
  260. controller: 'community.sub_community_head',
  261. token: token,
  262. community_id: this.community_id,
  263. country_name
  264. };
  265. let is_need_subscript = this.data.is_need_subscript;
  266. if(is_need_subscript==1) {
  267. //弹出订阅消息
  268. this.subscriptionNotice().then(()=>{
  269. that.preSubmit(s_data);
  270. }).catch(()=>{
  271. that.preSubmit(s_data);
  272. });
  273. } else {
  274. that.preSubmit(s_data);
  275. }
  276. },
  277. preSubmit: function(s_data) {
  278. if(!this.cansub) return;
  279. this.cansub = false;
  280. var that = this;
  281. app.util.request({
  282. url: 'entry/wxapp/user',
  283. data: s_data,
  284. method: 'post',
  285. dataType: 'json',
  286. success: function(res) {
  287. if (res.data.code == 0) {
  288. wx.showToast({
  289. title: '提交成功,等待审核',
  290. icon: 'none',
  291. duration: 2000
  292. })
  293. that.setData({
  294. apply_complete: true
  295. })
  296. } else {
  297. that.setData({
  298. needAuth: true
  299. })
  300. }
  301. that.cansub = true;
  302. }
  303. })
  304. },
  305. /**
  306. * 生命周期函数--监听页面加载
  307. */
  308. onLoad: function(options) {
  309. let that = this;
  310. status.setNavBgColor();
  311. status.setGroupInfo().then((groupInfo) => {
  312. let owner_name = groupInfo && groupInfo.owner_name || '团长';
  313. that.setData({ groupInfo })
  314. wx.setNavigationBarTitle({
  315. title: `${owner_name}申请`,
  316. })
  317. });
  318. var scene = decodeURIComponent(options.scene);
  319. if (scene != 'undefined') {
  320. this.community_id = scene;
  321. }
  322. this.getUserInfo();
  323. this.checkSubscript();
  324. },
  325. onShow: function () {
  326. let that = this;
  327. util.check_login_new().then((res) => {
  328. if (res) {
  329. that.setData({ needAuth: false });
  330. } else {
  331. that.setData({ needAuth: true });
  332. }
  333. })
  334. },
  335. authModal: function () {
  336. if (this.data.needAuth) {
  337. this.setData({ showAuthModal: !this.data.showAuthModal });
  338. return false;
  339. }
  340. return true;
  341. },
  342. /**
  343. * 授权成功回调
  344. */
  345. authSuccess: function() {
  346. let that = this;
  347. this.setData({
  348. needAuth: false
  349. }, () => {
  350. that.getUserInfo();
  351. })
  352. },
  353. getUserInfo: function() {
  354. let that = this;
  355. var token = wx.getStorageSync('token');
  356. app.util.request({
  357. 'url': 'entry/wxapp/user',
  358. 'data': {
  359. controller: 'user.get_user_info',
  360. token: token
  361. },
  362. dataType: 'json',
  363. success: function(res) {
  364. if (res.data.code == 0) {
  365. let member_info = res.data.data || { is_head: 0 };
  366. if(member_info.is_head==1){
  367. app.util.message('您已通过审核', '/lionfish_comshop/moduleA/groupCenter/index', 'error');
  368. }
  369. that.setData({
  370. member_info
  371. });
  372. } else {
  373. //is_login
  374. that.setData({
  375. needAuth: true
  376. })
  377. }
  378. }
  379. })
  380. },
  381. applyAgain: function() {
  382. var member_info = this.data.member_info;
  383. member_info.is_head = 0;
  384. this.setData({
  385. member_info: member_info
  386. });
  387. },
  388. countDown: function() {
  389. var that = this;
  390. clearInterval(clearTime),
  391. clearTime = setInterval(function() {
  392. var ts = that.data.timeStamp,
  393. ct = that.data.showCountDown;
  394. ts > 0 ? ts-- : (ct = true, clearInterval(clearTime), ts = 60),
  395. that.setData({
  396. showCountDown: ct,
  397. timeStamp: ts
  398. });
  399. }, 1000);
  400. },
  401. checkSubscript: function() {
  402. let that = this;
  403. var token = wx.getStorageSync('token');
  404. token && app.util.request({
  405. url: 'entry/wxapp/user',
  406. data: {
  407. controller: 'community.check_head_subscriptapply',
  408. token: token
  409. },
  410. dataType: 'json',
  411. success: function(res) {
  412. if (res.data.code == 0) {
  413. let { is_need_subscript,need_subscript_template } = res.data;
  414. that.setData({
  415. is_need_subscript,
  416. need_subscript_template
  417. });
  418. }
  419. }
  420. })
  421. }
  422. })