application.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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){
  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.uploadFile({
  93. url: 'http://192.168.100.234:8080/oneportal/visitor/editorAlumniVisitor.if',
  94. filePath: that.data.photo[0],
  95. header: { 'content-type': 'application/x-www-form-urlencoded;charset=utf-8', },
  96. name: 'file',
  97. formData: {
  98. 'inviteUserId': wx.getStorageSync('loginId'),
  99. 'visitorName': e.detail.value.name,
  100. 'visitorPhone': e.detail.value.phone,
  101. 'identity': that.data.array[parseInt(e.detail.value.type)],
  102. 'IDNumber': e.detail.value.idcard,
  103. 'phoneCode': e.detail.value.code,
  104. 'visitorReason': e.detail.value.text,
  105. 'remarks': '',
  106. },
  107. success(res) {
  108. console.log(res)
  109. if (JSON.parse(res.data).youtuMessage.errorno == 0) {
  110. wx.showToast({
  111. title: '上传成功',
  112. icon: 'none'
  113. })
  114. }
  115. }
  116. })
  117. },
  118. name:function(e){
  119. this.setData({
  120. name:e.detail.value
  121. })
  122. },
  123. idcard: function (e) {
  124. this.setData({
  125. idcard: e.detail.value
  126. })
  127. },
  128. phone: function (e) {
  129. this.setData({
  130. phone: e.detail.value
  131. })
  132. },
  133. text: function (e) {
  134. this.setData({
  135. text: e.detail.value
  136. })
  137. },
  138. previewImage:function(){
  139. wx.previewImage({
  140. urls: [this.data.filePaths[0]] // 需要预览的图片http链接列表
  141. })
  142. },
  143. next:function(){
  144. this.data.current++
  145. this.setData({
  146. current: this.data.current,
  147. swipercurrent: this.data.current
  148. })
  149. },
  150. /**
  151. * 生命周期函数--监听页面加载
  152. */
  153. onLoad: function (options) {
  154. },
  155. /**
  156. * 生命周期函数--监听页面初次渲染完成
  157. */
  158. onReady: function () {
  159. },
  160. /**
  161. * 生命周期函数--监听页面显示
  162. */
  163. onShow: function () {
  164. },
  165. /**
  166. * 生命周期函数--监听页面隐藏
  167. */
  168. onHide: function () {
  169. },
  170. /**
  171. * 生命周期函数--监听页面卸载
  172. */
  173. onUnload: function () {
  174. },
  175. /**
  176. * 页面相关事件处理函数--监听用户下拉动作
  177. */
  178. onPullDownRefresh: function () {
  179. },
  180. /**
  181. * 页面上拉触底事件的处理函数
  182. */
  183. onReachBottom: function () {
  184. },
  185. /**
  186. * 用户点击右上角分享
  187. */
  188. onShareAppMessage: function () {
  189. }
  190. })