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

353 lines
10KB

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