C端小程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

385 Zeilen
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. const imgurl = require("../../utils/imgurl");
  6. Page({
  7. data: {
  8. fenxiangUrl:imgurl.fenxiang.url,
  9. clockUrl:imgurl.clock.url,
  10. teljpgUrl:imgurl.teljpg.url,
  11. closedUrl:imgurl.closed.url,
  12. quesGouUrl:imgurl.ques_gou.url,
  13. headbgUrl:imgurl.headbg.url,
  14. quesBgUrl:imgurl.ques_bg.url,
  15. data: {
  16. title: null
  17. },
  18. showPage:false,
  19. questions1: null,
  20. questions2: null,
  21. carList: [],
  22. couponChannelId: null,
  23. couponId: null,
  24. orderId: "",
  25. hour: null,
  26. minute: "",
  27. tempFilePaths: null,
  28. userInfo: {},
  29. hasUserInfo: false,
  30. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  31. id: null,
  32. result: [],
  33. end_time: null,
  34. checked:false,
  35. clock: "已经截止",
  36. questionnaire: {},
  37. questionId: null,
  38. widthScreen: null,
  39. moveData: null,
  40. rotateData: null,
  41. alphaData: null,
  42. scaleData: null,
  43. skewData: null,
  44. matrixData: null,
  45. opacity:0,
  46. queueData:null,
  47. zIndex:11,
  48. display:"none",
  49. showbutton:false
  50. },
  51. phone: function (e) {
  52. let that = this;
  53. wx.makePhoneCall({
  54. phoneNumber: e.target.dataset.merchantlinkphone
  55. });
  56. },
  57. onLoad(options) {
  58. let that = this;
  59. wx.showLoading({
  60. title: "加载中..."
  61. });
  62. var parmer = {
  63. url: config.api.cardpayList,
  64. data: {
  65. cardId: options.cardId,
  66. pageNum:1,
  67. pageSize:10
  68. }
  69. };
  70. Http.get(parmer)
  71. .then(res => {
  72. if(res.code==200){
  73. that.setData({
  74. showPage:true
  75. })
  76. }
  77. if (res.data.endTime) {
  78. that.countdown(res.data.endTime);
  79. //当前时间与优惠券下架时间做计算
  80. var endTime = util.formatTime(res.data.endTime, "yyyy-MM-dd hh:mm:ss");
  81. if (util.timechuo(endTime).indexOf('-') == 0) {
  82. that.setData({
  83. endtime: "活动已结束",
  84. });
  85. } else {
  86. that.setData({
  87. endtime: util.timechuo(endTime)
  88. });
  89. }
  90. }
  91. wx.hideLoading();
  92. that.setData({
  93. data: res.data
  94. });
  95. if (res.data.validType == 1) {
  96. that.setData({
  97. validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd"),
  98. validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd"),
  99. });
  100. } else {
  101. that.setData({
  102. validDays: res.data.validDays
  103. });
  104. }
  105. }).catch(err => {
  106. wx.showToast({
  107. title: err.message,
  108. icon: 'none',
  109. duration: 2000,
  110. mask: false
  111. });
  112. })
  113. },
  114. /**
  115. * 支付订单更新
  116. */
  117. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this) => {
  118. let that = this;
  119. // 支付成功
  120. Http.post({
  121. url: config.api.payOrderUpdate,
  122. data: {
  123. payOrderId: payOrderId,
  124. orderId: orderId,
  125. status: status,
  126. reason: reason
  127. }
  128. })
  129. .then(res => {
  130. wx.hideLoading()
  131. // 有价券
  132. if (!type&&type!='free') {
  133. wx.navigateTo({
  134. url: `/pages/order/detail/index?orderId=${
  135. orderId
  136. }`
  137. });
  138. }else if(type=='free'){
  139. wx.navigateTo({
  140. url: `/pages/order/detail/index?orderId=${
  141. orderId
  142. }`
  143. });
  144. }
  145. })
  146. .catch(err => {
  147. console.log(err);
  148. if (!type) {
  149. setTimeout(function () {
  150. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  151. }, 2000)
  152. }
  153. })
  154. },
  155. /**
  156. * 发起支付
  157. */
  158. orderFunc(flag) {
  159. var that = this;
  160. // wx.showLoading({
  161. // title: "加载中..."
  162. // });
  163. Http.post({
  164. url: config.api.checkPhoneStatus,
  165. data: {}
  166. })
  167. .then(res => {
  168. var data = {
  169. couponChannelId: "" + that.data.couponChannelId,
  170. couponId: "" + that.data.couponId
  171. };
  172. if (that.data.couponChannelId == null) {
  173. var data = {
  174. couponId: "" + that.data.couponId
  175. };
  176. }
  177. /**
  178. * orderSave 下单
  179. */
  180. return Http.post({
  181. url: config.api.orderSave,
  182. data: data
  183. });
  184. })
  185. .catch(err => {
  186. if (err.code == "2011") {
  187. wx.showToast({
  188. title: "商户信息没找到",
  189. image:imgurl.fail.url,
  190. duration: 2000,
  191. mask: false
  192. });
  193. } else if (err.code == "2013") {
  194. wx.showToast({
  195. title: "商户信息禁用",
  196. image:imgurl.fail.url,
  197. duration: 2000,
  198. mask: false
  199. });
  200. } else if (err.code == "3000") {
  201. wx.showToast({
  202. title: "库存不足",
  203. image:imgurl.fail.url,
  204. duration: 2000,
  205. mask: false
  206. });
  207. } else if (err.code == "3001") {
  208. wx.showToast({
  209. title: "领取达到上限",
  210. image:imgurl.fail.url,
  211. duration: 2000,
  212. mask: false
  213. });
  214. } else if (err.code == "3002") {
  215. wx.showToast({
  216. title: "订单失败",
  217. image:imgurl.fail.url,
  218. duration: 2000,
  219. mask: false
  220. });
  221. } else if (err.code == "3003") {
  222. wx.showToast({
  223. title: "订单不存在",
  224. image:imgurl.fail.url,
  225. duration: 2000,
  226. mask: false
  227. });
  228. } else if (err.code == "3004") {
  229. wx.showToast({
  230. title: "订单不存在",
  231. image:imgurl.fail.url,
  232. duration: 2000,
  233. mask: false
  234. });
  235. } else if (err.code == "4003") {
  236. wx.showToast({
  237. title: "卡券已作废",
  238. image:imgurl.fail.url,
  239. duration: 2000,
  240. mask: false
  241. });
  242. } else if (err.code == 11005) {
  243. /**
  244. * 将值传到用户手机号授权的页面
  245. *
  246. */
  247. wx.redirectTo({
  248. url: "/pages/getphoneInfo/index?couponChannelId=" +
  249. that.data.couponChannelId +
  250. "&couponId=" +
  251. that.data.couponId
  252. });
  253. } else if (err.code == 11006) {
  254. // 用户手机已加密
  255. wx.redirectTo({
  256. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  257. that.data.couponChannelId +
  258. "&couponId=" +
  259. that.data.couponId
  260. });
  261. } else {
  262. wx.showToast({
  263. title: err.message,
  264. icon: 'none',
  265. duration: 2000,
  266. mask: false
  267. });
  268. }
  269. })
  270. .then(res => {
  271. if (typeof (res) != "undefined") {
  272. let orderId = "" + res.data.id;
  273. that.setData({
  274. orderId: orderId
  275. });
  276. if (res.data.payment > 0) {
  277. // 支付金额不为0
  278. /**
  279. * 支付订单创建
  280. */
  281. Http.post({
  282. url: config.api.payOrderCreate,
  283. data: {
  284. orderId: orderId
  285. }
  286. }).then(res => {
  287. var payOrderId = "" + res.data.payOrderId;
  288. wx.hideLoading();
  289. wx.requestPayment({
  290. timeStamp: res.data.timeStamp,
  291. nonceStr: res.data.nonceStr,
  292. package: res.data.package,
  293. signType: (res.data.signType) ? res.data.signType : "MD5",
  294. paySign: res.data.paySign,
  295. success: res => {
  296. wx.showLoading({
  297. title: '订单正在处理中...',
  298. })
  299. setTimeout(function(){
  300. wx.hideLoading()
  301. },5000)
  302. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that);
  303. if (res.errMsg == "requestPayment:ok") {
  304. setTimeout(function () {
  305. wx.hideLoading();
  306. }, 2000);
  307. /**
  308. * 用户支付成功以后跳转到券包列表
  309. */
  310. wx.setStorage({
  311. key: 'couponNum',
  312. data: "couponNum",
  313. })
  314. }
  315. },
  316. fail: res => {
  317. /**
  318. * 支付失败,需要更新订单的状态
  319. */
  320. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  321. that.setData({
  322. showbutton: false
  323. })
  324. return;
  325. },
  326. complete: res => {}
  327. });
  328. /// End payment --------
  329. })
  330. .catch(err => {
  331. wx.showToast({
  332. title: err.message,
  333. icon: 'none',
  334. duration: 2000,
  335. mask: false
  336. });
  337. })
  338. } else {
  339. // 免费券
  340. that.payOrderUpdate(orderId, "0", 1, '', 'free');
  341. wx.setStorage({
  342. key: 'couponNum',
  343. data: "couponNum"
  344. })
  345. }
  346. }
  347. })
  348. .catch(err => {
  349. wx.showToast({
  350. title: err.message,
  351. icon: 'none',
  352. duration: 2000,
  353. mask: false
  354. });
  355. })
  356. },
  357. onShow(){
  358. this.setData({
  359. showbutton:false
  360. })
  361. },
  362. onShareAppMessage: function (options) {
  363. var that = this;
  364. var shareObj = {
  365. title: that.data.data.title,
  366. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}&couponId=${that.data.couponId}`,
  367. success: function (res) {
  368. if (res.errMsg == 'shareAppMessage:ok') {}
  369. },
  370. fail: function (error) {
  371. if (res.errMsg == 'shareAppMessage:fail cancel') {} else if (res.errMsg == 'shareAppMessage:fail') {}
  372. }
  373. };
  374. // 来自页面内的按钮的转发
  375. if (options.from == 'button') {
  376. var eData = options.target.dataset.id;
  377. var couponId = options.target.dataset.couponid;
  378. shareObj.path = `/pages/index/index?couponChannelId=${eData}&couponId=${couponId}`;
  379. }
  380. // 返回shareObj
  381. return shareObj;
  382. },
  383. });