123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- // pages/invoice/authentication/authentication.js
- const app = getApp();
- const api = app.api;
- import WxValidate from '../../../utils/WxValidate'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- type:undefined,
- upFileInfoReverse:null,
- upFileInfoFont:null,
- otherOrganization:false,
- organizationPickList:[],
- organizationPickValue:null,
- formData:{
- idNo: null,
- idNoImgNegativeId: null, //反面
- idNoImgPositiveId: null, //正面
- organCode:"",
- organName:"",
- mobile: null,
- name: null,
- },
- rules: {
- name: {
- required: true,
- },
- mobile: {
- required: true,
- tel: true,
- },
- idNo: {
- required: true,
- idcard: true,
- },
- organCode:{
- required: true,
- },
- idNoImgNegativeId:{
- required: true,
- },
- idNoImgPositiveId:{
- required: true,
- }
- },
- messages: {
- name: {
- required: '请输入姓名',
- },
- mobile: {
- required: '请输入手机号',
- tel: '请输入正确的手机号',
- },
- idNo: {
- required: '请输入身份证号码',
- idcard: '请输入正确的身份证号码',
- },
- organCode:{
- required: '请选择组织机构',
- },
- idNoImgPositiveId:{
- required: '请上传身份证正面',
- },
- idNoImgNegativeId:{
- required: '请上传身份证反面',
- }
- },
- isValidate:false,
- isSubmit:false,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- const { rules, messages } = this.data;
- this.WxValidate = new WxValidate(rules, messages);
- this.setData({
- type:options.id
- })
- Promise.all([
- this.findByCode('organization'),
- ]).then((res)=>{
- console.log(res);
- const organizationPickList=res[0].data.dicInfoList;
- this.setData({
- organizationPickList:organizationPickList
- });
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- validateForm(showInfo=false){
- const {formData,otherOrganization} = this.data;
- let flag=true;
- if(otherOrganization&&formData.organName==''){
- flag=false
- if(showInfo===true){
- wx.showToast({
- title: '请输入机构名称',
- icon: 'none',
- duration: 2000
- })
- }
- }
- //传入表单数据,调用验证方法
- if (!this.WxValidate.checkForm(formData)) {
- flag=false
- if(showInfo===true){
- const error = this.WxValidate.errorList[0];
- wx.showToast({
- title: error.msg,
- icon: 'none',
- duration: 2000
- })
- }
- }
- this.setData({
- isValidate:flag
- });
- return flag
- },
- saveData() {
- const {formData,type,isSubmit} = this.data;
- //重复提交
- if(isSubmit){
- return;
- }
- let flag=this.validateForm(true);
- if(!flag){
- return;
- }
- // if(otherOrganization&&formData.organName==''){
- // wx.showToast({
- // title: '请输入机构名称',
- // icon: 'none',
- // duration: 2000
- // })
- // return false
- // }
- // // 传入表单数据,调用验证方法
- // if (!this.WxValidate.checkForm(formData)) {
- // const error = this.WxValidate.errorList[0];
- // wx.showToast({
- // title: error.msg,
- // icon: 'none',
- // duration: 2000
- // })
- // return false
- // }
- //console.log(this.WxValidate);
- this.setData({
- isSubmit:true,
- });
- app.post(api.updateArtistUserInvoice, formData).then(res => {
- //console.log(res);
- this.setData({
- isSubmit:false,
- });
- if(type==-1){
- wx.navigateBack({})
- }else if(type==0){
- wx.redirectTo({
- url:"/pages/user/personalInfo/personalInfo"
- })
- }else if(type==2){
- wx.redirectTo({
- url:"/pages/user/personalInfo/personalInfo?type=2"
- })
- /* wx.redirectTo({
- url:"/pages/settled/curatorInfo/curatorInfo"
- })*/
- }else{
- wx.redirectTo({
- url:"/pages/invoice/contract/contract"
- })
- }
- }).catch(()=>{
- this.setData({
- isSubmit:false,
- });
- })
- },
- changeInput(e){
- console.log(e);
- const id = e.currentTarget.id;
- const value = e.detail.value;
- this.setData({
- [id]: value
- });
- },
- findByCode(code){
- return app.post(api.findByCode,{
- "code": code
- })
- },
- chooseFileFront(){
- app.uploadFile({
- extension:['jpg','png','jpeg']
- }).then(res=>{
- console.log(res)
- const data=JSON.parse(res.data);
- this.setData({
- upFileInfoFont:data,
- 'formData.idNoImgPositiveId':data.id
- },()=>{
- this.validateForm()
- })
- }).catch(error=>{
- console.log(error)
- });
- },
- removeFileFront(){
- this.setData({
- upFileInfoFont:null,
- 'formData.idNoImgPositiveId':''
- },()=>{
- this.validateForm()
- })
- },
- chooseFileReverse(){
- app.uploadFile({
- extension:['jpg','png','jpeg']
- }).then(res=>{
- console.log(res)
- const data=JSON.parse(res.data);
- this.setData({
- upFileInfoReverse:data,
- 'formData.idNoImgNegativeId':data.id
- },()=>{
- this.validateForm()
- })
- }).catch(error=>{
- console.log(error)
- });
- },
- removeFileReverse(){
- this.setData({
- upFileInfoReverse:null,
- 'formData.idNoImgNegativeId':''
- },()=>{
- this.validateForm()
- })
- },
- getPhoneNumber(e) {
- console.log(e);
- if (e.detail.errMsg !== "getPhoneNumber:ok"){
- return;
- }
- const { encryptedData, iv } = e.detail;
- app.post(api.getUserPhone, {
- wxPhoneEncrypted: {
- encryptedData,
- ivStr: iv
- }
- }).then(res => {
- this.setData({
- 'formData.mobile': res.data.phone
- },()=>{
- this.validateForm()
- })
- });
- },
- organizationPickHandler: function(e) {
- const {value}=e.detail;
- let otherOrganization = false;
- if(this.data.organizationPickList[value].code === '99'){
- otherOrganization = true;
- }
- this.setData({
- organizationPickValue : value,
- otherOrganization : otherOrganization,
- 'formData.organCode':this.data.organizationPickList[value].code,
- 'formData.organName':this.data.organizationPickList[value].code==99?"":this.data.organizationPickList[value].name,
- },()=>{
- this.validateForm()
- });
- // this.setData({
- // organizationPickValue:value,
- // 'formData.sex':sexPickList[value].value
- // });
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|