editOperation.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // pages/role/editOperation.js
  2. const utils = require('../../utils/util')
  3. const form = require('../../utils/formValidation')
  4. const util = require('../../utils/util.js');
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. userInfo:{
  12. username: '',
  13. realname: '',
  14. telephone: '',
  15. password: '',
  16. },
  17. userId:''
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. this.setData({
  24. userId: options.userId
  25. })
  26. this.bindOperation()
  27. },
  28. /**
  29. * 生命周期函数--监听页面初次渲染完成
  30. */
  31. onReady: function () {
  32. },
  33. /**
  34. * 生命周期函数--监听页面显示
  35. */
  36. onShow: function () {
  37. },
  38. /**
  39. * 生命周期函数--监听页面隐藏
  40. */
  41. onHide: function () {
  42. },
  43. /**
  44. * 生命周期函数--监听页面卸载
  45. */
  46. onUnload: function () {
  47. },
  48. /**
  49. * 页面相关事件处理函数--监听用户下拉动作
  50. */
  51. onPullDownRefresh: function () {
  52. },
  53. /**
  54. * 页面上拉触底事件的处理函数
  55. */
  56. onReachBottom: function () {
  57. },
  58. /**
  59. * 用户点击右上角分享
  60. */
  61. onShareAppMessage: function () {
  62. },
  63. formSubmit: function(e) {
  64. //表单规则
  65. let rules = [{
  66. name: "realname",
  67. rule: ["required"], //可使用区间,此处主要测试功能
  68. msg: ["请输入运维姓名"]
  69. }, {
  70. name: "username",
  71. rule: ["required"],
  72. msg: ["请输入登录账号"]
  73. },{
  74. name: "telephone",
  75. rule: ["required", "isMobile"],
  76. msg: ["请输入电话号码", "请输入正确的手机号"]
  77. }];
  78. //进行表单检查
  79. let formData = e.detail.value;
  80. let checkRes = form.validation(formData, rules);
  81. if (!checkRes) {
  82. // wx.showToast({
  83. // title: "验证通过!",
  84. // icon: "none"
  85. // });
  86. var that = this
  87. console.log("1111")
  88. console.log(that.data.userInfo)
  89. console.log("2222")
  90. util.request(util.api.editRole, that.data.userInfo, "PUT", false, true,app.globalData.token).then((res)=>{
  91. if (res.code == 200) {
  92. wx.navigateTo({
  93. url: '/pages/role/operationList',
  94. })
  95. }
  96. }).catch((res) => {})
  97. } else {
  98. wx.showToast({
  99. title: checkRes,
  100. icon: "none"
  101. });
  102. return;
  103. }
  104. },
  105. formReset: function(e) {
  106. console.log("清空数据")
  107. },
  108. bindOperation(){
  109. var that = this
  110. util.request(util.api.queryByUserId, {id:that.data.userId}, "GET", false, true,app.globalData.token).then((res)=>{
  111. if (res.code == 200) {
  112. that.setData({
  113. userInfo: res.result,
  114. })
  115. }
  116. }).catch((res) => {})
  117. },
  118. // editOperation(){
  119. // var that = this
  120. // console.log("1111")
  121. // console.log(that.data.userInfo)
  122. // console.log("2222")
  123. // util.request(util.api.editRole, that.data.userInfo, "PUT", false, true,app.globalData.token).then((res)=>{
  124. // if (res.code == 200) {
  125. // wx.navigateTo({
  126. // url: '/pages/role/operationList',
  127. // })
  128. // }
  129. // }).catch((res) => {})
  130. // },
  131. inputedit: function (e) {
  132. let _this = this;
  133. let dataset = e.currentTarget.dataset;
  134. let value = e.detail.value;
  135. let name = dataset.name;
  136. _this.data[name] = value;
  137. _this.setData({
  138. [name]: _this.data[name]
  139. });
  140. },
  141. })