| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- // pages/agent/index.js
- import {
- saveAgent
- } from '../../services/index.js'
- import {
- imgServerUrl
- } from '../../config/config.js'
- import {
- showToast
- } from '../../utils/tips.js'
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- name: '',
- contact: '',
- year: '',
- sex: ["请选择", "男", "女"],
- sex_index: 0,
- imgServerUrl: imgServerUrl,
- canIUse: wx.canIUse('button.open-type.getUserInfo'),
- isLogin: false
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- this.getNodePos();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- //获取用户user_id和member_id,判断是否处于登录态
- var userId = wx.getStorageSync("user_id");
- var userToken = wx.getStorageSync("user_token");
- var memberId = wx.getStorageSync("member_id");
- var isLogin = false;
- if (userId && memberId) {
- isLogin = true;
- app.globalData.userId = userId;
- app.globalData.userToken = userToken;
- app.globalData.memberId = memberId;
- }
- this.setData({
- isLogin: isLogin
- })
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
- },
- imageLoad() {
- var that = this
- var query = wx.createSelectorQuery()
- query.select('.agent1').boundingClientRect()
- query.select('.agent2').boundingClientRect()
- query.select('.agent3').boundingClientRect()
- query.select('.agent4').boundingClientRect()
- query.exec(function(res) {
- console.log(res)
- that.setData({
- swiperH: res[0].height,
- swiperH2: res[1].height,
- swiperH3: res[2].height,
- swiperH4: res[3].height
- })
- })
- },
- //获取位置
- getNodePos() {
- var query = wx.createSelectorQuery()
- query.select('#agentJoin').boundingClientRect()
- var that = this;
- query.exec(function(res) {
- console.log(res)
- that.setData({
- basePos: res[0].top + 500,
- })
- })
- },
- baoming(e) {
- let top = e.currentTarget.dataset.top
- wx.pageScrollTo({
- scrollTop: top,
- duration: 0
- })
- },
- changeName: function(e) {
- console.log("s", e.detail.value);
- this.setData({
- name: e.detail.value
- })
- },
- changeContact: function(e) {
- console.log("s", e.detail.value);
- this.setData({
- contact: e.detail.value
- })
- },
- //改变性别
- bindSexChange(e) {
- console.log(e)
- let {
- value
- } = e.detail
- this.setData({
- sex_index: value
- })
- },
- changeYear: function(e) {
- console.log("s", e.detail.value);
- this.setData({
- year: e.detail.value
- })
- },
- submit() {
- if (!this.data.isLogin) {
- wx.navigateTo({
- url: '/pages/login/login',
- })
- return;
- }
- var name = this.data.name;
- var contact = this.data.contact;
- var sex = this.data.sex_index;
- var year = this.data.year;
- if (!name) {
- showToast("请填写姓名")
- return;
- }
- if (contact == "" || contact.length != 11) {
- showToast("请输入11位手机号")
- return;
- }
- if (sex == 0) {
- showToast("请选择性别")
- return;
- }
- if (!year) {
- showToast("请填写年龄")
- return;
- }
- var regNum = new RegExp('[0-9]', 'g');
- var rsNum = regNum.exec(year);
- console.log("rs",rsNum)
- if (!rsNum){
- showToast("年龄请输入正确的数字")
- return;
- }
- wx.showModal({
- title: '提示',
- content: '确定提交吗?',
- success: function(res) {
- if (res.confirm) {
- let paramsObj = {
- user_id: app.globalData.userId,
- user_token: app.globalData.userToken,
- member_id: app.globalData.memberId,
- name: name,
- phone: contact,
- gender: sex,
- age: year
- }
- Object.assign(paramsObj);
- saveAgent(paramsObj).then(data => {
- showToast('提交成功', 'success')
- setTimeout(function() {
- wx.navigateBack();
- }, 1000)
- })
- } else if (res.cancel) {
- }
- }
- })
- }
- })
|