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.

441 line
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. console.log(that.data.couponChannelId);
  191. console.log(that.data.couponId);
  192. //console.log("我即将要跳转到用户手机号授权的页面");
  193. if (err.code == "2011") {
  194. wx.showToast({
  195. title: "商户信息没找到",
  196. image: "./../../../assets/img/fail.png",
  197. duration: 2000,
  198. mask: false
  199. });
  200. }
  201. else if (err.code == "2013") {
  202. wx.showToast({
  203. title: "商户信息禁用",
  204. image: "./../../../assets/img/fail.png",
  205. duration: 2000,
  206. mask: false
  207. });
  208. }
  209. else if (err.code == "3000") {
  210. wx.showToast({
  211. title: "库存不足",
  212. image: "./../../../assets/img/fail.png",
  213. duration: 2000,
  214. mask: false
  215. });
  216. }
  217. else if (err.code == "3001") {
  218. wx.showToast({
  219. title: "领取达到上限",
  220. image: "./../../../assets/img/fail.png",
  221. duration: 2000,
  222. mask: false
  223. });
  224. }
  225. else if (err.code == "3002") {
  226. wx.showToast({
  227. title: "订单失败",
  228. image: "./../../../assets/img/fail.png",
  229. duration: 2000,
  230. mask: false
  231. });
  232. }
  233. else if (err.code == "3003") {
  234. wx.showToast({
  235. title: "订单不存在",
  236. image: "./../../../assets/img/fail.png",
  237. duration: 2000,
  238. mask: false
  239. });
  240. }
  241. else if (err.code == "3004") {
  242. wx.showToast({
  243. title: "订单不存在",
  244. image: "./../../../assets/img/fail.png",
  245. duration: 2000,
  246. mask: false
  247. });
  248. }
  249. else if (err.code == "4003") {
  250. wx.showToast({
  251. title: "卡券已作废",
  252. image: "./../../../assets/img/fail.png",
  253. duration: 2000,
  254. mask: false
  255. });
  256. }
  257. else if (err.code == 11005) {
  258. // 用户手机未授权
  259. /**
  260. * 将值传到用户手机号授权的页面
  261. *
  262. */
  263. wx.redirectTo({
  264. url: "/pages/getphoneInfo/index?couponChannelId=" +
  265. that.data.couponChannelId +
  266. "&couponId=" +
  267. that.data.couponId
  268. });
  269. }
  270. else if (err.code == 11006) {
  271. // 用户手机已加密
  272. wx.redirectTo({
  273. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  274. that.data.couponChannelId +
  275. "&couponId=" +
  276. that.data.couponId
  277. });
  278. } else {
  279. wx.showToast({
  280. title: err.message,
  281. image: "./../../../assets/img/fail.png",
  282. duration: 2000,
  283. mask: false
  284. });
  285. }
  286. })
  287. .then(res => {
  288. console.log(res);
  289. console.log("点击领取卡券一直在loading");
  290. if (typeof (res) != "undefined") {
  291. console.log("", res);
  292. let orderId = "" + res.data.id;
  293. that.setData({
  294. orderId: orderId
  295. });
  296. if (res.data.payment > 0) {
  297. // 支付金额不为0
  298. /**
  299. * 支付订单创建
  300. */
  301. Http.post({
  302. url: config.api.payOrderCreate,
  303. data: {
  304. orderId: orderId
  305. }
  306. }).then(res => {
  307. console.log(res);
  308. /// Begin payment ----
  309. var payOrderId = "" + res.data.payOrderId;
  310. wx.hideLoading();
  311. wx.requestPayment({
  312. timeStamp: res.data.timeStamp,
  313. nonceStr: res.data.nonceStr,
  314. package: res.data.package,
  315. signType: (res.data.signType) ? res.data.signType : "MD5",
  316. paySign: res.data.paySign,
  317. success: res => {
  318. that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功
  319. console.log(res);
  320. if (res.errMsg == "requestPayment:ok") {
  321. wx.showToast({
  322. title: "购买成功",
  323. image: "./../../../assets/img/success.png",
  324. duration: 1000,
  325. mask: false,
  326. success: function () {
  327. setTimeout(function () {
  328. wx.hideLoading();
  329. }, 1600);
  330. setTimeout(() => {
  331. wx.navigateTo({
  332. url: `/pages/order/detail/index?orderId=${
  333. that.data.orderId
  334. }`
  335. });
  336. }, 1000)
  337. }
  338. });
  339. /**
  340. * 用户支付成功以后跳转到券包列表
  341. */
  342. wx.setStorage({
  343. key: 'couponNum',
  344. data: "couponNum",
  345. })
  346. if (that.data.data.type == 5) {
  347. setTimeout(() => {
  348. wx.switchTab({
  349. url: '/pages/passCar/passCar'
  350. });
  351. }, 1600);
  352. // this.initUsrCarList()
  353. // 领取 5.停车券
  354. // TODO 选取用户下的车牌
  355. }
  356. }
  357. },
  358. fail: res => {
  359. that.payOrderUpdate(that.data.orderId, payOrderId, 2); // 支付失败
  360. console.log(res);
  361. // wx.showToast({
  362. // title: "支付失败",
  363. // image: "./../../../assets/img/fail.png",
  364. // duration: 2000,
  365. // mask: false
  366. // });
  367. return;
  368. },
  369. complete: res => {
  370. // console.log(res);
  371. // console.log("支付完成");
  372. // if (res.errMsg == "requestPayment:ok") {
  373. // } else {
  374. // wx.showToast({
  375. // title: "支付失败",
  376. // image: "./../../../assets/img/fail.png",
  377. // duration: 2000,
  378. // mask: false
  379. // });
  380. // }
  381. // return;
  382. }
  383. });
  384. /// End payment --------
  385. ///// virtual pay
  386. //var payOrderId = "" + res.data.out_trade_no;
  387. //that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功
  388. ///// end virtual pay
  389. });
  390. } else {
  391. // 免费券
  392. that.payOrderUpdate(orderId, "0", 1);
  393. wx.setStorage({
  394. key: 'couponNum',
  395. data: "couponNum"
  396. })
  397. wx.showToast({
  398. title: "领取成功",
  399. image: "./../../../assets/img/success.png",
  400. duration: 1000,
  401. mask: false,
  402. success: function () {
  403. setTimeout(function () {
  404. wx.navigateTo({
  405. url: `/pages/order/detail/index?orderId=${
  406. that.data.orderId
  407. }`
  408. });
  409. }, 1000)
  410. }
  411. });
  412. //////////////////////////停车券
  413. console.log(that.data.data.type)
  414. if (that.data.data.type == 5) {
  415. setTimeout(() => {
  416. wx.switchTab({
  417. url: '/pages/passCar/passCar'
  418. });
  419. }, 1600);
  420. }
  421. }
  422. }
  423. })
  424. .catch(err => {
  425. console.log("ERR", err);
  426. });
  427. }
  428. }
  429. });