C端小程序
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.

447 rivejä
13 KiB

  1. var config = require("../../../config/config.js");
  2. var app = getApp();
  3. const Http = require("../../../utils/HttpBasics");
  4. const util = require("../../../utils/util");
  5. Page({
  6. data: {
  7. data: {},
  8. carList: [],
  9. couponChannelId: null,
  10. couponId: null,
  11. orderId: "",
  12. day: "",
  13. hour: "",
  14. minute: ""
  15. },
  16. phone: function () {
  17. let that = this;
  18. console.log(that.data);
  19. if (that.data.data.merchantLinkPhone) {
  20. wx.makePhoneCall({
  21. phoneNumber: that.data.data.merchantLinkPhone
  22. });
  23. }
  24. },
  25. onLoad(options) {
  26. let that = this;
  27. wx.showLoading({
  28. title: "加载中..."
  29. });
  30. /**
  31. * 暂时注销
  32. * this.orderFunc()
  33. */
  34. // if (options.flag) {
  35. // // this.orderFunc();
  36. // }
  37. // else {
  38. // }
  39. that.setData({
  40. couponChannelId: options.couponChannelId,
  41. couponId: options.couponId
  42. });
  43. var parmer = {
  44. url: config.api.couponDetail,
  45. data: {
  46. couponChannelId: options.couponChannelId
  47. }
  48. };
  49. Http.get(parmer).then(res => {
  50. console.log(res);
  51. console.log("details");
  52. //当前时间与优惠券下架时间做计算
  53. var endTime = util.fmtDate(res.data.endTime);
  54. util.timechuo(endTime);
  55. that.setData({
  56. endtime: util.timechuo(endTime)
  57. });
  58. wx.hideLoading();
  59. that.setData({
  60. data: res.data
  61. });
  62. });
  63. // }
  64. },
  65. /**
  66. * 支付订单更新
  67. */
  68. payOrderUpdate: (orderId, payOrderId, status, reason) => {
  69. // 支付成功
  70. Http.post({
  71. url: config.api.payOrderUpdate,
  72. data: {
  73. payOrderId: payOrderId,
  74. orderId: orderId,
  75. status: status,
  76. reason: reason
  77. }
  78. })
  79. .then(res => {
  80. console.log("payOrderUpdate then", res);
  81. // wx.showToast({
  82. // title: "购买成功",
  83. // duration: 2500
  84. // });
  85. })
  86. .catch(err => {
  87. console.log("payOrderUpdate catch", err);
  88. });
  89. },
  90. /**
  91. * 拉取车牌列表
  92. */
  93. // init: function () {
  94. // var that = this
  95. // app.parkInitCallback = token => {
  96. // that.initPark()
  97. // that.initUsrCarList()
  98. // if (!app.globalData.carLogin) {
  99. // // 共同登录
  100. // Http.post({
  101. // url: config.api.carInit,
  102. // data: {
  103. // phone: app.globalData.phone
  104. // }
  105. // }).then(res => {
  106. // app.globalData.carLogin = true
  107. // app.globalData.parkVendor = res.data.vendor
  108. // if (res.data.token != "undefined") {
  109. // app.globalData.etcpToken = res.data.token
  110. // console.log("etcpToken", app.globalData.etcpToken)
  111. // }
  112. // // 获取 停车费
  113. // that.getStopFee()
  114. // })
  115. // }
  116. // }
  117. // if (app.globalData.token && app.globalData.token != null) {
  118. // app.parkInitCallback(app.globalData.token)
  119. // }
  120. // },
  121. // getStopFee: function () {
  122. // var that = this
  123. // // carLogin
  124. // for (var i = 0; i < that.data.carList.length; i++) {
  125. // that.getStopFeeItem(that.data.carList[i], i)
  126. // }
  127. // // console.log(JSON.stringify(getStopFeeItem))
  128. // },
  129. // initPark: function () {
  130. // var that = this
  131. // // 车场信息获取
  132. // Http.get({
  133. // url: config.api.getParkInfo,
  134. // data: {}
  135. // })
  136. // .then(res => {
  137. // console.log(res)
  138. // that.setData({
  139. // park: res.data,
  140. // })
  141. // })
  142. // },
  143. // initUsrCarList: function () {
  144. // var that = this
  145. // // 绑定车获取
  146. // Http.get({
  147. // url: config.api.getUserCarList,
  148. // data: {}
  149. // }).then(res => {
  150. // console.log('>>>>>>>>>>>>>>>>>1' + JSON.stringify(res));
  151. // that.setData({
  152. // carList: res.data
  153. // })
  154. // })
  155. // },
  156. /**
  157. * 发起支付
  158. */
  159. orderFunc() {
  160. var that = this;
  161. wx.showLoading({
  162. title: "加载中..."
  163. });
  164. if (that.data.data.type == 6) {} else {
  165. Http.post({
  166. url: config.api.checkPhoneStatus,
  167. data: {}
  168. })
  169. .then(res => {
  170. console.log(res);
  171. var data = {
  172. couponChannelId: "" + that.data.couponChannelId,
  173. couponId: "" + that.data.couponId
  174. };
  175. if (that.data.couponChannelId == null) {
  176. var data = {
  177. couponId: "" + that.data.couponId
  178. };
  179. }
  180. /**
  181. * orderSave 下单
  182. */
  183. return Http.post({
  184. url: config.api.orderSave,
  185. data: data
  186. });
  187. })
  188. .catch(err => {
  189. console.log(err);
  190. if (err.code == "2011") {
  191. wx.showToast({
  192. title: "商户信息没找到",
  193. image: "./../../../assets/img/fail.png",
  194. duration: 2000,
  195. mask: false
  196. });
  197. }
  198. else if (err.code == "2013") {
  199. wx.showToast({
  200. title: "商户信息禁用",
  201. image: "./../../../assets/img/fail.png",
  202. duration: 2000,
  203. mask: false
  204. });
  205. }
  206. else if (err.code == "3000") {
  207. wx.showToast({
  208. title: "库存不足",
  209. image: "./../../../assets/img/fail.png",
  210. duration: 2000,
  211. mask: false
  212. });
  213. }
  214. else if (err.code == "3001") {
  215. wx.showToast({
  216. title: "领取达到上限",
  217. image: "./../../../assets/img/fail.png",
  218. duration: 2000,
  219. mask: false
  220. });
  221. }
  222. else if (err.code == "3002") {
  223. wx.showToast({
  224. title: "订单失败",
  225. image: "./../../../assets/img/fail.png",
  226. duration: 2000,
  227. mask: false
  228. });
  229. }
  230. else if (err.code == "3003") {
  231. wx.showToast({
  232. title: "订单不存在",
  233. image: "./../../../assets/img/fail.png",
  234. duration: 2000,
  235. mask: false
  236. });
  237. }
  238. else if (err.code == "3004") {
  239. wx.showToast({
  240. title: "订单不存在",
  241. image: "./../../../assets/img/fail.png",
  242. duration: 2000,
  243. mask: false
  244. });
  245. }
  246. else if (err.code == "4003") {
  247. wx.showToast({
  248. title: "卡券已作废",
  249. image: "./../../../assets/img/fail.png",
  250. duration: 2000,
  251. mask: false
  252. });
  253. }
  254. else if (err.code == 11005) {
  255. // 用户手机未授权
  256. /**
  257. * 将值传到用户手机号授权的页面
  258. *
  259. */
  260. wx.redirectTo({
  261. url: "/pages/getphoneInfo/index?couponChannelId=" +
  262. that.data.couponChannelId +
  263. "&couponId=" +
  264. that.data.couponId
  265. });
  266. }
  267. else if (err.code == 11006) {
  268. // 用户手机已加密
  269. wx.redirectTo({
  270. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  271. that.data.couponChannelId +
  272. "&couponId=" +
  273. that.data.couponId
  274. });
  275. } else {
  276. wx.showToast({
  277. title: err.message,
  278. image: "./../../../assets/img/fail.png",
  279. duration: 2000,
  280. mask: false
  281. });
  282. }
  283. })
  284. .then(res => {
  285. console.log(res);
  286. console.log("点击领取卡券一直在loading");
  287. if (typeof (res) != "undefined") {
  288. console.log("", res);
  289. let orderId = "" + res.data.id;
  290. that.setData({
  291. orderId: orderId
  292. });
  293. if (res.data.payment > 0) {
  294. // 支付金额不为0
  295. /**
  296. * 支付订单创建
  297. */
  298. Http.post({
  299. url: config.api.payOrderCreate,
  300. data: {
  301. orderId: orderId
  302. }
  303. }).then(res => {
  304. console.log(res);
  305. /// Begin payment ----
  306. var payOrderId = "" + res.data.payOrderId;
  307. wx.hideLoading();
  308. wx.requestPayment({
  309. timeStamp: res.data.timeStamp,
  310. nonceStr: res.data.nonceStr,
  311. package: res.data.package,
  312. signType: (res.data.signType) ? res.data.signType : "MD5",
  313. paySign: res.data.paySign,
  314. success: res => {
  315. that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功
  316. console.log(res);
  317. if (res.errMsg == "requestPayment:ok") {
  318. // wx.showToast({
  319. // title: "购买成功",
  320. // image: "./../../../assets/img/success.png",
  321. // duration: 1000,
  322. // mask: false,
  323. // success: function () {
  324. // setTimeout(function () {
  325. // wx.hideLoading();
  326. // }, 2000);
  327. // setTimeout(() => {
  328. // wx.navigateTo({
  329. // url: `/pages/order/detail/index?orderId=${
  330. // that.data.orderId
  331. // }`
  332. // });
  333. // }, 1000)
  334. // }
  335. // });
  336. setTimeout(function () {
  337. wx.hideLoading();
  338. }, 2000);
  339. setTimeout(() => {
  340. wx.navigateTo({
  341. url: `/pages/order/detail/index?orderId=${
  342. that.data.orderId
  343. }`
  344. });
  345. }, 1000)
  346. /**
  347. * 用户支付成功以后跳转到券包列表
  348. */
  349. wx.setStorage({
  350. key: 'couponNum',
  351. data: "couponNum",
  352. })
  353. if (that.data.data.type == 5) {
  354. setTimeout(() => {
  355. wx.switchTab({
  356. url: '/pages/passCar/passCar'
  357. });
  358. }, 1600);
  359. // this.initUsrCarList()
  360. // 领取 5.停车券
  361. // TODO 选取用户下的车牌
  362. }
  363. }
  364. },
  365. fail: res => {
  366. that.payOrderUpdate(that.data.orderId, payOrderId, 2); // 支付失败
  367. console.log(res);
  368. // wx.showToast({
  369. // title: "支付失败",
  370. // image: "./../../../assets/img/fail.png",
  371. // duration: 2000,
  372. // mask: false
  373. // });
  374. return;
  375. },
  376. complete: res => {
  377. // console.log(res);
  378. // console.log("支付完成");
  379. // if (res.errMsg == "requestPayment:ok") {
  380. // } else {
  381. // wx.showToast({
  382. // title: "支付失败",
  383. // image: "./../../../assets/img/fail.png",
  384. // duration: 2000,
  385. // mask: false
  386. // });
  387. // }
  388. // return;
  389. }
  390. });
  391. /// End payment --------
  392. ///// virtual pay
  393. //var payOrderId = "" + res.data.out_trade_no;
  394. //that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功
  395. ///// end virtual pay
  396. });
  397. } else {
  398. // 免费券
  399. that.payOrderUpdate(orderId, "0", 1);
  400. wx.setStorage({
  401. key: 'couponNum',
  402. data: "couponNum"
  403. })
  404. // wx.showToast({
  405. // title: "领取成功",
  406. // image: "./../../../assets/img/success.png",
  407. // duration: 1000,
  408. // mask: false,
  409. // success: function () {
  410. // }
  411. // });
  412. setTimeout(function () {
  413. wx.navigateTo({
  414. url: `/pages/order/detail/index?orderId=${
  415. that.data.orderId
  416. }`
  417. });
  418. }, 1000)
  419. //////////////////////////停车券
  420. console.log(that.data.data.type)
  421. if (that.data.data.type == 5) {
  422. setTimeout(() => {
  423. wx.switchTab({
  424. url: '/pages/passCar/passCar'
  425. });
  426. }, 1600);
  427. }
  428. }
  429. }
  430. })
  431. .catch(err => {
  432. console.log("ERR", err);
  433. });
  434. }
  435. }
  436. });