application.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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: api.editorAlumniVisitor,
  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(JSON.parse(res.data))
  109. res = JSON.parse(res.data)
  110. if (res.errno == 0) {
  111. wx.showToast({
  112. title: '上传成功',
  113. icon: 'none'
  114. })
  115. }else{
  116. wx.showToast({
  117. title: res.data,
  118. icon: 'none'
  119. })
  120. }
  121. }
  122. })
  123. },
  124. name:function(e){
  125. this.setData({
  126. name:e.detail.value
  127. })
  128. },
  129. idcard: function (e) {
  130. this.setData({
  131. idcard: e.detail.value
  132. })
  133. },
  134. phone: function (e) {
  135. this.setData({
  136. phone: e.detail.value
  137. })
  138. },
  139. text: function (e) {
  140. this.setData({
  141. text: e.detail.value
  142. })
  143. },
  144. previewImage:function(){
  145. wx.previewImage({
  146. urls: [this.data.filePaths[0]] // 需要预览的图片http链接列表
  147. })
  148. },
  149. next:function(){
  150. this.data.current++
  151. this.setData({
  152. current: this.data.current,
  153. swipercurrent: this.data.current
  154. })
  155. },
  156. /**
  157. * 生命周期函数--监听页面加载
  158. */
  159. onLoad: function (options) {
  160. },
  161. /**
  162. * 生命周期函数--监听页面初次渲染完成
  163. */
  164. onReady: function () {
  165. },
  166. /**
  167. * 生命周期函数--监听页面显示
  168. */
  169. onShow: function () {
  170. },
  171. /**
  172. * 生命周期函数--监听页面隐藏
  173. */
  174. onHide: function () {
  175. },
  176. /**
  177. * 生命周期函数--监听页面卸载
  178. */
  179. onUnload: function () {
  180. },
  181. /**
  182. * 页面相关事件处理函数--监听用户下拉动作
  183. */
  184. onPullDownRefresh: function () {
  185. },
  186. /**
  187. * 页面上拉触底事件的处理函数
  188. */
  189. onReachBottom: function () {
  190. },
  191. /**
  192. * 用户点击右上角分享
  193. */
  194. onShareAppMessage: function () {
  195. }
  196. })