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

359 lines
9.6KB

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