C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

358 行
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. tempFilePaths: '',
  16. userInfo: {},
  17. hasUserInfo: false,
  18. canIUse: wx.canIUse('button.open-type.getUserInfo')
  19. },
  20. phone: function () {
  21. let that = this;
  22. console.log(that.data);
  23. if (that.data.data.merchantLinkPhone) {
  24. wx.makePhoneCall({
  25. phoneNumber: that.data.data.merchantLinkPhone
  26. });
  27. }
  28. },
  29. onLoad(options) {
  30. let that = this;
  31. wx.showLoading({
  32. title: "加载中..."
  33. });
  34. /**
  35. * 暂时注销
  36. * this.orderFunc()
  37. */
  38. that.setData({
  39. couponChannelId: options.couponChannelId,
  40. couponId: options.couponId
  41. });
  42. var parmer = {
  43. url: config.api.couponDetail,
  44. data: {
  45. couponChannelId: options.couponChannelId
  46. }
  47. };
  48. Http.get(parmer).then(res => {
  49. console.log(res.data);
  50. //当前时间与优惠券下架时间做计算
  51. var endTime = util.fmtDate(res.data.endTime);
  52. if (util.timechuo(endTime).indexOf('-') == 0) {
  53. that.setData({
  54. endtime: "活动已结束",
  55. });
  56. } else {
  57. that.setData({
  58. endtime: util.timechuo(endTime)
  59. });
  60. }
  61. wx.hideLoading();
  62. that.setData({
  63. data: res.data
  64. });
  65. if (res.data.validType == 1) {
  66. that.setData({
  67. validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dddd"),
  68. validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dddd"),
  69. });
  70. } else {
  71. that.setData({
  72. validDays: res.data.validDays
  73. });
  74. }
  75. });
  76. },
  77. /**
  78. * 支付订单更新
  79. */
  80. payOrderUpdate: (orderId, payOrderId, status, reason) => {
  81. // 支付成功
  82. Http.post({
  83. url: config.api.payOrderUpdate,
  84. data: {
  85. payOrderId: payOrderId,
  86. orderId: orderId,
  87. status: status,
  88. reason: reason
  89. }
  90. })
  91. .then(res => {
  92. console.log("payOrderUpdate then", res);
  93. })
  94. .catch(err => {
  95. console.log("payOrderUpdate catch", err);
  96. });
  97. },
  98. /**
  99. * 发起支付
  100. */
  101. orderFunc() {
  102. var that = this;
  103. wx.showLoading({
  104. title: "加载中..."
  105. });
  106. if (that.data.data.type == 6) { } else {
  107. Http.post({
  108. url: config.api.checkPhoneStatus,
  109. data: {}
  110. })
  111. .then(res => {
  112. console.log(res);
  113. var data = {
  114. couponChannelId: "" + that.data.couponChannelId,
  115. couponId: "" + that.data.couponId
  116. };
  117. if (that.data.couponChannelId == null) {
  118. var data = {
  119. couponId: "" + that.data.couponId
  120. };
  121. }
  122. /**
  123. * orderSave 下单
  124. */
  125. return Http.post({
  126. url: config.api.orderSave,
  127. data: data
  128. });
  129. })
  130. .catch(err => {
  131. console.log(err);
  132. if (err.code == "2011") {
  133. wx.showToast({
  134. title: "商户信息没找到",
  135. image: "./../../../assets/img/fail.png",
  136. duration: 2000,
  137. mask: false
  138. });
  139. } else if (err.code == "2013") {
  140. wx.showToast({
  141. title: "商户信息禁用",
  142. image: "./../../../assets/img/fail.png",
  143. duration: 2000,
  144. mask: false
  145. });
  146. } else if (err.code == "3000") {
  147. wx.showToast({
  148. title: "库存不足",
  149. image: "./../../../assets/img/fail.png",
  150. duration: 2000,
  151. mask: false
  152. });
  153. } else if (err.code == "3001") {
  154. wx.showToast({
  155. title: "领取达到上限",
  156. image: "./../../../assets/img/fail.png",
  157. duration: 2000,
  158. mask: false
  159. });
  160. } else if (err.code == "3002") {
  161. wx.showToast({
  162. title: "订单失败",
  163. image: "./../../../assets/img/fail.png",
  164. duration: 2000,
  165. mask: false
  166. });
  167. } else if (err.code == "3003") {
  168. wx.showToast({
  169. title: "订单不存在",
  170. image: "./../../../assets/img/fail.png",
  171. duration: 2000,
  172. mask: false
  173. });
  174. } else if (err.code == "3004") {
  175. wx.showToast({
  176. title: "订单不存在",
  177. image: "./../../../assets/img/fail.png",
  178. duration: 2000,
  179. mask: false
  180. });
  181. } else if (err.code == "4003") {
  182. wx.showToast({
  183. title: "卡券已作废",
  184. image: "./../../../assets/img/fail.png",
  185. duration: 2000,
  186. mask: false
  187. });
  188. } else if (err.code == 11005) {
  189. // 用户手机未授权
  190. /**
  191. * 将值传到用户手机号授权的页面
  192. *
  193. */
  194. wx.redirectTo({
  195. url: "/pages/getphoneInfo/index?couponChannelId=" +
  196. that.data.couponChannelId +
  197. "&couponId=" +
  198. that.data.couponId
  199. });
  200. } else if (err.code == 11006) {
  201. // 用户手机已加密
  202. wx.redirectTo({
  203. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  204. that.data.couponChannelId +
  205. "&couponId=" +
  206. that.data.couponId
  207. });
  208. } else {
  209. wx.showToast({
  210. title: err.message,
  211. image: "./../../../assets/img/fail.png",
  212. duration: 2000,
  213. mask: false
  214. });
  215. }
  216. })
  217. .then(res => {
  218. console.log(res);
  219. console.log("点击领取卡券一直在loading");
  220. if (typeof (res) != "undefined") {
  221. console.log("", res);
  222. let orderId = "" + res.data.id;
  223. that.setData({
  224. orderId: orderId
  225. });
  226. if (res.data.payment > 0) {
  227. // 支付金额不为0
  228. /**
  229. * 支付订单创建
  230. */
  231. Http.post({
  232. url: config.api.payOrderCreate,
  233. data: {
  234. orderId: orderId
  235. }
  236. }).then(res => {
  237. console.log(res);
  238. /// Begin payment ----
  239. var payOrderId = "" + res.data.payOrderId;
  240. wx.hideLoading();
  241. wx.requestPayment({
  242. timeStamp: res.data.timeStamp,
  243. nonceStr: res.data.nonceStr,
  244. package: res.data.package,
  245. signType: (res.data.signType) ? res.data.signType : "MD5",
  246. paySign: res.data.paySign,
  247. success: res => {
  248. that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功
  249. console.log(res);
  250. if (res.errMsg == "requestPayment:ok") {
  251. setTimeout(function () {
  252. wx.hideLoading();
  253. }, 2000);
  254. setTimeout(() => {
  255. wx.navigateTo({
  256. url: `/pages/order/detail/index?orderId=${
  257. that.data.orderId
  258. }`
  259. });
  260. }, 1000)
  261. /**
  262. * 用户支付成功以后跳转到券包列表
  263. */
  264. wx.setStorage({
  265. key: 'couponNum',
  266. data: "couponNum",
  267. })
  268. if (that.data.data.type == 5) {
  269. setTimeout(() => {
  270. wx.switchTab({
  271. url: '/pages/passCar/passCar'
  272. });
  273. }, 1600);
  274. // this.initUsrCarList()
  275. // 领取 5.停车券
  276. // TODO 选取用户下的车牌
  277. }
  278. }
  279. },
  280. fail: res => {
  281. that.payOrderUpdate(that.data.orderId, payOrderId, 2); // 支付失败
  282. console.log(res);
  283. return;
  284. },
  285. complete: res => {
  286. }
  287. });
  288. /// End payment --------
  289. ///// virtual pay
  290. //var payOrderId = "" + res.data.out_trade_no;
  291. //that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功
  292. ///// end virtual pay
  293. });
  294. } else {
  295. // 免费券
  296. that.payOrderUpdate(orderId, "0", 1);
  297. wx.setStorage({
  298. key: 'couponNum',
  299. data: "couponNum"
  300. })
  301. setTimeout(function () {
  302. wx.navigateTo({
  303. url: `/pages/order/detail/index?orderId=${
  304. that.data.orderId
  305. }`
  306. });
  307. }, 1000)
  308. //////////////////////////停车券
  309. console.log(that.data.data.type)
  310. if (that.data.data.type == 5) {
  311. setTimeout(() => {
  312. wx.switchTab({
  313. url: '/pages/passCar/passCar'
  314. });
  315. }, 1600);
  316. }
  317. }
  318. }
  319. })
  320. .catch(err => {
  321. console.log("ERR", err);
  322. });
  323. }
  324. },
  325. onShareAppMessage: function (options) {
  326. var that = this;
  327. var shareObj = {
  328. title: options.target.dataset.title,
  329. path: '/pages/index/index',
  330. success: function (res) {
  331. if (res.errMsg == 'shareAppMessage:ok') {
  332. console.log(res)
  333. }
  334. },
  335. fail: function (error) {
  336. if (res.errMsg == 'shareAppMessage:fail cancel') {
  337. console.log(error)
  338. } else if (res.errMsg == 'shareAppMessage:fail') {
  339. console.log(error)
  340. }
  341. }
  342. };
  343. // 来自页面内的按钮的转发
  344. if (options.from == 'button') {
  345. console.log(options)
  346. var eData = options.target.dataset.id;
  347. var couponId = options.target.dataset.couponid;
  348. shareObj.path = `/pages/coupon/detail/index?couponChannelId=${eData}&couponId=${couponId}`;
  349. }
  350. // 返回shareObj
  351. return shareObj;
  352. }
  353. });