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

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