apply.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. var app = getApp();
  2. import WxValidate from '../../utils/WxValidate.js';
  3. var u = true;
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. },
  10. /**
  11. * 组件的初始数据
  12. */
  13. data: {
  14. },
  15. attached: function() {
  16. this.initValidate();
  17. },
  18. /**
  19. * 组件的方法列表
  20. */
  21. methods: {
  22. //资料验证函数
  23. initValidate() {
  24. const rules = {
  25. form_username: {
  26. required: true,
  27. minlength: 1
  28. },
  29. form_mobile: {
  30. required: true,
  31. tel: true
  32. }
  33. }
  34. const messages = {
  35. form_username: {
  36. required: '请填写真实姓名',
  37. minlength: '请输入正确的姓名'
  38. },
  39. form_mobile: {
  40. required: '请填写手机号',
  41. tel: '请填写正确的手机号'
  42. }
  43. }
  44. this.WxValidate = new WxValidate(rules, messages)
  45. },
  46. /**
  47. * 输入框获得焦点
  48. */
  49. iptFocus: function (t) {
  50. let name = t.currentTarget.dataset.name;
  51. this.setData({
  52. currentFocus: name
  53. })
  54. },
  55. /**
  56. * 输入框失去焦点
  57. */
  58. iptBlur: function () {
  59. this.setData({
  60. currentFocus: ''
  61. })
  62. },
  63. //报错
  64. showModal(error) {
  65. wx.showModal({
  66. content: error.msg,
  67. showCancel: false,
  68. })
  69. },
  70. /**
  71. * 资料修改表单提交
  72. */
  73. formSubmit(e) {
  74. this.setData({
  75. btnLoading: true
  76. })
  77. const params = e.detail.value;
  78. //校验表单
  79. if (!this.WxValidate.checkForm(params)) {
  80. const error = this.WxValidate.errorList[0];
  81. this.showModal(error);
  82. this.setData({
  83. btnLoading: false
  84. })
  85. return false;
  86. }
  87. let token = wx.getStorageSync('token');
  88. params.token = token;
  89. app.util.ProReq('user.save_formData', params).then(res=>{
  90. wx.showModal({
  91. content: res.msg || '提交成功,等待审核后才可查看价格和购买',
  92. showCancel: false,
  93. success: ()=>{
  94. wx.setStorageSync('isparse_formdata', 0);
  95. wx.reLaunch({
  96. url: '/lionfish_comshop/pages/index/index',
  97. })
  98. }
  99. })
  100. }).catch(err=>{
  101. this.setData({
  102. btnLoading: false
  103. })
  104. app.util.message(err.msg || '提交失败,请重试', '', 'error');
  105. })
  106. }
  107. }
  108. })