东风启辰小程序端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

placingOrder.js 11KB

před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
před 5 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. app.wxRequest(app.globalData.urlRoot + "wxPay/preBuy", this.data.subscribeData, res => {
  261. this.data.subscribeData.mobile = sourceMobile;
  262. if (res.code == 200) {
  263. wx.requestPayment({
  264. timeStamp: res.data.jsSubmit.timeStamp,
  265. nonceStr: res.data.jsSubmit.nonceStr,
  266. signType: res.data.jsSubmit.signType,
  267. package: res.data.jsSubmit.package,
  268. paySign: res.data.jsSubmit.paySign,
  269. success:(option)=>{
  270. this.paySuccess(res.data.trade_id);
  271. },
  272. fail: (option) => {
  273. this.data.appointment = true;
  274. wx.showToast({
  275. title: '支付失败',
  276. icon:"none"
  277. })
  278. }
  279. })
  280. } else {
  281. this.data.appointment = true;
  282. wx.showToast({
  283. title: res.msg,
  284. icon: "none"
  285. })
  286. }
  287. }, this, "POST")
  288. },
  289. paySuccess: function (e) {//支付成功
  290. app.wxRequest(app.globalData.urlRoot + "wxPay/paySuccess", { source:2,trade_id:e},res=>{
  291. if(res.code==200){
  292. // wx.showToast({
  293. // title: '下订成功',
  294. // mask:true
  295. // })
  296. this.setData({
  297. getBuyState:true
  298. })
  299. app.globalData.getBuyState = {};
  300. app.globalData.getBuyState.success = true;
  301. app.globalData.getBuyState.cdate = res.data.cdate;
  302. app.globalData.getBuyState.coupon_code = res.data.coupon_code;
  303. // setTimeout(()=>{
  304. // this.closeXieyi();
  305. // },1500)
  306. } else {
  307. this.data.appointment = true;
  308. wx.showToast({
  309. title: res.msg,
  310. icon:'none'
  311. })
  312. }
  313. },this,"POST");
  314. },
  315. closePage:function(){
  316. this.closeXieyi();
  317. // wx.reLaunch({
  318. // url: '/pages/index/index',
  319. // })
  320. },
  321. provinceDataChange:function(e){
  322. if (e.detail.column==0) {
  323. var city = [];
  324. for (let i = 0; i < this.data.provinceDataAll[e.detail.value].children.length;i++){
  325. city.push(this.data.provinceDataAll[e.detail.value].children[i].city);
  326. }
  327. this.data.provinceDataArr[1] = city;
  328. this.setData({
  329. provinceDataArr: this.data.provinceDataArr
  330. })
  331. }
  332. },
  333. provinceDataChane:function(e){
  334. this.setData({
  335. provinceDataValue: e.detail.value,
  336. nowProvince: this.data.provinceDataArr[0][e.detail.value[0]] + " " + this.data.provinceDataArr[1][e.detail.value[1]],
  337. storeArr: this.data.provinceDataAll[e.detail.value[0]].children[e.detail.value[1]].children,
  338. storeValue:0
  339. })
  340. },
  341. storeChane:function(e){
  342. this.setData({
  343. storeValue:e.detail.value
  344. })
  345. },
  346. enterMycenter:function(){
  347. wx.reLaunch({
  348. url: '/pages/myCenter/myCenter',
  349. })
  350. },
  351. cutType: function () {
  352. this.setData({
  353. mobileType: this.data.mobileType == 1 ? 2 : 1
  354. })
  355. },
  356. tipShowControl:function(){
  357. this.setData({
  358. tipShow:!this.data.tipShow
  359. })
  360. },
  361. tipShowControl2:function(){
  362. this.setData({
  363. tipShow:!this.data.tipShow
  364. })
  365. this.preBuy();
  366. }
  367. }
  368. })