123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- // pages/createFile/createFile.js
- import { createDocument } from "../../api/document";
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- choseAvatar: false,
- choseAvaSrc: '',
- username: '',
- sexIndex: '0',
- relateIndex: 1,
- pickerText: '请选择',
- relativeText: '请选择',
- relativeRange: ['本人','父母', '子女', '配偶', '朋友', '祖孙', '兄妹', '其他'] // 关系 关系 1.本人 2.父母 3.子女 4.配偶 5.朋友 6.祖孙、7.兄妹、8.其他
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- 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
- })
- createDocument(data).then(res => {
- wx.hideLoading()
- wx.showToast({
- title: '保存成功',
- icon: 'success'
- })
- 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,
- relateIndex: selsectKey
- })
- },
- /**
- * 用户选择生日
- */
- bindPickerChange(e) {
- this.setData({
- pickerText: e.detail.value
- })
- },
- /**
- * 切换性别
- */
- handleSex(e) {
- console.log(e.currentTarget.dataset.index);
- this.setData({
- sexIndex: e.currentTarget.dataset.index
- })
- },
- /**
- * 用户选择头像
- */
- handleChoseAvatar() {
- var that = this
- wx.chooseMedia({
- count: 1,
- mediaType: ['image'],
- sourceType: ['album'],
- success (res) {
- console.log(res);
- // tempFilePath可以作为 img 标签的 src 属性显示图片
- const tempFilePaths = res.tempFiles[0].tempFilePath
- that.setData({
- choseAvatar: true,
- choseAvaSrc: tempFilePaths
- })
- }
- })
- }
- })
|