editIntroducer.js 3.7 KB

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