东风启辰小程序端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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