addOperation.js 2.8 KB

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