exhibition.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // pages/guanyuan/exhibition/exhibition.js
  2. const app = getApp();
  3. const api = app.api;
  4. import WxValidate from '../../../utils/WxValidate'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. type:undefined, //留资类型 0装裱 1布展
  11. formData:{
  12. nickname: null, //称谓
  13. phone: null, //电话
  14. content: null //内容
  15. },
  16. rules: {
  17. nickname: {
  18. required: true,
  19. },
  20. phone: {
  21. required: true,
  22. tel: true,
  23. }
  24. },
  25. messages: {
  26. nickname: {
  27. required: '请输入姓名',
  28. },
  29. phone: {
  30. required: '请输入手机号',
  31. tel: '请输入正确的手机号',
  32. }
  33. },
  34. isValidate:false,
  35. isSubmit:false,
  36. },
  37. /**
  38. * 生命周期函数--监听页面加载
  39. */
  40. onLoad: function (options) {
  41. const { rules, messages } = this.data;
  42. this.WxValidate = new WxValidate(rules, messages);
  43. this.setData({
  44. type:options.type
  45. })
  46. },
  47. getPhoneNumber(e) {
  48. console.log(e);
  49. if (e.detail.errMsg !== "getPhoneNumber:ok"){
  50. return;
  51. }
  52. const { encryptedData, iv } = e.detail;
  53. app.post(api.getUserPhone, {
  54. wxPhoneEncrypted: {
  55. encryptedData,
  56. ivStr: iv
  57. }
  58. }).then(res => {
  59. this.setData({
  60. 'formData.phone': res.data.phone
  61. },()=>{
  62. this.validateForm()
  63. })
  64. });
  65. },
  66. validateForm(showInfo=false){
  67. const {formData} = this.data;
  68. let flag=true;
  69. if (!this.WxValidate.checkForm(formData)) {
  70. flag=false
  71. if(showInfo===true){
  72. const error = this.WxValidate.errorList[0];
  73. wx.showToast({
  74. title: error.msg,
  75. icon: 'none',
  76. duration: 2000
  77. })
  78. }
  79. }
  80. this.setData({
  81. isValidate:flag
  82. });
  83. return flag
  84. },
  85. saveData: function (){
  86. const {formData,isSubmit} = this.data;
  87. // 传入表单数据,调用验证方法
  88. console.info(formData)
  89. //重复提交
  90. if(isSubmit){
  91. return;
  92. }
  93. let flag=this.validateForm(true);
  94. if(!flag){
  95. return;
  96. }
  97. formData.leaveInfoType = this.data.type;
  98. this.setData({
  99. isSubmit:true,
  100. });
  101. app.post(api.addLeaveInfo, formData).then(res => {
  102. //console.log(res);
  103. wx.redirectTo({
  104. url:"/pages/guanyuan/success/success"
  105. })
  106. this.setData({
  107. isSubmit:false,
  108. });
  109. }).catch(()=>{
  110. this.setData({
  111. isSubmit:false,
  112. });
  113. })
  114. },
  115. changeInput(e) {
  116. console.log(e);
  117. const id = e.currentTarget.id;
  118. const value = e.detail.value;
  119. this.setData({
  120. [id]: value
  121. },()=>{
  122. this.validateForm()
  123. });
  124. },
  125. /**
  126. * 生命周期函数--监听页面初次渲染完成
  127. */
  128. onReady: function () {
  129. },
  130. /**
  131. * 生命周期函数--监听页面显示
  132. */
  133. onShow: function () {
  134. },
  135. /**
  136. * 生命周期函数--监听页面隐藏
  137. */
  138. onHide: function () {
  139. },
  140. /**
  141. * 生命周期函数--监听页面卸载
  142. */
  143. onUnload: function () {
  144. },
  145. /**
  146. * 页面相关事件处理函数--监听用户下拉动作
  147. */
  148. onPullDownRefresh: function () {
  149. },
  150. /**
  151. * 页面上拉触底事件的处理函数
  152. */
  153. onReachBottom: function () {
  154. },
  155. /**
  156. * 用户点击右上角分享
  157. */
  158. onShareAppMessage: function () {
  159. }
  160. })