application.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. const api = require('../../../utils/api.js');
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. array: ['身份证', '护照', '临时身份证', '军官证'],
  8. index:0,
  9. codetext:'获取验证码',
  10. current:0
  11. },
  12. bindPickerChange(e) {
  13. console.log('picker发送选择改变,携带值为', e.detail.value)
  14. this.setData({
  15. index: e.detail.value
  16. })
  17. },
  18. swiper:function(e){
  19. let that=this
  20. that.setData({
  21. current:e.detail.current
  22. })
  23. },
  24. code:function(){
  25. let that=this
  26. if (!that.data.phone||that.data.phone.split('').length!=11) {
  27. wx.showToast({
  28. title: '请输入正确的手机号',
  29. icon:'none'
  30. })
  31. return false
  32. }
  33. that.data.codetext = 59
  34. let timer = setInterval(function () {
  35. if (that.data.codetext == 0) {
  36. clearTimeout(timer)
  37. that.setData({
  38. codetext: '重新发送'
  39. })
  40. }
  41. that.setData({
  42. codetext: that.data.codetext
  43. })
  44. that.data.codetext--
  45. }, 1000);
  46. wx.request({
  47. url: api.sendPhoneCode,
  48. data: { 'phone': that.data.phone},
  49. success(res){
  50. console.log(res)
  51. }
  52. })
  53. },
  54. photo:function(){
  55. let that = this
  56. wx.chooseImage({
  57. count: 1,
  58. sizeType: ['original', 'compressed'],
  59. sourceType: ['album', 'camera'],
  60. success(res) {
  61. // tempFilePath可以作为img标签的src属性显示图片
  62. that.data.filePaths = res.tempFilePaths
  63. that.setData({
  64. photo: that.data.filePaths
  65. })
  66. }
  67. })
  68. },
  69. formSubmit:function(e){
  70. let that = this
  71. if (!that.data.photo){
  72. wx.showToast({
  73. title: '请选择照片',
  74. icon:'none'
  75. })
  76. return false
  77. }
  78. if (!e.detail.value.name || !e.detail.value.phone || !e.detail.value.idcard || !e.detail.value.text){
  79. wx.showToast({
  80. title: '请填写访客基本信息',
  81. icon: 'none'
  82. })
  83. return false
  84. }
  85. // if (!e.detail.value.code){
  86. // wx.showToast({
  87. // title: '请填写短信验证码',
  88. // icon: 'none'
  89. // })
  90. // return false
  91. // }
  92. wx.showLoading({
  93. title: '正在提交',
  94. })
  95. wx.uploadFile({
  96. url: api.editorAlumniVisitor,
  97. filePath: that.data.photo[0],
  98. header: { 'content-type': 'application/x-www-form-urlencoded;charset=utf-8', },
  99. name: 'file',
  100. formData: {
  101. 'inviteUserId': wx.getStorageSync('loginId'),
  102. 'visitorName': e.detail.value.name,
  103. 'visitorPhone': e.detail.value.phone,
  104. 'identity': that.data.array[parseInt(e.detail.value.type)],
  105. 'IDNumber': e.detail.value.idcard,
  106. 'phoneCode': e.detail.value.code,
  107. 'visitorReason': e.detail.value.text,
  108. 'remarks': '',
  109. },
  110. success(res) {
  111. wx.hideLoading()
  112. res = JSON.parse(res.data)
  113. if (res.errno == 0) {
  114. wx.redirectTo({
  115. url: '/pages/success/index',
  116. })
  117. }else{
  118. wx.showToast({
  119. title: res.data,
  120. icon: 'none'
  121. })
  122. }
  123. }
  124. })
  125. },
  126. name:function(e){
  127. this.setData({
  128. name:e.detail.value
  129. })
  130. },
  131. idcard: function (e) {
  132. this.setData({
  133. idcard: e.detail.value
  134. })
  135. },
  136. phone: function (e) {
  137. this.setData({
  138. phone: e.detail.value
  139. })
  140. },
  141. text: function (e) {
  142. this.setData({
  143. text: e.detail.value
  144. })
  145. },
  146. previewImage:function(){
  147. wx.previewImage({
  148. urls: [this.data.filePaths[0]] // 需要预览的图片http链接列表
  149. })
  150. },
  151. up:function(){
  152. this.data.current--
  153. this.setData({
  154. current: this.data.current,
  155. swipercurrent: this.data.current
  156. })
  157. },
  158. next:function(){
  159. this.data.current++
  160. this.setData({
  161. current: this.data.current,
  162. swipercurrent: this.data.current
  163. })
  164. },
  165. /**
  166. * 生命周期函数--监听页面加载
  167. */
  168. onLoad: function (options) {
  169. },
  170. /**
  171. * 生命周期函数--监听页面初次渲染完成
  172. */
  173. onReady: function () {
  174. },
  175. /**
  176. * 生命周期函数--监听页面显示
  177. */
  178. onShow: function () {
  179. },
  180. /**
  181. * 生命周期函数--监听页面隐藏
  182. */
  183. onHide: function () {
  184. },
  185. /**
  186. * 生命周期函数--监听页面卸载
  187. */
  188. onUnload: function () {
  189. },
  190. /**
  191. * 页面相关事件处理函数--监听用户下拉动作
  192. */
  193. onPullDownRefresh: function () {
  194. },
  195. /**
  196. * 页面上拉触底事件的处理函数
  197. */
  198. onReachBottom: function () {
  199. },
  200. /**
  201. * 用户点击右上角分享
  202. */
  203. onShareAppMessage: function () {
  204. }
  205. })