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

yuyue.js 10KB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. },
  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.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.mobile2)) {
  109. if (this.data.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.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.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.mobile2;
  202. }
  203. this.data.subscribeData.parentOpenid = app.globalData.parentOpenid;
  204. app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
  205. this.data.subscribeData.mobile = sourceMobile;
  206. this.data.appointment = true;
  207. if (res.code == 200) {
  208. if (app.globalData.nowPage=='0'){
  209. wx.reLaunch({
  210. url: '/pages/index/index'
  211. })
  212. return;
  213. }
  214. wx.showToast({
  215. title: '预约成功'
  216. })
  217. this.data.subscribeData.realname = "";
  218. this.data.subscribeData.captcha = "";
  219. this.setData({
  220. subscribeData: this.data.subscribeData,
  221. verificationCode: '获取验证码',
  222. })
  223. this.setData({
  224. siteSelect: false
  225. })
  226. // this.setData({
  227. // isRegister: true
  228. // })
  229. // app.globalData.isRegister = true;
  230. // app.globalData.userMobile = this.data.subscribeData.mobile;
  231. } else {
  232. wx.showToast({
  233. title: res.msg,
  234. icon: "none"
  235. })
  236. }
  237. }, this, "POST")
  238. },
  239. provinceDataChange: function (e) {
  240. if (e.detail.column == 0) {
  241. var city = [];
  242. for (let i = 0; i < this.data.provinceDataAll[e.detail.value].children.length; i++) {
  243. city.push(this.data.provinceDataAll[e.detail.value].children[i].city);
  244. }
  245. this.data.provinceDataArr[1] = city;
  246. this.setData({
  247. provinceDataArr: this.data.provinceDataArr
  248. })
  249. }
  250. },
  251. provinceDataChane: function (e) {
  252. this.setData({
  253. provinceDataValue: e.detail.value,
  254. nowProvince: this.data.provinceDataArr[0][e.detail.value[0]] + " " + this.data.provinceDataArr[1][e.detail.value[1]],
  255. storeArr: this.data.provinceDataAll[e.detail.value[0]].children[e.detail.value[1]].children,
  256. storeValue: 0
  257. })
  258. },
  259. storeChane: function (e) {
  260. this.setData({
  261. storeValue: e.detail.value
  262. })
  263. },
  264. getUserPhone: function (e) {//获取用户手机号
  265. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  266. app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
  267. if (res.code == 200) {
  268. this.setData({
  269. phoneInputShow: true
  270. })
  271. this.cutType();
  272. if (res.data && res.data.decodeData) {
  273. this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
  274. this.setData({
  275. subscribeData: this.data.subscribeData
  276. })
  277. }
  278. } else {
  279. wx.showToast({
  280. title: res.msg,
  281. icon: "none"
  282. })
  283. }
  284. }, this);
  285. }
  286. },
  287. agreementState: function () {//协议
  288. this.setData({
  289. isAgreement: !this.data.isAgreement
  290. })
  291. },
  292. lookMore: function () {
  293. wx.navigateTo({
  294. url: '/pages/moreType/moreType',
  295. })
  296. },
  297. showSite: function () {//显示地址选择框
  298. if (!this.data.siteSelect) {
  299. if (!app.globalData.myCenterData) {
  300. } else {
  301. this.setData({
  302. siteSelect: true
  303. })
  304. }
  305. }
  306. },
  307. getUserLocation: function (e) {
  308. wx.getLocation({
  309. type: 'gcj02', //wgs84
  310. success: (res) => {
  311. this.getDistributorList(res.longitude, res.latitude);
  312. },
  313. fail: (res) => {
  314. this.getDistributorList("", "");
  315. }
  316. })
  317. },
  318. agreementControl: function () {
  319. this.setData({
  320. agreement: !this.data.agreement
  321. })
  322. },
  323. cutType:function(){
  324. this.setData({
  325. mobileType: this.data.mobileType==1?2:1
  326. })
  327. }
  328. }
  329. })