Personnel_edit.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. // parents/pages/information/information.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { ManagerEdit, UploadFile, ManagerSave, ManagerDel } from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData, hasLibraryService, hasVipService } = getApp()
  6. const { baseImgUrl, qrcodeInvalidToastText } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. baseImgUrl,
  13. isLoaded: 0,
  14. hiddenModel: false,
  15. deleteModel: false,
  16. MembersVipId:'',
  17. vip: {
  18. imgUrl: '',
  19. name: '',
  20. sex: '',
  21. jobs:''
  22. },
  23. gradeArray: ['一年级', '二年级', '三年级', '四年级', '五年级', '六年级', '七年级', '八年级', '九年级'],
  24. gradeIndex: 0,
  25. sexArray: ['男', '女'],
  26. sexIndex: 0,
  27. positionArray: ['馆长助理', '馆长'],
  28. positionIndex:0,
  29. footerArray: [
  30. {
  31. type: 1,
  32. text: '取消'
  33. },
  34. {
  35. type: 2,
  36. text: '保存'
  37. }
  38. ]
  39. },
  40. /**
  41. * 生命周期函数--监听页面加载
  42. */
  43. onLoad: function (options) {
  44. this.setData({
  45. MembersVipId: options.vipId
  46. });
  47. wx.setNavigationBarTitle({
  48. title: `个人资料`,
  49. })
  50. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`) || ''
  51. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  52. this.setData(options)
  53. this.getData(res => {
  54. this.setData({ isLoaded: 1 })
  55. })
  56. },
  57. /**
  58. * 生命周期函数--监听页面初次渲染完成
  59. */
  60. onReady: function () {
  61. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  62. for (const i in obj) {
  63. this[i] = obj[i]
  64. }
  65. },
  66. /**
  67. * 生命周期函数--监听页面显示
  68. */
  69. onShow: function () {
  70. },
  71. /**
  72. * 生命周期函数--监听页面隐藏
  73. */
  74. onHide: function () {
  75. },
  76. /**
  77. * 生命周期函数--监听页面卸载
  78. */
  79. onUnload: function () {
  80. },
  81. /**
  82. * 页面相关事件处理函数--监听用户下拉动作
  83. */
  84. onPullDownRefresh: function () {
  85. },
  86. /**
  87. * 页面上拉触底事件的处理函数
  88. */
  89. onReachBottom: function () {
  90. },
  91. /**
  92. * 用户点击右上角分享
  93. */
  94. onShareAppMessage: function () {
  95. if (isFn(sharePage)) return sharePage()
  96. },
  97. /**
  98. * 提示框隐藏
  99. */
  100. allShowModel: function () {
  101. this.setData({ hiddenModel: false, deleteModel: false })
  102. },
  103. /**
  104. * 提示框打开
  105. */
  106. showModel: function () {
  107. this.setData({ hiddenModel: true })
  108. },
  109. /**
  110. * 删除打开
  111. */
  112. sureDelete: function (e) {
  113. const { index } = e.currentTarget.dataset
  114. this.setData({ deleteModel: true, deleteIndex: index })
  115. },
  116. /**
  117. * 获取个人资料
  118. */
  119. getData: function (cb) {
  120. const continuousFn = { fn: this.getData, param: { ...arguments } }
  121. const { libId, month, MembersVipId } = this.data
  122. ManagerEdit({ data: { id:MembersVipId }, continuousFn }).then(res => {
  123. this.setData({ vip: { ...res.data } })
  124. cb && cb(res)
  125. }).catch(res => {
  126. cb && cb(res)
  127. })
  128. },
  129. /**
  130. * 上传头像
  131. */
  132. uploadImgCtl: function () {
  133. const continuousFn = { fn: this.uploadImgCtl, param: { ...arguments } }
  134. wx.chooseImage({
  135. count: 1,
  136. success: res => {
  137. UploadFile({ file: res.tempFilePaths, continuousFn }).then(res => {
  138. this.setData({ 'vip.imgUrl': res[0] })
  139. })
  140. }
  141. })
  142. },
  143. /**
  144. * 保存输入值
  145. */
  146. inputCtl: function (e) {
  147. const { value } = e.detail
  148. const { type } = e.currentTarget.dataset
  149. const { vip } = this.data
  150. vip[type] = value
  151. this.setData({ vip })
  152. },
  153. /**
  154. * 改变年级
  155. */
  156. pickerGradeCtl: function (e) {
  157. const { value } = e.detail
  158. const { gradeArray, gradeIndex } = this.data
  159. if (value == gradeIndex) {
  160. return
  161. }
  162. this.setData({ 'vip.grade': gradeArray[value], gradeIndex: value })
  163. },
  164. /**
  165. * 改变性别
  166. */
  167. pickerSexCtl: function (e) {
  168. const { value } = e.detail
  169. const { sexArray, sexIndex } = this.data
  170. this.setData({ 'vip.sex': ~~value + 1, sexIndex: value })
  171. },
  172. /**
  173. * 改变馆内职务
  174. */
  175. pickerpositionCtl: function (e) {
  176. const { value } = e.detail
  177. const { positionArray, positionIndex } = this.data
  178. this.setData({ 'vip.jobs': ~~value + 1, positionIndex: value })
  179. },
  180. /**
  181. * 提交按钮
  182. */
  183. submitCtl: function (e) {
  184. const continuousFn = { fn: this.submitCtl, param: { ...arguments } }
  185. const { type } = e.currentTarget.dataset
  186. const { vip, libId, MembersVipId} = this.data
  187. if (type == 1) {
  188. wx.navigateBack({
  189. delta: 1
  190. })
  191. } else if (type == 2) {
  192. if (!vip['name']) {
  193. wx.showToast({
  194. title: '请填写完姓名',
  195. icon: 'none'
  196. })
  197. return
  198. }
  199. ManagerSave({ data: { ...vip, libId, id: MembersVipId}, continuousFn }).then(res => {
  200. wx.showToast({
  201. title: '保存成功',
  202. })
  203. setTimeout(() => {
  204. navigateBack()
  205. }, 2000)
  206. })
  207. }
  208. },
  209. /**
  210. * 删除
  211. */
  212. delMembersVipIdCtl: function (e) {
  213. const continuousFn = { fn: this.submitCtl, param: { ...arguments } }
  214. const { MembersVipId } = this.data
  215. ManagerDel({ data: { id: MembersVipId }, continuousFn }).then(res => {
  216. wx.showToast({
  217. title: '保存成功',
  218. })
  219. setTimeout(() => {
  220. navigateBack()
  221. }, 2000)
  222. })
  223. }
  224. })