createFile.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // pages/createFile/createFile.js
  2. import { createDocument } from "../../api/document";
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. choseAvatar: false,
  9. choseAvaSrc: '',
  10. username: '',
  11. sexIndex: '0',
  12. relateIndex: 1,
  13. pickerText: '请选择',
  14. relativeText: '请选择',
  15. relativeRange: ['本人','父母', '子女', '配偶', '朋友', '祖孙', '兄妹', '其他'] // 关系 关系 1.本人 2.父母 3.子女 4.配偶 5.朋友 6.祖孙、7.兄妹、8.其他
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad(options) {
  21. },
  22. /**
  23. * 生命周期函数--监听页面初次渲染完成
  24. */
  25. onReady() {
  26. },
  27. /**
  28. * 生命周期函数--监听页面显示
  29. */
  30. onShow() {
  31. },
  32. bindUserNameInput (e) {
  33. this.setData({
  34. username: e.detail.value
  35. })
  36. },
  37. /**
  38. * 保存
  39. */
  40. handleSave() {
  41. if (this.data.choseAvaSrc == '') {
  42. wx.showToast({
  43. title: '请选择头像',
  44. icon: 'error'
  45. })
  46. return
  47. }
  48. if (this.data.username == '') {
  49. wx.showToast({
  50. title: '请输入姓名',
  51. icon: 'error'
  52. })
  53. return
  54. }
  55. if (this.data.pickerText == '请选择') {
  56. wx.showToast({
  57. title: '请选择生日',
  58. icon: 'error'
  59. })
  60. return
  61. }
  62. if (this.data.relativeText == '请选择') {
  63. wx.showToast({
  64. title: '请选择关系',
  65. icon: 'error'
  66. })
  67. return
  68. }
  69. var data = {
  70. realName: this.data.username,
  71. sex: this.data.sexIndex == 0 ? true : false,
  72. birthday: this.data.pickerText,
  73. relationship: this.data.relateIndex,
  74. headImg: this.data.choseAvaSrc
  75. }
  76. console.log(data);
  77. wx.showLoading({
  78. title: '加载中...',
  79. mask: true
  80. })
  81. createDocument(data).then(res => {
  82. wx.hideLoading()
  83. wx.showToast({
  84. title: '保存成功',
  85. icon: 'success'
  86. })
  87. wx.navigateBack()
  88. }).catch(e => {
  89. wx.hideLoading()
  90. wx.showModal({
  91. content: e,
  92. confirmColor: '#333',
  93. showCancel: false
  94. })
  95. })
  96. },
  97. /**
  98. * 选择关系
  99. */
  100. bindReaPickerChange(e) {
  101. console.log(e);
  102. var value = this.data.relativeRange[e.detail.value]
  103. var selsectKey = Number(e.detail.value) + 1
  104. console.log(selsectKey);
  105. this.setData({
  106. relativeText: value,
  107. relateIndex: selsectKey
  108. })
  109. },
  110. /**
  111. * 用户选择生日
  112. */
  113. bindPickerChange(e) {
  114. this.setData({
  115. pickerText: e.detail.value
  116. })
  117. },
  118. /**
  119. * 切换性别
  120. */
  121. handleSex(e) {
  122. console.log(e.currentTarget.dataset.index);
  123. this.setData({
  124. sexIndex: e.currentTarget.dataset.index
  125. })
  126. },
  127. /**
  128. * 用户选择头像
  129. */
  130. handleChoseAvatar() {
  131. var that = this
  132. wx.chooseMedia({
  133. count: 1,
  134. mediaType: ['image'],
  135. sourceType: ['album'],
  136. success (res) {
  137. console.log(res);
  138. // tempFilePath可以作为 img 标签的 src 属性显示图片
  139. const tempFilePaths = res.tempFiles[0].tempFilePath
  140. that.setData({
  141. choseAvatar: true,
  142. choseAvaSrc: tempFilePaths
  143. })
  144. }
  145. })
  146. }
  147. })