|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516 |
- // pages/userMsg/userMsg.js
- const app = getApp()
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
-
- },
-
- /**
- * 组件的初始数据
- */
- data: {
- imgUrl: app.globalData.urlStatic,//图片路径
- submitData: {
- realName: "",//姓名
- mobile: "",//电话
- province: "",//经销商省份
- city: "",//经销商城市
- agent_code:"",//经销商编码
- agentDetail:"",//经销商详情
- addressDetail: "",//地址详情
- captcha:"",
- scene:"",//场景值名称
- },
- mobile2:"",
- selectType:2,
- avatarUrlShow:"",
- userData:{
- avatarUrl:"",
- nickName:""
- },
- isAddress: false,//是否有地址
- marginT: 0,
- submitDataState:false,
- verificationCode:"获取验证码",
- sendCode:true,
- phoneInputShow: false,//是否显示电话输入框
- provinceDataAll: null,//地区所有数据
- provinceDataArr: [[""], [""]],//省市数据
- provinceDataValue: [0, 0],//选中的省市下标
- nowProvince: "",//选中的省市文字
- storeArr: [],//专营店数据
- storeValue: 0,//选中的专营店下标
- replaceTextarea:true,
- },
- attached:function(){
- if (app.globalData.userPhoneType == "ios") {
- this.setData({
- marginT: -20
- })
- }
- if (app.globalData.openid) {
- this.loadFun();
- } else {
- app.globalData.openidSuccessFuc = this.loadFun;
- }
- },
- /**
- * 组件的方法列表
- */
- methods: {
- loadFun: function () {
- if (app.globalData.userMobile) {
- this.data.submitData.mobile = app.globalData.userMobile;
- this.setData({
- phoneInputShow: true,
- submitData: this.data.submitData
- })
- }
- if (app.globalData.userInfoData.nickName) {
- this.data.userData.avatarUrl = app.globalData.userInfoData.avatarUrl;
- this.data.userData.nickName = app.globalData.userInfoData.nickName;
- this.setData({
- userData: this.data.userData,
- avatarUrlShow: app.globalData.userInfoData.avatarUrl
- })
- }
- this.getAddress();
- },
- getAddress: function () {//获取地址
- app.wxRequest(app.globalData.urlRoot + "address/getAddressV2", {}, res => {
- console.log(res);
- if (res.code == 200) {
- if (res.data && res.data.agentDetail) {
- this.data.isAddress = true;
- this.data.submitData.realName = res.data.realName;
- this.data.submitData.mobile = res.data.mobile;
- this.data.submitData.province = res.data.province;
- this.data.submitData.city = res.data.city;
- this.data.submitData.agentDetail = res.data.agentDetail;
- this.data.submitData.agent_code = res.data.agent_code;
- this.data.submitData.addressDetail = res.data.addressDetail;
- this.setData({
- submitData: this.data.submitData,
- mobile2:res.data.mobile
- })
- // if(!res.data.agentDetail){
- this.getDistributorList("","");
- // this.getUserLocation();//获取用户当前位置
- // }
- }else{
- this.getUserLocation();//获取用户当前位置
- }
- } else {
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- }, this);
- },
- addAddress: function () {//添加地址
- var mobile = this.data.submitData.mobile;
- if(this.data.selectType==2){
- this.data.submitData.mobile = this.data.mobile2;
- }
- app.wxRequest(app.globalData.urlRoot + "address/addAddressV2", this.data.submitData, res => {
- wx.showToast({
- title: res.msg,
- })
- if (res.code == 200) {
- if (app.globalData.skipType == 'mycenter') {
- app.globalData.skipType = null;
- wx.reLaunch({
- url: '/pages/myCenter/myCenter',
- })
- } else {
- this.closeXieyi();
- }
- }
- }, this, "POST")
- },
- updateAddress: function () {//更新地址
- var mobile = this.data.submitData.mobile;
- if(this.data.selectType==2){
- this.data.submitData.mobile = this.data.mobile2;
- }
- app.wxRequest(app.globalData.urlRoot + "address/updateAddressV2", this.data.submitData, res => {
- wx.showToast({
- title: res.msg,
- })
- if (res.code == 200) {
- if (app.globalData.skipType == 'mycenter') {
- app.globalData.skipType = null;
- wx.reLaunch({
- url: '/pages/myCenter/myCenter',
- })
- } else {
- this.closeXieyi();
- }
- }
- }, this, "POST");
- },
- getNickName: function(e) {//获取昵称
- this.data.userData.nickName = e.detail.value;
- this.setData({
- userData: this.data.userData
- })
- },
- getRealName: function (e) {//获取收货人
- this.data.submitData.realName = e.detail.value;
- this.setData({
- submitData: this.data.submitData
- })
- },
- getMobile: function (e) {//获取手机号码
- this.data.submitData.mobile = e.detail.value;
- this.setData({
- submitData: this.data.submitData
- })
- },
- getMobile2: function (e) {//获取用户输入的电话---无验证码
- this.setData({
- mobile2:e.detail.value
- })
- },
- getAddressDetail: function (e) {//获取详细地址
- this.data.submitData.addressDetail = e.detail.value;
- this.setData({
- submitData: this.data.submitData
- })
- },
- saveUserMsg:function(){
- if (!this.data.submitData.realName) {
- wx.showToast({
- title: '请输入姓名',
- icon: "none"
- })
- return;
- }
- if (!this.data.mobile2 && this.data.selectType==2) {
- wx.showToast({
- title: '请输入电话',
- icon: "none"
- })
- return;
- }
- if (this.data.selectType == 2) {
- if (!this.data.submitData.captcha) {
- wx.showToast({
- title: '请输入验证码',
- icon: "none"
- })
- return;
- }
- }
- if (!this.data.submitData.addressDetail) {
- wx.showToast({
- title: '请输入详细地址',
- icon: "none"
- })
- return;
- }
- if(
- !this.data.provinceDataArr ||
- !this.data.provinceDataArr[0] ||
- !this.data.provinceDataArr[0][this.data.provinceDataValue[0]] ||
- !this.data.provinceDataArr[1] ||
- !this.data.provinceDataArr[1][this.data.provinceDataValue[1]] ||
- !this.data.storeArr ||
- !this.data.storeArr[this.data.storeValue] ||
- !this.data.storeArr[this.data.storeValue].agent_code ||
- !this.data.storeArr[this.data.storeValue].agent_detail
- ){
- return;
- }
- this.data.submitData.province = this.data.provinceDataArr[0][this.data.provinceDataValue[0]];
- this.data.submitData.city = this.data.provinceDataArr[1][this.data.provinceDataValue[1]];
- this.data.submitData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
- this.data.submitData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
- this.data.submitData.scene = app.globalData.sceneSource;
- // console.log(this.data.submitData);
-
- // return;
- wx.showLoading({
- title: '保存中',
- mask: true
- })
- if(this.data.submitDataState){
- return;
- }
- this.data.submitDataState = true;
- app.wxRequest(app.globalData.urlRoot + "userInfo/updateUserInfo", this.data.userData, res => {
- this.data.submitDataState = false;
- wx.hideLoading();
- if (res.code == 200) {
- if(this.data.userData){
- var userInfoData = wx.getStorageSync("userInfoData");
- if(this.data.userData.avatarUrl){
- app.globalData.userInfoData.avatarUrl = this.data.userData.avatarUrl;
- if(userInfoData){
- userInfoData.avatarUrl = this.data.userData.avatarUrl;
- }
- }
- if(this.data.userData.nickName){
- app.globalData.userInfoData.nickName = this.data.userData.nickName;
- if(userInfoData){
- userInfoData.nickName = this.data.userData.nickName;
- }
- }
- wx.setStorageSync('userInfoData', userInfoData)
- }
- this.submitAddress();
- }
- }, this, "POST")
- },
- submitAddress: function () {//保存地址
- if (this.data.isAddress) {
- this.updateAddress();
- } else {
- this.addAddress();
- }
- },
- closeXieyi: function () {
- this.triggerEvent('address')
- },
- changeHeadImg:function(){
- wx.chooseImage({
- count:1,
- success:(res)=>{
- this.setData({
- avatarUrlShow: res.tempFilePaths[0]
- })
- wx.uploadFile({
- url: app.globalData.urlRoot + "upload/uploadImage",
- header: {
- "OPENID": app.globalData.openid,
- "VERSION": 100
- },
- filePath: res.tempFilePaths[0],
- name: "file",
- formData:{
- filePath:"avatar"
- },
- success: option => {
- var json = JSON.parse(option.data);
- if (json.code==200){
- this.data.userData.avatarUrl = json.data[0].url;
- this.setData({
- userData: this.data.userData
- })
- }else{
- wx.showToast({
- title: option.msg,
- icon: 'none'
- })
- }
- }
- })
- }
- })
- },
- changeSelectType:function(e){
- if(e){
- this.setData({
- selectType:e.currentTarget.dataset.type
- })
- }else{
- this.setData({
- selectType:1
- })
- }
- },
- getCaptcha: function (e) {//获取用户输入的验证码
- this.data.submitData.captcha = e.detail.value;
- this.setData({
- submitData:this.data.submitData
- })
- },
- getCode: function (e) {//获取验证码
- if (!app.mobileVerify(this.data.mobile2)) {
- if (this.data.mobile2) {
- wx.showToast({
- title: '请输入正确的电话',
- icon: 'none'
- })
- } else {
- wx.showToast({
- title: '请输入电话',
- icon: 'none'
- })
- }
- return;
- }
- if (!this.data.sendCode) {
- return;
- }
- this.data.sendCode = false;
- app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.mobile2 }, res => {
- if (res.code == 200) {
- this.countDown();
- wx.showToast({
- title: '验证码获取成功',
- icon: "none"
- })
- this.setData({
- verificationCode: 60
- })
- } else {
- this.data.sendCode = true;
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- }, this)
- },
- countDown: function () {//倒计时
- setTimeout(() => {
- this.setData({
- verificationCode: this.data.verificationCode - 1
- })
- if (this.data.verificationCode > 0) {
- this.countDown();
- } else {
- this.setData({
- verificationCode: "获取验证码"
- })
- this.data.sendCode = true;
- }
- }, 1000);
- },
- getUserPhone: function (e) {//获取用户手机号
- if (e.detail.errMsg == 'getPhoneNumber:ok') {
- app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
- if (res.code == 200) {
- this.setData({
- phoneInputShow: true
- })
- this.changeSelectType();
- if (res.data && res.data.decodeData) {
- this.data.submitData.mobile = res.data.decodeData.phoneNumber;
- this.setData({
- submitData: this.data.submitData
- })
- }
- } else {
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- }, this);
- }
- },
- getUserLocation: function (e) {
- wx.getLocation({
- type: 'wgs84', //wgs84 gcj02
- success: (res) => {
- this.getDistributorList(res.longitude, res.latitude);
- },
- fail: (res) => {
- this.getDistributorList("", "");
- }
- })
- },
- getDistributorList: function (longitude, latitude) {//获取经销商列表
- app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
- if (res.code == 200) {
- //整理数据
- var datas = res.data;
- var province = [];
- var city = [];
- for (let i = 0; i < res.data.list.length; i++) {
- province.push(res.data.list[i].province);
- }
- if(this.data.submitData.province){
- for(let i=0;i<province.length;i++){
- if(province[i]==this.data.submitData.province){
- res.data.nearData.provinceIndex = i;
- }
- }
- }
- for (let j = 0; j < res.data.list[res.data.nearData.provinceIndex].children.length; j++) {
- city.push(res.data.list[res.data.nearData.provinceIndex].children[j].city)
- }
- if(this.data.submitData.city){
- for(let i=0;i<city.length;i++){
- if(city[i]==this.data.submitData.city){
- res.data.nearData.cityIndex = i;
- }
- }
- }
- if(this.data.submitData.agentDetail){
- for(let i=0;i<res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children.length;i++){
- if(res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children[i].agent_detail==this.data.submitData.agentDetail){
- res.data.nearData.agentIndex = i;
- }
- }
- }else{
- res.data.nearData.agentIndex = 0;
- }
- //将数据赋值给变量
- this.setData({
- provinceDataAll: res.data.list,
- provinceDataArr: [province, city],
- provinceDataValue: [res.data.nearData.provinceIndex, res.data.nearData.cityIndex],
- nowProvince: province[res.data.nearData.provinceIndex] + " " + city[res.data.nearData.cityIndex],
- storeArr: res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children,
- storeValue: res.data.nearData.agentIndex
- })
- } else {
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- }, this);
- },
- provinceDataChange: function (e) {
- if (e.detail.column == 0) {
- var city = [];
- for (let i = 0; i < this.data.provinceDataAll[e.detail.value].children.length; i++) {
- city.push(this.data.provinceDataAll[e.detail.value].children[i].city);
- }
- this.data.provinceDataArr[1] = city;
- this.setData({
- provinceDataArr: this.data.provinceDataArr
- })
- }
- },
- provinceDataChane: function (e) {
- if(
- !this.data.provinceDataArr ||
- !this.data.provinceDataArr[0] ||
- !this.data.provinceDataArr[1] ||
- !this.data.provinceDataArr[1][e.detail.value[1]] ||
- !this.data.provinceDataAll ||
- !this.data.provinceDataAll[e.detail.value[0]] ||
- !this.data.provinceDataAll[e.detail.value[0]].children ||
- !this.data.provinceDataAll[e.detail.value[0]].children[e.detail.value[1]] ||
- !this.data.provinceDataAll[e.detail.value[0]].children[e.detail.value[1]].children
- ){
- return;
- }
- this.setData({
- provinceDataValue: e.detail.value,
- nowProvince: this.data.provinceDataArr[0][e.detail.value[0]] + " " + this.data.provinceDataArr[1][e.detail.value[1]],
- storeArr: this.data.provinceDataAll[e.detail.value[0]].children[e.detail.value[1]].children,
- storeValue: 0
- })
- },
- storeChane: function (e) {
- this.setData({
- storeValue: e.detail.value
- })
- },
- textareaBlur:function(){
- this.setData({
- replaceTextarea:!this.data.replaceTextarea
- })
- }
- }
- })
|