东风启辰小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

userMsg.js 13KB

5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. // pages/userMsg/userMsg.js
  2. const app = getApp()
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. properties: {
  8. },
  9. /**
  10. * 组件的初始数据
  11. */
  12. data: {
  13. imgUrl: app.globalData.urlStatic,//图片路径
  14. submitData: {
  15. realName: "",//姓名
  16. mobile: "",//电话
  17. province: "",//经销商省份
  18. city: "",//经销商城市
  19. agent_code:"",//经销商编码
  20. agentDetail:"",//经销商详情
  21. addressDetail: "",//地址详情
  22. captcha:"",
  23. scene:"",//场景值名称
  24. },
  25. mobile2:"",
  26. selectType:2,
  27. avatarUrlShow:"",
  28. userData:{
  29. avatarUrl:"",
  30. nickName:""
  31. },
  32. isAddress: false,//是否有地址
  33. marginT: 0,
  34. submitDataState:false,
  35. verificationCode:"获取验证码",
  36. sendCode:true,
  37. phoneInputShow: false,//是否显示电话输入框
  38. provinceDataAll: null,//地区所有数据
  39. provinceDataArr: [[""], [""]],//省市数据
  40. provinceDataValue: [0, 0],//选中的省市下标
  41. nowProvince: "",//选中的省市文字
  42. storeArr: [],//专营店数据
  43. storeValue: 0,//选中的专营店下标
  44. },
  45. attached:function(){
  46. if (app.globalData.userPhoneType == "ios") {
  47. this.setData({
  48. marginT: -20
  49. })
  50. }
  51. if (app.globalData.openid) {
  52. this.loadFun();
  53. } else {
  54. app.globalData.openidSuccessFuc = this.loadFun;
  55. }
  56. },
  57. /**
  58. * 组件的方法列表
  59. */
  60. methods: {
  61. loadFun: function () {
  62. if (app.globalData.userMobile) {
  63. this.data.submitData.mobile = app.globalData.userMobile;
  64. this.setData({
  65. phoneInputShow: true,
  66. submitData: this.data.submitData
  67. })
  68. }
  69. if (app.globalData.userInfoData) {
  70. this.data.userData.avatarUrl = app.globalData.userInfoData.avatarUrl;
  71. this.data.userData.nickName = app.globalData.userInfoData.nickName;
  72. this.setData({
  73. userData: this.data.userData,
  74. avatarUrlShow: app.globalData.userInfoData.avatarUrl
  75. })
  76. }
  77. this.getAddress();
  78. },
  79. getAddress: function () {//获取地址
  80. app.wxRequest(app.globalData.urlRoot + "address/getAddressV2", {}, res => {
  81. console.log(res);
  82. if (res.code == 200) {
  83. if (res.data) {
  84. this.data.isAddress = true;
  85. this.data.submitData.realName = res.data.realName;
  86. this.data.submitData.mobile = res.data.mobile;
  87. this.data.submitData.province = res.data.province;
  88. this.data.submitData.city = res.data.city;
  89. this.data.submitData.addressDetail = res.data.addressDetail;
  90. this.setData({
  91. submitData: this.data.submitData
  92. })
  93. if(!res.data.agentDetail){
  94. this.getUserLocation();//获取用户当前位置
  95. }
  96. }
  97. } else {
  98. wx.showToast({
  99. title: res.msg,
  100. icon: "none"
  101. })
  102. }
  103. }, this);
  104. },
  105. addAddress: function () {//添加地址
  106. app.wxRequest(app.globalData.urlRoot + "address/addAddress", this.data.submitData, res => {
  107. wx.showToast({
  108. title: res.msg,
  109. })
  110. if (res.code == 200) {
  111. if (app.globalData.skipType == 'mycenter') {
  112. app.globalData.skipType = null;
  113. wx.reLaunch({
  114. url: '/pages/myCenter/myCenter',
  115. })
  116. } else {
  117. this.closeXieyi();
  118. }
  119. }
  120. }, this, "POST")
  121. },
  122. updateAddress: function () {//更新地址
  123. app.wxRequest(app.globalData.urlRoot + "address/updateAddress", this.data.submitData, res => {
  124. wx.showToast({
  125. title: res.msg,
  126. })
  127. if (res.code == 200) {
  128. if (app.globalData.skipType == 'mycenter') {
  129. app.globalData.skipType = null;
  130. wx.reLaunch({
  131. url: '/pages/myCenter/myCenter',
  132. })
  133. } else {
  134. this.closeXieyi();
  135. }
  136. }
  137. }, this, "POST");
  138. },
  139. getNickName: function(e) {//获取昵称
  140. this.data.userData.nickName = e.detail.value;
  141. this.setData({
  142. userData: this.data.userData
  143. })
  144. },
  145. getRealName: function (e) {//获取收货人
  146. this.data.submitData.realName = e.detail.value;
  147. this.setData({
  148. submitData: this.data.submitData
  149. })
  150. },
  151. getMobile: function (e) {//获取手机号码
  152. this.data.submitData.mobile = e.detail.value;
  153. this.setData({
  154. submitData: this.data.submitData
  155. })
  156. },
  157. getMobile2: function (e) {//获取用户输入的电话---无验证码
  158. this.data.mobile2 = e.detail.value;
  159. },
  160. getAddressDetail: function (e) {//获取详细地址
  161. this.data.submitData.addressDetail = e.detail.value;
  162. this.setData({
  163. submitData: this.data.submitData
  164. })
  165. },
  166. saveUserMsg:function(){
  167. if (!this.data.submitData.realName) {
  168. wx.showToast({
  169. title: '请输入收货人',
  170. icon: "none"
  171. })
  172. return;
  173. }
  174. if (!app.mobileVerify(this.data.submitData.mobile)) {
  175. if (this.data.submitData.mobile) {
  176. wx.showToast({
  177. title: '请输入正确的电话',
  178. icon: 'none'
  179. })
  180. } else {
  181. wx.showToast({
  182. title: '请输入电话',
  183. icon: 'none'
  184. })
  185. }
  186. return;
  187. }
  188. if (!this.data.submitData.province) {
  189. wx.showToast({
  190. title: '请选择所在地区',
  191. icon: 'none'
  192. })
  193. return;
  194. }
  195. if (!this.data.submitData.addressDetail) {
  196. wx.showToast({
  197. title: '请输入详细地址',
  198. icon: "none"
  199. })
  200. return;
  201. }
  202. wx.showLoading({
  203. title: '保存中',
  204. mask: true
  205. })
  206. if(this.data.submitDataState){
  207. return;
  208. }
  209. this.data.submitDataState = true;
  210. app.wxRequest(app.globalData.urlRoot + "userInfo/updateUserInfo", this.data.userData, res => {
  211. this.data.submitDataState = false;
  212. wx.hideLoading();
  213. if (res.code == 200) {
  214. if(this.data.userData){
  215. var userInfoData = wx.getStorageSync("userInfoData");
  216. if(this.data.userData.avatarUrl){
  217. app.globalData.userInfoData.avatarUrl = this.data.userData.avatarUrl;
  218. userInfoData.avatarUrl = this.data.userData.avatarUrl;
  219. }
  220. if(this.data.userData.nickName){
  221. app.globalData.userInfoData.nickName = this.data.userData.nickName;
  222. userInfoData.nickName = this.data.userData.nickName;
  223. }
  224. wx.setStorageSync('userInfoData', userInfoData)
  225. }
  226. this.submitAddress();
  227. }
  228. }, this, "POST")
  229. },
  230. submitAddress: function () {//保存地址
  231. if (this.data.isAddress) {
  232. this.updateAddress();
  233. } else {
  234. this.addAddress();
  235. }
  236. },
  237. closeXieyi: function () {
  238. this.triggerEvent('address')
  239. },
  240. changeHeadImg:function(){
  241. wx.chooseImage({
  242. count:1,
  243. success:(res)=>{
  244. this.setData({
  245. avatarUrlShow: res.tempFilePaths[0]
  246. })
  247. wx.uploadFile({
  248. url: app.globalData.urlRoot + "upload/uploadImage",
  249. header: {
  250. "OPENID": app.globalData.openid,
  251. "VERSION": 100
  252. },
  253. filePath: res.tempFilePaths[0],
  254. name: "file",
  255. formData:{
  256. filePath:"avatar"
  257. },
  258. success: option => {
  259. var json = JSON.parse(option.data);
  260. if (json.code==200){
  261. this.data.userData.avatarUrl = json.data[0].url;
  262. this.setData({
  263. userData: this.data.userData
  264. })
  265. }else{
  266. wx.showToast({
  267. title: option.msg,
  268. icon: 'none'
  269. })
  270. }
  271. }
  272. })
  273. }
  274. })
  275. },
  276. changeSelectType:function(e){
  277. if(e){
  278. this.setData({
  279. selectType:e.currentTarget.dataset.type
  280. })
  281. }else{
  282. this.setData({
  283. selectType:1
  284. })
  285. }
  286. },
  287. getCaptcha: function (e) {//获取用户输入的验证码
  288. this.data.submitData.captcha = e.detail.value;
  289. },
  290. getCode: function (e) {//获取验证码
  291. if (!app.mobileVerify(this.data.mobile2)) {
  292. if (this.data.mobile2) {
  293. wx.showToast({
  294. title: '请输入正确的电话',
  295. icon: 'none'
  296. })
  297. } else {
  298. wx.showToast({
  299. title: '请输入电话',
  300. icon: 'none'
  301. })
  302. }
  303. return;
  304. }
  305. if (!this.data.sendCode) {
  306. return;
  307. }
  308. this.data.sendCode = false;
  309. // app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.mobile2 }, res => {
  310. // if (res.code == 200) {
  311. this.countDown();
  312. wx.showToast({
  313. title: '验证码获取成功',
  314. icon: "none"
  315. })
  316. this.setData({
  317. verificationCode: 60
  318. })
  319. // } else {
  320. // this.data.sendCode = true;
  321. // wx.showToast({
  322. // title: res.msg,
  323. // icon: "none"
  324. // })
  325. // }
  326. // }, this)
  327. },
  328. countDown: function () {//倒计时
  329. setTimeout(() => {
  330. this.setData({
  331. verificationCode: this.data.verificationCode - 1
  332. })
  333. if (this.data.verificationCode > 0) {
  334. this.countDown();
  335. } else {
  336. this.setData({
  337. verificationCode: "获取验证码"
  338. })
  339. this.data.sendCode = true;
  340. }
  341. }, 1000);
  342. },
  343. getUserPhone: function (e) {//获取用户手机号
  344. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  345. app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
  346. if (res.code == 200) {
  347. this.setData({
  348. phoneInputShow: true
  349. })
  350. this.changeSelectType();
  351. if (res.data && res.data.decodeData) {
  352. this.data.submitData.mobile = res.data.decodeData.phoneNumber;
  353. this.setData({
  354. submitData: this.data.submitData
  355. })
  356. }
  357. } else {
  358. wx.showToast({
  359. title: res.msg,
  360. icon: "none"
  361. })
  362. }
  363. }, this);
  364. }
  365. },
  366. getUserLocation: function (e) {
  367. wx.getLocation({
  368. type: 'wgs84', //wgs84 gcj02
  369. success: (res) => {
  370. this.getDistributorList(res.longitude, res.latitude);
  371. },
  372. fail: (res) => {
  373. this.getDistributorList("", "");
  374. }
  375. })
  376. },
  377. getDistributorList: function (longitude, latitude) {//获取经销商列表
  378. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
  379. if (res.code == 200) {
  380. //整理数据
  381. var datas = res.data;
  382. var province = [];
  383. var city = [];
  384. for (let i = 0; i < res.data.list.length; i++) {
  385. province.push(res.data.list[i].province);
  386. }
  387. for (let j = 0; j < res.data.list[res.data.nearData.provinceIndex].children.length; j++) {
  388. city.push(res.data.list[res.data.nearData.provinceIndex].children[j].city)
  389. }
  390. //将数据赋值给变量
  391. this.setData({
  392. provinceDataAll: res.data.list,
  393. provinceDataArr: [province, city],
  394. provinceDataValue: [res.data.nearData.provinceIndex, res.data.nearData.cityIndex],
  395. nowProvince: province[res.data.nearData.provinceIndex] + " " + city[res.data.nearData.cityIndex],
  396. storeArr: res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children,
  397. storeValue: res.data.nearData.agentIndex
  398. })
  399. } else {
  400. wx.showToast({
  401. title: res.msg,
  402. icon: "none"
  403. })
  404. }
  405. }, this);
  406. },
  407. provinceDataChange: function (e) {
  408. if (e.detail.column == 0) {
  409. var city = [];
  410. for (let i = 0; i < this.data.provinceDataAll[e.detail.value].children.length; i++) {
  411. city.push(this.data.provinceDataAll[e.detail.value].children[i].city);
  412. }
  413. this.data.provinceDataArr[1] = city;
  414. this.setData({
  415. provinceDataArr: this.data.provinceDataArr
  416. })
  417. }
  418. },
  419. provinceDataChane: function (e) {
  420. this.setData({
  421. provinceDataValue: e.detail.value,
  422. nowProvince: this.data.provinceDataArr[0][e.detail.value[0]] + " " + this.data.provinceDataArr[1][e.detail.value[1]],
  423. storeArr: this.data.provinceDataAll[e.detail.value[0]].children[e.detail.value[1]].children,
  424. storeValue: 0
  425. })
  426. },
  427. storeChane: function (e) {
  428. this.setData({
  429. storeValue: e.detail.value
  430. })
  431. }
  432. }
  433. })