抖音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.

750 rivejä
19 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 50) + '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. id: null,
  49. result: [],
  50. end_time: null,
  51. checked: false,
  52. questionnaire: {},
  53. questionId: null,
  54. widthScreen: null,
  55. moveData: null,
  56. rotateData: null,
  57. alphaData: null,
  58. scaleData: null,
  59. skewData: null,
  60. matrixData: null,
  61. opacity: 0,
  62. queueData: null,
  63. zIndex: 11,
  64. display: "none",
  65. showbutton: false,
  66. cardData: null,
  67. showCardOffer: false,
  68. isSamePeople: true,
  69. statusText: '',
  70. isReceived: false,
  71. receivedDisabled: false,
  72. clock: "结束",
  73. day: "00",
  74. hour: "00",
  75. min: "00",
  76. sec: "00",
  77. clock02: "00",
  78. day02: "00",
  79. hour02: "00",
  80. min02: "00",
  81. sec02: "00",
  82. countdown: "",
  83. showbutton1: false,
  84. limitCondition: "",
  85. minLimit: 0,
  86. maxLimit: 0,
  87. dispressEndDate: false,
  88. barTitle: "",
  89. activityStatus: "",
  90. //图文混排
  91. curHtml: '',
  92. contentType: 0,
  93. page: 1, //查询商户优惠券page
  94. idList: [],
  95. showBox: false, //手机号授权框
  96. },
  97. /**
  98. * 显示分享弹框
  99. */
  100. showshare: function () {
  101. this.setData({
  102. isshowposter: true,
  103. })
  104. },
  105. setPhone(paramData) { //子组件调用这个方法说明手机号已经授权成功
  106. this.setData({
  107. showBox: paramData.detail,
  108. })
  109. tt.showToast({
  110. title: '授权成功', // 内容
  111. icon: 'none', // 图标
  112. success: (res) => {
  113. },
  114. fail: (res) => {
  115. },
  116. });
  117. },
  118. setBox(paramData) {
  119. this.setData({
  120. showBox: paramData.detail
  121. })
  122. tt.showToast({
  123. title: '取消授权', // 内容
  124. icon: 'none', // 图标
  125. success: (res) => {
  126. },
  127. fail: (res) => {
  128. },
  129. });
  130. },
  131. /**
  132. * 隐藏分享弹框
  133. */
  134. hidemodal: function () {
  135. this.setData({
  136. isshowposter: false,
  137. })
  138. },
  139. /**
  140. * 显示分享海报
  141. */
  142. /* showPoster: function() {
  143. //跳转到海报生成页
  144. console.log(this.data.canIUse)
  145. // return;
  146. tt.navigateTo({
  147. url: `/pages/canvas/index?couponChannelId=${this.data.data.id}`
  148. })
  149. }, */
  150. showPoster: function () {
  151. //跳转到海报生成页
  152. let that = this;
  153. Http.get({
  154. url: config.api.checkUserStatus,
  155. data: {
  156. token: app.globalData.token
  157. }
  158. }).then(res => {
  159. tt.navigateTo({
  160. url: `/pages/canvas/index?couponChannelId=${that.data.data.id}`
  161. })
  162. }).catch(err => {
  163. console.log(err)
  164. if (err.code == 11004) {
  165. // 用户昵称未授权
  166. tt.redirectTo({
  167. url: `/pages/getuserinfo/index?couponChannelId=${that.data.data.id}&fromflag=poster`
  168. })
  169. }
  170. })
  171. },
  172. swiperChange: function (e) {
  173. this.setData({
  174. swiperCurrent: e.detail.current
  175. });
  176. },
  177. gohome(e) {
  178. console.log(e.currentTarget.dataset.id, "123")
  179. tt.navigateTo({
  180. url: `/pages/fillIndent/fillIndent?couponChannelId=${e.currentTarget.dataset.couponchannelid}&couponId=${e.currentTarget.dataset.couponid}&shippingtype=${e.currentTarget.dataset.shippingtype}`,
  181. })
  182. },
  183. gochild(e) {
  184. let id = e.currentTarget.dataset.id
  185. tt.navigateTo({
  186. url: `/pages/coupon/childDetail/childDetail?couponIds=${id}`,
  187. })
  188. },
  189. //获取当前登录用户信息
  190. getUserInfo: function () {
  191. let that = this;
  192. // 获取用户信息
  193. Http.get({
  194. url: config.api.getScore,
  195. data: {}
  196. })
  197. .then(res => {
  198. console.log(res)
  199. that.getQueryCardStatus()
  200. if (that.data.cardData.cuserId != res.data.id) {
  201. console.log(2222, 6666)
  202. that.setData({
  203. isSamePeople: false
  204. })
  205. }
  206. })
  207. },
  208. //获取卡转赠状态
  209. getQueryCardStatus() {
  210. let that = this;
  211. let param = {
  212. id: this.data.cardData.couponOrderId,
  213. cUserId: this.data.cardData.cuserId,
  214. updateDate: util.formatTime(Number(that.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
  215. }
  216. Http.get({
  217. url: config.api.queryCardStatus,
  218. data: param
  219. })
  220. .then(res => {
  221. console.log(res, 333333333333)
  222. })
  223. .catch(err => {
  224. that.setData({
  225. isReceived: true,
  226. statusText: err.message
  227. })
  228. })
  229. },
  230. receiveCard() {
  231. let that = this;
  232. let param = {
  233. id: this.data.cardData.couponOrderId,
  234. cUserId: this.data.cardData.cuserId,
  235. updateDate: util.formatTime(Number(this.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
  236. }
  237. this.setData({
  238. receivedDisabled: true
  239. })
  240. Http.post({
  241. url: config.api.cardAccept,
  242. data: param
  243. })
  244. .then(res => {
  245. tt.showToast({
  246. title: '领取成功!',
  247. icon: 'none',
  248. duration: 2000,
  249. mask: false
  250. });
  251. tt.reLaunch({
  252. url: '/pages/complete/index?couponOrderId=' + this.data.cardData.couponOrderId,
  253. })
  254. })
  255. .catch(err => {
  256. tt.showToast({
  257. title: err.message,
  258. icon: 'none',
  259. duration: 2000,
  260. mask: false
  261. });
  262. that.setData({
  263. receivedDisabled: false
  264. })
  265. })
  266. },
  267. closeAlert() {
  268. this.setData({
  269. showCardOffer: false
  270. })
  271. },
  272. goback: function () {
  273. tt.reLaunch({
  274. url: '/index/index',
  275. })
  276. },
  277. /**
  278. * 点击提交问题单选
  279. */
  280. formSubmit: function (e) {
  281. console.log(e);
  282. let that = this;
  283. /**
  284. * 多选
  285. */
  286. if (e.currentTarget.dataset.flags == 'multi') {
  287. if (that.data.anwserId.length == 0) {
  288. var answserIs = null
  289. } else {
  290. var answserIs = that.data.anwserId.join(",");
  291. }
  292. } else if (e.currentTarget.dataset.flags == 'single') {
  293. var answserIs = e.detail.value;
  294. }
  295. console.log(answserIs)
  296. console.log(e.currentTarget.dataset.questionid)
  297. Http.post({
  298. url: config.api.answerQuestion,
  299. data: {
  300. answer: answserIs,
  301. questionId: e.currentTarget.dataset.questionid
  302. }
  303. })
  304. .then(res => {
  305. that.closeQuestion();
  306. })
  307. .catch(err => {
  308. tt.showToast({
  309. title: err.message,
  310. icon: 'none',
  311. duration: 2000,
  312. mask: false
  313. });
  314. })
  315. },
  316. /**
  317. * 多选
  318. */
  319. checkboxChange: function (e) {
  320. console.log(e)
  321. this.setData({
  322. anwserId: e.detail.value
  323. })
  324. },
  325. closeQuestion: function () {
  326. let that = this;
  327. that.setData({
  328. display: "none",
  329. zIndex: 11,
  330. opacity: 0
  331. })
  332. setTimeout(function () {
  333. that.orderFunc();
  334. }, 500)
  335. },
  336. ifGetUser() {
  337. Http.get({
  338. url: config.api.checkUserStatus,
  339. data: {
  340. token: app.globalData.token
  341. }
  342. }).then(res => {}).catch(err => {
  343. if (err.code == 11004) {
  344. this.setData({
  345. isGetUser: false
  346. })
  347. }
  348. })
  349. },
  350. setIntervalTime(end_time) {
  351. let that = this;
  352. var EndTime = end_time;
  353. var NowTime = new Date().getTime();
  354. var total_micro_second = EndTime - NowTime || [];
  355. // 渲染倒计时时钟
  356. let obj = that.dateformat(total_micro_second);
  357. if (total_micro_second > 0) {
  358. that.setData({
  359. clock: obj,
  360. day: obj.a1,
  361. hour: obj.b1,
  362. min: obj.c1,
  363. sec: obj.d1,
  364. })
  365. } else {
  366. that.setData({
  367. clock: "00",
  368. day: "00",
  369. hour: "00",
  370. min: "00",
  371. sec: "00",
  372. })
  373. //如果倒计时结束,需要重新查询一下券的状态
  374. // 给getDetail一个标识
  375. that.getDetail(that.data.id, 'endclock');
  376. }
  377. total_micro_second -= 1000;
  378. },
  379. countdown: function (end_time) {
  380. let that = this;
  381. that.setIntervalTime(end_time);
  382. that.data.setInterval = setInterval(function () {
  383. that.setIntervalTime(end_time);
  384. }, 1000)
  385. },
  386. // 时间格式化输出,如11:03 25:19 每1s都会调用一次
  387. dateformat(micro_second) {
  388. // 总秒数
  389. var second = Math.floor(micro_second / 1000);
  390. // 天数
  391. var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  392. // 小时
  393. var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  394. // 分钟
  395. var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  396. // 秒
  397. var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
  398. // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
  399. return {
  400. a1: day,
  401. b1: hr,
  402. c1: min,
  403. d1: sec
  404. }
  405. },
  406. /**
  407. * 获取用户信息
  408. */
  409. onLoad(options) {
  410. console.log(options);
  411. this.setData({
  412. mouldType: app.globalData.mouldType,
  413. })
  414. let that = this;
  415. if (options.g) {
  416. app.globalData.havePlayEd1 = true;
  417. }
  418. tt.showLoading({
  419. title: "加载中..."
  420. });
  421. that.setData({
  422. onshow: false
  423. })
  424. if (options && (options.id || options.couponIds)) {
  425. that.getDetail(options.id, 'notendclock');
  426. }
  427. that.setData({
  428. couponChannelId: options.id,
  429. });
  430. this.getCouponMerchant(options.id)
  431. },
  432. getCouponMerchant(couponChannelId) { //获取适用门店
  433. Http.get({
  434. url: config.api.couponMerchant,
  435. data: {
  436. couponChannelId: couponChannelId
  437. }
  438. }).then(res => {
  439. const keys = Object.keys(res.data)
  440. const mallList = []
  441. let i = 0
  442. keys.forEach(item => {
  443. const arr = item.split('|')
  444. const obj = {
  445. tenantId: arr[0],
  446. mallName: arr[1],
  447. merchantVoList: res.data[item],
  448. expand: false
  449. }
  450. if (i == 0) {
  451. obj.expand = true
  452. }
  453. mallList.push(obj)
  454. i++
  455. })
  456. this.setData({
  457. mallList: mallList
  458. })
  459. })
  460. },
  461. getHtml(couponChannelId) {
  462. Http.get({
  463. url: config.api.couponHtmlDetail,
  464. data: {
  465. couponChannelId: couponChannelId
  466. }
  467. }).then(res => {
  468. console.log(res)
  469. if (res.code == 200 && res.data.html) {
  470. this.setData({
  471. curHtml: decodeURI(res.data.html)
  472. })
  473. app.globalData.curHtml = this.data.curHtml;
  474. }
  475. })
  476. },
  477. getDetail: function (couponChannelId, flag) {
  478. let that = this;
  479. var parmer = {
  480. url: config.api.getSnapshot,
  481. data: {
  482. orderId: couponChannelId
  483. }
  484. };
  485. Http.get(parmer)
  486. .then(res => {
  487. //aaa
  488. if (res.data.contentType != undefined && res.data.contentType == 1) {
  489. //获取图文展示详情html
  490. this.setData({
  491. contentType: res.data.contentType
  492. })
  493. this.getHtml(couponChannelId);
  494. }
  495. that.setData({
  496. couponId: res.data.couponId
  497. })
  498. that.setData({
  499. showPage: true
  500. })
  501. if (res && res.data && res.data.detailPicture) {
  502. that.setData({
  503. detailPicture: JSON.parse(res.data.detailPicture)
  504. })
  505. }
  506. if (res && res.data && res.data.coverPicture) {
  507. that.setData({
  508. coverPicture: JSON.parse(res.data.coverPicture)
  509. })
  510. }
  511. if (res && res.data && res.data.conditions) {
  512. that.setData({
  513. limitCondition: JSON.parse(res.data.conditions).type
  514. })
  515. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).min || JSON.parse(res.data.conditions).min == 0)) {
  516. that.setData({
  517. minLimit: JSON.parse(res.data.conditions).min
  518. })
  519. }
  520. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).max) || JSON.parse(res.data.conditions).max == 0) {
  521. that.setData({
  522. maxLimit: JSON.parse(res.data.conditions).max
  523. })
  524. }
  525. }
  526. /**
  527. * 将优惠券优惠卡的详情的BarTitle
  528. * 设置成券的名称
  529. */
  530. // tt.setNavigationBarTitle({
  531. // title: res.data.title
  532. // })
  533. that.setData({
  534. barTitle: res.data.title
  535. })
  536. var EndTime = res.data.validStartDate;
  537. var NowTime = new Date().getTime();
  538. /**
  539. * activityStatus==0 活动未开始
  540. * activityStatus==1 活动已开始
  541. * flag == endclock 说明倒计时已经结束
  542. */
  543. if (res.data.endTime && res.data.beginTime) {
  544. that.setData({
  545. begin_time: res.data.beginTime,
  546. end_time: res.data.endTime,
  547. activityStatus: res.data.activityStatus ? res.data.activityStatus : ''
  548. })
  549. if (res.data.activityStatus == 0 && flag != 'endclock') {
  550. that.countdown(res.data.beginTime);
  551. } else if (res.data.activityStatus != 0 && flag != 'endclock') {
  552. that.countdown(res.data.endTime);
  553. } else {
  554. clearInterval(that.data.setInterval)
  555. }
  556. if (res.data.activityStatus == 0) {
  557. var beginTime = util.formatTime(res.data.beginTime, "yyyy-MM-dd hh:mm:ss");
  558. if (util.timechuo(beginTime).indexOf('-') == 0) {
  559. that.setData({
  560. beginTime: "活动已结束",
  561. });
  562. } else {
  563. that.setData({
  564. beginTime: util.timechuo(beginTime)
  565. });
  566. }
  567. } else {
  568. var endTime = util.formatTime(res.data.endTime, "yyyy-MM-dd hh:mm:ss");
  569. if (util.timechuo(endTime).indexOf('-') == 0) {
  570. that.setData({
  571. endtime: "活动已结束",
  572. });
  573. } else {
  574. that.setData({
  575. endtime: util.timechuo(endTime)
  576. });
  577. }
  578. }
  579. }
  580. tt.hideLoading();
  581. that.setData({
  582. data: res.data,
  583. merchantVoList: res.data.merchantVoList
  584. });
  585. if (res.data.type == 10) {
  586. that.setData({
  587. salePriceStr: res.data.salePriceStr,
  588. pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"),
  589. pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"),
  590. priceStr: res.data.priceStr,
  591. tailPriceStr: res.data.tailPriceStr,
  592. origPriceStr: res.data.origPriceStr
  593. })
  594. }
  595. if (res.data.validType == 1) {
  596. that.setData({
  597. validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd"),
  598. validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd"),
  599. pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"),
  600. pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"),
  601. });
  602. } else {
  603. if (res.data.validDays) {
  604. that.setData({
  605. validDays: res.data.validDays
  606. });
  607. }
  608. }
  609. if (res.data.itemGroup) {
  610. let tempObj = that.data.data
  611. tempObj.itemGroup = JSON.parse(tempObj.itemGroup)
  612. that.setData({
  613. data: tempObj
  614. })
  615. console.log(that.data.data, "data");
  616. }
  617. if (res.data.productAttrs && res.data.skuAttrs) {
  618. let tempObj = that.data.data
  619. tempObj.productAttrs = JSON.parse(tempObj.productAttrs)
  620. tempObj.skuAttrs = JSON.parse(tempObj.skuAttrs)
  621. tempObj.productAttrs.map(item => {
  622. if (item.key == "appointment") {
  623. let tempAppoinObj = JSON.parse(item.data)
  624. if (tempAppoinObj.need_appointment) {
  625. let subscribeSing = "";
  626. if (tempAppoinObj.ahead_time_type == 1) {
  627. subscribeSing = `需提前${tempAppoinObj.ahead_day_num}天致电商家预约`
  628. } else if (tempAppoinObj.ahead_time_type == 2) {
  629. subscribeSing = `需提前${tempAppoinObj.ahead_hour_num}小时致电商家预约`
  630. } else if (tempAppoinObj.ahead_time_type == 3) {
  631. subscribeSing = `需提前${tempAppoinObj.ahead_minute_num}分钟致电商家预约`
  632. }
  633. tempObj.subscribeSing = subscribeSing
  634. }
  635. }
  636. if (item.key == "Notification") {
  637. if (item.data != '') {
  638. tempObj.curLsit = JSON.parse(item.data)
  639. }
  640. }
  641. if (item.key == "bring_out_meal") {
  642. tempObj.besides = item.data
  643. }
  644. if (item.key == "free_pack") {
  645. tempObj.pack = item.data
  646. }
  647. if (item.key == "superimposed_discounts") {
  648. tempObj.superimposed_discounts = item.data
  649. }
  650. if (item.key == "private_room") {
  651. tempObj.private_room = item.data
  652. }
  653. if (item.key == "rec_person_num_max") {
  654. tempObj.rec_person_num_max = item.data
  655. }
  656. if (item.key == 'Description' && item.isRequired) {
  657. tempObj.Description = JSON.parse(item.data)
  658. }
  659. if (item.key == "can_no_use_date") {
  660. tempObj.can_no_use_date = JSON.parse(item.data)
  661. }
  662. })
  663. tempObj.skuAttrs.map(item => {
  664. if (item.key == "commodity") {
  665. if (item.data != '') {
  666. tempObj.itemGroup = JSON.parse(item.data)
  667. }
  668. }
  669. })
  670. this.setData({
  671. data: tempObj
  672. })
  673. }
  674. }).catch(err => {
  675. tt.showToast({
  676. title: err.message,
  677. icon: 'none',
  678. duration: 2000,
  679. mask: false
  680. });
  681. })
  682. },
  683. onShow() {
  684. this.ifGetUser() //判断是否授权抖音
  685. this.setData({
  686. mouldType: app.globalData.mouldType,
  687. showbutton: false,
  688. showbutton1: false
  689. })
  690. if (this.data.end_time && this.data.activityStatus != 0) {
  691. this.countdown(this.data.end_time)
  692. } else if (this.data.begin_time && this.data.activityStatus == 0) {
  693. this.countdown(this.data.begin_time)
  694. }
  695. },
  696. onUnload: function () {
  697. let that = this;
  698. clearInterval(that.data.setInterval)
  699. },
  700. onHide: function () {
  701. let that = this;
  702. clearInterval(that.data.setInterval)
  703. },
  704. // 下拉刷新
  705. onPullDownRefresh: function () {
  706. this.getDetail(this.data.couponChannelId);
  707. tt.stopPullDownRefresh()
  708. },
  709. onReachBottom: function () {
  710. this.setData({
  711. page: this.data.page + 1
  712. })
  713. }
  714. });