12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import store from '../../../store'
- import create from '../../../utils/create'
- import fetch from '../../../utils/http'
- import { get as getApi } from '../../../config/api'
-
- const app = getApp()
-
- create(store, {
- data: {
- userInfo: null,
- },
- onReady() {
- wx.setNavigationBarTitle({
- title: '个人资料'
- })
- },
- SaveUserInfo() { // 提交表单数据
- if (this.store.data.userInfo.name === '') {
- wx.showToast({
- title: '昵称不能为空!',
- icon: 'none',
- })
- return false
- }
- if (!this.store.data.userInfo.phone || this.store.data.userInfo.phone == '') {
- wx.showToast({
- title: '手机号不能为空!',
- icon: 'none',
- })
- return false
- }
- var myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
- if (!myreg.test(this.store.data.userInfo.phone)) {
- wx.showToast({
- title: '手机号格式不正确!',
- icon: 'none',
- })
- return false
- }
- if (this.store.data.userInfo.idNum && this.store.data.userInfo.idNum!='') {
- var idreg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
- if (!idreg.test(this.store.data.userInfo.idNum)) {
- wx.showToast({
- title: '身份证格式不正确!',
- icon: 'none',
- })
- return false
- }
- }
-
- fetch({ ...getApi('user.update'), data: this.store.data.userInfo }).then(() => {
- // 同步到 globalData
- app.globalData.UserInfo = { ...this.store.data.userInfo }
-
- wx.showToast({
- title: '更新成功',
- icon: 'success',
- })
- }).catch((err) => {
- wx.showToast({
- title: '更新失败',
- icon: 'none',
- })
- })
- },
- FormInput(e) { // 表单输入数据绑定
- const key = e.target.dataset.name
- const val = e.detail.value
-
- this.store.data.userInfo = {
- ...this.store.data.userInfo,
- [`${key}`]: val,
- }
- this.update()
- },
- onShareAppMessage: function () {
- return app.globalData.ShareDate
- }
- })
|