apply.js 11 KB

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