apply.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. // lionfish_comshop/pages/groupCenter/apply.js
  2. var util = require('../../utils/util.js');
  3. var status = require('../../utils/index.js');
  4. var locat = require('../../utils/Location.js');
  5. var app = getApp()
  6. var clearTime = null;
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. pass: -2,
  13. canSubmit: false,
  14. region: ['选择地址', '', ''],
  15. addr_detail: '',
  16. lon_lat: '',
  17. focus_mobile: false,
  18. showCountDown: true,
  19. timeStamp: 60,
  20. apply_complete: false,
  21. wechat: '',
  22. needAuth: false,
  23. community_id: ''
  24. },
  25. bindRegionChange: function(e) {
  26. this.setData({
  27. region: e.detail.value.replace(/^\s*|\s*$/g, "")
  28. })
  29. },
  30. inputAddress: function(e) {
  31. this.setData({
  32. addr_detail: e.detail.value.replace(/^\s*|\s*$/g, "")
  33. })
  34. },
  35. inputCommunity: function(e) {
  36. this.setData({
  37. community_name: e.detail.value.replace(/^\s*|\s*$/g, "")
  38. })
  39. },
  40. inputMobile: function(e) {
  41. this.setData({
  42. mobile_detail: e.detail.value.replace(/^\s*|\s*$/g, "")
  43. })
  44. },
  45. inputRealName: function(e) {
  46. this.setData({
  47. head_name: e.detail.value.replace(/^\s*|\s*$/g, "")
  48. })
  49. },
  50. inputWechat: function(e) {
  51. this.setData({
  52. wechat: e.detail.value.replace(/^\s*|\s*$/g, "")
  53. })
  54. },
  55. chose_location: function() {
  56. var that = this;
  57. wx.chooseLocation({
  58. success: function(e) {
  59. var lon_lat = e.longitude + ',' + e.latitude;
  60. var path = e.address;
  61. var s_region = that.data.region;
  62. var dol_path = '';
  63. var str = path;
  64. var patt = new RegExp("(.*?省)(.*?市)(.*?区)", "g");
  65. var result = patt.exec(str);
  66. if (result == null) {
  67. patt = new RegExp("(.*?省)(.*?市)(.*?市)", "g");
  68. result = patt.exec(str);
  69. if (result == null) {
  70. patt = new RegExp("(.*?省)(.*?市)(.*县)", "g");
  71. result = patt.exec(str);
  72. if (result == null) {} else {
  73. if (s_region[0] != result[1] || s_region[1] != result[2] || s_region[2] != result[3]) {
  74. wx.showToast({
  75. title: '省市区信息已同步修改',
  76. icon: 'none',
  77. })
  78. }
  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. if (s_region[0] != result[1] || s_region[1] != result[2] || s_region[2] != result[3]) {
  86. wx.showToast({
  87. title: '省市区信息已同步修改',
  88. icon: 'none',
  89. })
  90. }
  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. } else {
  97. if (s_region[0] != result[1] || s_region[1] != result[2] || s_region[2] != result[3]) {
  98. wx.showToast({
  99. title: '省市区信息已同步修改',
  100. icon: 'none',
  101. })
  102. }
  103. s_region[0] = result[1];
  104. s_region[1] = result[2];
  105. s_region[2] = result[3];
  106. dol_path = path.replace(result[0], '');
  107. }
  108. var filename = dol_path + e.name;
  109. let address_component = '';
  110. locat.getGpsLocation(e.latitude, e.longitude).then((res) => {
  111. address_component = res;
  112. if (address_component) {
  113. s_region[0] = address_component.province;
  114. s_region[1] = address_component.city;
  115. s_region[2] = address_component.district;
  116. }
  117. that.setData({
  118. region: s_region,
  119. lon_lat: lon_lat,
  120. addr_detail: filename
  121. })
  122. });
  123. if (s_region[0] == '省') {
  124. wx.showToast({
  125. title: '请重新选择省市区',
  126. icon: 'none',
  127. })
  128. }
  129. }
  130. })
  131. },
  132. submit: function() {
  133. var token = wx.getStorageSync('token');
  134. var province_name = this.data.region[0];
  135. var city_name = this.data.region[1];
  136. var area_name = this.data.region[2];
  137. var addr_detail = this.data.addr_detail;
  138. var community_name = this.data.community_name;
  139. var mobile = this.data.mobile_detail;
  140. var lon_lat = this.data.lon_lat;
  141. var head_name = this.data.head_name;
  142. var wechat = this.data.wechat;
  143. var that = this;
  144. if (head_name == '' || head_name === void 0) {
  145. wx.showToast({
  146. title: '请填写姓名',
  147. icon: 'none'
  148. })
  149. return false;
  150. }
  151. if (mobile == '' || !(/^1(3|4|5|6|7|8|9)\d{9}$/.test(mobile))) {
  152. this.setData({
  153. focus_mobile: true
  154. })
  155. wx.showToast({
  156. title: '手机号码有误',
  157. icon: 'none'
  158. })
  159. return false;
  160. }
  161. if (wechat == '' || wechat === void 0) {
  162. wx.showToast({
  163. title: '请填写微信号',
  164. icon: 'none'
  165. })
  166. return false;
  167. }
  168. if (community_name == '' || community_name === void 0) {
  169. wx.showToast({
  170. title: '请填写小区名称',
  171. icon: 'none'
  172. })
  173. return false;
  174. }
  175. if (province_name == '省' && city_name == '市' && area_name == '区') {
  176. wx.showToast({
  177. title: '请选择地区',
  178. icon: 'none'
  179. })
  180. return false;
  181. }
  182. if (lon_lat == '' || lon_lat === void 0) {
  183. wx.showToast({
  184. title: '请选择地图位置',
  185. icon: 'none'
  186. })
  187. return false;
  188. }
  189. if (addr_detail == '' || addr_detail === void 0) {
  190. wx.showToast({
  191. title: '请填写详细地址',
  192. icon: 'none'
  193. })
  194. return false;
  195. }
  196. var s_data = {
  197. province_name,
  198. city_name,
  199. area_name,
  200. lon_lat,
  201. addr_detail,
  202. community_name,
  203. mobile,
  204. head_name,
  205. wechat,
  206. controller: 'community.sub_community_head',
  207. token: token,
  208. community_id: this.data.community_id
  209. };
  210. app.util.request({
  211. 'url': 'entry/wxapp/user',
  212. 'data': s_data,
  213. method: 'post',
  214. dataType: 'json',
  215. success: function(res) {
  216. if (res.data.code == 0) {
  217. wx.showToast({
  218. title: '提交成功,等待审核',
  219. icon: 'none',
  220. duration: 2000
  221. })
  222. that.setData({
  223. apply_complete: true
  224. })
  225. }
  226. }
  227. })
  228. },
  229. /**
  230. * 生命周期函数--监听页面加载
  231. */
  232. onLoad: function(options) {
  233. // this.countDown()
  234. status.setNavBgColor();
  235. var scene = decodeURIComponent(options.scene);
  236. if (scene != 'undefined') {
  237. this.setData({ community_id: scene })
  238. }
  239. var that = this;
  240. if (!util.check_login()) {
  241. this.setData({
  242. needAuth: true
  243. })
  244. } else {
  245. this.getUserInfo();
  246. }
  247. },
  248. /**
  249. * 授权成功回调
  250. */
  251. authSuccess: function() {
  252. let that = this;
  253. this.setData({
  254. needAuth: false
  255. }, () => {
  256. that.getUserInfo();
  257. })
  258. },
  259. getUserInfo: function() {
  260. let that = this;
  261. var token = wx.getStorageSync('token');
  262. app.util.request({
  263. 'url': 'entry/wxapp/user',
  264. 'data': {
  265. controller: 'user.get_user_info',
  266. token: token
  267. },
  268. dataType: 'json',
  269. success: function(res) {
  270. if (res.data.code == 0) {
  271. that.setData({
  272. member_info: res.data.data,
  273. });
  274. } else {
  275. //is_login
  276. that.setData({
  277. needAuth: true
  278. })
  279. }
  280. }
  281. })
  282. },
  283. applyAgain: function() {
  284. var member_info = this.data.member_info;
  285. member_info.is_head = 0;
  286. this.setData({
  287. member_info: member_info
  288. });
  289. },
  290. /**
  291. * 生命周期函数--监听页面初次渲染完成
  292. */
  293. onReady: function() {
  294. },
  295. /**
  296. * 生命周期函数--监听页面显示
  297. */
  298. onShow: function() {
  299. },
  300. /**
  301. * 生命周期函数--监听页面隐藏
  302. */
  303. onHide: function() {
  304. },
  305. countDown: function() {
  306. var that = this;
  307. clearInterval(clearTime),
  308. clearTime = setInterval(function() {
  309. var ts = that.data.timeStamp,
  310. ct = that.data.showCountDown;
  311. ts > 0 ? ts-- : (ct = true, clearInterval(clearTime), ts = 60),
  312. that.setData({
  313. showCountDown: ct,
  314. timeStamp: ts
  315. });
  316. }, 1000);
  317. },
  318. /**
  319. * 生命周期函数--监听页面卸载
  320. */
  321. onUnload: function() {
  322. }
  323. })