东风启辰小程序端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

354 linhas
11KB

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