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.

145 lines
2.7 KiB

// pages/user/subpage/newRel/newRel.js
import {http} from '../../../../utils/util'
Page({
/**
* 页面的初始数据
*/
data: {
form: {
name: '',
tel: '',
image: null,
},
upload: getApp().globalData.upload,
cdn: getApp().globalData.cdn,
plat: ''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
wx.setNavigationBarTitle({
title: '账号关联',
})
this.setData({
plat: options.type
})
},
blur(e) {
let a = "form." + e.currentTarget.dataset.mes
let b = e.detail.value
this.setData({
[a]: b
})
},
update() {
if (!this.data.form.name) {
wx.showToast({
title: '请输入姓名',
icon: 'none',
duration: 2000
})
} else if (!this.data.form.tel) {
wx.showToast({
title: '请输入手机号',
icon: 'none',
duration: 2000
})
} else if (!this.data.form.tel.match(/^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/)) {
wx.showToast({
title: '请输入正确的手机号',
icon: 'none',
duration: 2000
})
} else {
http("/userAccount/add", "post", {
name: this.data.form.name,
tel: this.data.form.tel,
validImg: this.data.form.image,
platform: Number(this.data.plat)
}).then(res=>{
wx.navigateBack({
delta: 1
})
wx.showToast({
title: '上传完成',
icon: 'none',
duration: 2000
})
})
}
},
chooseImage() {
let that = this
wx.chooseImage({
success(res) {
const tempFilePaths = res.tempFilePaths
wx.uploadFile({
url: that.data.upload + '/util/upload',
filePath: tempFilePaths[0],
name: 'file',
formData: {
'test': 'test'
},
success(res) {
console.log(JSON.parse(res.data))
that.setData({
'form.image': JSON.parse(res.data).data.fileUrl
})
//do something
}
})
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})