add.js 5.4 KB

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