抖音小程序C端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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