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.

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