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

325 linhas
9.9KB

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