123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- // lionfish_comshop/pages/groupCenter/apply.js
- var util = require('../../utils/util.js');
- var status = require('../../utils/index.js');
- var locat = require('../../utils/Location.js');
- var app = getApp()
- var clearTime = null;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- pass: -2,
- canSubmit: false,
- region: ['选择地址', '', ''],
- addr_detail: '',
- lon_lat: '',
- focus_mobile: false,
- showCountDown: true,
- timeStamp: 60,
- apply_complete: false,
- wechat: '',
- needAuth: false,
- community_id: ''
- },
- bindRegionChange: function(e) {
- this.setData({
- region: e.detail.value.replace(/^\s*|\s*$/g, "")
- })
- },
- inputAddress: function(e) {
- this.setData({
- addr_detail: e.detail.value.replace(/^\s*|\s*$/g, "")
- })
- },
- inputCommunity: function(e) {
- this.setData({
- community_name: e.detail.value.replace(/^\s*|\s*$/g, "")
- })
- },
- inputMobile: function(e) {
- this.setData({
- mobile_detail: e.detail.value.replace(/^\s*|\s*$/g, "")
- })
- },
- inputRealName: function(e) {
- this.setData({
- head_name: e.detail.value.replace(/^\s*|\s*$/g, "")
- })
- },
- inputWechat: function(e) {
- this.setData({
- wechat: e.detail.value.replace(/^\s*|\s*$/g, "")
- })
- },
- chose_location: function() {
- var that = this;
- wx.chooseLocation({
- success: function(e) {
- var lon_lat = e.longitude + ',' + e.latitude;
- var path = e.address;
- var s_region = that.data.region;
- var dol_path = '';
- var str = path;
- var patt = new RegExp("(.*?省)(.*?市)(.*?区)", "g");
- var result = patt.exec(str);
- if (result == null) {
- patt = new RegExp("(.*?省)(.*?市)(.*?市)", "g");
- result = patt.exec(str);
- if (result == null) {
- patt = new RegExp("(.*?省)(.*?市)(.*县)", "g");
- result = patt.exec(str);
- if (result == null) {} else {
- if (s_region[0] != result[1] || s_region[1] != result[2] || s_region[2] != result[3]) {
- wx.showToast({
- title: '省市区信息已同步修改',
- icon: 'none',
- })
- }
- s_region[0] = result[1];
- s_region[1] = result[2];
- s_region[2] = result[3];
- dol_path = path.replace(result[0], '');
- }
- } else {
- if (s_region[0] != result[1] || s_region[1] != result[2] || s_region[2] != result[3]) {
- wx.showToast({
- title: '省市区信息已同步修改',
- icon: 'none',
- })
- }
- s_region[0] = result[1];
- s_region[1] = result[2];
- s_region[2] = result[3];
- dol_path = path.replace(result[0], '');
- }
- } else {
- if (s_region[0] != result[1] || s_region[1] != result[2] || s_region[2] != result[3]) {
- wx.showToast({
- title: '省市区信息已同步修改',
- icon: 'none',
- })
- }
- s_region[0] = result[1];
- s_region[1] = result[2];
- s_region[2] = result[3];
- dol_path = path.replace(result[0], '');
- }
- var filename = dol_path + e.name;
- let address_component = '';
- locat.getGpsLocation(e.latitude, e.longitude).then((res) => {
- address_component = res;
- if (address_component) {
- s_region[0] = address_component.province;
- s_region[1] = address_component.city;
- s_region[2] = address_component.district;
- }
- that.setData({
- region: s_region,
- lon_lat: lon_lat,
- addr_detail: filename
- })
- });
- if (s_region[0] == '省') {
- wx.showToast({
- title: '请重新选择省市区',
- icon: 'none',
- })
- }
- }
- })
- },
- submit: function() {
- var token = wx.getStorageSync('token');
- var province_name = this.data.region[0];
- var city_name = this.data.region[1];
- var area_name = this.data.region[2];
- var addr_detail = this.data.addr_detail;
- var community_name = this.data.community_name;
- var mobile = this.data.mobile_detail;
- var lon_lat = this.data.lon_lat;
- var head_name = this.data.head_name;
- var wechat = this.data.wechat;
- var that = this;
- if (head_name == '' || head_name === void 0) {
- wx.showToast({
- title: '请填写姓名',
- icon: 'none'
- })
- return false;
- }
- if (mobile == '' || !(/^1(3|4|5|6|7|8|9)\d{9}$/.test(mobile))) {
- this.setData({
- focus_mobile: true
- })
- wx.showToast({
- title: '手机号码有误',
- icon: 'none'
- })
- return false;
- }
- if (wechat == '' || wechat === void 0) {
- wx.showToast({
- title: '请填写微信号',
- icon: 'none'
- })
- return false;
- }
- if (community_name == '' || community_name === void 0) {
- wx.showToast({
- title: '请填写小区名称',
- icon: 'none'
- })
- return false;
- }
- if (province_name == '省' && city_name == '市' && area_name == '区') {
- wx.showToast({
- title: '请选择地区',
- icon: 'none'
- })
- return false;
- }
- if (lon_lat == '' || lon_lat === void 0) {
- wx.showToast({
- title: '请选择地图位置',
- icon: 'none'
- })
- return false;
- }
- if (addr_detail == '' || addr_detail === void 0) {
- wx.showToast({
- title: '请填写详细地址',
- icon: 'none'
- })
- return false;
- }
- var s_data = {
- province_name,
- city_name,
- area_name,
- lon_lat,
- addr_detail,
- community_name,
- mobile,
- head_name,
- wechat,
- controller: 'community.sub_community_head',
- token: token,
- community_id: this.data.community_id
- };
- app.util.request({
- 'url': 'entry/wxapp/user',
- 'data': s_data,
- method: 'post',
- dataType: 'json',
- success: function(res) {
- if (res.data.code == 0) {
- wx.showToast({
- title: '提交成功,等待审核',
- icon: 'none',
- duration: 2000
- })
- that.setData({
- apply_complete: true
- })
- }
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- // this.countDown()
- status.setNavBgColor();
- var scene = decodeURIComponent(options.scene);
- if (scene != 'undefined') {
- this.setData({ community_id: scene })
- }
- var that = this;
- if (!util.check_login()) {
- this.setData({
- needAuth: true
- })
- } else {
- this.getUserInfo();
- }
- },
- /**
- * 授权成功回调
- */
- authSuccess: function() {
- let that = this;
- this.setData({
- needAuth: false
- }, () => {
- that.getUserInfo();
- })
- },
- getUserInfo: function() {
- let that = this;
- var token = wx.getStorageSync('token');
- app.util.request({
- 'url': 'entry/wxapp/user',
- 'data': {
- controller: 'user.get_user_info',
- token: token
- },
- dataType: 'json',
- success: function(res) {
- if (res.data.code == 0) {
- that.setData({
- member_info: res.data.data,
- });
- } else {
- //is_login
- that.setData({
- needAuth: true
- })
- }
- }
- })
- },
- applyAgain: function() {
- var member_info = this.data.member_info;
- member_info.is_head = 0;
- this.setData({
- member_info: member_info
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
- },
- countDown: function() {
- var that = this;
- clearInterval(clearTime),
- clearTime = setInterval(function() {
- var ts = that.data.timeStamp,
- ct = that.data.showCountDown;
- ts > 0 ? ts-- : (ct = true, clearInterval(clearTime), ts = 60),
- that.setData({
- showCountDown: ct,
- timeStamp: ts
- });
- }, 1000);
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- }
- })
|