东风启辰小程序端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

373 lines
11KB

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