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.

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