东风启辰小程序端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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