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