东风启辰小程序端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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