You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
218 lines
5.0 KiB
218 lines
5.0 KiB
var app = getApp();
|
|
import WxValidate from '../../utils/WxValidate';
|
|
var netUtil = require("../../utils/requestUtil.js"); //require引入
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
userInfo: null,
|
|
imgList: [],
|
|
qrcode: '',
|
|
vip_level_c: [],
|
|
vip_level: ''
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function(options) {
|
|
var userInfo = wx.getStorageSync('userInfo')
|
|
if(!userInfo){
|
|
wx.redirectTo({
|
|
url: '/pages/login/index',
|
|
})
|
|
}
|
|
var global_config = wx.getStorageSync('global_config')
|
|
if (userInfo) {
|
|
this.setData({
|
|
userInfo: userInfo,
|
|
vip_level_c: global_config.vip_level,
|
|
vip_level: userInfo.vip_level,
|
|
qrcode: userInfo.qrcode
|
|
})
|
|
if (userInfo.imgList) {
|
|
this.setData({
|
|
imgList: userInfo.imgList
|
|
|
|
})
|
|
}
|
|
}
|
|
console.log(this.data)
|
|
//验证
|
|
this.initValidate()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function() {
|
|
|
|
},
|
|
|
|
|
|
formSubmit: function(e) {
|
|
const params = e.detail.value
|
|
// 传入表单数据,调用验证方法
|
|
if (!this.WxValidate.checkForm(params)) {
|
|
const error = this.WxValidate.errorList[0]
|
|
this.showModal(error)
|
|
return false
|
|
}
|
|
//执行入库
|
|
this.updateData(params);
|
|
},
|
|
|
|
//插入用户数据
|
|
updateData: function(data) {
|
|
var self = this;
|
|
var method_url = 'index/member/modify';
|
|
var url = app.globalData.requestUrl + method_url;
|
|
netUtil.sendPost(url, data)
|
|
.then((res) => {
|
|
console.log(res)
|
|
if (res.statusCode == 200 && res.data.code == 200) {
|
|
//重新更改用户登录信息数据
|
|
wx.setStorageSync('userInfo', res.data.data);
|
|
wx.showToast({
|
|
title: '提交成功',
|
|
icon: 'success',
|
|
duration: 2000
|
|
})
|
|
} else {
|
|
wx.showToast({
|
|
title: res.data.msg,
|
|
icon: 'none',
|
|
duration: 3000
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
showModal: function(e) {
|
|
console.log(e);
|
|
wx.showToast({
|
|
title: e.msg,
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
},
|
|
|
|
//图片选择
|
|
ChooseImage() {
|
|
var self = this;
|
|
var url = app.globalData.requestUrl + 'index/upload/plupload';
|
|
wx.chooseImage({
|
|
count: 2, //默认9
|
|
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
|
|
sourceType: ['album', 'camera'], //从相册选择
|
|
success: (res) => {
|
|
//上传到服务器
|
|
wx.showToast({
|
|
title: '正在上传...',
|
|
icon: 'loading',
|
|
mask: true,
|
|
duration: 30000
|
|
})
|
|
let tempFilePaths = res.tempFilePaths;
|
|
for (var i in tempFilePaths) {
|
|
wx.uploadFile({
|
|
url: url,
|
|
filePath: tempFilePaths[i],
|
|
name: 'file',
|
|
success: function(res) {
|
|
//赋值操作
|
|
var data = JSON.parse(res.data);
|
|
self.setData({
|
|
imgList: self.data.imgList.length != 0 ? self.data.imgList.concat([data.url]) : [data.url]
|
|
})
|
|
//赋值图片隐藏域
|
|
self.setData({
|
|
qrcode: self.data.imgList.join(',')
|
|
})
|
|
|
|
},
|
|
fail: function(res) {
|
|
wx.showModal({
|
|
title: '错误提示',
|
|
content: '上传图片失败',
|
|
showCancel: false,
|
|
success: function(res) {}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
wx.hideToast();
|
|
}
|
|
});
|
|
|
|
},
|
|
ViewImage(e) {
|
|
wx.previewImage({
|
|
urls: this.data.imgList,
|
|
current: e.currentTarget.dataset.url
|
|
});
|
|
},
|
|
DelImg(e) {
|
|
wx.showModal({
|
|
title: '图片删除',
|
|
content: '确定要删除这张图片吗?',
|
|
cancelText: '再看看',
|
|
confirmText: '确认',
|
|
success: res => {
|
|
if (res.confirm) {
|
|
this.data.imgList.splice(e.currentTarget.dataset.index, 1);
|
|
this.setData({
|
|
imgList: this.data.imgList,
|
|
qrcode: this.data.imgList.join(',')
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
initValidate() {
|
|
// 验证字段的规则
|
|
const rules = {
|
|
phone: {
|
|
required: true,
|
|
},
|
|
qrcode: {
|
|
required: true,
|
|
},
|
|
truename: {
|
|
required: true,
|
|
},
|
|
card_number: {
|
|
required: true,
|
|
}
|
|
}
|
|
|
|
// 验证字段的提示信息,若不传则调用默认的信息
|
|
const messages = {
|
|
phone: {
|
|
required: "请输入手机号",
|
|
},
|
|
qrcode: {
|
|
required: "请上传二维码",
|
|
},
|
|
truename: {
|
|
required: "请输入真实姓名",
|
|
},
|
|
card_number: {
|
|
required: "请输入身份证号码",
|
|
}
|
|
}
|
|
|
|
// 创建实例对象
|
|
this.WxValidate = new WxValidate(rules, messages)
|
|
},
|
|
|
|
})
|