C端小程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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