东风启辰小程序端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

359 Zeilen
11KB

  1. // pages/yuyue/yuyue.js
  2. const app = getApp()
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. properties: {
  8. enterType:{
  9. type:String,
  10. value:''
  11. }
  12. },
  13. /**
  14. * 组件的初始数据
  15. */
  16. data: {
  17. imgUrl: app.globalData.urlStatic,//图片路径
  18. agreement:false,
  19. isAgreement: true,//是否同意协议
  20. phoneInputShow: false,//是否显示电话输入框
  21. siteSelect: false,//是否显示位置选择框
  22. provinceDataAll: null,//地区所有数据
  23. provinceDataArr: [[""], [""]],//省市数据
  24. provinceDataValue: [0, 0],//选中的省市下标
  25. nowProvince: "",//选中的省市文字
  26. storeArr: [],//专营店数据
  27. storeValue: 0,//选中的专营店下标
  28. verificationCode: '获取验证码',//验证码文案
  29. sendCode: true,
  30. appointment: true,
  31. mobile2:"",
  32. subscribeData: {
  33. realname: "",//姓名
  34. mobile: "",//手机号---无验证码
  35. captcha: "",//验证码
  36. province: "",//省份
  37. city:"",//城市
  38. agent_code: "",//经销商编码
  39. agentDetail: "",//经销商详细信息
  40. parentOpenid: app.globalData.parentOpenid,//好友openid
  41. scene: app.globalData.sceneSource
  42. },
  43. mobileType:2,
  44. userData:null
  45. },
  46. ready:function(){
  47. console.log(this.data.enterType);
  48. if (app.globalData.openid) {
  49. this.loadFun();
  50. } else {
  51. app.globalData.openidSuccessFuc = this.loadFun;
  52. }
  53. },
  54. /**
  55. * 组件的方法列表
  56. */
  57. methods: {
  58. closeXieyi: function () {
  59. this.triggerEvent('yuyue')
  60. },
  61. getRealname: function (e) {//获取用户输入的姓名
  62. this.data.subscribeData.realname = e.detail.value;
  63. },
  64. getMobile: function (e) {//获取用户输入的电话---有验证码
  65. this.data.subscribeData.mobile = e.detail.value;
  66. },
  67. getMobile2: function (e) {//获取用户输入的电话---无验证码
  68. this.data.mobile2 = e.detail.value;
  69. },
  70. getCaptcha: function (e) {//获取用户输入的验证码
  71. this.data.subscribeData.captcha = e.detail.value;
  72. },
  73. loadFun: function () {
  74. if (app.globalData.userMobile) {
  75. this.data.subscribeData.mobile = app.globalData.userMobile;
  76. this.setData({
  77. phoneInputShow: true,
  78. subscribeData: this.data.subscribeData
  79. })
  80. }
  81. if (app.globalData.userInfoData) {
  82. this.setData({
  83. userData: app.globalData.userInfoData
  84. })
  85. }
  86. this.getUserLocation();//获取用户当前位置
  87. },
  88. getDistributorList: function (longitude, latitude) {//获取经销商列表
  89. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
  90. if (res.code == 200) {
  91. //整理数据
  92. var datas = res.data;
  93. var province = [];
  94. var city = [];
  95. for (let i = 0; i < res.data.list.length; i++) {
  96. province.push(res.data.list[i].province);
  97. }
  98. for (let j = 0; j < res.data.list[res.data.nearData.provinceIndex].children.length; j++) {
  99. city.push(res.data.list[res.data.nearData.provinceIndex].children[j].city)
  100. }
  101. //将数据赋值给变量
  102. this.setData({
  103. provinceDataAll: res.data.list,
  104. provinceDataArr: [province, city],
  105. provinceDataValue: [res.data.nearData.provinceIndex, res.data.nearData.cityIndex],
  106. nowProvince: province[res.data.nearData.provinceIndex] + " " + city[res.data.nearData.cityIndex],
  107. storeArr: res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children,
  108. storeValue: res.data.nearData.agentIndex
  109. })
  110. } else {
  111. wx.showToast({
  112. title: res.msg,
  113. icon: "none"
  114. })
  115. }
  116. }, this);
  117. },
  118. getCode: function (e) {//获取验证码
  119. if (!app.mobileVerify(this.data.mobile2)) {
  120. if (this.data.mobile2) {
  121. wx.showToast({
  122. title: '请输入正确的电话',
  123. icon: 'none'
  124. })
  125. } else {
  126. wx.showToast({
  127. title: '请输入电话',
  128. icon: 'none'
  129. })
  130. }
  131. return;
  132. }
  133. if (!this.data.sendCode) {
  134. return;
  135. }
  136. this.data.sendCode = false;
  137. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.mobile2 }, res => {
  138. if (res.code == 200) {
  139. this.countDown();
  140. wx.showToast({
  141. title: '验证码获取成功',
  142. icon: "none"
  143. })
  144. this.setData({
  145. verificationCode: 60
  146. })
  147. } else {
  148. this.data.sendCode = true;
  149. wx.showToast({
  150. title: res.msg,
  151. icon: "none"
  152. })
  153. }
  154. }, this)
  155. },
  156. countDown: function () {//倒计时
  157. setTimeout(() => {
  158. this.setData({
  159. verificationCode: this.data.verificationCode - 1
  160. })
  161. if (this.data.verificationCode > 0) {
  162. this.countDown();
  163. } else {
  164. this.setData({
  165. verificationCode: "获取验证码"
  166. })
  167. this.data.sendCode = true;
  168. }
  169. }, 1000);
  170. },
  171. subscribeFun: function (e) {//预约鉴赏
  172. if (!this.data.subscribeData.realname) {
  173. wx.showToast({
  174. title: '请输入姓名',
  175. icon: "none"
  176. })
  177. return;
  178. }
  179. if (!this.data.mobile2 && this.data.mobileType==2) {
  180. wx.showToast({
  181. title: '请输入电话',
  182. icon: "none"
  183. })
  184. return;
  185. }
  186. if (this.data.mobileType == 2) {
  187. if (!this.data.subscribeData.captcha) {
  188. wx.showToast({
  189. title: '请输入验证码',
  190. icon: "none"
  191. })
  192. return;
  193. }
  194. }
  195. if (!this.data.isAgreement) {
  196. wx.showToast({
  197. title: '请同意协议',
  198. icon: 'none'
  199. })
  200. return;
  201. }
  202. if (!this.data.appointment) {
  203. return;
  204. }
  205. this.data.appointment = false;
  206. this.data.subscribeData.province = this.data.provinceDataArr[0][this.data.provinceDataValue[0]];
  207. this.data.subscribeData.city = this.data.provinceDataArr[1][this.data.provinceDataValue[1]];
  208. this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
  209. this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
  210. var sourceMobile = this.data.subscribeData.mobile;
  211. if(this.data.mobileType==2){
  212. this.data.subscribeData.mobile = this.data.mobile2;
  213. }
  214. this.data.subscribeData.parentOpenid = app.globalData.parentOpenid;
  215. app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
  216. this.data.subscribeData.mobile = sourceMobile;
  217. this.data.appointment = true;
  218. if (res.code == 200) {
  219. if (this.data.enterType=='coupon'){
  220. wx.reLaunch({
  221. url: '/pages/index/index'
  222. })
  223. return;
  224. }
  225. wx.showToast({
  226. title: '预约成功',
  227. mask:true
  228. })
  229. setTimeout(()=>{
  230. this.closeXieyi();
  231. },1500)
  232. // this.data.subscribeData.realname = "";
  233. // this.data.subscribeData.captcha = "";
  234. // this.setData({
  235. // subscribeData: this.data.subscribeData,
  236. // verificationCode: '获取验证码',
  237. // })
  238. // this.setData({
  239. // siteSelect: false
  240. // })
  241. // this.setData({
  242. // isRegister: true
  243. // })
  244. // app.globalData.isRegister = true;
  245. // app.globalData.userMobile = this.data.subscribeData.mobile;
  246. } else {
  247. wx.showToast({
  248. title: res.msg,
  249. icon: "none"
  250. })
  251. }
  252. }, this, "POST")
  253. },
  254. provinceDataChange: function (e) {
  255. if (e.detail.column == 0) {
  256. var city = [];
  257. for (let i = 0; i < this.data.provinceDataAll[e.detail.value].children.length; i++) {
  258. city.push(this.data.provinceDataAll[e.detail.value].children[i].city);
  259. }
  260. this.data.provinceDataArr[1] = city;
  261. this.setData({
  262. provinceDataArr: this.data.provinceDataArr
  263. })
  264. }
  265. },
  266. provinceDataChane: function (e) {
  267. this.setData({
  268. provinceDataValue: e.detail.value,
  269. nowProvince: this.data.provinceDataArr[0][e.detail.value[0]] + " " + this.data.provinceDataArr[1][e.detail.value[1]],
  270. storeArr: this.data.provinceDataAll[e.detail.value[0]].children[e.detail.value[1]].children,
  271. storeValue: 0
  272. })
  273. },
  274. storeChane: function (e) {
  275. this.setData({
  276. storeValue: e.detail.value
  277. })
  278. },
  279. getUserPhone: function (e) {//获取用户手机号
  280. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  281. app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
  282. if (res.code == 200) {
  283. this.setData({
  284. phoneInputShow: true
  285. })
  286. this.cutType();
  287. if (res.data && res.data.decodeData) {
  288. this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
  289. this.setData({
  290. subscribeData: this.data.subscribeData
  291. })
  292. }
  293. } else {
  294. wx.showToast({
  295. title: res.msg,
  296. icon: "none"
  297. })
  298. }
  299. }, this);
  300. }
  301. },
  302. agreementState: function () {//协议
  303. this.setData({
  304. isAgreement: !this.data.isAgreement
  305. })
  306. },
  307. lookMore: function () {
  308. wx.navigateTo({
  309. url: '/pages/moreType/moreType',
  310. })
  311. },
  312. showSite: function () {//显示地址选择框
  313. if (!this.data.siteSelect) {
  314. if (!app.globalData.myCenterData) {
  315. } else {
  316. this.setData({
  317. siteSelect: true
  318. })
  319. }
  320. }
  321. },
  322. getUserLocation: function (e) {
  323. wx.getLocation({
  324. type: 'wgs84', //wgs84 gcj02
  325. success: (res) => {
  326. this.getDistributorList(res.longitude, res.latitude);
  327. },
  328. fail: (res) => {
  329. this.getDistributorList("", "");
  330. }
  331. })
  332. },
  333. agreementControl: function () {
  334. this.setData({
  335. agreement: !this.data.agreement
  336. })
  337. },
  338. cutType:function(){
  339. this.setData({
  340. mobileType: this.data.mobileType==1?2:1
  341. })
  342. },
  343. getUserWxMsg:function(e){//通过微信获取用户信息
  344. if (e.detail.errMsg == "getUserInfo:ok") {
  345. this.data.userData = {};
  346. this.data.userData.avatarUrl = e.detail.userInfo.avatarUrl;
  347. this.data.userData.nickName = e.detail.userInfo.nickName;
  348. this.setData({
  349. userData: this.data.userData
  350. })
  351. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  352. }
  353. this.subscribeFun();
  354. }
  355. }
  356. })