|
|
@@ -0,0 +1,374 @@
|
|
|
+var app = new Vue({
|
|
|
+ 'el': '#app',
|
|
|
+ 'data': {
|
|
|
+ // 当前导航
|
|
|
+ curNav: 'member',
|
|
|
+ // 用户信息
|
|
|
+ memberInfo: {},
|
|
|
+ // 参数
|
|
|
+ params: {
|
|
|
+ id: 0,
|
|
|
+ address: '广西壮族自治区 南宁市 西乡塘区',
|
|
|
+ birthday: '',
|
|
|
+ birthday_code: ' ',
|
|
|
+ education: 0,
|
|
|
+ salary: 0,
|
|
|
+ occupation: '',
|
|
|
+ now_address: '广西壮族自治区 南宁市 西乡塘区',
|
|
|
+ home_address: '广西壮族自治区 南宁市 西乡塘区',
|
|
|
+ },
|
|
|
+ // 条件参数
|
|
|
+ ages: [],
|
|
|
+ // 身高
|
|
|
+ heights: [],
|
|
|
+ // 体重
|
|
|
+ weights: [],
|
|
|
+ // 收入
|
|
|
+ salarys: [],
|
|
|
+ // 学历
|
|
|
+ educations: [],
|
|
|
+ // 收入
|
|
|
+ incomes: [],
|
|
|
+ // 职业
|
|
|
+ positions: [],
|
|
|
+ // 性别
|
|
|
+ sexs: ['男', '女'],
|
|
|
+ // 婚姻状况
|
|
|
+ marrieds: [],
|
|
|
+ // 资产状况
|
|
|
+ propertys: [],
|
|
|
+ time: 60,
|
|
|
+ timeText: '获取验证码',
|
|
|
+ timeId: null,
|
|
|
+ // 提交状态
|
|
|
+ submitting: {'sendcode': null, 'submit': null},
|
|
|
+ id: 0,
|
|
|
+ },
|
|
|
+ created: function () {
|
|
|
+ this.id = getParam('id');
|
|
|
+ this.getParams();
|
|
|
+ },
|
|
|
+ updated: function () {
|
|
|
+ var _this = this;
|
|
|
+
|
|
|
+ _this.initData();
|
|
|
+ },
|
|
|
+
|
|
|
+ methods: {
|
|
|
+ // 获取用户信息
|
|
|
+ getInfo: function () {
|
|
|
+ var _this = this;
|
|
|
+ $.showLoading("数据加载中...");
|
|
|
+ $.post('/api/member/getHomeInfo', {type: 2}, function (res) {
|
|
|
+ $.hideLoading();
|
|
|
+ if (res.code == 'success') {
|
|
|
+ _this.memberInfo = res.data
|
|
|
+ _this.params = res.data.homeInfo
|
|
|
+ _this.params.realname = _this.params.real_name;
|
|
|
+ _this.params.mobile_txt = _this.params.mobile;
|
|
|
+ _this.params.nickname = _this.params.user_nickname;
|
|
|
+ //_this.initData()
|
|
|
+ } else if (res.code == 'exception') {
|
|
|
+ $.showLoading(res.message);
|
|
|
+ } else {
|
|
|
+ $.toast(res.message, 'text');
|
|
|
+ }
|
|
|
+ }, "json");
|
|
|
+ },
|
|
|
+ // 初始化参数
|
|
|
+ getParams: function () {
|
|
|
+ var _this = this;
|
|
|
+ $.post('/api/index/params', {}, function (res) {
|
|
|
+ if (res.code == 'success') {
|
|
|
+ var paramDatas = res.data;
|
|
|
+ _this.positions = typeof (paramDatas.positions) != 'undefined' ? paramDatas.positions : [""];
|
|
|
+ _this.marrieds = typeof (paramDatas.marrieds) != 'undefined' ? paramDatas.marrieds : [""];
|
|
|
+ if (paramDatas && paramDatas.incomes) {
|
|
|
+ // _this.salarys.push('请选择');
|
|
|
+ $.each(paramDatas.incomes, function (k, item) {
|
|
|
+ if(k>0) {
|
|
|
+ _this.salarys.push(item.name);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ if (paramDatas && paramDatas.educations) {
|
|
|
+ $.each(paramDatas.educations, function (k, item) {
|
|
|
+ if(k>0){
|
|
|
+ _this.educations.push(item);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ if (paramDatas && paramDatas.propertys) {
|
|
|
+ $.each(paramDatas.propertys, function (k, item) {
|
|
|
+ if(k>0){
|
|
|
+ _this.propertys.push(item);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ _this.getInfo();
|
|
|
+ } else {
|
|
|
+ $.toast(res.message, 'text');
|
|
|
+ }
|
|
|
+ }, "json");
|
|
|
+ },
|
|
|
+ // 编辑控制
|
|
|
+ checkInput: function(name, val){
|
|
|
+ if(val){
|
|
|
+ $.toast(name+'不能修改', 'text');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+ // 初始化
|
|
|
+ initData: function () {
|
|
|
+ var _this = this;
|
|
|
+ // 生日
|
|
|
+ var years = [];
|
|
|
+ var date = new Date();
|
|
|
+ var year = date.getFullYear()-20;
|
|
|
+ for(var i=20;i>=0;i--){
|
|
|
+ years.push(year-i);
|
|
|
+ }
|
|
|
+ _this.params.birthday_code = _this.params.birthday_code? _this.params.birthday_code+' ' : (year-10)+'-01-01 ';
|
|
|
+ $("#birthday").datetimePicker({
|
|
|
+ title: '请选择出生日期',
|
|
|
+ dateFormat: 'yyyy-mm-dd',
|
|
|
+ years: years,
|
|
|
+ /*min: '1980-01-01',
|
|
|
+ max: year+'-01-02',*/
|
|
|
+ yearSplit: '-',
|
|
|
+ monthSplit: '-',
|
|
|
+ dateSplit: '',
|
|
|
+ value: _this.params.birthday_code + ' ',
|
|
|
+ times: function () {
|
|
|
+ return [];
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ // 居住地
|
|
|
+ var address = _this.params.now_address? $.trim(_this.params.now_address).split(' ') : []
|
|
|
+ if(address && address.length==2){
|
|
|
+ _this.params.now_address = $.trim(_this.params.now_address)+ ' 市辖区';
|
|
|
+ }
|
|
|
+
|
|
|
+ $("#now_address").val(_this.params.now_address);
|
|
|
+ $("#now_address").cityPicker({
|
|
|
+ title: "请选择所在地",
|
|
|
+ showDistrict: true,
|
|
|
+ onChange: function (picker, values, displayValues) {
|
|
|
+ console.log(displayValues)
|
|
|
+ _this.params.now_address = displayValues.join(' ');
|
|
|
+ }
|
|
|
+ // showDistrict: false
|
|
|
+ });
|
|
|
+
|
|
|
+ $.each(_this.sexs, function (k, item) {
|
|
|
+ if (_this.params.sex == k+1) {
|
|
|
+ $("#sex").val(item);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ $("#sex").picker({
|
|
|
+ title: "请选择性别",
|
|
|
+ cols: [
|
|
|
+ {
|
|
|
+ textAlign: 'center',
|
|
|
+ values: _this.sexs,
|
|
|
+ value: _this.params.sex,
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ onChange: function (data) {
|
|
|
+ _this.params.sex = data.cols[0].activeIndex+1;
|
|
|
+ $("#sex").attr('data-code', data.cols[0].activeIndex+1);
|
|
|
+ },
|
|
|
+ onConfirm: function (data) {
|
|
|
+ _this.params.sex = data.cols[0].activeIndex+1;
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ $("#married").picker({
|
|
|
+ title: "请选择性别",
|
|
|
+ cols: [
|
|
|
+ {
|
|
|
+ textAlign: 'center',
|
|
|
+ values: _this.marrieds,
|
|
|
+ value: _this.params.married,
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ onChange: function (data) {
|
|
|
+ _this.params.married = data.cols[0].activeIndex + 1;
|
|
|
+ $("#married").attr('data-code', data.cols[0].activeIndex + 1);
|
|
|
+ },
|
|
|
+ onConfirm: function (data) {
|
|
|
+ _this.params.married = data.cols[0].activeIndex + 1;
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+ // 发送验证码
|
|
|
+ sendCode: function(){
|
|
|
+ var _this = this;
|
|
|
+ if(_this.submitting.sendcode){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(_this.params.mobile_txt && _this.params.mobile_txt == _this.params.mobile){
|
|
|
+ $.toast('手机号码未修改','text');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(_this.params.mobile == '' || _this.params.mobile == null){
|
|
|
+ $.toast('请填写手机号','text');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ var patternMobile = /1[3-9][0-9]{9}/;
|
|
|
+ if (!patternMobile.test(_this.params.mobile)) {
|
|
|
+ $.toast("请填写正确格式的手机号码", 'text');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ _this.submitting.sendcode = true;
|
|
|
+
|
|
|
+ // 发送验证码
|
|
|
+ $.showLoading('提交中');
|
|
|
+ $.post('/api/sms/sendCode',{mobile: _this.params.mobile, id: _this.params.id}, function(res){
|
|
|
+ $.hideLoading();
|
|
|
+ if(res.code == 'success'){
|
|
|
+ _this.timeLock();
|
|
|
+ }else{
|
|
|
+ _this.submitting.sendcode = false;
|
|
|
+ }
|
|
|
+ $.toast(res.message, 'text');
|
|
|
+
|
|
|
+ }, "json");
|
|
|
+ },
|
|
|
+ // 倒计时
|
|
|
+ timeLock: function(){
|
|
|
+ var _this = this;
|
|
|
+ _this.timeId = setInterval(function(){
|
|
|
+ _this.time--;
|
|
|
+ _this.timeText = _this.time+'s';
|
|
|
+ if(_this.time<=0){
|
|
|
+ _this.time = 60;
|
|
|
+ _this.timeText = '获取验证码';
|
|
|
+ _this.submitting.sendcode = false;
|
|
|
+ clearInterval(_this.timeId)
|
|
|
+ }
|
|
|
+
|
|
|
+ }, 1000);
|
|
|
+ },
|
|
|
+ // 提交数据
|
|
|
+ postSubmit: function(){
|
|
|
+ var _this = this;
|
|
|
+ if(_this.submitting.submit){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var sex = $("#sex").attr('data-code');
|
|
|
+ var education = $("#education").attr('data-code');
|
|
|
+ var occupation = $("#occupation").attr('data-code');
|
|
|
+ var occupation_text = $.trim($("#occupation").val());
|
|
|
+ if(typeof(sex) != 'undefined'){
|
|
|
+ _this.params.sex = $("#sex").attr('data-code');
|
|
|
+ }
|
|
|
+ if(typeof(education) != 'undefined'){
|
|
|
+ _this.params.education = $("#education").attr('data-code');
|
|
|
+ }
|
|
|
+ if(typeof(occupation) != 'undefined'){
|
|
|
+ _this.params.occupation = $("#occupation").attr('data-code');
|
|
|
+ }
|
|
|
+ if(occupation_text != '' && occupation_text != null){
|
|
|
+ _this.params.occupation = occupation_text;
|
|
|
+ }
|
|
|
+ _this.params.birthday = $("#birthday").val();
|
|
|
+ _this.params.age = $("#age").attr('data-code');
|
|
|
+ _this.params.salary = $("#salary").attr('data-code');
|
|
|
+ _this.params.height = $("#height").attr('data-code');
|
|
|
+ _this.params.weight = $("#weight").attr('data-code');
|
|
|
+ _this.params.now_address = $("#now_address").val();
|
|
|
+ _this.params.home_address = $("#home_address").val();
|
|
|
+ _this.params.married = $("#married").attr('data-code');
|
|
|
+ _this.params.property = $("#property").attr('data-code');
|
|
|
+ console.log(_this.params);
|
|
|
+ if(_this.params.nickname == ''){
|
|
|
+ $.toast("请填写昵称", 'text');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(_this.params.sex <=0 || _this.params.sex == ''){
|
|
|
+ $.toast("请选择您的性别", 'text');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(_this.params.now_address == '' || _this.params.now_address == null){
|
|
|
+ $.toast("请选择您的所在地", 'text');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(_this.params.wechat_code == '' || _this.params.wechat_code == null){
|
|
|
+ $.toast("请填写微信号", 'text');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ var params = JSON.parse(JSON.stringify(_this.params));
|
|
|
+ if(_this.params.mobile_txt != _this.params.mobile){
|
|
|
+ var patternMobile = /1[3-9][0-9]{9}/;
|
|
|
+ if (!patternMobile.test(_this.params.mobile)) {
|
|
|
+ $.toast("请填写正确格式的手机号码", 'text');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(_this.params.code == '' || _this.params.code == null){
|
|
|
+ $.toast("请填写短信验证码", 'text');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ var pattCode = /^[0-9]{4,6}$/;
|
|
|
+ if(!pattCode.test(_this.params.code)){
|
|
|
+ $.toast("请填写正确格式的短信验证码", 'text');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ params.mobile = '';
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ _this.submitting.submit = true;
|
|
|
+ $.showLoading('数据保存中...');
|
|
|
+ $.ajax({
|
|
|
+ url: '/api/member/saveInfo',
|
|
|
+ data: params,
|
|
|
+ type: "post",
|
|
|
+ dataType: 'json',
|
|
|
+ success: function(res) {
|
|
|
+ $.hideLoading();
|
|
|
+ _this.submitting.submit = false;
|
|
|
+ if(res.code == 'success'){
|
|
|
+ $.toast(res.message,'text');
|
|
|
+ setTimeout(function(){
|
|
|
+ location.href = '/weixin/member/profile';
|
|
|
+ }, 500);
|
|
|
+ }else if (res.code == 'exception'){
|
|
|
+ var url = res.data.url;
|
|
|
+ $.toast(res.message,'text');
|
|
|
+ if(url){
|
|
|
+ setTimeout(function(){
|
|
|
+ $.hideLoading();
|
|
|
+ location.href = url;
|
|
|
+ }, 500)
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $.toast(res.message,'text');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error:function (res) {
|
|
|
+ _this.submitting.submit = false;
|
|
|
+ $.toast(res.message,'text');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|