C端小程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

996 líneas
28 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. isshowposter:false,//是否显示分享弹框
  9. fenxiangUrl: imgurl.fenxiang.url,
  10. clockUrl: imgurl.clock.url,
  11. teljpgUrl: imgurl.teljpg.url,
  12. closedUrl: imgurl.closed.url,
  13. quesGouUrl: imgurl.ques_gou.url,
  14. headbgUrl: imgurl.headbg.url,
  15. quesBgUrl: imgurl.ques_bg.url,
  16. close02: imgurl.close02.url,
  17. share01: imgurl.share01.url,
  18. fail: imgurl.fail.url,
  19. wmhome: imgurl.wmhome.url,
  20. swiperCurrent: 0,
  21. hidden: "hidden",
  22. height: "",
  23. detailPicture:[],
  24. coverPicture:[],
  25. more: "点击查看更多",
  26. showMore: true,
  27. data: {
  28. title: null
  29. },
  30. showPage: false,
  31. questions1: null,
  32. questions2: null,
  33. carList: [],
  34. couponChannelId: null,
  35. orderId: "",
  36. hour: null,
  37. day: null,
  38. month: null,
  39. year: null,
  40. minute: "",
  41. tempFilePaths: null,
  42. userInfo: {},
  43. hasUserInfo: false,
  44. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  45. id: null,
  46. result: [],
  47. end_time: null,
  48. checked: false,
  49. questionnaire: {},
  50. questionId: null,
  51. widthScreen: null,
  52. moveData: null,
  53. rotateData: null,
  54. alphaData: null,
  55. scaleData: null,
  56. skewData: null,
  57. matrixData: null,
  58. opacity: 0,
  59. queueData: null,
  60. zIndex: 11,
  61. display: "none",
  62. showbutton: false,
  63. cardData: null,
  64. showCardOffer: false,
  65. isSamePeople: true,
  66. statusText: '',
  67. isReceived: false,
  68. receivedDisabled: false,
  69. clock: "结束",
  70. day: "00",
  71. hour: "00",
  72. min: "00",
  73. sec: "00",
  74. clock02: "00",
  75. day02: "00",
  76. hour02: "00",
  77. min02: "00",
  78. sec02: "00",
  79. countdown: "",
  80. showbutton1: false,
  81. limitCondition:"",
  82. minLimit:0,
  83. maxLimit:0,
  84. dispressEndDate:false
  85. },
  86. /**
  87. * 显示分享弹框
  88. */
  89. showshare: function() {
  90. this.setData({
  91. isshowposter: true,
  92. })
  93. },
  94. /**
  95. * 隐藏分享弹框
  96. */
  97. hidemodal: function() {
  98. this.setData({
  99. isshowposter: false,
  100. })
  101. },
  102. /**
  103. * 跳转到门店列表的详情页面
  104. */
  105. gotoDetail(e) {
  106. wx.navigateTo({
  107. url: `/pages/index/detail/index?id=${e.currentTarget.dataset.id}`
  108. })
  109. },
  110. /**
  111. * 显示分享海报
  112. */
  113. showPoster: function() {
  114. //跳转到海报生成页
  115. wx.navigateTo({
  116. url: `/pages/canvas/index?couponChannelId=${this.data.data.id}`
  117. })
  118. },
  119. swiperChange: function (e) {
  120. this.setData({
  121. swiperCurrent: e.detail.current
  122. });
  123. },
  124. phone: function(e) {
  125. let that = this;
  126. wx.makePhoneCall({
  127. phoneNumber: e.target.dataset.merchantlinkphone
  128. });
  129. },
  130. // 点击查看更多
  131. more: function() {
  132. let that = this;
  133. if (that.data.more == '点击查看更多') {
  134. this.setData({
  135. hidden: "",
  136. height: that.data.data.merchantVoList.length * 140 + 'rpx',
  137. more: "点击收起",
  138. showMore: true
  139. })
  140. } else {
  141. this.setData({
  142. hidden: "hidden",
  143. height: 4 * 140 + 'rpx',
  144. more: "点击查看更多",
  145. showMore: true
  146. })
  147. }
  148. },
  149. //获取当前登录用户信息
  150. getUserInfo: function() {
  151. let that = this;
  152. // 获取用户信息
  153. Http.get({
  154. url: config.api.getScore,
  155. data: {}
  156. })
  157. .then(res => {
  158. console.log(res)
  159. that.getQueryCardStatus()
  160. if (that.data.cardData.cuserId != res.data.id) {
  161. console.log(2222, 6666)
  162. that.setData({
  163. isSamePeople: false
  164. })
  165. }
  166. })
  167. },
  168. //获取卡转赠状态
  169. getQueryCardStatus() {
  170. let that = this;
  171. let param = {
  172. id: this.data.cardData.couponOrderId,
  173. cUserId: this.data.cardData.cuserId,
  174. updateDate: util.formatTime(Number(that.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
  175. }
  176. Http.get({
  177. url: config.api.queryCardStatus,
  178. data: param
  179. })
  180. .then(res => {
  181. console.log(res, 333333333333)
  182. })
  183. .catch(err => {
  184. that.setData({
  185. isReceived: true,
  186. statusText: err.message
  187. })
  188. })
  189. },
  190. receiveCard() {
  191. let that = this;
  192. let param = {
  193. id: this.data.cardData.couponOrderId,
  194. cUserId: this.data.cardData.cuserId,
  195. updateDate: util.formatTime(Number(this.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
  196. }
  197. this.setData({
  198. receivedDisabled: true
  199. })
  200. Http.post({
  201. url: config.api.cardAccept,
  202. data: param
  203. })
  204. .then(res => {
  205. wx.showToast({
  206. title: '领取成功!',
  207. icon: 'none',
  208. duration: 2000,
  209. mask: false
  210. });
  211. wx.reLaunch({
  212. url: '/pages/complete/index?couponOrderId=' + this.data.cardData.couponOrderId,
  213. })
  214. })
  215. .catch(err => {
  216. wx.showToast({
  217. title: err.message,
  218. icon: 'none',
  219. duration: 2000,
  220. mask: false
  221. });
  222. that.setData({
  223. receivedDisabled: false
  224. })
  225. })
  226. },
  227. closeAlert() {
  228. this.setData({
  229. showCardOffer: false
  230. })
  231. },
  232. goback: function() {
  233. wx.switchTab({
  234. url: '/pages/main/index',
  235. })
  236. },
  237. /**
  238. * 点击提交问题单选
  239. */
  240. formSubmit: function(e) {
  241. console.log(e);
  242. let that = this;
  243. /**
  244. * 多选
  245. */
  246. if (e.currentTarget.dataset.flags == 'multi') {
  247. if (that.data.anwserId.length == 0) {
  248. var answserIs = null
  249. } else {
  250. var answserIs = that.data.anwserId.join(",");
  251. }
  252. } else if (e.currentTarget.dataset.flags == 'single') {
  253. var answserIs = e.detail.value;
  254. }
  255. console.log(answserIs)
  256. console.log(e.currentTarget.dataset.questionid)
  257. Http.post({
  258. url: config.api.answerQuestion,
  259. data: {
  260. answer: answserIs,
  261. questionId: e.currentTarget.dataset.questionid
  262. }
  263. })
  264. .then(res => {
  265. that.closeQuestion();
  266. })
  267. .catch(err => {
  268. wx.showToast({
  269. title: err.message,
  270. icon: 'none',
  271. duration: 2000,
  272. mask: false
  273. });
  274. })
  275. },
  276. /**
  277. * 多选
  278. */
  279. checkboxChange: function(e) {
  280. console.log(e)
  281. this.setData({
  282. anwserId: e.detail.value
  283. })
  284. },
  285. closeQuestion: function() {
  286. let that = this;
  287. that.setData({
  288. display: "none",
  289. zIndex: 11,
  290. opacity: 0
  291. })
  292. setTimeout(function() {
  293. that.orderFunc();
  294. }, 500)
  295. },
  296. gotopay: function(e) {
  297. let that = this;
  298. console.log(e);
  299. wx.showLoading();
  300. if (e.currentTarget.dataset.type == 51 || e.currentTarget.dataset.type == 50){
  301. wx.navigateTo({
  302. url: '/pages/integralmall/payIntegcoupondetail/index?couponChannelId=' + that.data.couponChannelId + '&couponId=' + that.data.couponId,
  303. })
  304. }else{
  305. let formId = e.detail.formId;
  306. var discount = e.detail.target.dataset.discount;
  307. that.setData({
  308. queueData: null,
  309. showbutton: true,
  310. formId: formId
  311. })
  312. Http.get({
  313. url: config.api.getQuestion,
  314. data: {
  315. couponType: JSON.stringify(that.data.data.type)
  316. }
  317. })
  318. .then(res => {
  319. wx.hideLoading();
  320. if (res.data == undefined) {
  321. that.orderFunc(discount);
  322. that.setData({
  323. flag: false
  324. })
  325. } else if (res.data) {
  326. var animation = wx.createAnimation({});
  327. animation.translate((that.data.widthScreen - that.data.widthScreen), 0).scale(1).opacity(1).step({
  328. duration: 500
  329. })
  330. that.setData({
  331. queueData: animation.export(),
  332. zIndex: 9,
  333. opacity: 1,
  334. display: "block",
  335. questionnaire: JSON.parse(res.data.content),
  336. questionId: res.data.id
  337. });
  338. }
  339. })
  340. .catch(err => {
  341. wx.hideLoading();
  342. wx.showToast({
  343. title: err.message,
  344. icon: 'none',
  345. duration: 2000,
  346. mask: false
  347. });
  348. })
  349. }
  350. },
  351. setIntervalTime(end_time) {
  352. let that = this;
  353. var EndTime = end_time;
  354. var NowTime = new Date().getTime();
  355. var total_micro_second = EndTime - NowTime || [];
  356. // 渲染倒计时时钟
  357. let obj = that.dateformat(total_micro_second);
  358. if (total_micro_second > 0) {
  359. that.setData({
  360. clock: obj,
  361. day: obj.a1,
  362. hour: obj.b1,
  363. min: obj.c1,
  364. sec: obj.d1,
  365. })
  366. } else {
  367. that.setData({
  368. clock: "00",
  369. day: "00",
  370. hour: "00",
  371. min: "00",
  372. sec: "00",
  373. })
  374. //如果倒计时结束,需要重新查询一下券的状态
  375. // 给getDetail一个标识
  376. that.getDetail(that.data.couponChannelId, 'endclock');
  377. }
  378. total_micro_second -= 1000;
  379. },
  380. countdown: function(end_time) {
  381. let that = this;
  382. that.setIntervalTime(end_time);
  383. that.data.setInterval = setInterval(function() {
  384. that.setIntervalTime(end_time);
  385. }, 1000)
  386. },
  387. // 时间格式化输出,如11:03 25:19 每1s都会调用一次
  388. dateformat(micro_second) {
  389. // 总秒数
  390. var second = Math.floor(micro_second / 1000);
  391. // 天数
  392. var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  393. // 小时
  394. var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  395. // 分钟
  396. var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  397. // 秒
  398. var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
  399. // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
  400. return {
  401. a1: day,
  402. b1: hr,
  403. c1: min,
  404. d1: sec
  405. }
  406. },
  407. /**
  408. * 获取用户信息
  409. */
  410. onLoad(options) {
  411. let that = this;
  412. wx.showLoading({
  413. title: "加载中..."
  414. });
  415. that.setData({
  416. onshow: false
  417. })
  418. if (options && options.couponChannelId){
  419. that.getDetail(options.couponChannelId, 'notendclock');
  420. }
  421. /**
  422. * 转赠判断
  423. */
  424. if (options.cuserId) {
  425. this.setData({
  426. showCardOffer: true,
  427. cardData: options
  428. })
  429. this.getUserInfo()
  430. }
  431. that.setData({
  432. couponChannelId: options.couponChannelId,
  433. title: that.data.data.title ? that.data.data.title : '',
  434. });
  435. if (options.cardType) {
  436. that.setData({
  437. cardType: options.cardType
  438. })
  439. }
  440. },
  441. getDetail: function(couponChannelId, flag) {
  442. let that = this;
  443. var parmer = {
  444. url: config.api.couponDetail,
  445. data: {
  446. couponChannelId: couponChannelId
  447. }
  448. };
  449. Http.get(parmer)
  450. .then(res => {
  451. that.setData({
  452. couponId: res.data.couponId
  453. })
  454. that.setData({
  455. showPage: true
  456. })
  457. if (res && res.data && res.data.detailPicture) {
  458. that.setData({
  459. detailPicture: JSON.parse(res.data.detailPicture)
  460. })
  461. }
  462. if (res && res.data && res.data.coverPicture) {
  463. that.setData({
  464. coverPicture: JSON.parse(res.data.coverPicture)
  465. })
  466. }
  467. if (res && res.data && res.data.conditions){
  468. that.setData({
  469. limitCondition: JSON.parse(res.data.conditions).type
  470. })
  471. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).min || JSON.parse(res.data.conditions).min==0)){
  472. that.setData({
  473. minLimit: JSON.parse(res.data.conditions).min
  474. })
  475. }
  476. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).max) || JSON.parse(res.data.conditions).max == 0) {
  477. that.setData({
  478. maxLimit: JSON.parse(res.data.conditions).max
  479. })
  480. }
  481. }
  482. /**
  483. * 将优惠券优惠卡的详情的BarTitle
  484. * 设置成券的名称
  485. */
  486. wx.setNavigationBarTitle({
  487. title: res.data.title
  488. })
  489. var EndTime = res.data.validStartDate;
  490. var NowTime = new Date().getTime();
  491. /**
  492. * activityStatus==0 活动未开始
  493. * activityStatus==1 活动已开始
  494. * flag == endclock 说明倒计时已经结束
  495. */
  496. if (res.data.endTime && res.data.beginTime) {
  497. that.setData({
  498. begin_time: res.data.beginTime,
  499. end_time: res.data.endTime,
  500. })
  501. if (res.data.activityStatus == 0 && flag != 'endclock') {
  502. that.countdown(res.data.beginTime);
  503. } else if (res.data.activityStatus != 0 && flag != 'endclock') {
  504. that.countdown(res.data.endTime);
  505. } else {
  506. clearInterval(that.data.setInterval)
  507. }
  508. if (res.data.activityStatus == 0) {
  509. var beginTime = util.formatTime(res.data.beginTime, "yyyy-MM-dd hh:mm:ss");
  510. if (util.timechuo(beginTime).indexOf('-') == 0) {
  511. that.setData({
  512. beginTime: "活动已结束",
  513. });
  514. } else {
  515. that.setData({
  516. beginTime: util.timechuo(beginTime)
  517. });
  518. }
  519. } else {
  520. var endTime = util.formatTime(res.data.endTime, "yyyy-MM-dd hh:mm:ss");
  521. if (util.timechuo(endTime).indexOf('-') == 0) {
  522. that.setData({
  523. endtime: "活动已结束",
  524. });
  525. } else {
  526. that.setData({
  527. endtime: util.timechuo(endTime)
  528. });
  529. }
  530. }
  531. }
  532. wx.hideLoading();
  533. that.setData({
  534. data: res.data
  535. });
  536. if (that.data.data.merchantVoList && that.data.data.merchantVoList.length <= 4) {
  537. that.setData({
  538. height: that.data.data.merchantVoList.length * 140 + 'rpx',
  539. showMore: false
  540. })
  541. } else if (that.data.data.merchantVoList && that.data.data.merchantVoList.length > 4) {
  542. that.setData({
  543. height: 4 * 140 + 'rpx'
  544. })
  545. }
  546. if (res.data.validType == 1) {
  547. that.setData({
  548. validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd"),
  549. validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd"),
  550. });
  551. } else {
  552. if (res.data.validDays) {
  553. that.setData({
  554. validDays: res.data.validDays
  555. });
  556. }
  557. }
  558. }).catch(err => {
  559. wx.showToast({
  560. title: err.message,
  561. icon: 'none',
  562. duration: 2000,
  563. mask: false
  564. });
  565. })
  566. },
  567. /**
  568. * 邀请好友继续砍价
  569. */
  570. inviteFriend: function(e) {
  571. let that = this;
  572. let formId = e.detail.formId;
  573. that.setData({
  574. formId: formId
  575. })
  576. that.orderFunc("discount");
  577. that.setData({
  578. showbutton1: true
  579. })
  580. },
  581. /**
  582. * 支付订单更新
  583. */
  584. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this) => {
  585. let that = this;
  586. // 支付成功
  587. Http.post({
  588. url: config.api.payOrderUpdate,
  589. data: {
  590. payOrderId: payOrderId,
  591. orderId: orderId,
  592. status: status,
  593. reason: reason
  594. }
  595. })
  596. .then(res => {
  597. wx.hideLoading()
  598. // 有价券
  599. if (!type && type != 'free') {
  600. wx.navigateTo({
  601. url: `/pages/order/detail/index?orderId=${
  602. orderId
  603. }&cardIf=true`
  604. });
  605. } else if (type == 'free') {
  606. wx.navigateTo({
  607. url: `/pages/order/detail/index?orderId=${
  608. orderId
  609. }`
  610. });
  611. }
  612. })
  613. .catch(err => {
  614. console.log(err);
  615. if (!type) {
  616. setTimeout(function() {
  617. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  618. }, 2000)
  619. }
  620. })
  621. },
  622. checkPhoneStatus: function() {
  623. let that = this;
  624. Http.get({
  625. url: config.api.checkPhoneStatus,
  626. data: {}
  627. })
  628. .then(res => {
  629. console.log(666, '授权成功!')
  630. that.receiveCard()
  631. })
  632. .catch(err => {
  633. if (err.code == 11005) {
  634. /**
  635. * 手机号没有授权,将值传到用户手机号授权的页面
  636. *
  637. */
  638. wx.redirectTo({
  639. url: "/pages/getphoneInfo/index?path=index&cuserId=" + that.data.cardData.cuserId + "&couponChannelId=" + that.data.cardData.couponChannelId + "&userName=" + that.data.cardData.userName + "&coverImg=" + that.data.cardData.coverImg + "&avatarUrl=" + that.data.cardData.avatarUrl + "&couponOrderId=" + that.data.cardData.couponOrderId + "&updateDate=" + that.data.cardData.updateDate,
  640. });
  641. } else if (err.code == 11006) {
  642. // 用户手机已加密
  643. wx.redirectTo({
  644. url: "/pages/phoneinput/phoneinput?path=index&cuserId=" + that.data.cardData.cuserId + "&couponChannelId=" + that.data.cardData.couponChannelId + "&userName=" + that.data.cardData.userName + "&coverImg=" + that.data.cardData.coverImg + "&avatarUrl=" + that.data.cardData.avatarUrl + "&couponOrderId=" + that.data.cardData.couponOrderId + "&updateDate=" + that.data.cardData.updateDate,
  645. });
  646. } else {
  647. wx.showToast({
  648. title: err.message,
  649. icon: 'none',
  650. duration: 2000,
  651. mask: false
  652. });
  653. }
  654. })
  655. },
  656. /**
  657. * 发起支付
  658. */
  659. orderFunc(discount) {
  660. let that = this;
  661. Http.get({
  662. url: config.api.checkPhoneStatus,
  663. data: {}
  664. })
  665. .then(res => {
  666. if (discount == 'discount') {
  667. var data = {
  668. couponChannelId: "" + that.data.couponChannelId,
  669. couponId: "" + that.data.couponId,
  670. formId: "" + that.data.formId,
  671. press: true
  672. }
  673. } else if (discount == 'discount1') {
  674. var data = {
  675. couponChannelId: "" + that.data.couponChannelId,
  676. couponId: "" + that.data.couponId,
  677. formId: "" + that.data.formId,
  678. press: false
  679. }
  680. } else if (that.data.couponChannelId == null) {
  681. var data = {
  682. couponId: "" + that.data.couponId,
  683. formId: "" + that.data.formId,
  684. };
  685. } else {
  686. var data = {
  687. couponChannelId: "" + that.data.couponChannelId,
  688. couponId: "" + that.data.couponId,
  689. formId: "" + that.data.formId,
  690. }
  691. }
  692. /**
  693. * orderSave 下单
  694. */
  695. return Http.post({
  696. url: config.api.orderSave,
  697. data: data
  698. });
  699. })
  700. .catch(err => {
  701. wx.hideLoading()
  702. that.setData({
  703. showbutton: false,
  704. showbutton1: false
  705. })
  706. if (err.code == 2011) {
  707. wx.showToast({
  708. title: "商户信息没找到",
  709. image: './../../../assets/images/fail.png',
  710. duration: 2000,
  711. mask: false
  712. });
  713. } else if (err.code == 2013) {
  714. wx.showToast({
  715. title: "商户信息禁用",
  716. image: './../../../assets/images/fail.png',
  717. duration: 2000,
  718. mask: false
  719. });
  720. } else if (err.code == 3000) {
  721. wx.showToast({
  722. title: "库存不足",
  723. image: './../../../assets/images/fail.png',
  724. duration: 2000,
  725. mask: false
  726. });
  727. } else if (err.code == 3001) {
  728. wx.showToast({
  729. title: "您已超过限购",
  730. image: './../../../assets/images/fail.png',
  731. duration: 2000,
  732. mask: false
  733. });
  734. } else if (err.code == 3002) {
  735. wx.showToast({
  736. title: "订单失败",
  737. image: './../../../assets/images/fail.png',
  738. duration: 2000,
  739. mask: false
  740. });
  741. } else if (err.code == 3003) {
  742. wx.showToast({
  743. title: "订单不存在",
  744. image: './../../../assets/images/fail.png',
  745. duration: 2000,
  746. mask: false
  747. });
  748. } else if (err.code == 3004) {
  749. wx.showToast({
  750. title: "订单不存在",
  751. image: './../../../assets/images/fail.png',
  752. duration: 2000,
  753. mask: false
  754. });
  755. } else if (err.code == 4003) {
  756. wx.showToast({
  757. title: "卡券已作废",
  758. image: './../../../assets/images/fail.png',
  759. duration: 2000,
  760. mask: false
  761. });
  762. } else if (err.code == 3012) {
  763. that.getUnPaidOrder(that.data.couponId, discount);
  764. } else if (err.code == 11005) {
  765. /**
  766. * 将值传到用户手机号授权的页面
  767. *
  768. */
  769. wx.redirectTo({
  770. url: "/pages/getphoneInfo/index?couponChannelId=" +
  771. that.data.couponChannelId
  772. });
  773. } else if (err.code == 11006) {
  774. // 用户手机已加密
  775. wx.redirectTo({
  776. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  777. that.data.couponChannelId
  778. });
  779. } else {
  780. wx.showToast({
  781. title: err.message,
  782. icon: 'none',
  783. duration: 2000,
  784. mask: false
  785. });
  786. }
  787. })
  788. .then(res => {
  789. if (discount != 'discount') {
  790. if (typeof(res) != "undefined") {
  791. let orderId = "" + res.data.id;
  792. that.setData({
  793. orderId: orderId
  794. });
  795. if (res.data.payment > 0) {
  796. // 支付金额不为0
  797. /**
  798. * 支付订单创建
  799. */
  800. Http.post({
  801. url: config.api.payOrderCreate,
  802. data: {
  803. orderId: orderId
  804. }
  805. })
  806. .then(res => {
  807. var payOrderId = "" + res.data.payOrderId;
  808. wx.hideLoading();
  809. wx.requestPayment({
  810. timeStamp: res.data.timeStamp,
  811. nonceStr: res.data.nonceStr,
  812. package: res.data.package,
  813. signType: (res.data.signType) ? res.data.signType : "MD5",
  814. paySign: res.data.paySign,
  815. success: res => {
  816. wx.showLoading({
  817. title: '订单正在处理中...',
  818. })
  819. setTimeout(function() {
  820. wx.hideLoading()
  821. }, 5000)
  822. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that);
  823. if (res.errMsg == "requestPayment:ok") {
  824. setTimeout(function() {
  825. wx.hideLoading();
  826. }, 2000);
  827. /**
  828. * 用户支付成功以后跳转到券包列表
  829. */
  830. if (that.data.cardType == 100) {
  831. wx.setStorage({
  832. key: 'couponNum2',
  833. data: "couponNum2"
  834. })
  835. } else if (that.data.data.type != 5 && that.data.cardType != 100) {
  836. wx.setStorage({
  837. key: 'couponNum',
  838. data: "couponNum"
  839. })
  840. }
  841. }
  842. },
  843. fail: res => {
  844. wx.hideLoading();
  845. /**
  846. * 支付失败,需要更新订单的状态
  847. */
  848. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  849. that.setData({
  850. showbutton: false
  851. })
  852. return;
  853. },
  854. complete: res => {}
  855. });
  856. /// End payment --------
  857. })
  858. .catch(err => {
  859. wx.hideLoading();
  860. wx.showToast({
  861. title: err.message,
  862. icon: 'none',
  863. duration: 2000,
  864. mask: false
  865. });
  866. })
  867. } else {
  868. // 免费券
  869. that.payOrderUpdate(orderId, "0", 1, '', 'free');
  870. if (that.data.cardType == 100) {
  871. wx.setStorage({
  872. key: 'couponNum2',
  873. data: "couponNum2"
  874. })
  875. } else if (that.data.data.type != "5" && that.data.cardType != 100) {
  876. wx.setStorage({
  877. key: 'couponNum',
  878. data: "couponNum"
  879. })
  880. }
  881. }
  882. }
  883. } else {
  884. if (res) {
  885. wx.navigateTo({
  886. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.id}`,
  887. })
  888. }
  889. }
  890. })
  891. },
  892. // 获得未支付的订单
  893. getUnPaidOrder(couponId, discount){
  894. let that = this;
  895. Http.get({
  896. url: config.api.getUnPaidOrder,
  897. data: {
  898. couponId: couponId
  899. }
  900. }).then(res=>{
  901. /**
  902. * discount 砍价订单
  903. * discount1 砍价按原价购买订单
  904. */
  905. that.setData({
  906. disOrderNumber: res.data.orderNumber,
  907. })
  908. if (res.data&&res.data.pressEndDate){
  909. that.setData({
  910. dispressEndDate:true
  911. })
  912. }else{
  913. that.setData({
  914. dispressEndDate: false
  915. })
  916. }
  917. if (that.data.dispressEndDate){
  918. wx.showModal({
  919. title: '提示',
  920. content: "您有未支付砍价订单,请先进行支付",
  921. confirmText:"去支付",
  922. success: function (res) {
  923. if (res.confirm) {
  924. wx.navigateTo({
  925. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${that.data.disOrderNumber}`,
  926. })
  927. }
  928. }
  929. })
  930. } else{
  931. wx.showModal({
  932. title: '提示',
  933. content: '您有未支付订单,请先进行支付',
  934. confirmText: "去支付",
  935. success: function (res) {
  936. if (res.confirm) {
  937. wx.navigateTo({
  938. url: `/pages/order/detail/index?orderId=${that.data.disOrderNumber}`,
  939. })
  940. }
  941. }
  942. })
  943. }
  944. }).catch(error=>{
  945. console.log(error)
  946. })
  947. },
  948. onShow() {
  949. this.setData({
  950. showbutton: false,
  951. showbutton1: false
  952. })
  953. if (this.data.end_time) {
  954. this.countdown(this.data.end_time)
  955. }
  956. },
  957. onUnload: function() {
  958. let that = this;
  959. clearInterval(that.data.setInterval)
  960. },
  961. onHide: function() {
  962. let that = this;
  963. clearInterval(that.data.setInterval)
  964. },
  965. onShareAppMessage: function(options) {
  966. var that = this;
  967. console.log(options)
  968. var shareObj = {
  969. title: that.data.data.title,
  970. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}`,
  971. success: function(res) {
  972. if (res.errMsg == 'shareAppMessage:ok') {}
  973. },
  974. fail: function(error) {
  975. if (res.errMsg == 'shareAppMessage:fail cancel') {} else if (res.errMsg == 'shareAppMessage:fail') {}
  976. }
  977. };
  978. // 来自页面内的按钮的转发
  979. if (options.from == 'button') {
  980. var eData = options.target.dataset.id;
  981. shareObj.path = `/pages/index/index?couponChannelId=${eData}&frommd=JC`;
  982. }
  983. // 返回shareObj
  984. return shareObj;
  985. },
  986. // 下拉刷新
  987. onPullDownRefresh: function() {
  988. this.getDetail(this.data.couponChannelId);
  989. wx.stopPullDownRefresh()
  990. }
  991. });