authentication.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. type:undefined,
  11. upFileInfoReverse:null,
  12. upFileInfoFont:null,
  13. otherOrganization:false,
  14. organizationPickList:[],
  15. organizationPickValue:null,
  16. formData:{
  17. idNo: null,
  18. idNoImgNegativeId: null, //反面
  19. idNoImgPositiveId: null, //正面
  20. organCode:"",
  21. organName:"",
  22. mobile: null,
  23. name: null,
  24. },
  25. rules: {
  26. name: {
  27. required: true,
  28. },
  29. mobile: {
  30. required: true,
  31. tel: true,
  32. },
  33. idNo: {
  34. required: true,
  35. idcard: true,
  36. },
  37. organCode:{
  38. required: true,
  39. },
  40. idNoImgNegativeId:{
  41. required: true,
  42. },
  43. idNoImgPositiveId:{
  44. required: true,
  45. }
  46. },
  47. messages: {
  48. name: {
  49. required: '请输入姓名',
  50. },
  51. mobile: {
  52. required: '请输入手机号',
  53. tel: '请输入正确的手机号',
  54. },
  55. idNo: {
  56. required: '请输入身份证号码',
  57. idcard: '请输入正确的身份证号码',
  58. },
  59. organCode:{
  60. required: '请选择组织机构',
  61. },
  62. idNoImgPositiveId:{
  63. required: '请上传身份证正面',
  64. },
  65. idNoImgNegativeId:{
  66. required: '请上传身份证反面',
  67. }
  68. },
  69. isValidate:false,
  70. isSubmit:false,
  71. },
  72. /**
  73. * 生命周期函数--监听页面加载
  74. */
  75. onLoad: function (options) {
  76. const { rules, messages } = this.data;
  77. this.WxValidate = new WxValidate(rules, messages);
  78. this.setData({
  79. type:options.id
  80. })
  81. Promise.all([
  82. this.findByCode('organization'),
  83. ]).then((res)=>{
  84. console.log(res);
  85. const organizationPickList=res[0].data.dicInfoList;
  86. this.setData({
  87. organizationPickList:organizationPickList
  88. });
  89. });
  90. },
  91. /**
  92. * 生命周期函数--监听页面初次渲染完成
  93. */
  94. onReady: function () {
  95. },
  96. /**
  97. * 生命周期函数--监听页面显示
  98. */
  99. onShow: function () {
  100. },
  101. validateForm(showInfo=false){
  102. const {formData,otherOrganization} = this.data;
  103. let flag=true;
  104. if(otherOrganization&&formData.organName==''){
  105. flag=false
  106. if(showInfo===true){
  107. wx.showToast({
  108. title: '请输入机构名称',
  109. icon: 'none',
  110. duration: 2000
  111. })
  112. }
  113. }
  114. //传入表单数据,调用验证方法
  115. if (!this.WxValidate.checkForm(formData)) {
  116. flag=false
  117. if(showInfo===true){
  118. const error = this.WxValidate.errorList[0];
  119. wx.showToast({
  120. title: error.msg,
  121. icon: 'none',
  122. duration: 2000
  123. })
  124. }
  125. }
  126. this.setData({
  127. isValidate:flag
  128. });
  129. return flag
  130. },
  131. saveData() {
  132. const {formData,type,isSubmit} = this.data;
  133. //重复提交
  134. if(isSubmit){
  135. return;
  136. }
  137. let flag=this.validateForm(true);
  138. if(!flag){
  139. return;
  140. }
  141. // if(otherOrganization&&formData.organName==''){
  142. // wx.showToast({
  143. // title: '请输入机构名称',
  144. // icon: 'none',
  145. // duration: 2000
  146. // })
  147. // return false
  148. // }
  149. // // 传入表单数据,调用验证方法
  150. // if (!this.WxValidate.checkForm(formData)) {
  151. // const error = this.WxValidate.errorList[0];
  152. // wx.showToast({
  153. // title: error.msg,
  154. // icon: 'none',
  155. // duration: 2000
  156. // })
  157. // return false
  158. // }
  159. //console.log(this.WxValidate);
  160. this.setData({
  161. isSubmit:true,
  162. });
  163. app.post(api.updateArtistUserInvoice, formData).then(res => {
  164. //console.log(res);
  165. this.setData({
  166. isSubmit:false,
  167. });
  168. if(type==-1){
  169. wx.navigateBack({})
  170. }else if(type==0){
  171. wx.redirectTo({
  172. url:"/pages/user/personalInfo/personalInfo"
  173. })
  174. }else if(type==2){
  175. wx.redirectTo({
  176. url:"/pages/user/personalInfo/personalInfo?type=2"
  177. })
  178. /* wx.redirectTo({
  179. url:"/pages/settled/curatorInfo/curatorInfo"
  180. })*/
  181. }else{
  182. wx.redirectTo({
  183. url:"/pages/invoice/contract/contract"
  184. })
  185. }
  186. }).catch(()=>{
  187. this.setData({
  188. isSubmit:false,
  189. });
  190. })
  191. },
  192. changeInput(e){
  193. console.log(e);
  194. const id = e.currentTarget.id;
  195. const value = e.detail.value;
  196. this.setData({
  197. [id]: value
  198. });
  199. },
  200. findByCode(code){
  201. return app.post(api.findByCode,{
  202. "code": code
  203. })
  204. },
  205. chooseFileFront(){
  206. app.uploadFile({
  207. extension:['jpg','png','jpeg']
  208. }).then(res=>{
  209. console.log(res)
  210. const data=JSON.parse(res.data);
  211. this.setData({
  212. upFileInfoFont:data,
  213. 'formData.idNoImgPositiveId':data.id
  214. },()=>{
  215. this.validateForm()
  216. })
  217. }).catch(error=>{
  218. console.log(error)
  219. });
  220. },
  221. removeFileFront(){
  222. this.setData({
  223. upFileInfoFont:null,
  224. 'formData.idNoImgPositiveId':''
  225. },()=>{
  226. this.validateForm()
  227. })
  228. },
  229. chooseFileReverse(){
  230. app.uploadFile({
  231. extension:['jpg','png','jpeg']
  232. }).then(res=>{
  233. console.log(res)
  234. const data=JSON.parse(res.data);
  235. this.setData({
  236. upFileInfoReverse:data,
  237. 'formData.idNoImgNegativeId':data.id
  238. },()=>{
  239. this.validateForm()
  240. })
  241. }).catch(error=>{
  242. console.log(error)
  243. });
  244. },
  245. removeFileReverse(){
  246. this.setData({
  247. upFileInfoReverse:null,
  248. 'formData.idNoImgNegativeId':''
  249. },()=>{
  250. this.validateForm()
  251. })
  252. },
  253. getPhoneNumber(e) {
  254. console.log(e);
  255. if (e.detail.errMsg !== "getPhoneNumber:ok"){
  256. return;
  257. }
  258. const { encryptedData, iv } = e.detail;
  259. app.post(api.getUserPhone, {
  260. wxPhoneEncrypted: {
  261. encryptedData,
  262. ivStr: iv
  263. }
  264. }).then(res => {
  265. this.setData({
  266. 'formData.mobile': res.data.phone
  267. },()=>{
  268. this.validateForm()
  269. })
  270. });
  271. },
  272. organizationPickHandler: function(e) {
  273. const {value}=e.detail;
  274. let otherOrganization = false;
  275. if(this.data.organizationPickList[value].code === '99'){
  276. otherOrganization = true;
  277. }
  278. this.setData({
  279. organizationPickValue : value,
  280. otherOrganization : otherOrganization,
  281. 'formData.organCode':this.data.organizationPickList[value].code,
  282. 'formData.organName':this.data.organizationPickList[value].code==99?"":this.data.organizationPickList[value].name,
  283. },()=>{
  284. this.validateForm()
  285. });
  286. // this.setData({
  287. // organizationPickValue:value,
  288. // 'formData.sex':sexPickList[value].value
  289. // });
  290. },
  291. /**
  292. * 生命周期函数--监听页面隐藏
  293. */
  294. onHide: function () {
  295. },
  296. /**
  297. * 生命周期函数--监听页面卸载
  298. */
  299. onUnload: function () {
  300. },
  301. /**
  302. * 页面相关事件处理函数--监听用户下拉动作
  303. */
  304. onPullDownRefresh: function () {
  305. },
  306. /**
  307. * 页面上拉触底事件的处理函数
  308. */
  309. onReachBottom: function () {
  310. },
  311. /**
  312. * 用户点击右上角分享
  313. */
  314. onShareAppMessage: function () {
  315. }
  316. })