东风启辰小程序端
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

364 líneas
9.7KB

  1. // pages/coupon/coupon.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. countNum:0,
  10. pageShow: false,//是否显示页面 false
  11. isAppointmentShow: false,//是否显示预约弹框
  12. phoneInputShow: false,//是否显示电话输入框
  13. siteSelect: false,//是否显示位置选择框
  14. provinceDataAll: null,//地区所有数据
  15. provinceDataArr: [[""], [""]],//省市数据
  16. provinceDataValue: [0, 0],//选中的省市下标
  17. nowProvince: "",//选中的省市文字
  18. storeArr: [],//专营店数据
  19. storeValue: 0,//选中的专营店下标
  20. verificationCode: '获取验证码',//验证码文案
  21. sendCode: true,
  22. appointment: true,
  23. subscribeData: {
  24. realname: "",//姓名
  25. mobile: "",//手机号
  26. captcha: "",//验证码
  27. province: "",//省份
  28. city:"",//城市
  29. agent_code: "",//经销商编码
  30. agentDetail: "",//经销商详细信息
  31. parentOpenid: app.globalData.parentOpenid,//好友openid
  32. },
  33. submitSuccess:false,
  34. placing:false
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad: function (options) {
  40. if (options.scene) {
  41. this.data.subscribeData.parentOpenid = options.scene;
  42. wx.setStorageSync("parentOpenid", options.scene);
  43. app.globalData.parentOpenid = options.scene;
  44. }
  45. if (app.globalData.openid) {
  46. this.loadFun();
  47. } else {
  48. app.globalData.openidSuccessFuc = this.loadFun;
  49. }
  50. },
  51. loadFun:function(){
  52. if (this.data.subscribeData.parentOpenid == app.globalData.openid){
  53. wx.reLaunch({
  54. url: '/pages/index/index',
  55. })
  56. } else {
  57. this.getOrderInfo();
  58. }
  59. },
  60. /**
  61. * 生命周期函数--监听页面初次渲染完成
  62. */
  63. onReady: function () {
  64. },
  65. /**
  66. * 生命周期函数--监听页面显示
  67. */
  68. onShow: function () {
  69. },
  70. /**
  71. * 生命周期函数--监听页面隐藏
  72. */
  73. onHide: function () {
  74. },
  75. /**
  76. * 生命周期函数--监听页面卸载
  77. */
  78. onUnload: function () {
  79. },
  80. /**
  81. * 页面相关事件处理函数--监听用户下拉动作
  82. */
  83. onPullDownRefresh: function () {
  84. },
  85. /**
  86. * 页面上拉触底事件的处理函数
  87. */
  88. onReachBottom: function () {
  89. },
  90. /**
  91. * 用户点击右上角分享
  92. */
  93. onShareAppMessage: function () {
  94. return app.sharePack();
  95. },
  96. receive: function () {//立即领取
  97. wx.reLaunch({
  98. url: '/pages/index/index',
  99. })
  100. },
  101. getOrderInfo: function () {//查询是否已注册
  102. app.wxRequest(app.globalData.urlRoot +"userInfo/getOrderInfo",{},res=>{
  103. if(res.code==200){
  104. if(res.data){
  105. wx.reLaunch({
  106. url: '/pages/index/index',
  107. })
  108. // this.setData({
  109. // pageShow: true
  110. // })
  111. }else{
  112. this.setData({
  113. pageShow:true
  114. })
  115. }
  116. }
  117. },this)
  118. },
  119. cutPage:function(){//发现启辰星
  120. wx.reLaunch({
  121. url: '/pages/index/index',
  122. })
  123. },
  124. showAppointment:function(){
  125. this.placingControl();
  126. },
  127. getUserPhone: function (e) {//获取用户手机号
  128. this.setData({
  129. phoneInputShow: true
  130. })
  131. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  132. app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
  133. if (res.code == 200) {
  134. if (res.data && res.data.decodeData) {
  135. this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
  136. this.setData({
  137. subscribeData: this.data.subscribeData
  138. })
  139. }
  140. } else {
  141. wx.showToast({
  142. title: res.msg,
  143. icon: "none"
  144. })
  145. }
  146. }, this);
  147. }
  148. },
  149. getUserLocation: function (e) {
  150. wx.getLocation({
  151. type: 'gcj02', //
  152. success: (res) => {
  153. this.getDistributorList(res.longitude, res.latitude);
  154. },
  155. fail: (res) => {
  156. this.getDistributorList("", "");
  157. },
  158. complete: (res) => {
  159. this.setData({
  160. isAppointmentShow: true
  161. })
  162. }
  163. })
  164. },
  165. getDistributorList: function (longitude, latitude) {//获取经销商列表
  166. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
  167. if (res.code == 200) {
  168. //整理数据
  169. var datas = res.data;
  170. var province = [];
  171. var city = [];
  172. for (let i = 0; i < res.data.list.length; i++) {
  173. province.push(res.data.list[i].province);
  174. }
  175. for (let j = 0; j < res.data.list[res.data.nearData.provinceIndex].children.length; j++) {
  176. city.push(res.data.list[res.data.nearData.provinceIndex].children[j].city)
  177. }
  178. //将数据赋值给变量
  179. this.setData({
  180. provinceDataAll: res.data.list,
  181. provinceDataArr: [province, city],
  182. provinceDataValue: [res.data.nearData.provinceIndex, res.data.nearData.cityIndex],
  183. nowProvince: province[res.data.nearData.provinceIndex] + " " + city[res.data.nearData.cityIndex],
  184. storeArr: res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children,
  185. storeValue: res.data.nearData.agentIndex
  186. })
  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. this.data.subscribeData.province = this.data.provinceDataArr[0][this.data.provinceDataValue[0]];
  284. this.data.subscribeData.city = this.data.provinceDataArr[1][this.data.provinceDataValue[1]];
  285. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  286. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  287. app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
  288. this.data.appointment = true;
  289. if (res.code == 200) {
  290. app.globalData.userMobile = this.data.subscribeData.mobile;
  291. this.setData({
  292. submitSuccess:true
  293. })
  294. } else {
  295. wx.showToast({
  296. title: res.msg,
  297. icon: "none"
  298. })
  299. }
  300. }, this, "POST")
  301. },
  302. getUserWxMsg: function (e) {
  303. if (e.detail.errMsg == "getUserInfo:ok") {
  304. this.setData({
  305. userData: e.detail.userInfo
  306. })
  307. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  308. }
  309. },
  310. showSite: function () {//显示地址选择框
  311. if (!this.data.siteSelect) {
  312. }
  313. },
  314. controlWindow: function () {
  315. this.setData({
  316. submitSuccess: !this.data.submitSuccess
  317. })
  318. },
  319. provinceDataChange: function (e) {
  320. if (e.detail.column == 0) {
  321. var city = [];
  322. for (let i = 0; i < this.data.provinceDataAll[e.detail.value].children.length; i++) {
  323. city.push(this.data.provinceDataAll[e.detail.value].children[i].city);
  324. }
  325. this.data.provinceDataArr[1] = city;
  326. this.setData({
  327. provinceDataArr: this.data.provinceDataArr
  328. })
  329. }
  330. },
  331. provinceDataChane: function (e) {
  332. this.setData({
  333. provinceDataValue: e.detail.value,
  334. nowProvince: this.data.provinceDataArr[0][e.detail.value[0]] + " " + this.data.provinceDataArr[1][e.detail.value[1]],
  335. storeArr: this.data.provinceDataAll[e.detail.value[0]].children[e.detail.value[1]].children,
  336. storeValue: 0
  337. })
  338. },
  339. storeChane: function (e) {
  340. this.setData({
  341. storeValue: e.detail.value
  342. })
  343. },
  344. placingControl:function(){
  345. this.setData({
  346. placing: !this.data.placing
  347. })
  348. }
  349. })