apply.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. import WxValidate from '../../utils/WxValidate.js';
  4. var u = true;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. imgGroup: [],
  11. otherImgGroup: [],
  12. imgMax: 4,
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function(options) {
  18. this.initValidate(); //验证规则函数
  19. },
  20. /**
  21. * 生命周期函数--监听页面显示
  22. */
  23. onShow: function() {
  24. },
  25. //资料验证函数
  26. initValidate() {
  27. const rules = {
  28. head_name: {
  29. required: true,
  30. minlength: 1
  31. },
  32. head_mobile: {
  33. required: true,
  34. tel: true
  35. }
  36. }
  37. const messages = {
  38. head_name: {
  39. required: '请填写店铺名称',
  40. minlength: '请输入正确的店铺名称'
  41. },
  42. head_mobile: {
  43. required: '请填写手机号',
  44. tel: '请填写正确的手机号'
  45. }
  46. }
  47. this.WxValidate = new WxValidate(rules, messages)
  48. },
  49. /**
  50. * 输入框获得焦点
  51. */
  52. iptFocus: function(t) {
  53. let name = t.currentTarget.dataset.name;
  54. this.setData({
  55. currentFocus: name
  56. })
  57. },
  58. /**
  59. * 输入框失去焦点
  60. */
  61. iptBlur: function() {
  62. this.setData({
  63. currentFocus: ''
  64. })
  65. },
  66. chooseImage: function () {
  67. u = false;
  68. },
  69. changeImg: function (e) {
  70. u = e.detail.len === e.detail.value.length;
  71. this.setData({
  72. imgGroup: e.detail.value
  73. });
  74. },
  75. chooseImageOther: function () {
  76. u = false;
  77. },
  78. changeImgOther: function (e) {
  79. u = e.detail.len === e.detail.value.length;
  80. this.setData({
  81. otherImgGroup: e.detail.value
  82. });
  83. },
  84. //报错
  85. showModal(error) {
  86. wx.showModal({
  87. content: error.msg,
  88. showCancel: false,
  89. })
  90. },
  91. /**
  92. * 资料修改表单提交
  93. */
  94. formSubmit(e) {
  95. this.setData({ btnLoading: true })
  96. const params = e.detail.value
  97. //校验表单
  98. if (!this.WxValidate.checkForm(params)) {
  99. const error = this.WxValidate.errorList[0];
  100. this.showModal(error);
  101. this.setData({ btnLoading: false })
  102. return false;
  103. }
  104. },
  105. /**
  106. * 用户点击右上角分享
  107. */
  108. onShareAppMessage: function() {
  109. }
  110. })