|
@@ -1,4 +1,6 @@
|
|
|
// pages/createFile/createFile.js
|
|
|
+import { createDocument } from "../../api/document";
|
|
|
+
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
@@ -7,10 +9,12 @@ Page({
|
|
|
data: {
|
|
|
choseAvatar: false,
|
|
|
choseAvaSrc: '',
|
|
|
+ username: '',
|
|
|
sexIndex: '0',
|
|
|
+ relateIndex: 1,
|
|
|
pickerText: '请选择',
|
|
|
relativeText: '请选择',
|
|
|
- relativeRange: ['爸爸','妈妈', '爷爷', '奶奶']
|
|
|
+ relativeRange: ['本人','父母', '子女', '配偶', '朋友'] // 关系 关系 1.本人 2.父母 3.子女 4.配偶 5.朋友
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -34,28 +38,84 @@ Page({
|
|
|
|
|
|
},
|
|
|
|
|
|
+ bindUserNameInput (e) {
|
|
|
+ this.setData({
|
|
|
+ username: e.detail.value
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
/**
|
|
|
* 保存
|
|
|
*/
|
|
|
handleSave() {
|
|
|
+ if (this.data.choseAvaSrc == '') {
|
|
|
+ wx.showToast({
|
|
|
+ title: '请选择头像',
|
|
|
+ icon: 'error'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (this.data.username == '') {
|
|
|
+ wx.showToast({
|
|
|
+ title: '请输入姓名',
|
|
|
+ icon: 'error'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (this.data.pickerText == '请选择') {
|
|
|
+ wx.showToast({
|
|
|
+ title: '请选择生日',
|
|
|
+ icon: 'error'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (this.data.relativeText == '请选择') {
|
|
|
+ wx.showToast({
|
|
|
+ title: '请选择关系',
|
|
|
+ icon: 'error'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var data = {
|
|
|
+ realName: this.data.username,
|
|
|
+ sex: this.data.sexIndex == 0 ? true : false,
|
|
|
+ birthday: this.data.pickerText,
|
|
|
+ relationship: this.data.relateIndex,
|
|
|
+ headImg: this.data.choseAvaSrc
|
|
|
+ }
|
|
|
+ console.log(data);
|
|
|
wx.showLoading({
|
|
|
title: '加载中...',
|
|
|
mask: true
|
|
|
})
|
|
|
- setTimeout(() => {
|
|
|
- wx.hideLoading({
|
|
|
- success: (res) => {},
|
|
|
+ createDocument(data).then(res => {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showToast({
|
|
|
+ title: '保存成功',
|
|
|
+ icon: 'success'
|
|
|
})
|
|
|
- }, 1400);
|
|
|
+ wx.navigateBack()
|
|
|
+ }).catch(e => {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showModal({
|
|
|
+ content: e,
|
|
|
+ confirmColor: '#333',
|
|
|
+ showCancel: false
|
|
|
+ })
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 选择关系
|
|
|
*/
|
|
|
bindReaPickerChange(e) {
|
|
|
+ console.log(e);
|
|
|
var value = this.data.relativeRange[e.detail.value]
|
|
|
+ var selsectKey = Number(e.detail.value) + 1
|
|
|
+ console.log(selsectKey);
|
|
|
this.setData({
|
|
|
- relativeText: value
|
|
|
+ relativeText: value,
|
|
|
+ relateIndex: selsectKey
|
|
|
})
|
|
|
},
|
|
|
|
|
@@ -83,14 +143,14 @@ Page({
|
|
|
*/
|
|
|
handleChoseAvatar() {
|
|
|
var that = this
|
|
|
- wx.chooseImage({
|
|
|
+ wx.chooseMedia({
|
|
|
count: 1,
|
|
|
- sizeType: ['original', 'compressed'],
|
|
|
- sourceType: ['album', 'camera'],
|
|
|
+ mediaType: ['image'],
|
|
|
+ sourceType: ['album'],
|
|
|
success (res) {
|
|
|
+ console.log(res);
|
|
|
// tempFilePath可以作为 img 标签的 src 属性显示图片
|
|
|
- const tempFilePaths = res.tempFilePaths
|
|
|
- console.log(tempFilePaths);
|
|
|
+ const tempFilePaths = res.tempFiles[0].tempFilePath
|
|
|
that.setData({
|
|
|
choseAvatar: true,
|
|
|
choseAvaSrc: tempFilePaths
|