add.js 2.6 KB

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