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

325 lines
8.7KB

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