东风启辰小程序端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

388 rindas
11KB

  1. // pages/myCenter/myCenter.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. isLogin:false,//登录状态
  10. selectNow:0,//现在的选项
  11. taskNow:1,//现在的任务类型
  12. recordNow: 1,//现在的记录类型
  13. taskList: [],//任务列表
  14. shareFriendList:[],//星探小分队列表
  15. provinceArr: [],//省
  16. provinceValue: 0,//选中的省下标
  17. storeArr: [],//店铺
  18. storeValue: 0,//选中的店铺下标
  19. verificationCode: '获取验证码',//验证码文案
  20. sendCode: true,
  21. subscribeData: {
  22. realname: "",//姓名
  23. mobile: "",//手机号
  24. captcha: "",//验证码
  25. province: "",//省份
  26. agent_code: "",//经销商编码
  27. agentDetail: "",//经销商详细信息
  28. parentOpenid: "",//好友openid
  29. },
  30. userData:{
  31. avatarUrl: null,
  32. nickName: null,
  33. userLevel: 0
  34. },
  35. descFrameShow:false,//是否显示奖品详情
  36. ruleShow: false,//是否显示星探等级规则
  37. isRegister: false,//查询是否已注册
  38. parames:{
  39. page:1,
  40. count:20
  41. },
  42. noData:false,
  43. },
  44. /**
  45. * 生命周期函数--监听页面加载
  46. */
  47. onLoad: function (options) {
  48. if (app.globalData.openid) {
  49. this.loadFun();
  50. } else {
  51. app.globalData.openidSuccessFuc = this.loadFun;
  52. }
  53. },
  54. loadFun: function () {
  55. this.getUserInfo();
  56. this.getTaskProgress();
  57. this.getShareList();
  58. if (app.globalData.myCenterData) {
  59. this.setData({
  60. provinceArr: app.globalData.indexData.provinceArr,
  61. storeArr: app.globalData.indexData.storeArr,
  62. provinceValue: app.globalData.indexData.provinceValue,
  63. storeValue: app.globalData.indexData.storeValue,
  64. isRegister: app.globalData.isRegister
  65. })
  66. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  67. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  68. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  69. }else{
  70. app.globalData.myCenterData = {};
  71. this.getUserLocation();
  72. this.getOrderInfo();
  73. }
  74. },
  75. /**
  76. * 生命周期函数--监听页面初次渲染完成
  77. */
  78. onReady: function () {
  79. },
  80. /**
  81. * 生命周期函数--监听页面显示
  82. */
  83. onShow: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面隐藏
  87. */
  88. onHide: function () {
  89. },
  90. /**
  91. * 生命周期函数--监听页面卸载
  92. */
  93. onUnload: function () {
  94. },
  95. /**
  96. * 页面相关事件处理函数--监听用户下拉动作
  97. */
  98. onPullDownRefresh: function () {
  99. },
  100. /**
  101. * 页面上拉触底事件的处理函数
  102. */
  103. onReachBottom: function () {
  104. },
  105. /**
  106. * 用户点击右上角分享
  107. */
  108. onShareAppMessage: function () {
  109. },
  110. selectChange:function(e){
  111. this.setData({
  112. selectNow: e.currentTarget.dataset.value
  113. })
  114. if (e.currentTarget.dataset.value==3){
  115. this.data.parames.page=0;
  116. this.data.getShareList = [];
  117. }
  118. },
  119. selectTask: function (e) {
  120. if (e.currentTarget.dataset.type==2){
  121. return;
  122. }
  123. this.setData({
  124. taskNow: e.currentTarget.dataset.type
  125. })
  126. },
  127. selectRecord: function (e) {
  128. this.setData({
  129. recordNow: e.currentTarget.dataset.type
  130. })
  131. },
  132. getUserLocation: function (e) {
  133. wx.getLocation({
  134. type: 'gcj02', //wgs84
  135. success: (res) => {
  136. this.getDistributorList(res.longitude, res.latitude);
  137. },
  138. fail: (res) => {
  139. this.getDistributorList("", "");
  140. }
  141. })
  142. },
  143. getDistributorList: function (longitude, latitude) {//获取经销商列表
  144. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
  145. if (res.code == 200) {
  146. this.setData({
  147. provinceArr: res.data.list,
  148. storeArr: res.data.list[res.data.nearData.provinceIndex].children,
  149. provinceValue: res.data.nearData.provinceIndex,
  150. storeValue: res.data.nearData.cityIndex
  151. })
  152. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  153. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  154. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  155. app.globalData.myCenterData.provinceArr = res.data.list;
  156. app.globalData.myCenterData.storeArr = res.data.list[res.data.nearData.provinceIndex].children;
  157. app.globalData.myCenterData.provinceValue = res.data.nearData.provinceIndex;
  158. app.globalData.myCenterData.storeValue = res.data.nearData.cityIndex;
  159. } else {
  160. wx.showToast({
  161. title: res.msg,
  162. icon: "none"
  163. })
  164. }
  165. }, this);
  166. },
  167. provinceChane: function (e) {//选中省
  168. this.setData({
  169. provinceValue: e.detail.value,
  170. storeArr: this.data.provinceArr[e.detail.value].children,
  171. storeValue: 0
  172. })
  173. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  174. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  175. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  176. },
  177. storeChane: function (e) {//选中店铺
  178. this.setData({
  179. storeValue: e.detail.value,
  180. })
  181. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  182. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  183. },
  184. getCode: function (e) {//获取验证码
  185. if (!app.mobileVerify(this.data.subscribeData.mobile)) {
  186. if (this.data.subscribeData.mobile) {
  187. wx.showToast({
  188. title: '请输入正确的电话',
  189. icon: 'none'
  190. })
  191. } else {
  192. wx.showToast({
  193. title: '请输入电话',
  194. icon: 'none'
  195. })
  196. }
  197. return;
  198. }
  199. if (!this.data.sendCode) {
  200. return;
  201. }
  202. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: '18831849567' }, res => {
  203. console.log(res);
  204. if (res.code == 200) {
  205. this.countDown();
  206. wx.showToast({
  207. title: '验证码获取成功',
  208. icon: "none"
  209. })
  210. this.setData({
  211. verificationCode: 60
  212. })
  213. this.data.sendCode = false;
  214. } else {
  215. wx.showToast({
  216. title: res.msg,
  217. icon: "none"
  218. })
  219. }
  220. }, this)
  221. },
  222. countDown: function () {//倒计时
  223. setTimeout(() => {
  224. this.setData({
  225. verificationCode: this.data.verificationCode - 1
  226. })
  227. if (this.data.verificationCode > 0) {
  228. this.countDown();
  229. } else {
  230. this.setData({
  231. verificationCode: "获取验证码"
  232. })
  233. this.data.sendCode = true;
  234. }
  235. }, 1000);
  236. },
  237. getRealname: function (e) {//获取用户输入的姓名
  238. this.data.subscribeData.realname = e.detail.value;
  239. },
  240. getMobile: function (e) {//获取用户输入的电话
  241. this.data.subscribeData.mobile = e.detail.value;
  242. },
  243. getCaptcha: function (e) {//获取用户输入的验证码
  244. this.data.subscribeData.captcha = e.detail.value;
  245. },
  246. subscribeFun: function (e) {//预约鉴赏
  247. if(!this.data.subscribeData.realname){
  248. wx.showToast({
  249. title: '请输入姓名',
  250. icon:"none"
  251. })
  252. return;
  253. }
  254. if (!this.data.subscribeData.mobile) {
  255. wx.showToast({
  256. title: '请输入电话',
  257. icon: "none"
  258. })
  259. return;
  260. }
  261. if (!this.data.subscribeData.captcha) {
  262. wx.showToast({
  263. title: '请输入验证码',
  264. icon: "none"
  265. })
  266. return;
  267. }
  268. app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
  269. if (res.code == 200) {
  270. wx.showToast({
  271. title: '预约成功'
  272. })
  273. this.setData({
  274. isRegister: true
  275. })
  276. app.globalData.isRegister = true;
  277. app.globalData.userMobile = this.data.subscribeData.mobile;
  278. } else {
  279. wx.showToast({
  280. title: res.msg,
  281. icon: "none"
  282. })
  283. }
  284. }, this, "POST")
  285. },
  286. getUserWxMsg:function(e){//通过微信获取用户信息
  287. if (e.detail.errMsg == "getUserInfo:ok") {
  288. this.data.userData.avatarUrl = e.detail.userInfo.avatarUrl;
  289. this.data.userData.nickName = e.detail.userInfo.nickName;
  290. this.data.userData.userLevel = 0;
  291. this.setData({
  292. userData: this.data.userData,
  293. isLogin: true
  294. })
  295. app.wxRequest(app.globalData.urlRoot + "userInfo/updateUserInfo", { avatarUrl: e.detail.userInfo.avatarUrl, nickName: e.detail.userInfo.nickName},res=>{},this,"POST")
  296. }
  297. },
  298. getUserInfo:function(e){//获取个人信息
  299. app.wxRequest(app.globalData.urlRoot + 'userInfo/getUserInfo', {}, res => {
  300. if(res.code==200){
  301. // res.data.userLevel = 3;
  302. if(res.data.avatarUrl){
  303. this.data.userData.avatarUrl = res.data.avatarUrl;
  304. this.data.userData.nickName = res.data.nickName;
  305. this.data.userData.userLevel = res.data.userLevel;
  306. this.setData({
  307. userData:this.data.userData,
  308. isLogin:true
  309. })
  310. }
  311. }
  312. },this)
  313. },
  314. getTaskProgress: function () {//获取任务完成度 1每日任务
  315. app.wxRequest(app.globalData.urlRoot + "task/getTaskProgress", { taskType: this.data.taskNow},res=>{
  316. if(res.code==200){
  317. this.setData({
  318. taskList:res.data
  319. })
  320. }
  321. },this)
  322. },
  323. lookDesc:function(e){//查看奖品详情
  324. this.setData({
  325. descFrameShow: e.currentTarget.dataset.value
  326. })
  327. },
  328. lookRule: function (e) {//查看奖品详情
  329. this.setData({
  330. ruleShow: e.currentTarget.dataset.value
  331. })
  332. },
  333. getShareList: function () {//星探小分队
  334. app.wxRequest(app.globalData.urlRoot + "share/getFriendRegisterList", this.data.parames,res=>{
  335. console.log(res);
  336. if(res.code==200){
  337. for(let i=0;i<res.data.length;i++){
  338. this.data.shareFriendList.push(res.data[i]);
  339. }
  340. this.setData({
  341. shareFriendList: this.data.shareFriendList
  342. })
  343. if (res.data.length<this.data.parames.count){
  344. this.setData({
  345. noData: true
  346. })
  347. }
  348. console.log(this.data.shareFriendList);
  349. }
  350. },this);
  351. },
  352. getOrderInfo: function () {//查询是否已注册
  353. app.wxRequest(app.globalData.urlRoot + "userInfo/getOrderInfo", {}, res => {
  354. if (res.code == 200) {
  355. if (res.data) {
  356. this.setData({
  357. isRegister: true
  358. })
  359. app.globalData.isRegister = true;
  360. app.globalData.userMobile = res.data.mobile;
  361. }
  362. } else {
  363. console.log(res.msg)
  364. }
  365. }, this);
  366. },
  367. scrolltolower:function(){//星探小分队滚动条触底时执行
  368. if(!this.data.noData){
  369. this.data.parames.page+=1;
  370. this.getShareList();
  371. }
  372. }
  373. })