东风启辰小程序端
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.

331 rinda
8.8KB

  1. // pages/coupon/coupon.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. friendOpenid:null,//朋友的openid
  10. countNum:0,
  11. pageShow: false,//是否显示页面 false
  12. isAppointmentShow: false,//是否显示预约弹框
  13. phoneInputShow: false,//是否显示电话输入框
  14. siteSelect: false,//是否显示位置选择框
  15. provinceArr: [],//省
  16. provinceValue: 0,//选中的省下标
  17. storeArr: [],//店铺
  18. storeValue: 0,//选中的店铺下标
  19. verificationCode: '获取验证码',//验证码文案
  20. sendCode: true,
  21. appointment: true,
  22. subscribeData: {
  23. realname: "",//姓名
  24. mobile: "",//手机号
  25. captcha: "",//验证码
  26. province: "",//省份
  27. agent_code: "",//经销商编码
  28. agentDetail: "",//经销商详细信息
  29. parentOpenid: app.globalData.friendOpenid,//好友openid
  30. },
  31. submitSuccess:false
  32. },
  33. /**
  34. * 生命周期函数--监听页面加载
  35. */
  36. onLoad: function (options) {
  37. if (options.friendOpenid) {
  38. this.data.friendOpenid = options.friendOpenid;
  39. wx.setStorageSync("friendOpenid", options.friendOpenid);
  40. app.globalData.friendOpenid = options.friendOpenid;
  41. }
  42. if (app.globalData.openid) {
  43. this.loadFun();
  44. } else {
  45. app.globalData.openidSuccessFuc = this.loadFun;
  46. }
  47. },
  48. loadFun:function(){
  49. this.getOrderInfo();
  50. },
  51. /**
  52. * 生命周期函数--监听页面初次渲染完成
  53. */
  54. onReady: function () {
  55. },
  56. /**
  57. * 生命周期函数--监听页面显示
  58. */
  59. onShow: function () {
  60. },
  61. /**
  62. * 生命周期函数--监听页面隐藏
  63. */
  64. onHide: function () {
  65. },
  66. /**
  67. * 生命周期函数--监听页面卸载
  68. */
  69. onUnload: function () {
  70. },
  71. /**
  72. * 页面相关事件处理函数--监听用户下拉动作
  73. */
  74. onPullDownRefresh: function () {
  75. },
  76. /**
  77. * 页面上拉触底事件的处理函数
  78. */
  79. onReachBottom: function () {
  80. },
  81. /**
  82. * 用户点击右上角分享
  83. */
  84. onShareAppMessage: function () {
  85. return app.sharePack();
  86. },
  87. receive: function () {//立即领取
  88. wx.reLaunch({
  89. url: '/pages/index/index',
  90. })
  91. },
  92. getOrderInfo: function () {//查询是否已注册
  93. app.wxRequest(app.globalData.urlRoot +"userInfo/getOrderInfo",{},res=>{
  94. if(res.code==200){
  95. if(res.data){
  96. wx.reLaunch({
  97. url: '/pages/index/index',
  98. })
  99. }else{
  100. this.setData({
  101. pageShow:true
  102. })
  103. }
  104. }
  105. },this)
  106. },
  107. cutPage:function(){//发现启辰星
  108. wx.reLaunch({
  109. url: '/pages/index/index',
  110. })
  111. },
  112. showAppointment:function(){
  113. this.setData({
  114. isAppointmentShow:true
  115. })
  116. },
  117. provinceChane: function (e) {//选中省
  118. this.setData({
  119. provinceValue: e.detail.value,
  120. storeArr: this.data.provinceArr[e.detail.value].children,
  121. storeValue: 0
  122. })
  123. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  124. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  125. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  126. },
  127. storeChane: function (e) {//选中店铺
  128. this.setData({
  129. storeValue: e.detail.value,
  130. })
  131. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  132. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  133. },
  134. getUserPhone: function (e) {//获取用户手机号
  135. this.setData({
  136. phoneInputShow: true
  137. })
  138. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  139. app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
  140. if (res.code == 200) {
  141. if (res.data && res.data.decodeData) {
  142. this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
  143. this.setData({
  144. subscribeData: this.data.subscribeData
  145. })
  146. }
  147. } else {
  148. wx.showToast({
  149. title: res.msg,
  150. icon: "none"
  151. })
  152. }
  153. }, this);
  154. }
  155. },
  156. getUserLocation: function (e) {
  157. wx.getLocation({
  158. type: 'gcj02', //
  159. success: (res) => {
  160. this.getDistributorList(res.longitude, res.latitude);
  161. },
  162. fail: (res) => {
  163. this.getDistributorList("", "");
  164. },
  165. complete: (res) => {
  166. this.setData({
  167. siteSelect: true,
  168. })
  169. }
  170. })
  171. },
  172. getDistributorList: function (longitude, latitude) {//获取经销商列表
  173. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
  174. if (res.code == 200) {
  175. this.setData({
  176. provinceArr: res.data.list,
  177. storeArr: res.data.list[res.data.nearData.provinceIndex].children,
  178. provinceValue: res.data.nearData.provinceIndex,
  179. storeValue: res.data.nearData.cityIndex
  180. })
  181. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  182. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  183. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  184. app.globalData.indexData.provinceArr = res.data.list;
  185. app.globalData.indexData.storeArr = res.data.list[res.data.nearData.provinceIndex].children;
  186. app.globalData.indexData.provinceValue = res.data.nearData.provinceIndex;
  187. app.globalData.indexData.storeValue = res.data.nearData.cityIndex;
  188. } else {
  189. wx.showToast({
  190. title: res.msg,
  191. icon: "none"
  192. })
  193. }
  194. }, this);
  195. },
  196. getCode: function (e) {//获取验证码
  197. if (!app.mobileVerify(this.data.subscribeData.mobile)) {
  198. if (this.data.subscribeData.mobile) {
  199. wx.showToast({
  200. title: '请输入正确的电话',
  201. icon: 'none'
  202. })
  203. } else {
  204. wx.showToast({
  205. title: '请输入电话',
  206. icon: 'none'
  207. })
  208. }
  209. return;
  210. }
  211. if (!this.data.sendCode) {
  212. return;
  213. }
  214. this.data.sendCode = false;
  215. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.subscribeData.mobile }, res => {
  216. if (res.code == 200) {
  217. this.countDown();
  218. wx.showToast({
  219. title: '验证码获取成功',
  220. icon: "none"
  221. })
  222. this.setData({
  223. verificationCode: 60
  224. })
  225. } else {
  226. this.data.sendCode = true;
  227. wx.showToast({
  228. title: res.msg,
  229. icon: "none"
  230. })
  231. }
  232. }, this)
  233. },
  234. countDown: function () {//倒计时
  235. setTimeout(() => {
  236. this.setData({
  237. verificationCode: this.data.verificationCode - 1
  238. })
  239. if (this.data.verificationCode > 0) {
  240. this.countDown();
  241. } else {
  242. this.setData({
  243. verificationCode: "获取验证码"
  244. })
  245. this.data.sendCode = true;
  246. }
  247. }, 1000);
  248. },
  249. getRealname: function (e) {//获取用户输入的姓名
  250. this.data.subscribeData.realname = e.detail.value;
  251. },
  252. getMobile: function (e) {//获取用户输入的电话
  253. this.data.subscribeData.mobile = e.detail.value;
  254. },
  255. getCaptcha: function (e) {//获取用户输入的验证码
  256. this.data.subscribeData.captcha = e.detail.value;
  257. },
  258. subscribeFun: function (e) {//预约鉴赏
  259. if (!this.data.subscribeData.realname) {
  260. wx.showToast({
  261. title: '请输入姓名',
  262. icon: "none"
  263. })
  264. return;
  265. }
  266. if (!this.data.subscribeData.mobile) {
  267. wx.showToast({
  268. title: '请输入电话',
  269. icon: "none"
  270. })
  271. return;
  272. }
  273. if (!this.data.subscribeData.captcha) {
  274. wx.showToast({
  275. title: '请输入验证码',
  276. icon: "none"
  277. })
  278. return;
  279. }
  280. if (!this.data.appointment) {
  281. return;
  282. }
  283. this.data.appointment = false;
  284. app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
  285. this.data.appointment = true;
  286. if (res.code == 200) {
  287. app.globalData.userMobile = this.data.subscribeData.mobile;
  288. this.setData({
  289. submitSuccess:true
  290. })
  291. } else {
  292. wx.showToast({
  293. title: res.msg,
  294. icon: "none"
  295. })
  296. }
  297. }, this, "POST")
  298. },
  299. getUserWxMsg: function (e) {
  300. if (e.detail.errMsg == "getUserInfo:ok") {
  301. this.setData({
  302. userData: e.detail.userInfo
  303. })
  304. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  305. }
  306. },
  307. showSite: function () {//显示地址选择框
  308. if (!this.data.siteSelect) {
  309. this.getUserLocation();//获取用户当前位置
  310. }
  311. },
  312. enterMyCenter: function () {
  313. wx.reLaunch({
  314. url: '/pages/myCenter/myCenter',
  315. })
  316. }
  317. })