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

332 lines
10KB

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