东风启辰小程序端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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. replaceTextarea:true,
  45. },
  46. attached:function(){
  47. if (app.globalData.userPhoneType == "ios") {
  48. this.setData({
  49. marginT: -20
  50. })
  51. }
  52. if (app.globalData.openid) {
  53. this.loadFun();
  54. } else {
  55. app.globalData.openidSuccessFuc = this.loadFun;
  56. }
  57. },
  58. /**
  59. * 组件的方法列表
  60. */
  61. methods: {
  62. loadFun: function () {
  63. if (app.globalData.userMobile) {
  64. this.data.submitData.mobile = app.globalData.userMobile;
  65. this.setData({
  66. phoneInputShow: true,
  67. submitData: this.data.submitData
  68. })
  69. }
  70. if (app.globalData.userInfoData.nickName) {
  71. this.data.userData.avatarUrl = app.globalData.userInfoData.avatarUrl;
  72. this.data.userData.nickName = app.globalData.userInfoData.nickName;
  73. this.setData({
  74. userData: this.data.userData,
  75. avatarUrlShow: app.globalData.userInfoData.avatarUrl
  76. })
  77. }
  78. this.getAddress();
  79. },
  80. getAddress: function () {//获取地址
  81. app.wxRequest(app.globalData.urlRoot + "address/getAddressV2", {}, res => {
  82. console.log(res);
  83. if (res.code == 200) {
  84. if (res.data) {
  85. this.data.isAddress = true;
  86. this.data.submitData.realName = res.data.realName;
  87. this.data.submitData.mobile = res.data.mobile;
  88. this.data.submitData.province = res.data.province;
  89. this.data.submitData.city = res.data.city;
  90. this.data.submitData.agentDetail = res.data.agentDetail;
  91. this.data.submitData.agent_code = res.data.agent_code;
  92. this.data.submitData.addressDetail = res.data.addressDetail;
  93. this.setData({
  94. submitData: this.data.submitData,
  95. mobile2:res.data.mobile
  96. })
  97. // if(!res.data.agentDetail){
  98. this.getDistributorList("","");
  99. // this.getUserLocation();//获取用户当前位置
  100. // }
  101. }else{
  102. this.getUserLocation();//获取用户当前位置
  103. }
  104. } else {
  105. wx.showToast({
  106. title: res.msg,
  107. icon: "none"
  108. })
  109. }
  110. }, this);
  111. },
  112. addAddress: function () {//添加地址
  113. var mobile = this.data.submitData.mobile;
  114. if(this.data.selectType==2){
  115. this.data.submitData.mobile = this.data.mobile2;
  116. }
  117. app.wxRequest(app.globalData.urlRoot + "address/addAddressV2", this.data.submitData, res => {
  118. wx.showToast({
  119. title: res.msg,
  120. })
  121. if (res.code == 200) {
  122. if (app.globalData.skipType == 'mycenter') {
  123. app.globalData.skipType = null;
  124. wx.reLaunch({
  125. url: '/pages/myCenter/myCenter',
  126. })
  127. } else {
  128. this.closeXieyi();
  129. }
  130. }
  131. }, this, "POST")
  132. },
  133. updateAddress: function () {//更新地址
  134. var mobile = this.data.submitData.mobile;
  135. if(this.data.selectType==2){
  136. this.data.submitData.mobile = this.data.mobile2;
  137. }
  138. app.wxRequest(app.globalData.urlRoot + "address/updateAddressV2", this.data.submitData, res => {
  139. wx.showToast({
  140. title: res.msg,
  141. })
  142. if (res.code == 200) {
  143. if (app.globalData.skipType == 'mycenter') {
  144. app.globalData.skipType = null;
  145. wx.reLaunch({
  146. url: '/pages/myCenter/myCenter',
  147. })
  148. } else {
  149. this.closeXieyi();
  150. }
  151. }
  152. }, this, "POST");
  153. },
  154. getNickName: function(e) {//获取昵称
  155. this.data.userData.nickName = e.detail.value;
  156. this.setData({
  157. userData: this.data.userData
  158. })
  159. },
  160. getRealName: function (e) {//获取收货人
  161. this.data.submitData.realName = e.detail.value;
  162. this.setData({
  163. submitData: this.data.submitData
  164. })
  165. },
  166. getMobile: function (e) {//获取手机号码
  167. this.data.submitData.mobile = e.detail.value;
  168. this.setData({
  169. submitData: this.data.submitData
  170. })
  171. },
  172. getMobile2: function (e) {//获取用户输入的电话---无验证码
  173. this.setData({
  174. mobile2:e.detail.value
  175. })
  176. },
  177. getAddressDetail: function (e) {//获取详细地址
  178. this.data.submitData.addressDetail = e.detail.value;
  179. this.setData({
  180. submitData: this.data.submitData
  181. })
  182. },
  183. saveUserMsg:function(){
  184. if (!this.data.submitData.realName) {
  185. wx.showToast({
  186. title: '请输入姓名',
  187. icon: "none"
  188. })
  189. return;
  190. }
  191. if (!this.data.mobile2 && this.data.selectType==2) {
  192. wx.showToast({
  193. title: '请输入电话',
  194. icon: "none"
  195. })
  196. return;
  197. }
  198. if (this.data.selectType == 2) {
  199. if (!this.data.submitData.captcha) {
  200. wx.showToast({
  201. title: '请输入验证码',
  202. icon: "none"
  203. })
  204. return;
  205. }
  206. }
  207. if (!this.data.submitData.addressDetail) {
  208. wx.showToast({
  209. title: '请输入详细地址',
  210. icon: "none"
  211. })
  212. return;
  213. }
  214. this.data.submitData.province = this.data.provinceDataArr[0][this.data.provinceDataValue[0]];
  215. this.data.submitData.city = this.data.provinceDataArr[1][this.data.provinceDataValue[1]];
  216. this.data.submitData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  217. this.data.submitData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  218. this.data.submitData.scene = app.globalData.sceneSource;
  219. // console.log(this.data.submitData);
  220. // return;
  221. wx.showLoading({
  222. title: '保存中',
  223. mask: true
  224. })
  225. if(this.data.submitDataState){
  226. return;
  227. }
  228. this.data.submitDataState = true;
  229. app.wxRequest(app.globalData.urlRoot + "userInfo/updateUserInfo", this.data.userData, res => {
  230. this.data.submitDataState = false;
  231. wx.hideLoading();
  232. if (res.code == 200) {
  233. if(this.data.userData){
  234. var userInfoData = wx.getStorageSync("userInfoData");
  235. if(this.data.userData.avatarUrl){
  236. console.log("userData")
  237. app.globalData.userInfoData.avatarUrl = this.data.userData.avatarUrl;
  238. if(userInfoData){
  239. userInfoData.avatarUrl = this.data.userData.avatarUrl;
  240. }
  241. }
  242. if(this.data.userData.nickName){
  243. app.globalData.userInfoData.nickName = this.data.userData.nickName;
  244. if(userInfoData){
  245. userInfoData.nickName = this.data.userData.nickName;
  246. }
  247. }
  248. wx.setStorageSync('userInfoData', userInfoData)
  249. }
  250. this.submitAddress();
  251. }
  252. }, this, "POST")
  253. },
  254. submitAddress: function () {//保存地址
  255. if (this.data.isAddress) {
  256. this.updateAddress();
  257. } else {
  258. this.addAddress();
  259. }
  260. },
  261. closeXieyi: function () {
  262. this.triggerEvent('address')
  263. },
  264. changeHeadImg:function(){
  265. wx.chooseImage({
  266. count:1,
  267. success:(res)=>{
  268. this.setData({
  269. avatarUrlShow: res.tempFilePaths[0]
  270. })
  271. wx.uploadFile({
  272. url: app.globalData.urlRoot + "upload/uploadImage",
  273. header: {
  274. "OPENID": app.globalData.openid,
  275. "VERSION": 100
  276. },
  277. filePath: res.tempFilePaths[0],
  278. name: "file",
  279. formData:{
  280. filePath:"avatar"
  281. },
  282. success: option => {
  283. var json = JSON.parse(option.data);
  284. if (json.code==200){
  285. this.data.userData.avatarUrl = json.data[0].url;
  286. this.setData({
  287. userData: this.data.userData
  288. })
  289. }else{
  290. wx.showToast({
  291. title: option.msg,
  292. icon: 'none'
  293. })
  294. }
  295. }
  296. })
  297. }
  298. })
  299. },
  300. changeSelectType:function(e){
  301. if(e){
  302. this.setData({
  303. selectType:e.currentTarget.dataset.type
  304. })
  305. }else{
  306. this.setData({
  307. selectType:1
  308. })
  309. }
  310. },
  311. getCaptcha: function (e) {//获取用户输入的验证码
  312. this.data.submitData.captcha = e.detail.value;
  313. this.setData({
  314. submitData:this.data.submitData
  315. })
  316. },
  317. getCode: function (e) {//获取验证码
  318. if (!app.mobileVerify(this.data.mobile2)) {
  319. if (this.data.mobile2) {
  320. wx.showToast({
  321. title: '请输入正确的电话',
  322. icon: 'none'
  323. })
  324. } else {
  325. wx.showToast({
  326. title: '请输入电话',
  327. icon: 'none'
  328. })
  329. }
  330. return;
  331. }
  332. if (!this.data.sendCode) {
  333. return;
  334. }
  335. this.data.sendCode = false;
  336. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.mobile2 }, res => {
  337. if (res.code == 200) {
  338. this.countDown();
  339. wx.showToast({
  340. title: '验证码获取成功',
  341. icon: "none"
  342. })
  343. this.setData({
  344. verificationCode: 60
  345. })
  346. } else {
  347. this.data.sendCode = true;
  348. wx.showToast({
  349. title: res.msg,
  350. icon: "none"
  351. })
  352. }
  353. }, this)
  354. },
  355. countDown: function () {//倒计时
  356. setTimeout(() => {
  357. this.setData({
  358. verificationCode: this.data.verificationCode - 1
  359. })
  360. if (this.data.verificationCode > 0) {
  361. this.countDown();
  362. } else {
  363. this.setData({
  364. verificationCode: "获取验证码"
  365. })
  366. this.data.sendCode = true;
  367. }
  368. }, 1000);
  369. },
  370. getUserPhone: function (e) {//获取用户手机号
  371. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  372. app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
  373. if (res.code == 200) {
  374. this.setData({
  375. phoneInputShow: true
  376. })
  377. this.changeSelectType();
  378. if (res.data && res.data.decodeData) {
  379. this.data.submitData.mobile = res.data.decodeData.phoneNumber;
  380. this.setData({
  381. submitData: this.data.submitData
  382. })
  383. }
  384. } else {
  385. wx.showToast({
  386. title: res.msg,
  387. icon: "none"
  388. })
  389. }
  390. }, this);
  391. }
  392. },
  393. getUserLocation: function (e) {
  394. wx.getLocation({
  395. type: 'wgs84', //wgs84 gcj02
  396. success: (res) => {
  397. this.getDistributorList(res.longitude, res.latitude);
  398. },
  399. fail: (res) => {
  400. this.getDistributorList("", "");
  401. }
  402. })
  403. },
  404. getDistributorList: function (longitude, latitude) {//获取经销商列表
  405. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
  406. if (res.code == 200) {
  407. //整理数据
  408. var datas = res.data;
  409. var province = [];
  410. var city = [];
  411. for (let i = 0; i < res.data.list.length; i++) {
  412. province.push(res.data.list[i].province);
  413. }
  414. if(this.data.submitData.province){
  415. for(let i=0;i<province.length;i++){
  416. if(province[i]==this.data.submitData.province){
  417. res.data.nearData.provinceIndex = i;
  418. }
  419. }
  420. }
  421. for (let j = 0; j < res.data.list[res.data.nearData.provinceIndex].children.length; j++) {
  422. city.push(res.data.list[res.data.nearData.provinceIndex].children[j].city)
  423. }
  424. if(this.data.submitData.city){
  425. for(let i=0;i<city.length;i++){
  426. if(city[i]==this.data.submitData.city){
  427. res.data.nearData.cityIndex = i;
  428. }
  429. }
  430. }
  431. if(this.data.submitData.agentDetail){
  432. for(let i=0;i<res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children.length;i++){
  433. if(res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children[i].agent_detail==this.data.submitData.agentDetail){
  434. res.data.nearData.agentIndex = i;
  435. }
  436. }
  437. }else{
  438. res.data.nearData.agentIndex = 0;
  439. }
  440. //将数据赋值给变量
  441. this.setData({
  442. provinceDataAll: res.data.list,
  443. provinceDataArr: [province, city],
  444. provinceDataValue: [res.data.nearData.provinceIndex, res.data.nearData.cityIndex],
  445. nowProvince: province[res.data.nearData.provinceIndex] + " " + city[res.data.nearData.cityIndex],
  446. storeArr: res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children,
  447. storeValue: res.data.nearData.agentIndex
  448. })
  449. } else {
  450. wx.showToast({
  451. title: res.msg,
  452. icon: "none"
  453. })
  454. }
  455. }, this);
  456. },
  457. provinceDataChange: function (e) {
  458. if (e.detail.column == 0) {
  459. var city = [];
  460. for (let i = 0; i < this.data.provinceDataAll[e.detail.value].children.length; i++) {
  461. city.push(this.data.provinceDataAll[e.detail.value].children[i].city);
  462. }
  463. this.data.provinceDataArr[1] = city;
  464. this.setData({
  465. provinceDataArr: this.data.provinceDataArr
  466. })
  467. }
  468. },
  469. provinceDataChane: function (e) {
  470. if(
  471. !this.data.provinceDataArr ||
  472. !this.data.provinceDataArr[0] ||
  473. !this.data.provinceDataArr[1] ||
  474. !this.data.provinceDataArr[1][e.detail.value[0]] ||
  475. !this.data.provinceDataArr[1][e.detail.value[1]] ||
  476. !this.data.provinceDataAll ||
  477. !this.data.provinceDataAll[e.detail.value[0]] ||
  478. !this.data.provinceDataAll[e.detail.value[0]].children ||
  479. !this.data.provinceDataAll[e.detail.value[0]].children[e.detail.value[1]] ||
  480. !this.data.provinceDataAll[e.detail.value[0]].children[e.detail.value[1]].children
  481. ){
  482. return;
  483. }
  484. this.setData({
  485. provinceDataValue: e.detail.value,
  486. nowProvince: this.data.provinceDataArr[0][e.detail.value[0]] + " " + this.data.provinceDataArr[1][e.detail.value[1]],
  487. storeArr: this.data.provinceDataAll[e.detail.value[0]].children[e.detail.value[1]].children,
  488. storeValue: 0
  489. })
  490. },
  491. storeChane: function (e) {
  492. this.setData({
  493. storeValue: e.detail.value
  494. })
  495. },
  496. textareaBlur:function(){
  497. this.setData({
  498. replaceTextarea:!this.data.replaceTextarea
  499. })
  500. }
  501. }
  502. })