add.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // pages/ZCWDK/add/add.js
  2. import {
  3. request
  4. } from "../../api/request"
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. // 部门列表
  11. deptList: [],
  12. // 当前选择部门
  13. deptChoose: '',
  14. // 手机号验证是否通过
  15. ajxtrue: false
  16. },
  17. // 手机号验证
  18. blurPhone: function (e) {
  19. var phone = e.detail.value;
  20. if (!(/^1[34578]\d{9}$/.test(phone))) {
  21. this.setData({
  22. ajxtrue: false
  23. })
  24. } else {
  25. this.setData({
  26. ajxtrue: true
  27. })
  28. }
  29. },
  30. // 表单提交
  31. formSubmit(e) {
  32. if (e.detail.value.phone == '') {
  33. wx.showToast({
  34. title: '手机号不能为空',
  35. icon: 'error',
  36. duration: 2000
  37. })
  38. } else if (this.data.ajxtrue == false) {
  39. wx.showToast({
  40. title: '手机号有误',
  41. icon: 'error',
  42. duration: 2000
  43. })
  44. } else if (e.detail.value.dept == '') {
  45. wx.showToast({
  46. title: '部门不能为空',
  47. icon: 'error',
  48. duration: 2000
  49. })
  50. } else if (e.detail.value.remark == '') {
  51. wx.showToast({
  52. title: '问题不能为空',
  53. icon: 'error',
  54. duration: 2000
  55. })
  56. } else {
  57. request({
  58. url: '/elk/saveSub',
  59. method: 'POST',
  60. data: e.detail.value
  61. }).then(res => {
  62. if (res.result) {
  63. wx.showToast({
  64. title: '提交成功',
  65. icon: 'success',
  66. duration: 2000
  67. })
  68. }
  69. })
  70. }
  71. },
  72. // 选择部门
  73. bindPickerChange: function (e) {
  74. this.setData({
  75. deptChoose: this.data.deptList[e.detail.value]
  76. })
  77. },
  78. // 获取所有的分类
  79. getSubDeptAll() {
  80. request({
  81. url: '/elk/getSubDeptAll',
  82. method: 'GET'
  83. }).then(res => {
  84. this.setData({
  85. deptList: res.data
  86. })
  87. })
  88. },
  89. // 返回
  90. back() {
  91. wx.navigateBack({
  92. delta: 1
  93. });
  94. },
  95. /**
  96. * 生命周期函数--监听页面加载
  97. */
  98. onLoad(options) {
  99. // 获取所有分类
  100. this.getSubDeptAll();
  101. },
  102. /**
  103. * 生命周期函数--监听页面初次渲染完成
  104. */
  105. onReady() {
  106. },
  107. /**
  108. * 生命周期函数--监听页面显示
  109. */
  110. onShow() {
  111. },
  112. /**
  113. * 生命周期函数--监听页面隐藏
  114. */
  115. onHide() {
  116. },
  117. /**
  118. * 生命周期函数--监听页面卸载
  119. */
  120. onUnload() {
  121. },
  122. /**
  123. * 页面相关事件处理函数--监听用户下拉动作
  124. */
  125. onPullDownRefresh() {
  126. },
  127. /**
  128. * 页面上拉触底事件的处理函数
  129. */
  130. onReachBottom() {
  131. },
  132. /**
  133. * 用户点击右上角分享
  134. */
  135. onShareAppMessage() {
  136. return {
  137. title: '我要提问'
  138. }
  139. }
  140. })