东风启辰小程序端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

331 line
9.8KB

  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. if (app.globalData.userMobile) {
  77. this.data.subscribeData.mobile = app.globalData.userMobile;
  78. this.setData({
  79. phoneInputShow: true,
  80. subscribeData: this.data.subscribeData
  81. })
  82. }
  83. },
  84. getRealname: function (e) {//获取用户输入的姓名
  85. this.data.subscribeData.realname = e.detail.value;
  86. },
  87. getMobile: function (e) {//获取用户输入的电话
  88. this.data.subscribeData.mobile = e.detail.value;
  89. },
  90. getCaptcha: function (e) {//获取用户输入的验证码
  91. this.data.subscribeData.captcha = e.detail.value;
  92. },
  93. getDistributorList: function (longitude, latitude) {//获取经销商列表
  94. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
  95. if (res.code == 200) {
  96. //整理数据
  97. var datas = res.data;
  98. var province = [];
  99. var city = [];
  100. for(let i=0;i<res.data.list.length;i++){
  101. province.push(res.data.list[i].province);
  102. }
  103. for (let j = 0; j < res.data.list[res.data.nearData.provinceIndex].children.length; j++) {
  104. city.push(res.data.list[res.data.nearData.provinceIndex].children[j].city)
  105. }
  106. //将数据赋值给变量
  107. this.setData({
  108. provinceDataAll: res.data.list,
  109. provinceDataArr: [province, city],
  110. provinceDataValue: [res.data.nearData.provinceIndex, res.data.nearData.cityIndex],
  111. nowProvince: province[res.data.nearData.provinceIndex] + " " + city[res.data.nearData.cityIndex],
  112. storeArr: res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children,
  113. storeValue: res.data.nearData.agentIndex
  114. })
  115. } else {
  116. wx.showToast({
  117. title: res.msg,
  118. icon: "none"
  119. })
  120. }
  121. }, this);
  122. },
  123. getCode: function (e) {//获取验证码
  124. if (!app.mobileVerify(this.data.subscribeData.mobile)) {
  125. if (this.data.subscribeData.mobile) {
  126. wx.showToast({
  127. title: '请输入正确的电话',
  128. icon: 'none'
  129. })
  130. } else {
  131. wx.showToast({
  132. title: '请输入电话',
  133. icon: 'none'
  134. })
  135. }
  136. return;
  137. }
  138. if (!this.data.sendCode) {
  139. return;
  140. }
  141. this.data.sendCode = false;
  142. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.subscribeData.mobile }, res => {
  143. if (res.code == 200) {
  144. this.countDown();
  145. wx.showToast({
  146. title: '验证码获取成功',
  147. icon: "none"
  148. })
  149. this.setData({
  150. verificationCode: 60
  151. })
  152. } else {
  153. this.data.sendCode = true;
  154. wx.showToast({
  155. title: res.msg,
  156. icon: "none"
  157. })
  158. }
  159. }, this)
  160. },
  161. countDown: function () {//倒计时
  162. setTimeout(() => {
  163. this.setData({
  164. verificationCode: this.data.verificationCode - 1
  165. })
  166. if (this.data.verificationCode > 0) {
  167. this.countDown();
  168. } else {
  169. this.setData({
  170. verificationCode: "获取验证码"
  171. })
  172. this.data.sendCode = true;
  173. }
  174. }, 1000);
  175. },
  176. getUserLocation: function (e) {
  177. wx.getLocation({
  178. type: 'gcj02', //wgs84
  179. success: (res) => {
  180. this.getDistributorList(res.longitude, res.latitude);
  181. },
  182. fail: (res) => {
  183. this.getDistributorList("", "");
  184. },
  185. complete: (res) => {
  186. this.setData({
  187. siteSelect: true,
  188. })
  189. }
  190. })
  191. },
  192. showSite: function () {//显示地址选择框
  193. if (!this.data.siteSelect) {
  194. this.getUserLocation();//获取用户当前位置
  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. })