authenticationCompany.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // pages/invoice/authentication/authentication.js
  2. const app = getApp();
  3. const api = app.api;
  4. import WxValidate from '../../../utils/WxValidate'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. businessLicenseFileInfo:null,
  11. upFileInfoFont:null,
  12. formData:{
  13. name:"",
  14. phoneNumber:"",
  15. businessLicenseNo:"",
  16. address:"",
  17. businessLicenseImgId:""
  18. },
  19. rules: {
  20. name: {
  21. required: true,
  22. },
  23. phoneNumber: {
  24. required: true,
  25. phone: true,
  26. },
  27. businessLicenseNo:{
  28. required: true,
  29. },
  30. address:{
  31. required: true,
  32. },
  33. businessLicenseImgId:{
  34. required: true,
  35. }
  36. },
  37. messages: {
  38. name: {
  39. required: '请输入公司名',
  40. },
  41. businessLicenseNo:{
  42. required: '请输入公司统一信用代码',
  43. },
  44. phoneNumber: {
  45. required: '公司联系电话',
  46. phone: '请输入正确的电话',
  47. },
  48. address:{
  49. required: '请输入公司地址',
  50. },
  51. businessLicenseImgId:{
  52. required: '请上传公司营业执照',
  53. }
  54. },
  55. isValidate:false,
  56. isSubmit:false
  57. },
  58. /**
  59. * 生命周期函数--监听页面加载
  60. */
  61. onLoad: function (options) {
  62. const { rules, messages } = this.data;
  63. this.WxValidate = new WxValidate(rules, messages);
  64. },
  65. /**
  66. * 生命周期函数--监听页面初次渲染完成
  67. */
  68. onReady: function () {
  69. },
  70. /**
  71. * 生命周期函数--监听页面显示
  72. */
  73. onShow: function () {
  74. },
  75. validateHanlder(){
  76. const {formData} = this.data;
  77. if (!this.WxValidate.checkForm(formData)) {
  78. this.setData({
  79. isValidate:false
  80. })
  81. }else{
  82. this.setData({
  83. isValidate:true
  84. })
  85. }
  86. },
  87. saveData() {
  88. const {formData,isSubmit} = this.data;
  89. if(isSubmit){
  90. return
  91. }
  92. // 传入表单数据,调用验证方法
  93. if (!this.WxValidate.checkForm(formData)) {
  94. const error = this.WxValidate.errorList[0];
  95. wx.showToast({
  96. title: error.msg,
  97. icon: 'none',
  98. duration: 2000
  99. })
  100. return false
  101. }
  102. console.log(this.WxValidate);
  103. wx.requestSubscribeMessage({
  104. tmplIds: [
  105. 'EnF59db6rv1QhwUc67GuKNQBw-R-VZNAB5xVXyP40A4',
  106. ],
  107. success: (res)=> {
  108. this.setData({
  109. isSubmit:true
  110. });
  111. app.post(api.addCompanyDetails, formData).then(res => {
  112. this.setData({
  113. isSubmit:false,
  114. });
  115. wx.redirectTo({
  116. url:"/pages/settled/success/success"
  117. })
  118. //console.log(res);
  119. /* wx.redirectTo({
  120. url:"/pages/invoice/contract/contract"
  121. })*/
  122. }).catch(()=>{
  123. this.setData({
  124. isSubmit:false
  125. });
  126. })
  127. }
  128. })
  129. },
  130. changeInput(e){
  131. console.log(e);
  132. const id = e.currentTarget.id;
  133. const value = e.detail.value;
  134. this.setData({
  135. [id]: value
  136. });
  137. },
  138. chooseFile(){
  139. app.uploadFile({
  140. extension:['jpg','png','jpeg']
  141. }).then(res=>{
  142. console.log(res)
  143. const data=JSON.parse(res.data);
  144. this.setData({
  145. businessLicenseFileInfo:data,
  146. 'formData.businessLicenseImgId':data.id
  147. },()=>{
  148. this.validateHanlder();
  149. })
  150. }).catch(error=>{
  151. console.log(error)
  152. });
  153. },
  154. removeChooseFile(){
  155. this.setData({
  156. businessLicenseFileInfo:null,
  157. 'formData.businessLicenseImgId':''
  158. })
  159. },
  160. /**
  161. * 生命周期函数--监听页面隐藏
  162. */
  163. onHide: function () {
  164. },
  165. /**
  166. * 生命周期函数--监听页面卸载
  167. */
  168. onUnload: function () {
  169. },
  170. /**
  171. * 页面相关事件处理函数--监听用户下拉动作
  172. */
  173. onPullDownRefresh: function () {
  174. },
  175. /**
  176. * 页面上拉触底事件的处理函数
  177. */
  178. onReachBottom: function () {
  179. },
  180. /**
  181. * 用户点击右上角分享
  182. */
  183. onShareAppMessage: function () {
  184. }
  185. })