add.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. // pages/operPeople/add.js
  2. const utils = require('../../utils/util.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. type: 0, //0是新增,1是编辑
  9. userInfo: '',
  10. userInfoBei: '', //被编辑人信息
  11. showRoles: [],
  12. rolesList: [],
  13. rolesIndex: '',
  14. ents: [],
  15. entsIndex: '',
  16. name: '',
  17. mobile: ''
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. this.setData({
  24. userInfo: utils.getInfo()
  25. })
  26. this.setData({
  27. type: Number(options.type)
  28. })
  29. if (this.data.type === 0) {
  30. this.getRoles()
  31. }
  32. if (this.data.type === 1) {
  33. this.setData({
  34. mobile: options.mobile
  35. })
  36. this.getDetail()
  37. }
  38. },
  39. //如果是编辑操作,就获取回显信息
  40. getDetail() {
  41. wx.setNavigationBarTitle({
  42. title: '编辑人员'
  43. })
  44. let params = {
  45. mobile: this.data.mobile
  46. }
  47. utils.axios({
  48. method: 'get',
  49. url: '/auth/oper/user/findManageInfoByMobile',
  50. data: params,
  51. sendBefore() {
  52. wx.showLoading({
  53. title: '信息加载中...',
  54. mask: true
  55. })
  56. },
  57. complete() {
  58. wx.hideLoading()
  59. },
  60. success: res => {
  61. this.setData({
  62. name: res.data.name,
  63. userInfoBei: res.data
  64. })
  65. this.getRoles()
  66. }
  67. })
  68. },
  69. //提交
  70. submitData() {
  71. if (this.data.type === 0) {
  72. this.addNew()
  73. }
  74. if (this.data.type === 1) {
  75. this.edit()
  76. }
  77. },
  78. //新增人员
  79. addNew() {
  80. let params = {
  81. currentUserMobile: utils.getInfo().mobile,
  82. reqChannel: 5,
  83. name: utils.trimAll(this.data.name),
  84. mobile: utils.trimAll(this.data.mobile)
  85. }
  86. if (params.name === '') {
  87. utils.toast('员工姓名不能为空')
  88. return
  89. }
  90. if (params.mobile === '') {
  91. utils.toast('员工手机号码不能为空')
  92. return
  93. }
  94. if (this.data.rolesIndex !== '') {
  95. params.roleIds = [this.data.rolesList[this.data.rolesIndex].id]
  96. }
  97. if (this.data.entsIndex !== '') {
  98. params.entTaxIds = [this.data.ents[this.data.entsIndex].entTaxId]
  99. }
  100. utils.axios({
  101. method: 'post',
  102. url: '/auth/oper/user/save',
  103. data: params,
  104. sendBefore() {
  105. wx.showLoading({
  106. title: '人员新增中...',
  107. mask: true
  108. })
  109. },
  110. complete() {
  111. wx.hideLoading()
  112. },
  113. success: res => {
  114. utils.funPrev(prev => {
  115. prev.toFresh()
  116. utils.toast('人员新增成功')
  117. wx.navigateBack()
  118. })
  119. }
  120. })
  121. },
  122. //编辑人员
  123. edit() {
  124. let params = {
  125. currentUserMobile: utils.getInfo().mobile,
  126. reqChannel: 5,
  127. name: utils.trimAll(this.data.name),
  128. mobile: utils.trimAll(this.data.mobile),
  129. status: true
  130. }
  131. if (params.name === '') {
  132. utils.toast('员工姓名不能为空')
  133. return
  134. }
  135. if (params.mobile === '') {
  136. utils.toast('员工手机号码不能为空')
  137. return
  138. }
  139. if (this.data.rolesIndex !== '') {
  140. params.roleIds = [this.data.rolesList[this.data.rolesIndex].id]
  141. }
  142. if (this.data.entsIndex !== '') {
  143. params.entTaxIds = [this.data.ents[this.data.entsIndex].entTaxId]
  144. }
  145. utils.axios({
  146. method: 'post',
  147. url: '/auth/oper/user/updateManageInfo',
  148. data: params,
  149. sendBefore() {
  150. wx.showLoading({
  151. title: '保存中...',
  152. mask: true
  153. })
  154. },
  155. complete() {
  156. wx.hideLoading()
  157. },
  158. success: res => {
  159. utils.funPrev(prev => {
  160. prev.toFresh()
  161. utils.toast('编辑成功')
  162. wx.navigateBack()
  163. })
  164. }
  165. })
  166. },
  167. //角色列表
  168. getRoles() {
  169. utils.axios({
  170. method: 'get',
  171. url: '/auth/oper/role/findCategoryRoles',
  172. sendBefore() {
  173. wx.showLoading({
  174. title: '角色获取中...',
  175. mask: true
  176. })
  177. },
  178. complete() {
  179. wx.hideLoading()
  180. },
  181. success: res => {
  182. let rolesList = res.data
  183. let showRoles = []
  184. for (let i = 0; i < rolesList.length; i++) {
  185. showRoles.push(rolesList[i].remark)
  186. }
  187. this.setData({
  188. showRoles,
  189. rolesList
  190. })
  191. if (this.data.type === 1) {
  192. let userRoles = this.data.userInfoBei.userRoles[0].remark
  193. for (let i = 0; i < rolesList.length; i++) {
  194. if (rolesList[i].remark === userRoles) {
  195. this.setData({
  196. rolesIndex: i
  197. })
  198. }
  199. }
  200. }
  201. }
  202. })
  203. },
  204. setRoles(e) {
  205. let rolesIndex = Number(e.detail.value)
  206. this.setData({
  207. rolesIndex
  208. })
  209. },
  210. //员工姓名
  211. getName(e) {
  212. let value = e.detail.value
  213. this.setData({
  214. name: value
  215. })
  216. },
  217. getMobile(e) {
  218. let value = e.detail.value
  219. this.setData({
  220. mobile: value
  221. })
  222. },
  223. /**
  224. * 生命周期函数--监听页面初次渲染完成
  225. */
  226. onReady: function () {
  227. },
  228. /**
  229. * 生命周期函数--监听页面显示
  230. */
  231. onShow: function () {
  232. },
  233. /**
  234. * 生命周期函数--监听页面隐藏
  235. */
  236. onHide: function () {
  237. },
  238. /**
  239. * 生命周期函数--监听页面卸载
  240. */
  241. onUnload: function () {
  242. },
  243. /**
  244. * 页面相关事件处理函数--监听用户下拉动作
  245. */
  246. onPullDownRefresh: function () {
  247. },
  248. /**
  249. * 页面上拉触底事件的处理函数
  250. */
  251. onReachBottom: function () {
  252. },
  253. /**
  254. * 用户点击右上角分享
  255. */
  256. onShareAppMessage: function () {
  257. }
  258. })