var WxParse = null;
var app = getApp()
var that=null
var sopenFrame=null
var areas = null;
var name = "";
      var strmoney="";
      var dgzh="";
      var frname="";
      var fridcard="";
      var number="";
      var tel="";
      var Province="";
      var City="";
      var County="";
      var detail="";
      var fwbody="";
      var AccountName="";
      var BankName="";
      var BankCard="";
      var BankDepos="";
var context = null; // 使用 wx.createContext 获取绘图上下文 context
var mCanvas = null;
Page( {
  data: {
    loadingHidden:false,
    loading:false,
    sjname:"",
    number:"",
    dgzh:"",
    frname:"",
    fridcard:"",
    tel:"",
    sjimage0:"../../images/add.png",
    sjimage1:"../../images/add.png",
    sjimage2:"../../images/add.png",
    sjimage3:"../../images/add.png",
    sjimage4:"../../images/add.png",
    sjimage5:"../../images/add.png",
    sjimage6:"../../images/add.png",
    addimage0:"",
    addimage1:"",
    addimage2:"",
    addimage3:"",
    addimage4:"",
    addimage5:"",
    addimage6:"",
    annotatemap:"",
    detail:"",
    fwbody:"",
    sectionHidden:true,
    sectionHidden0:true,
    IFDefault:1,
    savebutton:"下一步",
    Provinces:[],
    Citylist:[],
            Citys:[],
            Countys:[],
            hx_index:-1,
            hx_index0:-1,
            hx_index1:-1,
            area:"",
            addressId:0,
            clslist:[],
            hc_index:-1,
            clsid:0,
            clsname:"",
            latitude:0,
            longitude:0,
            scale:15,
            markers:  [],
            bzlatitude:0,
            bzlongitude:0,
            ylmoney:0,
            ylmoney0:0,
            byNumber:0,
            index: -1,
            AccountName:"",
            BankCard:"",
            BankDepos:"",
    BankNames:[],
    uid:0,
    hasDraw: false, //默认没有画
    showtitle:"",
        showbody:""
  },
  onReady: function(e) {
    // 使用 wx.createMapContext 获取 map 上下文 
    this.mapCtx = wx.createMapContext('myMap');
  },
  onLoad: function() {
    
      that = this
      WxParse = require('../../wxParse/wxParse.js');
      areas = require('../../area.js'); 
     
      
      that.setData({
        Provinces:areas.areaslist,
        Citylist:areas.Citylist
      })
      that.rdata()
      this.setData({
        hasDraw: false,
      })
     
    },rdata: function() {
      var userId = wx.getStorageSync("userId")
      var LoginId = wx.getStorageSync("LoginId")
      var userInfodata = wx.getStorageSync("userInfo")
      var userInfo = JSON.parse(userInfodata)
      if(userId&&LoginId){
        var userInfo = JSON.parse(userInfodata)
        that.setData({
            uid:userInfo.id
         })
        }
      wx.request({
        url: app.globalData.apiurl + "/xapiajax.ashx", 
        data: { 
          action:"getbusinessinfo",
           userId:(!userId?"":userId),
           LoginId:(!LoginId?"":LoginId)
        },
        method:"GET",
        dataType:"json", 
        success (res) { 
          if(res.data.status==1){
         
              var webbank=res.data.webbank
              
              var webbanks=webbank.split('|')
              var banks=""
              var index=0
              
              for(var i=0;i<webbanks.length;i++){
                    if(banks!=""){
                       banks+=",{\"key\":\""+webbanks[i]+"\"}"
                    }else{
                       banks+="{\"key\":\""+webbanks[i]+"\"}"
                    }
                   
              }
              var body = res.data.showbody;
                      WxParse.wxParse('body', 'html', body, that);
            that.setData({
              index: index,
                    BankNames:JSON.parse("["+banks+"]"),
              clslist:res.data.clslist,
              ylmoney:res.data.ylmoney,
              ylmoney0:res.data.ylmoney0,
              showtitle:res.data.showtitle,  
              loadingHidden:true
             })
             var sjbyNumber = wx.getStorageSync("appsjbyNumber");
             if(sjbyNumber!=null){
              
               var sjclsid = wx.getStorageSync("appsjclsid");
               
               if(sjclsid!=null){
                  var clsindex=-1;
                  var clsname="";
                 for(var i=0;i<that.data.clslist.length;i++){
                    if(that.data.clslist[i].id==sjclsid){
                        clsindex=i;
                        clsname=that.data.clslist[i].name;
                    }
                 }
                 that.setData({
                    hc_index:clsindex,
                    clsid:sjclsid,
                    clsname:clsname,
                 })    
               }
               var sjname = wx.getStorageSync("appsjname");
               if(sjname!=null){
                that.setData({
                  sjname:sjname
                })    
               }
               var sjylmoney = wx.getStorageSync("appsjylmoney");
               if(sjylmoney!=null){
                that.setData({
                  sjylmoney:sjylmoney
                })    
               }
               var sjnumber = wx.getStorageSync("appsjnumber");
               if(sjnumber!=null){
                that.setData({
                  number:sjnumber
                })    
               }
               var sjdgzh = wx.getStorageSync("appsjdgzh");
               if(sjdgzh!=null){
                that.setData({
                  dgzh:sjdgzh
                })    
               }
               var sjfrname = wx.getStorageSync("appsjfrname");
               if(sjfrname!=null){
                that.setData({
                  frname:sjfrname
                })    
               }
               var sjfridcard = wx.getStorageSync("appsjfridcard");
               if(sjfridcard!=null){
                that.setData({
                  fridcard:sjfridcard
                })    
               }
               var sjtel = wx.getStorageSync("appsjtel");
               if(sjtel!=null){
                that.setData({
                  tel:sjtel
                })    
               }
               var sjProvince = wx.getStorageSync("appsjProvince");
               var sjCity = wx.getStorageSync("appsjCity");
               var sjCounty = wx.getStorageSync("appsjCounty");
               if(sjProvince!=null&&sjCity!=null&&sjCounty!=null){
                var area="";
                var hx_index=-1,hx_index0=-1,hx_index1=-1;
                var provinces=that.data.Provinces
                var acitys=[];
                var acountys=[];
                for(var i=0;i<provinces.length;i++){
                      if(provinces[i].ProvinceID==sjProvince){
                        hx_index=i;
                        var citys=provinces[i].City;
                        acitys=citys;
                        area=provinces[i].ProvinceName;
                        for(var j=0;j<citys.length;j++){
                             if(citys[j].CityID==sjCity){
                                  hx_index0=j;
                                  var countys=citys[j].County;
                                  acountys=countys;
                                  area+=citys[j].CityName;
                                  for(var k=0;k<countys.length;k++){
                                       if(countys[k].CountyID==sjCounty){
                                           hx_index1=k;
                                           area+=countys[k].CountyName;
                                            break;
                                       } 
                                      
                                  }
                                  break;
                             }
                             
                        }
                        break;
                      }
                }
               
                that.setData({
                  area:area,
                  hx_index:hx_index,
                  hx_index0:hx_index0,
                  hx_index1:hx_index1,
                  Citys:acitys,
                  Countys:acountys,
                })    
               }
               var sjdetail = wx.getStorageSync("appsjdetail");
               if(sjdetail!=null){
                that.setData({
                  detail:sjdetail
                })    
               }
               var sjlatitude = wx.getStorageSync("appsjlatitude");
               var sjlongitude = wx.getStorageSync("appsjlongitude");
               if(sjlatitude!=null&&sjlongitude!=null){
                if(sjlatitude!="0"&&sjlongitude!="0"){
                that.setData({
                  bzlatitude:sjlatitude,
                  bzlongitude:sjlongitude,
                  annotatemap:"已标注"
                })    
              }
               }
               var sjfwbody = wx.getStorageSync("appsjfwbody");
               if(sjfwbody!=null){
                that.setData({
                  fwbody:sjfwbody
                })    
               }
               var sjimage0 = wx.getStorageSync("appsjimage0");
               var sjaddimage0 = wx.getStorageSync("appaddimage0");
               if(sjimage0!=null&&sjaddimage0!=null){
                that.setData({
                  sjimage0:sjimage0,
                  addimage0:sjaddimage0,
                })    
               }
               var sjimage1 = wx.getStorageSync("appsjimage1");
               var sjaddimage1 = wx.getStorageSync("appaddimage1");
               if(sjimage1!=null&&sjaddimage1!=null){
                that.setData({
                  sjimage1:sjimage1,
                  addimage1:sjaddimage1,
                })    
               }
               var sjimage2 = wx.getStorageSync("appsjimage2");
               var sjaddimage2 = wx.getStorageSync("appaddimage2");
               if(sjimage2!=null&&sjaddimage2!=null){
                that.setData({
                  sjimage2:sjimage2,
                  addimage2:sjaddimage2,
                })    
               }
               var sjimage3 = wx.getStorageSync("appsjimage3");
               var sjaddimage3 = wx.getStorageSync("appaddimage3");
               if(sjaddimage3!=null&&sjaddimage3!=null){
                that.setData({
                  sjimage3:sjimage3,
                  addimage3:sjaddimage3,
                })    
               }
               var sjimage4 = wx.getStorageSync("appsjimage4");
               var sjaddimage4 = wx.getStorageSync("appaddimage4");
               if(sjimage4!=null&&sjaddimage4!=null){
                that.setData({
                  sjimage4:sjimage4,
                  addimage4:sjaddimage4,
                })    
               }
               
              
               var sjAccountName = wx.getStorageSync("appsjAccountName");
               if(sjAccountName!=null){
                that.setData({
                  AccountName:sjAccountName
                })    
               }
               var sjBankName = wx.getStorageSync("appsjBankName");
               if(sjBankName!=null){
                for(var i=0;i<webbanks.length;i++){
                    if(webbanks[i]==sjBankName){
                        index=i;
                    }
                }
                that.setData({
                  index:index
                })    
               }
               var sjBankCard = wx.getStorageSync("appsjBankCard");
               if(sjBankCard!=null){
                that.setData({
                  BankCard:sjBankCard
                })    
               }
               var sjBankDepos = wx.getStorageSync("appsjBankDepos");
               if(sjBankDepos!=null){
                that.setData({
                  BankDepos:sjBankDepos
                })    
               }
             }
          }
        }
        })
            
    },getylmoney:function(e) {
       
    },clsChange:function(e) {
      var index=e.detail.value;
      that.setData({
        hc_index: index,
        clsid:that.data.clslist[index].id,
        clsname:that.data.clslist[index].name,
        sectionHidden0:true
      })
    },onarea:function(e) {
      that.setData({
          sectionHidden:false
      })
    },ProvinceChange:function(e) {
      var index=e.detail.value;
      var citys=that.data.Provinces[index].City
      that.setData({
        hx_index: index,
        hx_index0: -1,
        hx_index1: -1,
        Citys:citys
      })
      if(citys.length==0){
        that.setData({
           sectionHidden:true,
           area:that.data.Provinces[that.data.hx_index].ProvinceName
         })
      }
    },CityChange:function(e) {
      var index=e.detail.value
      var countys=that.data.Citys[index].County
      that.setData({
        hx_index0: index,
        hx_index1: -1,
        Countys:countys
      })
      if(countys.length==0){
        that.setData({
           sectionHidden:true,
           area:that.data.Provinces[that.data.hx_index].ProvinceName+that.data.Citys[that.data.hx_index0].CityName
         })
      }
    },CountyChange:function(e) {
      that.setData({
        hx_index1: e.detail.value
      })  
      that.setData({
        sectionHidden:true,
        area:that.data.Provinces[that.data.hx_index].ProvinceName+that.data.Citys[that.data.hx_index0].CityName+that.data.Countys[that.data.hx_index1].CountyName
      })
    },onannotatemap:function(e) {
      if(that.data.hx_index==-1||that.data.hx_index0==-1){
        wx.showToast({
          title: "请选选择地区！",
          icon: "none",
          duration: 3000
         })
      }else{
//获取经纬度
wx.getLocation({
  type: 'gcj02',
  success: function (res) {
    var latitude = res.latitude
    var longitude = res.longitude
    that.setData({
      latitude: latitude,
      longitude: longitude,
    })
    
  },fail: function (res) {
    wx.showToast({
      title: "获取定位失败！",
      icon: "none",
      duration: 3000
     })
  }
})

          /*var center="";
          if(that.data.hx_index>-1&&that.data.hx_index0>-1){
            center=that.data.Citys[that.data.hx_index0].center
            if(that.data.hx_index1>-1){
                center=that.data.Countys[that.data.hx_index1].center
            }
            if(center!=""){
              var acenter=center.split(",");
            that.setData({
              latitude: acenter[1],
              longitude: acenter[0],
            })
            }
          }*/

          that.setData({
               sectionHidden0:false,
               loading:true,
               savebutton:"标注好了，返回"
          })
          var sopenFrame0=setInterval(function (){
            clearInterval(sopenFrame0);  
          that.setData({
              loading:false 
          })
           },1000)
       }
    },maptap:function(e) {
     
      that.setData({
        loading:true,
        bzlatitude: e.detail.latitude,
        bzlongitude: e.detail.longitude,
        annotatemap:"已标注",
        markers:  [{
          id:8900,
          latitude: e.detail.latitude,
          longitude:  e.detail.longitude,
          iconPath: '../../images/position-picker2.png',
              width: 80,
              height: 80,
              enableDragging: true
        }]
      })
      var sopenFrame0=setInterval(function (){
        clearInterval(sopenFrame0);  
      that.setData({
          loading:false 
      })
       },300)
    },
    regionchange(e) {
      console.log(e)
    },markertap:function(e) {
      
    },closesection:function(e) {
      that.setData({
        sectionHidden:true,
        
      })
    },closesection0:function(e) {
      that.setData({
        sectionHidden0:true,
        savebutton:"提交"
      })
    },insection:function(e) {
      
    },onsjimage:function(e) {
      var id = e.currentTarget.dataset.id
      var yimage=that.data.sjimage0
      if(id==1){
        yimage=that.data.sjimage1
      }else if(id==2){
        yimage=that.data.sjimage2
      }else if(id==3){
        yimage=that.data.sjimage3
      }else if(id==4){
        yimage=that.data.sjimage4
      }else if(id==5){
        yimage=that.data.sjimage5
      }else if(id==6){
        yimage=that.data.sjimage6
      }
      if(yimage=="../../images/ajaxLoader.gif"){
        wx.showToast({
          title: "正在上传中...",
          icon: "none",
          duration: 3000
         })
      }else{
      wx.chooseImage({
        count: 1,
        sizeType: ['original'],
        sourceType: ['album', 'camera'],
        success (res) {
              const tempFilePaths = res.tempFilePaths;
              if(id==0){
                that.setData({
                  sjimage0:"../../images/ajaxLoader.gif"
               })
              }else if(id==1){
                that.setData({
                  sjimage1:"../../images/ajaxLoader.gif"
                })
              }else if(id==2){
                that.setData({
                  sjimage2:"../../images/ajaxLoader.gif"
                })
              }else if(id==3){
                that.setData({
                  sjimage3:"../../images/ajaxLoader.gif"
                })
              }else if(id==4){
                that.setData({
                  sjimage4:"../../images/ajaxLoader.gif"
                })
              }else if(id==5){
                that.setData({
                  sjimage5:"../../images/ajaxLoader.gif"
                })
              }else if(id==6){
                that.setData({
                  sjimage6:"../../images/ajaxLoader.gif"
                })
              }
              
              var userId = wx.getStorageSync("userId")
      var LoginId = wx.getStorageSync("LoginId")
              wx.uploadFile({
                url: app.globalData.apiurl + "/xapiajax.ashx", //仅为示例，非真实的接口地址
                filePath: tempFilePaths[0],
                name: 'image',
                formData: {
                  action:"uploadImage",
                  userId:(!userId?"":userId),
                  LoginId:(!LoginId?"":LoginId)
                },
                fail: function(err) {
                  wx.showToast({
                    title: "上传出错了",
                    icon: "none",
                    duration: 2000
                })
                if(id==0){
                  that.setData({
                    sjimage0:yimage
                 })
                }else if(id==1){
                  that.setData({
                    sjimage1:yimage
                  })
                }else if(id==2){
                  that.setData({
                    sjimage2:yimage
                  })
                }else if(id==3){
                  that.setData({
                    sjimage3:yimage
                  })
                }else if(id==4){
                  that.setData({
                    sjimage4:yimage
                  })
                }else if(id==5){
                  that.setData({
                    sjimage5:yimage
                  })
                }else if(id==6){
                  that.setData({
                    sjimage6:yimage
                  })
                }
                },
                success (res0){
                   try{
                    var data=JSON.parse(res0.data);
                    
                   
                    if(data.status==1){
                      wx.showToast({
                        title: data.msg,
                        icon: "success",
                        duration: 1000
                      })
                      if(id==0){
                        that.setData({
                          sjimage0:data.url,
                          addimage0:data.pic
                       })
                      }else if(id==1){
                        that.setData({
                          sjimage1:data.url,
                          addimage1:data.pic
                        })
                      }else if(id==2){
                        that.setData({
                          sjimage2:data.url,
                          addimage2:data.pic
                        })
                      }else if(id==3){
                        that.setData({
                          sjimage3:data.url,
                          addimage3:data.pic
                        })
                      }else if(id==4){
                        that.setData({
                          sjimage4:data.url,
                          addimage4:data.pic
                        })
                      }else if(id==5){
                        that.setData({
                          sjimage5:data.url,
                          addimage5:data.pic
                        })
                      }else if(id==6){
                        that.setData({
                          sjimage6:data.url,
                          addimage6:data.pic
                        })
                      }
                        
                    }else{
                      wx.showToast({
                        title: data.msg,
                        icon: "none",
                        duration: 2000
                    })
                    if(id==0){
                      that.setData({
                        sjimage0:yimage
                     })
                    }else if(id==1){
                      that.setData({
                        sjimage1:yimage
                      })
                    }else if(id==2){
                      that.setData({
                        sjimage2:yimage
                      })
                    }else if(id==3){
                      that.setData({
                        sjimage3:yimage
                      })
                    }else if(id==4){
                      that.setData({
                        sjimage4:yimage
                      })
                    }else if(id==5){
                      that.setData({
                        sjimage5:yimage
                      })
                    }else if(id==6){
                      that.setData({
                        sjimage6:yimage
                      })
                    }
                      
                    }
                   }catch(err){
                    wx.showToast({
                      title: "上传出错",
                      icon: "none",
                      duration: 2000
                  })
                  if(id==0){
                    that.setData({
                      sjimage0:yimage
                   })
                  }else if(id==1){
                    that.setData({
                      sjimage1:yimage
                    })
                  }else if(id==2){
                    that.setData({
                      sjimage2:yimage
                    })
                  }else if(id==3){
                    that.setData({
                      sjimage3:yimage
                    })
                  }else if(id==4){
                    that.setData({
                      sjimage4:yimage
                    })
                  }else if(id==5){
                    that.setData({
                      sjimage5:yimage
                    })
                  }else if(id==6){
                    that.setData({
                      sjimage6:yimage
                    })
                  }
                   }
                }
                
              });
        }
      })
    }
    },BankChange:function(e) {
      var index=e.detail.value;
      var key=that.data.BankNames[index].key
      that.setData({
        index: index
      })
     
    },saveaddress:function(e) {
      var type = e.detail.target.dataset.type;
      
      if(type==1){
        
        if(that.data.byNumber==0){
          
          name = e.detail.value.txtName.replace(/\s+/g, "");
          strmoney=e.detail.value.txtylmoney.replace(/\s+/g, "");
          dgzh=e.detail.value.txtdgzh.replace(/\s+/g, "");
          frname=e.detail.value.txtfrname.replace(/\s+/g, "");
          fridcard=e.detail.value.txtfridcard.replace(/\s+/g, "");
          number=e.detail.value.txtnumber.replace(/\s+/g, "");
          tel=e.detail.value.txttel.replace(/\s+/g, "");
          
          Province=(that.data.hx_index==-1?"":that.data.Provinces[that.data.hx_index].ProvinceID);
          City=(that.data.hx_index0==-1?"":that.data.Citys[that.data.hx_index0].CityID);
          County=(that.data.hx_index1==-1?"":that.data.Countys[that.data.hx_index1].CountyID);
          
          detail=e.detail.value.detail.replace(/\s+/g, "");
          fwbody=e.detail.value.fwbody;
          wx.setStorageSync("appsjclsid",that.data.clsid);
          
          wx.setStorageSync("appsjname",name);
          wx.setStorageSync("appsjylmoney",strmoney);
          wx.setStorageSync("appsjdgzh",dgzh);
          wx.setStorageSync("appsjfrname",frname);
          wx.setStorageSync("appsjfridcard",fridcard);
          wx.setStorageSync("appsjnumber",number);
          wx.setStorageSync("appsjtel",tel);
          wx.setStorageSync("appsjProvince",Province);
          wx.setStorageSync("appsjCity",City);
          wx.setStorageSync("appsjCounty",County);
          wx.setStorageSync("appsjdetail",detail);
          wx.setStorageSync("appsjlongitude",that.data.bzlongitude);
          wx.setStorageSync("appsjlatitude",that.data.bzlatitude);
          wx.setStorageSync("appsjfwbody",fwbody);
          wx.setStorageSync("appsjimage0",that.data.sjimage0);
          wx.setStorageSync("appsjimage1",that.data.sjimage1);
          wx.setStorageSync("appsjimage2",that.data.sjimage2);
          wx.setStorageSync("appsjimage3",that.data.sjimage3);
          wx.setStorageSync("appsjimage4",that.data.sjimage4);
          wx.setStorageSync("appaddimage0",that.data.addimage0);
          wx.setStorageSync("appaddimage1",that.data.addimage1);
          wx.setStorageSync("appaddimage2",that.data.addimage2);
          wx.setStorageSync("appaddimage3",that.data.addimage3);
          wx.setStorageSync("appaddimage4",that.data.addimage4);
          
       }
      if(that.data.byNumber==1){
          AccountName=e.detail.value.AccountName.replace(/\s+/g, "");
          BankName=(that.data.index==-1?"":that.data.BankNames[that.data.index].key);
          BankCard=e.detail.value.BankCard.replace(/\s+/g, "");
          BankDepos=e.detail.value.BankDepos.replace(/\s+/g, "");
          wx.setStorageSync("appsjAccountName",AccountName);
          wx.setStorageSync("appsjBankName",BankName);
          wx.setStorageSync("appsjBankCard",BankCard);
          wx.setStorageSync("appsjBankDepos",BankDepos);
      }
      wx.setStorageSync("appsjbyNumber",that.data.byNumber);
      wx.showToast({
        title: "保存成功",
        icon: "success",
        duration: 3000
       })
      }else{
      if(that.data.savebutton=="标注好了，返回")
      {
      that.setData({
        sectionHidden0:true,
        savebutton:"下一步"
      })
    }else{
     
      
      if(that.data.byNumber==0){
          name = e.detail.value.txtName.replace(/\s+/g, "");
          strmoney=e.detail.value.txtylmoney.replace(/\s+/g, "");
          dgzh=e.detail.value.txtdgzh.replace(/\s+/g, "");
          frname=e.detail.value.txtfrname.replace(/\s+/g, "");
          fridcard=e.detail.value.txtfridcard.replace(/\s+/g, "");
          number=e.detail.value.txtnumber.replace(/\s+/g, "");
          tel=e.detail.value.txttel.replace(/\s+/g, "");
          Province=(that.data.hx_index==-1?"":that.data.Provinces[that.data.hx_index].ProvinceID)
          City=(that.data.hx_index0==-1?"":that.data.Citys[that.data.hx_index0].CityID)
          County=(that.data.hx_index1==-1?"":that.data.Countys[that.data.hx_index1].CountyID)
          detail=e.detail.value.detail.replace(/\s+/g, "");
          fwbody=e.detail.value.fwbody
       }
     
      if(that.data.byNumber==1){
          AccountName=e.detail.value.AccountName.replace(/\s+/g, "");
          BankName=(that.data.index==-1?"":that.data.BankNames[that.data.index].key);
          BankCard=e.detail.value.BankCard.replace(/\s+/g, "");
          BankDepos=e.detail.value.BankDepos.replace(/\s+/g, "");
      }

      var userId = wx.getStorageSync("userId")
      var LoginId = wx.getStorageSync("LoginId")
      var b=true
     
      if(that.data.clsid==0){
        b=false
        wx.showToast({
          title: "商家分类未选择！",
          icon: "none",
          duration: 3000
         })
    }
    if(b){
      if(name==""){
          b=false
          wx.showToast({
            title: "商家名称不能为空！",
            icon: "none",
            duration: 3000
           })
      }
     }
     var money=0;
     if(b){
      
      if(strmoney!=""){
           money=parseFloat(strmoney);
           if(money<parseFloat(that.data.ylmoney) || money>parseFloat(that.data.ylmoney0)){
            b=false
            wx.showToast({
              title: "商家让利范围："+that.data.ylmoney+"至" + that.data.ylmoney0 + "%！",
              icon: "none",
              duration: 3000
             })
           }
      }else{
        b=false
        wx.showToast({
          title: "商家让利不能为空！",
          icon: "none",
          duration: 3000
         })
      }
     }
     if(b){
      if(number==""){
        b=false
        wx.showToast({
          title: "信用代码不能为空！",
          icon: "none",
          duration: 3000
         })
      }
    }
    
    if(b){
      if(frname==""){
        b=false
        wx.showToast({
          title: "法人姓名不能为空！",
          icon: "none",
          duration: 3000
         })
      }
    }
    if(b){
      if(fridcard==""){
        b=false
        wx.showToast({
          title: "法人身份证号码不能为空！",
          icon: "none",
          duration: 3000
         })
      }
    }
    
    if(b){
      if(tel==""){
        b=false
        wx.showToast({
          title: "联系电话不能为空！",
          icon: "none",
          duration: 3000
         })
      }
    }
 
    if(b){
      if(that.data.addimage0==""){
        b=false
        wx.showToast({
          title: "门头图片未上传！",
          icon: "none",
          duration: 3000
         })
      }
    }
    if(b){
      if(that.data.addimage1==""){
        b=false
        wx.showToast({
          title: "营业执照未上传！",
          icon: "none",
          duration: 3000
         })
      }
    }
    if(b){
      if(that.data.addimage2==""){
        b=false
        wx.showToast({
          title: "银行卡照片未上传！",
          icon: "none",
          duration: 3000
         })
      }
    }
    if(b){
      if(that.data.addimage3==""){
        b=false
        wx.showToast({
          title: "身份证正面未上传！",
          icon: "none",
          duration: 3000
         })
      }
    }
    if(b){
      if(that.data.addimage4==""){
        b=false
        wx.showToast({
          title: "身份证反面未上传！",
          icon: "none",
          duration: 3000
         })
      }
    }
    if(b){
      if(that.data.hx_index==-1){
        b=false
        wx.showToast({
          title: "省份必须选择！",
          icon: "none",
          duration: 3000
         })
      }
    }
    if(b){
      if(that.data.hx_index0==-1){
        b=false
        wx.showToast({
          title: "城市必须选择！",
          icon: "none",
          duration: 3000
         })
      }
    }
    if(b){
      if(detail==null || detail==""){
        b=false
        wx.showToast({
          title: "详细地址不能为空！",
          icon: "none",
          duration: 3000
         })
      }
    }
    if(b){
      if(that.data.bzlatitude==0||that.data.bzlongitude==0){
        b=false
        wx.showToast({
          title: "未标注地图！",
          icon: "none",
          duration: 3000
         })
      }
    }
  
    if(that.data.byNumber==1||that.data.byNumber==2){
      if(b){
        if(AccountName==null || AccountName==""){
          b=false
          wx.showToast({
            title: "开户姓名不能为空！",
            icon: "none",
            duration: 3000
           })
        }
      }
      if(b){
        if(BankName==null || BankName==""){
          b=false
          wx.showToast({
            title: "银行名称未选择！",
            icon: "none",
            duration: 3000
           })
        }
      }
      if(b){
        if(BankCard==null || BankCard==""){
          b=false
          wx.showToast({
            title: "银行卡号不能为空！",
            icon: "none",
            duration: 3000
           })
        }
      }
      if(b){
        if(BankDepos==null || BankDepos==""){
          b=false
          wx.showToast({
            title: "开户行不能为空！",
            icon: "none",
            duration: 3000
           })
        }
      }
    }
    if(that.data.byNumber==3){
         if(b){
             if(!that.data.hasDraw){
              b=false
              wx.showToast({
                title: "您还没有签字！",
                icon: "none",
                duration: 3000
               }) 
             }
         }
    }
    if(b){
    if(that.data.byNumber==0){
      that.setData({
        byNumber:1,
        savebutton:"下一步"
      })
    }else if(that.data.byNumber==1){
      that.setData({
        byNumber:2,
        savebutton:"下一步"
      })
    }else if(that.data.byNumber==2){
      that.setData({
        byNumber:3,
        savebutton:"提交"
      })
      wx.createSelectorQuery()
      .select('#canvas') // 在 WXML 中填入的 id
      .fields({
        node: true,
        size: true
      })
      .exec((res) => {
        // Canvas 对象
        const canvas = res[0].node
        mCanvas = res[0].node
        // 渲染上下文
        context = canvas.getContext('2d')
        // Canvas 画布的实际绘制宽高
        const width = res[0].width
        const height = res[0].height
        // 初始化画布大小
        const dpr = wx.getWindowInfo().pixelRatio
        canvas.width = width * dpr
        canvas.height = height * dpr
        context.scale(dpr, dpr)
        //绘制背景
        context.fillStyle = '#eee'
        context.clearRect(0, 0, canvas.width, canvas.height)
        context.fillRect(0, 0, canvas.width, canvas.height)
      })
    }
    else if(that.data.byNumber==3){
        if(that.data.savebutton=='提交'){
        that.setData({
            savebutton:"请稍候..."
        })
        wx.canvasToTempFilePath({
          canvas: mCanvas,
          success: function (ress) {

            wx.uploadFile({
              url: app.globalData.apiurl + "/xapiajax.ashx", //仅为示例，非真实的接口地址
              filePath:  ress.tempFilePath,
              name: 'image',
              formData: {
                action:"uploadImage",
                userId:(!userId?"":userId),
                LoginId:(!LoginId?"":LoginId)
              },
              success (res0){
  
               var returndata=JSON.parse(res0.data);
      wx.request({
        url: app.globalData.apiurl + "/xapiajax.ashx", 
        data: { 
          action:"updatebusinessinfo",
           userId:(!userId?"":userId),
           LoginId:(!LoginId?"":LoginId),
           clsid:that.data.clsid,
           name:name,
           money:money,
           dgzh:dgzh,
           frname:frname,
           fridcard:fridcard,
           number:number,
           tel:tel,
           image0:that.data.addimage0,
           image1:that.data.addimage1,
           image2:that.data.addimage2,
           image3:that.data.addimage3,
           image4:that.data.addimage4,
           image5:that.data.addimage5,
           image6:that.data.addimage6,
           image7:returndata.pic,
           province:Province,
           city:City,
           county:County,
           address:detail,
           longitude:that.data.bzlongitude,
           latitude:that.data.bzlatitude,
           fwbody:fwbody,
           accountname:AccountName,
           bankname:BankName,
           bankcard:BankCard,
           bankaddress:BankDepos,
        },
        method:"POST",
        dataType:"json", 
        header: { 
          "content-type": "application/x-www-form-urlencoded" // 默认值
        },
        success (res) { 
          if(res.data.status==1){
            wx.setStorageSync('userInfo', JSON.stringify(res.data.userInfo)) 
            app.globalData.IFRefreshmy=1
           var sopenFrame0=setInterval(function (){
            clearInterval(sopenFrame0);      
           wx.showModal({
            title: "申请提示",
            content:"您的申请已经提交成功了，请等待审核！",
                            showCancel:false,
                            success (res1) {
                              if (res1.confirm) {
            
             

             wx.navigateBack({})

            }
          }
        })
      }, 2000);
          }else{
            that.setData({
              savebutton:"提交"
             }) 
             wx.showToast({
              title: res.data.msg,
              icon: "none",
              duration: 3000
             })
          }
          }
      })
    
    }
  })
    }
  
  })
        }
      }
    }


    }
  }
    },
    canvasIdErrorCallback: function (e) {},
    //开始
    canvasStart: function (event) {
      context.moveTo(event.touches[0].x, event.touches[0].y);
    },
    //过程
    canvasMove: function (event) {
      var x = event.touches[0].x;
      var y = event.touches[0].y;
      context.lineWidth = 4
      context.lineCap = 'round'
      context.lineJoin = 'round'
      context.lineTo(x, y);
      context.stroke();
      this.setData({
        hasDraw: true,
      });
    },
    canvasEnd: function (event) {
   
    },
    clickClear: function () {
      context.clearRect(0, 0, mCanvas.width, mCanvas.height); //清除画布
      context.beginPath() //清空画笔
      this.setData({
        hasDraw: false,
      });
    }
})
