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

coupon.js 10KB

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 년 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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.getUserLocation();//获取用户当前位置
  117. },
  118. provinceChane: function (e) {//选中省
  119. this.setData({
  120. provinceValue: e.detail.value,
  121. cityArr: this.data.provinceArr[e.detail.value].children,
  122. cityValue: 0,
  123. storeArr: this.data.provinceArr[e.detail.value].children[0].children,
  124. storeValue: 0
  125. })
  126. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  127. this.data.subscribeData.city = this.data.cityArr[this.data.cityValue].city;
  128. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  129. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  130. },
  131. cityChane: function (e) {//选中城市
  132. this.setData({
  133. cityValue: e.detail.value,
  134. storeArr: this.data.provinceArr[this.data.provinceValue].children[e.detail.value].children,
  135. storeValue: 0
  136. })
  137. this.data.subscribeData.city = this.data.cityArr[this.data.cityValue].city;
  138. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  139. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  140. },
  141. storeChane: function (e) {//选中店铺
  142. this.setData({
  143. storeValue: e.detail.value,
  144. })
  145. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  146. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  147. },
  148. getUserPhone: function (e) {//获取用户手机号
  149. this.setData({
  150. phoneInputShow: true
  151. })
  152. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  153. app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
  154. if (res.code == 200) {
  155. if (res.data && res.data.decodeData) {
  156. this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
  157. this.setData({
  158. subscribeData: this.data.subscribeData
  159. })
  160. }
  161. } else {
  162. wx.showToast({
  163. title: res.msg,
  164. icon: "none"
  165. })
  166. }
  167. }, this);
  168. }
  169. },
  170. getUserLocation: function (e) {
  171. wx.getLocation({
  172. type: 'gcj02', //
  173. success: (res) => {
  174. this.getDistributorList(res.longitude, res.latitude);
  175. },
  176. fail: (res) => {
  177. this.getDistributorList("", "");
  178. },
  179. complete: (res) => {
  180. this.setData({
  181. isAppointmentShow: true
  182. })
  183. }
  184. })
  185. },
  186. getDistributorList: function (longitude, latitude) {//获取经销商列表
  187. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
  188. if (res.code == 200) {
  189. app.globalData.myCenterData = {};
  190. this.setData({
  191. provinceArr: res.data.list,
  192. cityArr: res.data.list[res.data.nearData.provinceIndex].children,
  193. storeArr: res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children,
  194. provinceValue: res.data.nearData.provinceIndex,
  195. cityValue: res.data.nearData.cityIndex,
  196. storeValue: res.data.nearData.agentIndex
  197. })
  198. this.data.subscribeData.province = this.data.provinceArr[this.data.provinceValue].province;
  199. this.data.subscribeData.city = this.data.cityArr[this.data.cityValue].city;
  200. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  201. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  202. app.globalData.myCenterData.provinceArr = res.data.list;
  203. app.globalData.myCenterData.cityArr = res.data.list[res.data.nearData.provinceIndex].children;
  204. app.globalData.myCenterData.storeArr = res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children;
  205. app.globalData.myCenterData.provinceValue = res.data.nearData.provinceIndex;
  206. app.globalData.myCenterData.cityValue = res.data.nearData.cityValue;
  207. app.globalData.myCenterData.storeValue = res.data.nearData.agentIndex;
  208. } else {
  209. wx.showToast({
  210. title: res.msg,
  211. icon: "none"
  212. })
  213. }
  214. }, this);
  215. },
  216. getCode: function (e) {//获取验证码
  217. if (!app.mobileVerify(this.data.subscribeData.mobile)) {
  218. if (this.data.subscribeData.mobile) {
  219. wx.showToast({
  220. title: '请输入正确的电话',
  221. icon: 'none'
  222. })
  223. } else {
  224. wx.showToast({
  225. title: '请输入电话',
  226. icon: 'none'
  227. })
  228. }
  229. return;
  230. }
  231. if (!this.data.sendCode) {
  232. return;
  233. }
  234. this.data.sendCode = false;
  235. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.subscribeData.mobile }, res => {
  236. if (res.code == 200) {
  237. this.countDown();
  238. wx.showToast({
  239. title: '验证码获取成功',
  240. icon: "none"
  241. })
  242. this.setData({
  243. verificationCode: 60
  244. })
  245. } else {
  246. this.data.sendCode = true;
  247. wx.showToast({
  248. title: res.msg,
  249. icon: "none"
  250. })
  251. }
  252. }, this)
  253. },
  254. countDown: function () {//倒计时
  255. setTimeout(() => {
  256. this.setData({
  257. verificationCode: this.data.verificationCode - 1
  258. })
  259. if (this.data.verificationCode > 0) {
  260. this.countDown();
  261. } else {
  262. this.setData({
  263. verificationCode: "获取验证码"
  264. })
  265. this.data.sendCode = true;
  266. }
  267. }, 1000);
  268. },
  269. getRealname: function (e) {//获取用户输入的姓名
  270. this.data.subscribeData.realname = e.detail.value;
  271. },
  272. getMobile: function (e) {//获取用户输入的电话
  273. this.data.subscribeData.mobile = e.detail.value;
  274. },
  275. getCaptcha: function (e) {//获取用户输入的验证码
  276. this.data.subscribeData.captcha = e.detail.value;
  277. },
  278. subscribeFun: function (e) {//预约鉴赏
  279. if (!this.data.subscribeData.realname) {
  280. wx.showToast({
  281. title: '请输入姓名',
  282. icon: "none"
  283. })
  284. return;
  285. }
  286. if (!this.data.subscribeData.mobile) {
  287. wx.showToast({
  288. title: '请输入电话',
  289. icon: "none"
  290. })
  291. return;
  292. }
  293. if (!this.data.subscribeData.captcha) {
  294. wx.showToast({
  295. title: '请输入验证码',
  296. icon: "none"
  297. })
  298. return;
  299. }
  300. if (!this.data.appointment) {
  301. return;
  302. }
  303. this.data.appointment = false;
  304. app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
  305. this.data.appointment = true;
  306. if (res.code == 200) {
  307. app.globalData.userMobile = this.data.subscribeData.mobile;
  308. this.setData({
  309. submitSuccess:true
  310. })
  311. } else {
  312. wx.showToast({
  313. title: res.msg,
  314. icon: "none"
  315. })
  316. }
  317. }, this, "POST")
  318. },
  319. getUserWxMsg: function (e) {
  320. if (e.detail.errMsg == "getUserInfo:ok") {
  321. this.setData({
  322. userData: e.detail.userInfo
  323. })
  324. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  325. }
  326. },
  327. showSite: function () {//显示地址选择框
  328. if (!this.data.siteSelect) {
  329. }
  330. },
  331. enterMyCenter: function () {
  332. wx.reLaunch({
  333. url: '/pages/myCenter/myCenter',
  334. })
  335. }
  336. })