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

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