C端小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

1037 linhas
29 KiB

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