东风启辰小程序端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

placingOrder.js 9.9KB

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