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.

887 lines
23 KiB

  1. // pages/spellGroup/mySpellGroup/index.js
  2. const navigationBarHeight = (getApp().statusBarHeight + 50) + 'px'
  3. var config = require("../../../config/config.js");
  4. const Http = require("../../../utils/HttpBasics");
  5. const imgurl = require("../../../utils/imgurl");
  6. const utils = require("../../../utils/util.js");
  7. let app = getApp();
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. mouldType: 0,
  14. mouldConfig: {},
  15. navigationBarHeight,
  16. fenxiang: imgurl.fenxiang1.url,
  17. homeSelectedO: imgurl.homeSelectedO.url,
  18. isshowposter: false, //是否显示分享弹框
  19. teljpgUrl: imgurl.teljpg.url,
  20. wmhome: imgurl.wmhome.url,
  21. share01: imgurl.share01.url,
  22. close02: imgurl.close02.url,
  23. closedUrl: imgurl.closed.url,
  24. quesGouUrl: imgurl.ques_gou.url,
  25. headbgUrl: imgurl.headbg.url,
  26. quesBgUrl: imgurl.ques_bg.url,
  27. couponChannelId: '',
  28. couponId: '',
  29. data: null,
  30. spellData: null,
  31. canSpell: true,
  32. canBuyIf: true,
  33. clock: "00",
  34. day: "00",
  35. hour: "00",
  36. min: "00",
  37. sec: "00",
  38. detailPicture: [],
  39. coverPicture: [],
  40. swiperCurrent: 0,
  41. showTime: true,
  42. limitCondition: "",
  43. minLimit: 0,
  44. maxLimit: 0,
  45. spellGroupOrder: false,
  46. opacity: 0,
  47. queueData: null,
  48. zIndex: 11,
  49. display: "none",
  50. orderGroupId: '',
  51. merchantVoList: [],
  52. goHomeUrl: "",
  53. mallList: '',
  54. contentType: ''
  55. },
  56. /**
  57. * 生命周期函数--监听页面加载
  58. */
  59. onLoad: function (options) {
  60. this.setData({
  61. mouldType: app.globalData.mouldType,
  62. mouldConfig: app.globalData.mouldConfig,
  63. goHomeUrl: app.globalData.goHomeUrl,
  64. })
  65. Http.get({
  66. url: config.api.checkUserStatus,
  67. data: {
  68. token: app.globalData.token
  69. }
  70. }).then(res => {
  71. Http.get({
  72. url: config.api.checkPhoneStatus,
  73. data: {}
  74. }).then(res => {
  75. this.setData({
  76. couponChannelId: options.couponChannelId,
  77. couponId: options.couponId ? options.couponId : ''
  78. })
  79. if (options && options.couponChannelId) {
  80. this.getDetail(options.couponChannelId);
  81. }
  82. if (options && options.couponId) {
  83. this.getOneSpell(options.couponId)
  84. }
  85. }).catch(res => {
  86. wx.redirectTo({
  87. url: `/pages/getphoneInfo/index`
  88. });
  89. })
  90. }).catch(res => {
  91. wx.redirectTo({
  92. url: `/pages/getuserinfo/index`
  93. })
  94. })
  95. },
  96. /**
  97. * 显示分享海报
  98. */
  99. /* showPoster: function() {
  100. //跳转到海报生成页
  101. wx.navigateTo({
  102. url: `/pages/canvas/index?couponChannelId=${this.data.data.id}`
  103. })
  104. }, */
  105. showPoster: function () {
  106. console.log(this.data.data)
  107. let that = this;
  108. Http.get({
  109. url: config.api.checkUserStatus,
  110. data: {
  111. token: app.globalData.token
  112. }
  113. }).then(res => {
  114. wx.navigateTo({
  115. url: `/pages/canvas/index?couponChannelId=${that.data.data.id}`
  116. })
  117. }).catch(err => {
  118. console.log(err)
  119. if (err.code == 11004) {
  120. // 用户昵称未授权
  121. wx.redirectTo({
  122. url: `/pages/getuserinfo/index?couponChannelId=${that.data.data.id}&fromflag=poster`
  123. })
  124. }
  125. })
  126. //跳转到海报生成页
  127. },
  128. /**
  129. * 显示分享弹框
  130. */
  131. showshare: function () {
  132. this.setData({
  133. isshowposter: true,
  134. })
  135. },
  136. /**
  137. * 隐藏分享弹框
  138. */
  139. hidemodal: function () {
  140. this.setData({
  141. isshowposter: false,
  142. })
  143. },
  144. gotoIndex: function () {
  145. let this_ = this
  146. wx.switchTab({
  147. url: this_.data.goHomeUrl,
  148. })
  149. },
  150. /**
  151. * 拨打电话
  152. */
  153. phone: function (e) {
  154. let that = this;
  155. wx.makePhoneCall({
  156. phoneNumber: e.target.dataset.merchantlinkphone
  157. });
  158. },
  159. /**
  160. * 直接购买
  161. */
  162. gotoBuy(e) {
  163. let that = this;
  164. this.setData({
  165. canBuyIf: false,
  166. formId: e.detail.formId,
  167. queueData: null,
  168. orderGroupId: ''
  169. })
  170. that.getQuestions();
  171. },
  172. getQuestions(type) {
  173. let that = this;
  174. Http.get({
  175. url: config.api.getQuestion,
  176. data: {
  177. couponType: JSON.stringify(that.data.data.type)
  178. }
  179. })
  180. .then(res => {
  181. wx.hideLoading();
  182. if (res.data == undefined) {
  183. // 立即购买
  184. that.orderFunc(type);
  185. } else if (res.data) {
  186. var animation = wx.createAnimation({});
  187. animation.translate((that.data.widthScreen - that.data.widthScreen), 0).scale(1).opacity(1).step({
  188. duration: 500
  189. })
  190. that.setData({
  191. queueData: animation.export(),
  192. zIndex: 9,
  193. opacity: 1,
  194. display: "block",
  195. questionnaire: JSON.parse(res.data.content),
  196. questionId: res.data.id
  197. });
  198. }
  199. })
  200. .catch(err => {
  201. wx.hideLoading();
  202. wx.showToast({
  203. title: err.message,
  204. icon: 'none',
  205. duration: 2000,
  206. mask: false
  207. });
  208. })
  209. },
  210. /**
  211. * 点击提交问题单选
  212. */
  213. formSubmit: function (e) {
  214. console.log(e);
  215. let that = this;
  216. /**
  217. * 多选
  218. */
  219. if (e.currentTarget.dataset.flags == 'multi') {
  220. if (that.data.anwserId.length == 0) {
  221. var answserIs = null
  222. } else {
  223. var answserIs = that.data.anwserId.join(",");
  224. }
  225. } else if (e.currentTarget.dataset.flags == 'single') {
  226. var answserIs = e.detail.value;
  227. }
  228. console.log(answserIs)
  229. console.log(e.currentTarget.dataset.questionid)
  230. Http.post({
  231. url: config.api.answerQuestion,
  232. data: {
  233. answer: answserIs,
  234. questionId: e.currentTarget.dataset.questionid
  235. }
  236. })
  237. .then(res => {
  238. that.closeQuestion();
  239. })
  240. .catch(err => {
  241. wx.showToast({
  242. title: err.message,
  243. icon: 'none',
  244. duration: 2000,
  245. mask: false
  246. });
  247. })
  248. },
  249. /**
  250. * 多选
  251. */
  252. checkboxChange: function (e) {
  253. console.log(e)
  254. this.setData({
  255. anwserId: e.detail.value
  256. })
  257. },
  258. closeQuestion: function () {
  259. let that = this;
  260. that.setData({
  261. display: "none",
  262. zIndex: 11,
  263. opacity: 0
  264. })
  265. setTimeout(function () {
  266. that.orderFunc();
  267. }, 500)
  268. },
  269. // 时间格式化输出,如11:03 25:19 每1s都会调用一次
  270. dateformat(micro_second) {
  271. // 总秒数
  272. var second = Math.floor(micro_second / 1000);
  273. // 天数
  274. var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  275. // 小时
  276. var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  277. // 分钟
  278. var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  279. // 秒
  280. var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
  281. // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
  282. return {
  283. a1: day,
  284. b1: hr,
  285. c1: min,
  286. d1: sec
  287. }
  288. },
  289. countdown(time) {
  290. let that = this;
  291. var EndTime = time;
  292. if (that.data.spellData != null) {
  293. EndTime = that.data.spellData.expiredDate;
  294. }
  295. var NowTime = new Date().getTime();
  296. var total_micro_second = EndTime - NowTime || [];
  297. // 渲染倒计时时钟
  298. let obj = that.dateformat(total_micro_second);
  299. if (total_micro_second > 0) {
  300. that.setData({
  301. clock: obj,
  302. day: obj.a1,
  303. hour: obj.b1,
  304. min: obj.c1,
  305. sec: obj.d1,
  306. })
  307. } else {
  308. that.setData({
  309. clock: "00",
  310. day: "00",
  311. hour: "00",
  312. min: "00",
  313. sec: "00",
  314. })
  315. }
  316. if (that.data.showTime) {
  317. setTimeout(function () {
  318. total_micro_second -= 1000;
  319. that.countdown();
  320. }, 1000)
  321. }
  322. },
  323. // 获得未支付的订单
  324. getUnPaidOrder(couponId) {
  325. let that = this;
  326. Http.get({
  327. url: config.api.getUnPaidOrder,
  328. data: {
  329. couponId: couponId
  330. }
  331. }).then(res => {
  332. that.setData({
  333. disOrderNumber: res.data.orderNumber,
  334. couponChannelId: res.data.couponChannelId,
  335. orderGroupId: res.data.orderGroupId,
  336. composeOrderType: res.data.composeOrderType
  337. })
  338. // 拼团订单
  339. if (res.data.payment / 100 != Number(that.data.data.price)) {
  340. that.setData({
  341. spellGroupOrder: true
  342. })
  343. } else {
  344. // 原价购买订单
  345. that.setData({
  346. spellGroupOrder: false
  347. })
  348. }
  349. if (that.data.spellGroupOrder) {
  350. wx.showModal({
  351. title: '提示',
  352. content: "您有未支付拼团订单,请先进行支付",
  353. confirmText: "去支付",
  354. success: function (res1) {
  355. if (res1.confirm) {
  356. wx.navigateTo({
  357. url: `/pages/spellGroup/paySpellGroup/index?orderId=${res.data.composeOrderId}&couponChannelId=${that.data.couponChannelId}&couponId=${couponId}&orderGroupId={that.data.orderGroupId}&composeOrderType=${that.data.composeOrderType}`,
  358. })
  359. }
  360. }
  361. })
  362. } else {
  363. wx.showModal({
  364. title: '提示',
  365. content: '您有未支付订单,请先进行支付',
  366. confirmText: "去支付",
  367. success: function (res1) {
  368. if (res1.confirm) {
  369. wx.navigateTo({
  370. url: `/pages/order/detail/index?orderId=${res.data.composeOrderId}&composeOrderType=${that.data.composeOrderType}`,
  371. })
  372. }
  373. }
  374. })
  375. }
  376. }).catch(error => {
  377. console.log(error)
  378. wx.showToast({
  379. title: error.message,
  380. icon: "none",
  381. duration: 3000
  382. })
  383. })
  384. },
  385. /**
  386. * 发起拼团
  387. */
  388. gotoSpell(e) {
  389. app.globalData.previewFlag = false
  390. let that = this;
  391. that.setData({
  392. canSpell: false,
  393. formId: e.detail.formId,
  394. orderGroupId: 0
  395. })
  396. that.getQuestions(0);
  397. },
  398. //参与别人的拼团
  399. gotoPartner() {
  400. console.log(this.data.spellData.nickName, 'nickname');
  401. wx.navigateTo({
  402. url: `/pages/joinFrDpell/index?orderId=${this.data.spellData.orderId}&couponId=${this.data.spellData.couponId}&orderGroupId=${this.data.spellData.orderGroupId}&nickName=${this.data.spellData.nickName}&couponChannelId=${this.data.couponChannelId}&avatarUrl=${this.data.spellData.avatarUrl}`
  403. });
  404. },
  405. /**
  406. * 获取一个拼团信息
  407. */
  408. getOneSpell(couponId) {
  409. let that = this;
  410. Http.get({
  411. url: config.api.queryRemainOne,
  412. data: {
  413. couponId: couponId
  414. }
  415. }).then(res => {
  416. wx.stopPullDownRefresh();
  417. if (res.data) {
  418. that.countdown(res.data.expiredDate);
  419. that.setData({
  420. spellData: res.data
  421. });
  422. }
  423. });
  424. },
  425. getHtml(couponChannelId) {
  426. Http.get({
  427. url: config.api.couponHtmlDetail,
  428. data: {
  429. couponChannelId: couponChannelId
  430. }
  431. }).then(res => {
  432. console.log(res)
  433. if (res.code == 200 && res.data.html) {
  434. this.setData({
  435. curHtml: decodeURI(res.data.html),
  436. type: res.data.type
  437. })
  438. app.globalData.curHtml = this.data.curHtml;
  439. console.log(app.globalData.curHtml)
  440. }
  441. })
  442. },
  443. /**
  444. * 获取券详情信息
  445. */
  446. getDetail(couponChannelId) {
  447. let that = this;
  448. Http.get({
  449. url: config.api.couponDetail,
  450. data: {
  451. couponChannelId: couponChannelId
  452. }
  453. }).then(res => {
  454. wx.stopPullDownRefresh();
  455. let data = res.data;
  456. if (res.data.contentType != undefined && res.data.contentType == 1) {
  457. //获取图文展示详情html
  458. this.setData({
  459. contentType: res.data.contentType
  460. })
  461. this.getHtml(couponChannelId);
  462. }
  463. if (res && res.data && res.data.detailPicture) {
  464. that.setData({
  465. detailPicture: JSON.parse(res.data.detailPicture)
  466. })
  467. }
  468. if (res && res.data && res.data.coverPicture) {
  469. that.setData({
  470. coverPicture: JSON.parse(res.data.coverPicture)
  471. })
  472. }
  473. if (res && res.data && res.data.conditions) {
  474. that.setData({
  475. limitCondition: JSON.parse(res.data.conditions).type
  476. })
  477. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).min || JSON.parse(res.data.conditions).min == 0)) {
  478. that.setData({
  479. minLimit: JSON.parse(res.data.conditions).min
  480. })
  481. }
  482. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).max) || JSON.parse(res.data.conditions).max == 0) {
  483. that.setData({
  484. maxLimit: JSON.parse(res.data.conditions).max
  485. })
  486. }
  487. }
  488. data.price = (data.price / 100).toFixed(2)
  489. data.salePrice = (data.salePrice / 100).toFixed(2);
  490. data.validStartDate = utils.formatTime(data.validStartDate, 'yyyy-MM-dd')
  491. data.validEndDate = utils.formatTime(data.validEndDate, 'yyyy-MM-dd')
  492. that.setData({
  493. data,
  494. // merchantVoList: data.merchantVoList
  495. });
  496. Http.get({
  497. url: config.api.couponMerchant,
  498. data: {
  499. couponChannelId: couponChannelId
  500. }
  501. }).then(res => {
  502. const keys = Object.keys(res.data)
  503. const mallList = []
  504. keys.forEach(item => {
  505. const arr = item.split('|')
  506. const obj = {
  507. tenantId: arr[0],
  508. mallName: arr[1],
  509. merchantVoList: res.data[item],
  510. expand: true
  511. }
  512. mallList.push(obj)
  513. })
  514. this.setData({
  515. mallList: mallList
  516. })
  517. console.log(this.data.mallList, 'mallList');
  518. })
  519. });
  520. },
  521. /**
  522. * 去拼团
  523. */
  524. goToOrderGroup(orderId, orderGroupId, _this) {
  525. let that = this;
  526. // 支付成功
  527. Http.post({
  528. url: config.api.toOrderGroup,
  529. data: {
  530. id: orderGroupId,
  531. orderId,
  532. couponId: _this.data.data.couponId
  533. }
  534. })
  535. .then(res => {
  536. wx.navigateTo({
  537. url: `/pages/spellDetail/index?orderId=${orderId}&couponId=${_this.data.data.couponId}&orderGroupId=${res.data.orderGroupId}&couponChannelId=${_this.data.couponChannelId}`
  538. });
  539. })
  540. .catch(err => {
  541. console.log(err);
  542. })
  543. },
  544. /**
  545. * 支付订单更新
  546. */
  547. payOrderUpdate: (orderId, payOrderId, status, reason, _this, orderGroupId) => {
  548. console.log(orderGroupId, 7777)
  549. let that = this;
  550. // 支付成功
  551. Http.post({
  552. url: config.api.payOrderUpdate,
  553. data: {
  554. payOrderId: payOrderId,
  555. composeOrderId: orderId,
  556. status: status,
  557. reason: reason
  558. }
  559. })
  560. .then(res => {
  561. wx.hideLoading()
  562. if (orderGroupId !== 0) {
  563. wx.navigateTo({
  564. url: '/pages/order/detail/index?orderId=' + res.data.mainOrderId,
  565. })
  566. } else {
  567. _this.goToOrderGroup(res.data.singleOrder.id, res.data.mainOrderId, _this)
  568. }
  569. })
  570. .catch(err => {
  571. if (err.code != 12002) {
  572. setTimeout(function () {
  573. _this.payOrderUpdate(orderId, payOrderId, status, reason, _this, orderGroupId);
  574. }, 2000)
  575. }
  576. })
  577. },
  578. /**
  579. * 发起支付
  580. */
  581. orderFunc() {
  582. let that = this;
  583. let orderGroupId = this.data.orderGroupId;
  584. let data = {
  585. couponChannelId: this.data.data.id,
  586. couponId: this.data.data.couponId,
  587. formId: this.data.formId
  588. }
  589. /**
  590. * 拼团订单
  591. */
  592. if (this.data.orderGroupId == 0) {
  593. data.orderGroupId = this.data.orderGroupId,
  594. that.setData({
  595. isFromSpell: true
  596. })
  597. } else {
  598. that.setData({
  599. isFromSpell: false
  600. })
  601. }
  602. Http.get({
  603. url: config.api.checkUserStatus,
  604. data: {
  605. token: app.globalData.token
  606. }
  607. }).then(res => {
  608. Http.get({
  609. url: config.api.checkPhoneStatus,
  610. data: {}
  611. }).then(res => {
  612. /**
  613. * orderSave 下单
  614. */
  615. return Http.post({
  616. url: config.api.orderSave,
  617. data: data
  618. });
  619. }).catch(err => {
  620. console.log(err);
  621. that.setData({
  622. showbutton: false,
  623. showbutton1: false,
  624. canSpell: true,
  625. canBuyIf: true
  626. })
  627. if (err.code == 2011) {
  628. wx.showToast({
  629. title: "商户信息没找到",
  630. image: './../../../assets/images/fail.png',
  631. duration: 2000,
  632. mask: false
  633. });
  634. } else if (err.code == 2013) {
  635. wx.showToast({
  636. title: "商户信息禁用",
  637. image: './../../../assets/images/fail.png',
  638. duration: 2000,
  639. mask: false
  640. });
  641. } else if (err.code == 3000) {
  642. wx.showToast({
  643. title: "库存不足",
  644. image: './../../../assets/images/fail.png',
  645. duration: 2000,
  646. mask: false
  647. });
  648. } else if (err.code == 3001) {
  649. wx.showToast({
  650. title: "您已超过限购",
  651. image: './../../../assets/images/fail.png',
  652. duration: 2000,
  653. mask: false
  654. });
  655. } else if (err.code == 3002) {
  656. wx.showToast({
  657. title: "订单失败",
  658. image: './../../../assets/images/fail.png',
  659. duration: 2000,
  660. mask: false
  661. });
  662. } else if (err.code == 3003) {
  663. wx.showToast({
  664. title: "订单不存在",
  665. image: './../../../assets/images/fail.png',
  666. duration: 2000,
  667. mask: false
  668. });
  669. } else if (err.code == 3004) {
  670. wx.showToast({
  671. title: "订单不存在",
  672. image: './../../../assets/images/fail.png',
  673. duration: 2000,
  674. mask: false
  675. });
  676. } else if (err.code == 4003) {
  677. wx.showToast({
  678. title: "卡券已作废",
  679. image: './../../../assets/images/fail.png',
  680. duration: 2000,
  681. mask: false
  682. });
  683. } else if (err.code == 3012) {
  684. // wx.showToast({
  685. // title: err.message,
  686. // icon: "none"
  687. // })
  688. that.getUnPaidOrder(that.data.data.couponId);
  689. } else if (err.code == 11005) {
  690. /**
  691. * 将值传到用户手机号授权的页面
  692. *
  693. */
  694. wx.redirectTo({
  695. url: `/pages/getphoneInfo/index?path=spell&couponChannelId=${that.data.couponChannelId}&couponId=${that.data.data.couponId}`
  696. });
  697. } else if (err.code == 11006) {
  698. // 用户手机已加密
  699. wx.redirectTo({
  700. url: `/pages/phoneinput/phoneinput?path=spell&couponChannelId=${that.data.couponChannelId}&couponId=${that.data.data.couponId}`
  701. });
  702. } else {
  703. wx.showToast({
  704. title: err.message,
  705. icon: 'none',
  706. duration: 2000,
  707. mask: false
  708. });
  709. }
  710. }).then(res => {
  711. console.log(res, "123")
  712. if (typeof (res) != "undefined") {
  713. let orderId = "" + res.data.mainOrderId;
  714. that.setData({
  715. orderId: orderId,
  716. composeOrderType: res.data.composeOrderType,
  717. canSpell: false,
  718. canBuyIf: true
  719. });
  720. // 支付金额不为0
  721. /**
  722. * 支付订单创建
  723. */
  724. Http.post({
  725. url: config.api.payOrderCreate,
  726. data: {
  727. orderId: orderId,
  728. composeOrderType: that.data.composeOrderType
  729. }
  730. }).then(res => {
  731. var payOrderId = "" + res.data.payOrderId;
  732. wx.hideLoading();
  733. wx.requestPayment({
  734. timeStamp: res.data.timeStamp,
  735. nonceStr: res.data.nonceStr,
  736. package: res.data.package,
  737. signType: (res.data.signType) ? res.data.signType : "MD5",
  738. paySign: res.data.paySign,
  739. success: res => {
  740. that.setData({
  741. canSpell: false
  742. })
  743. wx.showLoading({
  744. title: '订单正在处理中...',
  745. })
  746. // setTimeout(function() {
  747. // wx.hideLoading()
  748. // }, 5000)
  749. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', that, orderGroupId);
  750. if (res.errMsg == "requestPayment:ok") {
  751. setTimeout(function () {
  752. wx.hideLoading();
  753. }, 2000);
  754. }
  755. },
  756. fail: res => {
  757. /**
  758. * 支付失败,需要更新订单的状态
  759. */
  760. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', that, orderGroupId);
  761. that.setData({
  762. showbutton: false,
  763. canSpell: true,
  764. canBuyIf: true
  765. })
  766. return;
  767. },
  768. complete: res => { }
  769. });
  770. /// End payment --------
  771. })
  772. .catch(err => {
  773. that.setData({
  774. canSpell: true,
  775. canBuyIf: true
  776. })
  777. wx.showToast({
  778. title: err.message,
  779. icon: 'none',
  780. duration: 2000,
  781. mask: false
  782. });
  783. })
  784. }
  785. })
  786. })
  787. .catch(err => {
  788. console.log(err)
  789. if (err.code == 11004) {
  790. wx.redirectTo({
  791. url: `/pages/getuserinfo/index?fromflag=spellcoupondetail&couponChannelIdflag=${that.data.couponChannelId}`,
  792. })
  793. } else {
  794. wx.showToast({
  795. title: err.message,
  796. icon: "none",
  797. duration: 2500
  798. })
  799. }
  800. })
  801. },
  802. /**
  803. * 生命周期函数--监听页面显示
  804. */
  805. onShow() {
  806. this.setData({
  807. mouldType: app.globalData.mouldType,
  808. canSpell: true,
  809. canBuyIf: true,
  810. showTime: true,
  811. })
  812. if (this.data.spellData != null) {
  813. this.countdown()
  814. }
  815. },
  816. /**
  817. * 生命周期函数--监听页面隐藏
  818. */
  819. onHide: function () {
  820. this.setData({
  821. showTime: false
  822. })
  823. },
  824. /**
  825. * 生命周期函数--监听页面卸载
  826. */
  827. onUnload: function () {
  828. this.setData({
  829. showTime: false
  830. })
  831. },
  832. /**
  833. * 页面相关事件处理函数--监听用户下拉动作
  834. */
  835. onPullDownRefresh: function (e) {
  836. let that = this;
  837. console.log(this.data.couponId, 222)
  838. that.getDetail(that.data.couponChannelId);
  839. if (that.data.couponId) {
  840. that.getOneSpell(that.data.couponId)
  841. }
  842. },
  843. onShareAppMessage: function (options) {
  844. app.globalData.previewFlag = true
  845. console.log(options)
  846. var that = this;
  847. var shareObj = {
  848. title: that.data.data.title,
  849. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}&couponId=${that.data.data.couponId}&spellGroup=spellGroup`,
  850. success: function (res) {
  851. if (res.errMsg == 'shareAppMessage:ok') { }
  852. },
  853. fail: function (error) {
  854. if (res.errMsg == 'shareAppMessage:fail cancel') { } else if (res.errMsg == 'shareAppMessage:fail') { }
  855. }
  856. };
  857. // 来自页面内的按钮的转发
  858. if (options.from == 'button') {
  859. var eData = options.target.dataset.id;
  860. shareObj.path = `/pages/index/index?couponChannelId=${eData}&couponId=${that.data.data.couponId}&spellGroup=spellGroup&frommd=JC`;
  861. }
  862. console.log(shareObj)
  863. // 返回shareObj
  864. return shareObj;
  865. },
  866. })