application.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. // if(that.data.current==1){
  21. // if (!this.data.name || !this.data.idcard || !this.data.phone || !this.data.text) {
  22. // if (!(/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(that.data.idcard)) && !(/^1[3456789]\d{9}$/.test(that.data.phone))) {
  23. // that.setData({
  24. // isYesno: true,
  25. // current: e.detail.current
  26. // })
  27. // return false
  28. // }
  29. // }else{
  30. // that.setData({
  31. // isYesno: false,
  32. // current: e.detail.current
  33. // })
  34. // return false
  35. // }
  36. // }
  37. that.setData({
  38. current: e.detail.current
  39. })
  40. },
  41. code:function(){
  42. let that=this
  43. if (!that.data.phone||that.data.phone.split('').length!=11) {
  44. wx.showToast({
  45. title: '请输入正确的手机号',
  46. icon:'none'
  47. })
  48. return false
  49. }
  50. that.data.codetext = 59
  51. let timer = setInterval(function () {
  52. if (that.data.codetext == 0) {
  53. clearTimeout(timer)
  54. that.setData({
  55. codetext: '重新发送'
  56. })
  57. }
  58. that.setData({
  59. codetext: that.data.codetext
  60. })
  61. that.data.codetext--
  62. }, 1000);
  63. wx.request({
  64. url: api.sendPhoneCode,
  65. data: { 'phone': that.data.phone},
  66. success(res){
  67. console.log(res)
  68. }
  69. })
  70. },
  71. photo:function(){
  72. let that = this
  73. wx.chooseImage({
  74. count: 1,
  75. sizeType: ['original', 'compressed'],
  76. sourceType: ['album', 'camera'],
  77. success(res) {
  78. // tempFilePath可以作为img标签的src属性显示图片
  79. that.data.filePaths = res.tempFilePaths
  80. that.setData({
  81. photo: that.data.filePaths
  82. })
  83. }
  84. })
  85. },
  86. formSubmit:function(e){
  87. let that = this
  88. if (!that.data.photo){
  89. wx.showToast({
  90. title: '请选择照片',
  91. icon:'none'
  92. })
  93. return false
  94. }
  95. if (!e.detail.value.name || !e.detail.value.phone || !e.detail.value.idcard || !e.detail.value.text){
  96. wx.showToast({
  97. title: '请填写访客基本信息',
  98. icon: 'none'
  99. })
  100. return false
  101. }
  102. // if (!e.detail.value.code){
  103. // wx.showToast({
  104. // title: '请填写短信验证码',
  105. // icon: 'none'
  106. // })
  107. // return false
  108. // }
  109. wx.showLoading({
  110. title: '正在提交',
  111. })
  112. wx.uploadFile({
  113. url: api.editorAlumniVisitor,
  114. filePath: that.data.photo[0],
  115. header: { 'content-type': 'application/x-www-form-urlencoded;charset=utf-8', },
  116. name: 'file',
  117. formData: {
  118. 'inviteUserId': wx.getStorageSync('loginId'),
  119. 'visitorName': e.detail.value.name,
  120. 'visitorPhone': e.detail.value.phone,
  121. 'identity': that.data.array[parseInt(e.detail.value.type)],
  122. 'IDNumber': e.detail.value.idcard,
  123. 'phoneCode': e.detail.value.code,
  124. 'visitorReason': e.detail.value.text,
  125. 'remarks': '',
  126. },
  127. success(res) {
  128. wx.hideLoading()
  129. res = JSON.parse(res.data)
  130. if (res.errno == 0) {
  131. wx.redirectTo({
  132. url: '/pages/success/index',
  133. })
  134. }else{
  135. wx.showToast({
  136. title: res.data,
  137. icon: 'none'
  138. })
  139. }
  140. }
  141. })
  142. },
  143. ifYesno(){
  144. let that=this
  145. if (that.data.name || that.data.idcard || that.data.phone || that.data.text) {
  146. if ((/^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/.test(that.data.name))&&(/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(that.data.idcard)) && (/^1[3456789]\d{9}$/.test(that.data.phone))) {
  147. that.setData({
  148. isYesno: true
  149. })
  150. }else{
  151. that.setData({
  152. isYesno: false
  153. })
  154. }
  155. }else{
  156. that.setData({
  157. isYesno: false
  158. })
  159. }
  160. },
  161. name:function(e){
  162. this.setData({
  163. name:e.detail.value
  164. })
  165. this.ifYesno()
  166. },
  167. idcard: function (e) {
  168. this.setData({
  169. idcard: e.detail.value
  170. })
  171. this.ifYesno()
  172. },
  173. phone: function (e) {
  174. this.setData({
  175. phone: e.detail.value
  176. })
  177. this.ifYesno()
  178. },
  179. text: function (e) {
  180. this.setData({
  181. text: e.detail.value
  182. })
  183. this.ifYesno()
  184. },
  185. previewImage:function(){
  186. wx.previewImage({
  187. urls: [this.data.filePaths[0]] // 需要预览的图片http链接列表
  188. })
  189. },
  190. up:function(){
  191. this.data.current--
  192. this.setData({
  193. current: this.data.current,
  194. swipercurrent: this.data.current
  195. })
  196. },
  197. next:function(){
  198. debugger
  199. console.log(this.data)
  200. if(!this.data.photo){
  201. wx.showToast({
  202. title: '请先上传头像照',
  203. icon:'none'
  204. })
  205. return false
  206. }else if(this.data.current==1){
  207. if (!this.data.name || !this.data.idcard || !this.data.phone || !this.data.text) {
  208. wx.showToast({
  209. title: '资料请填写完整',
  210. icon: 'none'
  211. })
  212. return false
  213. }
  214. if (!(/^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/.test(this.data.name))){
  215. wx.showToast({
  216. title: '名称输入不合法',
  217. icon: 'none'
  218. })
  219. return false
  220. }
  221. if (!(/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(this.data.idcard))){
  222. wx.showToast({
  223. title: '身份证输入不合法',
  224. icon:'none'
  225. })
  226. return false
  227. }
  228. if (!(/^1[3456789]\d{9}$/.test(this.data.phone))){
  229. wx.showToast({
  230. title: '手机号输入不合法',
  231. icon: 'none'
  232. })
  233. return false
  234. }
  235. }
  236. this.data.current++
  237. this.setData({
  238. current: this.data.current,
  239. swipercurrent: this.data.current,
  240. isYesno: true
  241. })
  242. },
  243. /**
  244. * 生命周期函数--监听页面加载
  245. */
  246. onLoad: function (options) {
  247. },
  248. /**
  249. * 生命周期函数--监听页面初次渲染完成
  250. */
  251. onReady: function () {
  252. },
  253. /**
  254. * 生命周期函数--监听页面显示
  255. */
  256. onShow: function () {
  257. },
  258. /**
  259. * 生命周期函数--监听页面隐藏
  260. */
  261. onHide: function () {
  262. },
  263. /**
  264. * 生命周期函数--监听页面卸载
  265. */
  266. onUnload: function () {
  267. },
  268. /**
  269. * 页面相关事件处理函数--监听用户下拉动作
  270. */
  271. onPullDownRefresh: function () {
  272. },
  273. /**
  274. * 页面上拉触底事件的处理函数
  275. */
  276. onReachBottom: function () {
  277. },
  278. /**
  279. * 用户点击右上角分享
  280. */
  281. onShareAppMessage: function () {
  282. }
  283. })