edit.js 2.9 KB

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